fix codetest failure - ASSERT_ARGS does not have a ; after and
[parrot.git] / src / nci / api.c
blob6ae4e8313493c0ed92e5fa0561b37445c9b6abbc
1 /* nci.c
2 Copyright (C) 2001-2009, Parrot Foundation.
3 $Id$
5 =head1 NAME
7 src/nci/api.c - Native Call Interface routines
9 =head1 DESCRIPTION
11 This file implements the interface to the Parrot Native Call Interface system,
12 which builds parrot to C call frames.
14 =head2 Functions
16 =over 4
18 =cut
22 #include "parrot/parrot.h"
23 #include "parrot/nci.h"
24 #include "api.str"
26 /* HEADERIZER HFILE: include/parrot/nci.h */
30 =item C<PMC * build_call_func(PARROT_INTERP, STRING *signature)>
32 This function serves a single purpose. It takes the function signature for a
33 C function we want to call and returns a PMC with a pointer to a function
34 that can call it.
36 =cut
40 PARROT_CANNOT_RETURN_NULL
41 PMC *
42 build_call_func(PARROT_INTERP, ARGIN(STRING *signature))
44 ASSERT_ARGS(build_call_func)
46 PMC * const iglobals = interp->iglobals;
47 PMC *nci_funcs;
48 PMC *thunk;
50 /* fixup empty signatures */
51 if (STRING_IS_EMPTY(signature))
52 signature = CONST_STRING(interp, "v");
54 if (PMC_IS_NULL(iglobals))
55 PANIC(interp, "iglobals isn't created yet");
57 nci_funcs = VTABLE_get_pmc_keyed_int(interp, iglobals, IGLOBALS_NCI_FUNCS);
58 if (PMC_IS_NULL(nci_funcs))
59 PANIC(interp, "iglobals.nci_funcs isn't created_yet");
61 thunk = VTABLE_get_pmc_keyed_str(interp, nci_funcs, signature);
63 if (PMC_IS_NULL(thunk)) {
64 /* try to dynamically build a thunk */
65 PMC *nci_fb_cb = VTABLE_get_pmc_keyed_int(interp, iglobals, IGLOBALS_NCI_FB_CB);
66 if (!PMC_IS_NULL(nci_fb_cb)) {
67 void *cb_ptr = VTABLE_get_pointer(interp, nci_fb_cb);
68 nci_fb_func_t cb = (nci_fb_func_t)D2FPTR(cb_ptr);
69 if (cb_ptr) {
70 PMC *nci_fb_ud = VTABLE_get_pmc_keyed_int(interp, iglobals, IGLOBALS_NCI_FB_UD);
71 thunk = cb(interp, nci_fb_ud, signature);
76 if (!PMC_IS_NULL(thunk)) {
77 PARROT_ASSERT(thunk->vtable);
78 return thunk;
81 Parrot_ex_throw_from_c_args(interp, NULL,
82 EXCEPTION_UNIMPLEMENTED,
83 "No NCI thunk available for signature '%S'", signature);
88 =back
90 =cut
95 * Local variables:
96 * c-file-style: "parrot"
97 * End:
98 * vim: expandtab shiftwidth=4: