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 */
27 static symbol_table_t symbol_table=
49 Dynamic loading works like this:
50 dynaload opens the shared object and
51 loads all the functions into an array of functions
52 it returns a string from the dynamic function that
53 can be supplied to the parser for evaling.
57 DSO_call(DSO_handle *handle,int func_index,HV* hv) {
58 mm_log((1,"DSO_call(handle 0x%X, func_index %d, hv 0x%X)\n",handle,func_index,hv));
59 (handle->function_list[func_index].iptr)((void*)hv);
63 DSO_funclist(DSO_handle *handle) {
64 return handle->function_list;
68 #if defined( OS_hpux )
71 DSO_open(char* file,char** evalstring) {
73 void *d_handle,**plugin_symtab,**plugin_utiltab;
74 int rc,*iptr, (*fptr)(int);
75 func_ptr *function_list;
76 DSO_handle *dso_handle;
77 void (*f)(void *s,void *u); /* these will just have to be void for now */
82 mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );
84 if ( (tt_handle = shl_load(file, BIND_DEFERRED,0L)) == NULL) return NULL;
85 if ( (shl_findsym(&tt_handle, I_EVALSTR,TYPE_UNDEFINED,(void*)evalstring))) return NULL;
88 if ( (shl_findsym(&tt_handle, "symbol_table",TYPE_UNDEFINED,(void*)&plugin_symtab))) return NULL;
89 if ( (shl_findsym(&tt_handle, "util_table",TYPE_UNDEFINED,&plugin_utiltab))) return NULL;
90 (*plugin_symtab)=&symbol_table;
91 (*plugin_utiltab)=&i_UTIL_table;
94 if ( (shl_findsym(&tt_handle, I_INSTALL_TABLES ,TYPE_UNDEFINED, &f ))) return NULL;
96 mm_log( (1,"Calling install_tables\n") );
97 f(&symbol_table,&i_UTIL_table);
98 mm_log( (1,"Call ok.\n") );
100 if ( (shl_findsym(&tt_handle, I_FUNCTION_LIST ,TYPE_UNDEFINED,(func_ptr*)&function_list))) return NULL;
101 if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */
104 dso_handle->handle=tt_handle; /* needed to close again */
105 dso_handle->function_list=function_list;
106 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
107 free(dso_handle); return NULL;
109 strcpy(dso_handle->filename,file);
111 mm_log((1,"DSO_open <- (0x%X)\n",dso_handle));
112 return (void*)dso_handle;
116 DSO_close(void *ptr) {
117 DSO_handle *handle=(DSO_handle*) ptr;
118 mm_log((1,"DSO_close(ptr 0x%X)\n",ptr));
119 return !shl_unload((handle->handle));
125 DSO_open(char *file, char **evalstring) {
127 func_ptr *function_list;
128 DSO_handle *dso_handle;
130 void (*f)(void *s,void *u); /* these will just have to be void for now */
132 mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );
135 if ((d_handle = LoadLibrary(file)) == NULL) {
136 mm_log((1, "DSO_open: LoadLibrary(%s) failed: %lu\n", file, GetLastError()));
139 if ( (*evalstring = (char *)GetProcAddress(d_handle, I_EVALSTR)) == NULL) {
140 mm_log((1,"DSO_open: GetProcAddress didn't fine '%s': %lu\n", I_EVALSTR, GetLastError()));
141 FreeLibrary(d_handle);
144 if ((f = (void (*)(void *, void*))GetProcAddress(d_handle, I_INSTALL_TABLES)) == NULL) {
145 mm_log((1, "DSO_open: GetProcAddress didn't find '%s': %lu\n", I_INSTALL_TABLES, GetLastError()));
146 FreeLibrary(d_handle);
149 mm_log((1, "Calling install tables\n"));
150 f(&symbol_table, &i_UTIL_table);
151 mm_log((1, "Call ok\n"));
153 if ( (function_list = (func_ptr *)GetProcAddress(d_handle, I_FUNCTION_LIST)) == NULL) {
154 mm_log((1, "DSO_open: GetProcAddress didn't find '%s': %lu\n", I_FUNCTION_LIST, GetLastError()));
155 FreeLibrary(d_handle);
158 if ( (dso_handle = (DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) { /* checked 17jul05 tonyc */
159 mm_log( (1, "DSO_Open: out of memory\n") );
160 FreeLibrary(d_handle);
163 dso_handle->handle=d_handle; /* needed to close again */
164 dso_handle->function_list=function_list;
165 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
167 FreeLibrary(d_handle);
170 strcpy(dso_handle->filename,file);
172 mm_log( (1,"DSO_open <- 0x%X\n",dso_handle) );
173 return (void*)dso_handle;
178 DSO_close(void *ptr) {
179 DSO_handle *handle = (DSO_handle *)ptr;
180 BOOL result = FreeLibrary(handle->handle);
181 free(handle->filename);
189 /* OS/2 has no dlclose; Perl doesn't provide one. */
190 #ifdef __EMX__ /* OS/2 */
192 dlclose(minthandle_t h) {
193 return DosFreeModule(h) ? -1 : 0;
198 DSO_open(char* file,char** evalstring) {
200 func_ptr *function_list;
201 DSO_handle *dso_handle;
203 void (*f)(void *s,void *u); /* these will just have to be void for now */
207 mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );
209 if ( (d_handle = dlopen(file, RTLD_LAZY)) == NULL) {
210 mm_log( (1,"DSO_open: dlopen failed: %s.\n",dlerror()) );
214 if ( (*evalstring = (char *)dlsym(d_handle, I_EVALSTR)) == NULL) {
215 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_EVALSTR,dlerror()) );
221 I'll just leave this thing in here for now if I need it real soon
223 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_SYMBOL_TABLE ));
224 if ( (plugin_symtab = dlsym(d_handle, I_SYMBOL_TABLE)) == NULL) {
225 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_SYMBOL_TABLE,dlerror()) );
229 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_UTIL_TABLE ));
230 if ( (plugin_utiltab = dlsym(d_handle, I_UTIL_TABLE)) == NULL) {
231 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_UTIL_TABLE,dlerror()) );
237 f = (void(*)(void *s,void *u))dlsym(d_handle, I_INSTALL_TABLES);
238 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_INSTALL_TABLES ));
239 if ( (f = (void(*)(void *s,void *u))dlsym(d_handle, I_INSTALL_TABLES)) == NULL) {
240 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_INSTALL_TABLES,dlerror()) );
244 mm_log( (1,"Calling install_tables\n") );
245 f(&symbol_table,&i_UTIL_table);
246 mm_log( (1,"Call ok.\n") );
248 /* (*plugin_symtab)=&symbol_table;
249 (*plugin_utiltab)=&i_UTIL_table; */
251 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_FUNCTION_LIST ));
252 if ( (function_list=(func_ptr *)dlsym(d_handle, I_FUNCTION_LIST)) == NULL) {
253 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_FUNCTION_LIST,dlerror()) );
257 if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */
260 dso_handle->handle=d_handle; /* needed to close again */
261 dso_handle->function_list=function_list;
262 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
266 strcpy(dso_handle->filename,file);
268 mm_log( (1,"DSO_open <- 0x%X\n",dso_handle) );
269 return (void*)dso_handle;
273 DSO_close(void *ptr) {
275 mm_log((1,"DSO_close(ptr 0x%X)\n",ptr));
276 handle=(DSO_handle*) ptr;
277 return !dlclose(handle->handle);