3 typedef shl_t minthandle_t;
5 #define WIN32_LEAN_AND_MEAN
7 typedef HMODULE minthandle_t;
8 #undef WIN32_LEAN_AND_MEAN
11 typedef void *minthandle_t;
16 struct DSO_handle_tag {
19 func_ptr *function_list;
24 /* #include "XSUB.h" so we can compile on threaded perls */
28 do_get_context(void) {
29 return im_get_context();
32 static symbol_table_t symbol_table=
54 Dynamic loading works like this:
55 dynaload opens the shared object and
56 loads all the functions into an array of functions
57 it returns a string from the dynamic function that
58 can be supplied to the parser for evaling.
62 DSO_call(DSO_handle *handle,int func_index,HV* hv) {
63 mm_log((1,"DSO_call(handle %p, func_index %d, hv %p)\n",
64 handle, func_index, hv));
65 (handle->function_list[func_index].iptr)((void*)hv);
69 DSO_funclist(DSO_handle *handle) {
70 return handle->function_list;
74 #if defined( OS_hpux )
77 DSO_open(char* file,char** evalstring) {
79 void *d_handle,**plugin_symtab,**plugin_utiltab;
80 int rc,*iptr, (*fptr)(int);
81 func_ptr *function_list;
82 DSO_handle *dso_handle;
83 void (*f)(void *s,void *u); /* these will just have to be void for now */
88 mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );
90 if ( (tt_handle = shl_load(file, BIND_DEFERRED,0L)) == NULL) return NULL;
91 if ( (shl_findsym(&tt_handle, I_EVALSTR,TYPE_UNDEFINED,(void*)evalstring))) return NULL;
94 if ( (shl_findsym(&tt_handle, "symbol_table",TYPE_UNDEFINED,(void*)&plugin_symtab))) return NULL;
95 if ( (shl_findsym(&tt_handle, "util_table",TYPE_UNDEFINED,&plugin_utiltab))) return NULL;
96 (*plugin_symtab)=&symbol_table;
97 (*plugin_utiltab)=&i_UTIL_table;
100 if ( (shl_findsym(&tt_handle, I_INSTALL_TABLES ,TYPE_UNDEFINED, &f ))) return NULL;
102 mm_log( (1,"Calling install_tables\n") );
103 f(&symbol_table,&i_UTIL_table);
104 mm_log( (1,"Call ok.\n") );
106 if ( (shl_findsym(&tt_handle, I_FUNCTION_LIST ,TYPE_UNDEFINED,(func_ptr*)&function_list))) return NULL;
107 if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */
110 dso_handle->handle=tt_handle; /* needed to close again */
111 dso_handle->function_list=function_list;
112 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
113 free(dso_handle); return NULL;
115 strcpy(dso_handle->filename,file);
117 mm_log((1,"DSO_open <- (0x%X)\n",dso_handle));
118 return (void*)dso_handle;
122 DSO_close(void *ptr) {
123 DSO_handle *handle=(DSO_handle*) ptr;
124 mm_log((1,"DSO_close(ptr 0x%X)\n",ptr));
125 return !shl_unload((handle->handle));
131 DSO_open(char *file, char **evalstring) {
133 func_ptr *function_list;
134 DSO_handle *dso_handle;
136 void (*f)(void *s,void *u); /* these will just have to be void for now */
138 mm_log( (1,"DSO_open(file '%s' (%p), evalstring %p)\n",file,file,evalstring) );
141 if ((d_handle = LoadLibrary(file)) == NULL) {
142 mm_log((1, "DSO_open: LoadLibrary(%s) failed: %lu\n", file, GetLastError()));
145 if ( (*evalstring = (char *)GetProcAddress(d_handle, I_EVALSTR)) == NULL) {
146 mm_log((1,"DSO_open: GetProcAddress didn't fine '%s': %lu\n", I_EVALSTR, GetLastError()));
147 FreeLibrary(d_handle);
150 if ((f = (void (*)(void *, void*))GetProcAddress(d_handle, I_INSTALL_TABLES)) == NULL) {
151 mm_log((1, "DSO_open: GetProcAddress didn't find '%s': %lu\n", I_INSTALL_TABLES, GetLastError()));
152 FreeLibrary(d_handle);
155 mm_log((1, "Calling install tables\n"));
156 f(&symbol_table, &i_UTIL_table);
157 mm_log((1, "Call ok\n"));
159 if ( (function_list = (func_ptr *)GetProcAddress(d_handle, I_FUNCTION_LIST)) == NULL) {
160 mm_log((1, "DSO_open: GetProcAddress didn't find '%s': %lu\n", I_FUNCTION_LIST, GetLastError()));
161 FreeLibrary(d_handle);
164 if ( (dso_handle = (DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) { /* checked 17jul05 tonyc */
165 mm_log( (1, "DSO_Open: out of memory\n") );
166 FreeLibrary(d_handle);
169 dso_handle->handle=d_handle; /* needed to close again */
170 dso_handle->function_list=function_list;
171 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
173 FreeLibrary(d_handle);
176 strcpy(dso_handle->filename,file);
178 mm_log( (1,"DSO_open <- %p\n",dso_handle) );
179 return (void*)dso_handle;
184 DSO_close(void *ptr) {
185 DSO_handle *handle = (DSO_handle *)ptr;
186 BOOL result = FreeLibrary(handle->handle);
187 free(handle->filename);
195 /* OS/2 has no dlclose; Perl doesn't provide one. */
196 #ifdef __EMX__ /* OS/2 */
198 dlclose(minthandle_t h) {
199 return DosFreeModule(h) ? -1 : 0;
204 DSO_open(char* file,char** evalstring) {
206 func_ptr *function_list;
207 DSO_handle *dso_handle;
209 void (*f)(void *s,void *u); /* these will just have to be void for now */
213 mm_log( (1,"DSO_open(file '%s' (%p), evalstring %p)\n",
214 file, file, evalstring) );
216 if ( (d_handle = dlopen(file, RTLD_LAZY)) == NULL) {
217 mm_log( (1,"DSO_open: dlopen failed: %s.\n",dlerror()) );
221 if ( (*evalstring = (char *)dlsym(d_handle, I_EVALSTR)) == NULL) {
222 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_EVALSTR,dlerror()) );
228 I'll just leave this thing in here for now if I need it real soon
230 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_SYMBOL_TABLE ));
231 if ( (plugin_symtab = dlsym(d_handle, I_SYMBOL_TABLE)) == NULL) {
232 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_SYMBOL_TABLE,dlerror()) );
236 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_UTIL_TABLE ));
237 if ( (plugin_utiltab = dlsym(d_handle, I_UTIL_TABLE)) == NULL) {
238 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_UTIL_TABLE,dlerror()) );
244 f = (void(*)(void *s,void *u))dlsym(d_handle, I_INSTALL_TABLES);
245 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_INSTALL_TABLES ));
246 if ( (f = (void(*)(void *s,void *u))dlsym(d_handle, I_INSTALL_TABLES)) == NULL) {
247 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_INSTALL_TABLES,dlerror()) );
251 mm_log( (1,"Calling install_tables\n") );
252 f(&symbol_table,&i_UTIL_table);
253 mm_log( (1,"Call ok.\n") );
255 /* (*plugin_symtab)=&symbol_table;
256 (*plugin_utiltab)=&i_UTIL_table; */
258 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_FUNCTION_LIST ));
259 if ( (function_list=(func_ptr *)dlsym(d_handle, I_FUNCTION_LIST)) == NULL) {
260 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_FUNCTION_LIST,dlerror()) );
264 if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */
267 dso_handle->handle=d_handle; /* needed to close again */
268 dso_handle->function_list=function_list;
269 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
273 strcpy(dso_handle->filename,file);
275 mm_log( (1,"DSO_open <- %p\n",dso_handle) );
276 return (void*)dso_handle;
280 DSO_close(void *ptr) {
282 mm_log((1,"DSO_close(ptr %p)\n",ptr));
283 handle=(DSO_handle*) ptr;
284 return !dlclose(handle->handle);