2 Copyright (C) 2001-2009, Parrot Foundation.
7 src/nci/api.c - Native Call Interface routines
11 This file implements the interface to the Parrot Native Call Interface system,
12 which builds parrot to C call frames.
22 #include "parrot/parrot.h"
23 #include "parrot/nci.h"
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
40 PARROT_CANNOT_RETURN_NULL
42 build_call_func(PARROT_INTERP
, ARGIN(STRING
*signature
))
44 ASSERT_ARGS(build_call_func
)
46 PMC
* const iglobals
= interp
->iglobals
;
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
);
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
);
81 Parrot_ex_throw_from_c_args(interp
, NULL
,
82 EXCEPTION_UNIMPLEMENTED
,
83 "No NCI thunk available for signature '%S'", signature
);
96 * c-file-style: "parrot"
98 * vim: expandtab shiftwidth=4: