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=
53 Dynamic loading works like this:
54 dynaload opens the shared object and
55 loads all the functions into an array of functions
56 it returns a string from the dynamic function that
57 can be supplied to the parser for evaling.
61 DSO_call(DSO_handle *handle,int func_index,HV* hv) {
62 mm_log((1,"DSO_call(handle %p, func_index %d, hv %p)\n",
63 handle, func_index, hv));
64 (handle->function_list[func_index].iptr)((void*)hv);
68 DSO_funclist(DSO_handle *handle) {
69 return handle->function_list;
73 #if defined( OS_hpux )
76 DSO_open(char* file,char** evalstring) {
78 void *d_handle,**plugin_symtab,**plugin_utiltab;
79 int rc,*iptr, (*fptr)(int);
80 func_ptr *function_list;
81 DSO_handle *dso_handle;
82 void (*f)(void *s,void *u); /* these will just have to be void for now */
87 mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );
89 if ( (tt_handle = shl_load(file, BIND_DEFERRED,0L)) == NULL) return NULL;
90 if ( (shl_findsym(&tt_handle, I_EVALSTR,TYPE_UNDEFINED,(void*)evalstring))) return NULL;
93 if ( (shl_findsym(&tt_handle, "symbol_table",TYPE_UNDEFINED,(void*)&plugin_symtab))) return NULL;
94 if ( (shl_findsym(&tt_handle, "util_table",TYPE_UNDEFINED,&plugin_utiltab))) return NULL;
95 (*plugin_symtab)=&symbol_table;
96 (*plugin_utiltab)=&i_UTIL_table;
99 if ( (shl_findsym(&tt_handle, I_INSTALL_TABLES ,TYPE_UNDEFINED, &f ))) return NULL;
101 mm_log( (1,"Calling install_tables\n") );
102 f(&symbol_table,&i_UTIL_table);
103 mm_log( (1,"Call ok.\n") );
105 if ( (shl_findsym(&tt_handle, I_FUNCTION_LIST ,TYPE_UNDEFINED,(func_ptr*)&function_list))) return NULL;
106 if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */
109 dso_handle->handle=tt_handle; /* needed to close again */
110 dso_handle->function_list=function_list;
111 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
112 free(dso_handle); return NULL;
114 strcpy(dso_handle->filename,file);
116 mm_log((1,"DSO_open <- (0x%X)\n",dso_handle));
117 return (void*)dso_handle;
121 DSO_close(void *ptr) {
122 DSO_handle *handle=(DSO_handle*) ptr;
123 mm_log((1,"DSO_close(ptr 0x%X)\n",ptr));
124 return !shl_unload((handle->handle));
130 DSO_open(char *file, char **evalstring) {
132 func_ptr *function_list;
133 DSO_handle *dso_handle;
135 void (*f)(void *s,void *u); /* these will just have to be void for now */
137 mm_log( (1,"DSO_open(file '%s' (%p), evalstring %p)\n",file,file,evalstring) );
140 if ((d_handle = LoadLibrary(file)) == NULL) {
141 mm_log((1, "DSO_open: LoadLibrary(%s) failed: %lu\n", file, GetLastError()));
144 if ( (*evalstring = (char *)GetProcAddress(d_handle, I_EVALSTR)) == NULL) {
145 mm_log((1,"DSO_open: GetProcAddress didn't fine '%s': %lu\n", I_EVALSTR, GetLastError()));
146 FreeLibrary(d_handle);
149 if ((f = (void (*)(void *, void*))GetProcAddress(d_handle, I_INSTALL_TABLES)) == NULL) {
150 mm_log((1, "DSO_open: GetProcAddress didn't find '%s': %lu\n", I_INSTALL_TABLES, GetLastError()));
151 FreeLibrary(d_handle);
154 mm_log((1, "Calling install tables\n"));
155 f(&symbol_table, &i_UTIL_table);
156 mm_log((1, "Call ok\n"));
158 if ( (function_list = (func_ptr *)GetProcAddress(d_handle, I_FUNCTION_LIST)) == NULL) {
159 mm_log((1, "DSO_open: GetProcAddress didn't find '%s': %lu\n", I_FUNCTION_LIST, GetLastError()));
160 FreeLibrary(d_handle);
163 if ( (dso_handle = (DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) { /* checked 17jul05 tonyc */
164 mm_log( (1, "DSO_Open: out of memory\n") );
165 FreeLibrary(d_handle);
168 dso_handle->handle=d_handle; /* needed to close again */
169 dso_handle->function_list=function_list;
170 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
172 FreeLibrary(d_handle);
175 strcpy(dso_handle->filename,file);
177 mm_log( (1,"DSO_open <- %p\n",dso_handle) );
178 return (void*)dso_handle;
183 DSO_close(void *ptr) {
184 DSO_handle *handle = (DSO_handle *)ptr;
185 BOOL result = FreeLibrary(handle->handle);
186 free(handle->filename);
194 /* OS/2 has no dlclose; Perl doesn't provide one. */
195 #ifdef __EMX__ /* OS/2 */
197 dlclose(minthandle_t h) {
198 return DosFreeModule(h) ? -1 : 0;
203 DSO_open(char* file,char** evalstring) {
205 func_ptr *function_list;
206 DSO_handle *dso_handle;
208 void (*f)(void *s,void *u); /* these will just have to be void for now */
212 mm_log( (1,"DSO_open(file '%s' (%p), evalstring %p)\n",
213 file, file, evalstring) );
215 if ( (d_handle = dlopen(file, RTLD_LAZY)) == NULL) {
216 mm_log( (1,"DSO_open: dlopen failed: %s.\n",dlerror()) );
220 if ( (*evalstring = (char *)dlsym(d_handle, I_EVALSTR)) == NULL) {
221 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_EVALSTR,dlerror()) );
227 I'll just leave this thing in here for now if I need it real soon
229 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_SYMBOL_TABLE ));
230 if ( (plugin_symtab = dlsym(d_handle, I_SYMBOL_TABLE)) == NULL) {
231 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_SYMBOL_TABLE,dlerror()) );
235 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_UTIL_TABLE ));
236 if ( (plugin_utiltab = dlsym(d_handle, I_UTIL_TABLE)) == NULL) {
237 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_UTIL_TABLE,dlerror()) );
243 f = (void(*)(void *s,void *u))dlsym(d_handle, I_INSTALL_TABLES);
244 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_INSTALL_TABLES ));
245 if ( (f = (void(*)(void *s,void *u))dlsym(d_handle, I_INSTALL_TABLES)) == NULL) {
246 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()) );
265 /* checked 17jul05 tonyc */
266 if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) {
271 dso_handle->handle=d_handle; /* needed to close again */
272 dso_handle->function_list=function_list;
273 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
278 strcpy(dso_handle->filename,file);
280 mm_log( (1,"DSO_open <- %p\n",dso_handle) );
281 return (void*)dso_handle;
285 DSO_close(void *ptr) {
288 mm_log((1,"DSO_close(ptr %p)\n",ptr));
289 handle=(DSO_handle*) ptr;
290 result = !dlclose(handle->handle);
291 free(handle->filename);