Skip to content
This repository
branch: gc_ms2_sf
Fetching contributors…

Cannot retrieve contributors at this time

file 171 lines (103 sloc) 2.795 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
/*
Copyright (C) 2001-2010, Parrot Foundation.

=head1 NAME

src/pmc/parrotlibrary.pmc - Dynamic Library

=head1 DESCRIPTION

Class for holding info about a dynamic library.

Properties:

    _filename full path/file of lib
    _ro true after init

All ParrotLibrary PMCs are in interp->iglobals.

When a dynamic library (pmc or ops) is loaded, the load function returns
a ParrotLibrary PMC.

=head2 Methods

=over 4

=cut

*/

#define PMC_dlhandle(x) ((Parrot_ParrotLibrary_attributes*)PMC_data(x))->dl_handle
#define PMC_oplib_init(x) ((Parrot_ParrotLibrary_attributes*)PMC_data(x))->oplib_init

/* HEADERIZER HFILE: none */
/* HEADERIZER BEGIN: static */
/* HEADERIZER END: static */

pmclass ParrotLibrary auto_attrs provides library {
    ATTR void * dl_handle; /* DLL handle */
    ATTR void * oplib_init; /* oplib init function */

/*

=item C<void init()>

Initializes the library with a C<NULL> oplib init function.

=cut

*/

    VTABLE void init() {}

/*

=item C<void destroy()>

Destroys the library, closing the shared library.

=cut

*/

    VTABLE void destroy() {
        void *dl_handle = PMC_dlhandle(SELF);
        if (dl_handle)
            Parrot_dlclose(dl_handle);
    }


/*

=item C<PMC *clone()>

Creates and returns a clone of the library.

=cut

*/

    VTABLE PMC *clone() {
        PMC * const dest = Parrot_pmc_new(INTERP, SELF->vtable->base_type);

        if (PMC_oplib_init(SELF))
            PMC_oplib_init(dest) = PMC_oplib_init(SELF);

        if (PMC_dlhandle(SELF)) {
            PMC_dlhandle(dest) = PMC_dlhandle(SELF);
            PObj_custom_destroy_SET(dest);
        }

        if (PMC_metadata(SELF))
            PMC_metadata(dest) = VTABLE_clone(INTERP, PMC_metadata(SELF));

        return dest;
    }

/*

=item C<INTVAL get_bool()>

Returns whether a library has been successfully loaded.

=cut

*/

    VTABLE INTVAL get_bool() {
        return (PMC_dlhandle(SELF) != NULL);
    }

/*

=item C<STRING *get_string()>

Returns the name of the loaded library.

=cut

*/

    VTABLE STRING *get_string() {
        STRING * const key = CONST_STRING(INTERP, "_filename");
        PMC * const prop = VTABLE_getprop(INTERP, SELF, key);

        return VTABLE_get_string(INTERP, prop);
    }

/*

=item C<void *get_pointer()>

Gets the pointer to the shared library handle.

=cut

*/

    VTABLE void *get_pointer() {
        return PMC_dlhandle(SELF);
    }

/*

=item C<void set_pointer(void *handle)>

Sets the pointer to the shared library handle.

=cut

*/

    VTABLE void set_pointer(void *handle) {
        PMC_dlhandle(SELF) = handle;
        PObj_custom_destroy_SET(SELF);
    }
}

/*

=back

=cut

*/

/*
 * Local variables:
 * c-file-style: "parrot"
 * End:
 * vim: expandtab shiftwidth=4:
 */
Something went wrong with that request. Please try again.