2 Copyright (C) 2001-2009, Parrot Foundation.
7 src/pmc/parrotlibrary.pmc - Dynamic Library
11 Class for holding info about a dynamic library.
15 _filename full path/file of lib
18 All ParrotLibrary PMCs are in interp->iglobals.
20 When a dynamic library (pmc or ops) is loaded, the load function returns
31 #define PMC_dlhandle(x) ((Parrot_ParrotLibrary_attributes*)PMC_data(x))->dl_handle
32 #define PMC_oplib_init(x) ((Parrot_ParrotLibrary_attributes*)PMC_data(x))->oplib_init
34 pmclass ParrotLibrary need_ext provides library {
35 ATTR void * dl_handle; /* DLL handle */
36 ATTR void * oplib_init; /* oplib init function */
42 Initializes the library with a C<NULL> oplib init function.
49 Parrot_ParrotLibrary_attributes * const attrs =
50 mem_allocate_zeroed_typed(Parrot_ParrotLibrary_attributes);
51 PMC_data(SELF) = attrs;
52 PObj_active_destroy_SET(SELF);
57 =item C<void destroy()>
59 Destroys the library, closing the shared library.
65 VTABLE void destroy() {
66 void *dl_handle = PMC_dlhandle(SELF);
68 Parrot_dlclose(dl_handle);
69 mem_sys_free(PMC_data(SELF));
70 PMC_data(SELF) = NULL;
78 Creates and returns a clone of the library.
85 PMC * const dest = pmc_new(INTERP, SELF->vtable->base_type);
86 PMC_oplib_init(dest) = PMC_oplib_init(SELF);
87 PMC_dlhandle(dest) = PMC_dlhandle(SELF);
89 if (PMC_metadata(SELF))
90 PMC_metadata(dest) = VTABLE_clone(INTERP, PMC_metadata(SELF));
97 =item C<INTVAL get_bool()>
99 Returns whether a library has been successfully loaded.
105 VTABLE INTVAL get_bool() {
106 return (PMC_dlhandle(SELF) != NULL);
111 =item C<STRING *get_string()>
113 Returns the name of the loaded library.
119 VTABLE STRING *get_string() {
120 STRING * const key = CONST_STRING(INTERP, "_filename");
121 PMC * const prop = VTABLE_getprop(INTERP, SELF, key);
123 return VTABLE_get_string(INTERP, prop);
128 =item C<void set_pointer(void *handle)>
130 Set the pointer to the shared library handle.
136 VTABLE void set_pointer(void *handle) {
137 PMC_dlhandle(SELF) = handle;
147 Date: Mon, 29 Sep 2003 14:37:11 -0400 (EDT)
148 Subject: Library loading and initialization sequence
153 Initial version by leo 2003.10.12.
161 * c-file-style: "parrot"
163 * vim: expandtab shiftwidth=4: