3 /* #include "XSUB.h" so we can compile on threaded perls */
6 static symbol_table_t symbol_table={i_has_format,ICL_set_internal,ICL_info,
7 i_img_new,i_img_empty,i_img_empty_ch,i_img_exorcise,
8 i_img_info,i_img_setmask,i_img_getmask,
9 i_box,i_line,i_arc,i_copyto,i_copyto_trans,i_rubthru};
13 Dynamic loading works like this:
14 dynaload opens the shared object and
15 loads all the functions into an array of functions
16 it returns a string from the dynamic function that
17 can be supplied to the parser for evaling.
21 DSO_call(DSO_handle *handle,int func_index,HV* hv) {
22 mm_log((1,"DSO_call(handle 0x%X, func_index %d, hv 0x%X)\n",handle,func_index,hv));
23 (handle->function_list[func_index].iptr)((void*)hv);
27 #if defined( OS_hpux )
30 DSO_open(char* file,char** evalstring) {
32 void *d_handle,**plugin_symtab,**plugin_utiltab;
33 int rc,*iptr, (*fptr)(int);
34 func_ptr *function_list;
35 DSO_handle *dso_handle;
36 void (*f)(void *s,void *u); /* these will just have to be void for now */
41 mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );
43 if ( (tt_handle = shl_load(file, BIND_DEFERRED,0L)) == NULL) return NULL;
44 if ( (shl_findsym(&tt_handle, I_EVALSTR,TYPE_UNDEFINED,(void*)evalstring))) return NULL;
47 if ( (shl_findsym(&tt_handle, "symbol_table",TYPE_UNDEFINED,(void*)&plugin_symtab))) return NULL;
48 if ( (shl_findsym(&tt_handle, "util_table",TYPE_UNDEFINED,&plugin_utiltab))) return NULL;
49 (*plugin_symtab)=&symbol_table;
50 (*plugin_utiltab)=&i_UTIL_table;
53 if ( (shl_findsym(&tt_handle, I_INSTALL_TABLES ,TYPE_UNDEFINED, &f ))) return NULL;
55 mm_log( (1,"Calling install_tables\n") );
56 f(&symbol_table,&i_UTIL_table);
57 mm_log( (1,"Call ok.\n") );
59 if ( (shl_findsym(&tt_handle, I_FUNCTION_LIST ,TYPE_UNDEFINED,(func_ptr*)&function_list))) return NULL;
60 if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */
63 dso_handle->handle=tt_handle; /* needed to close again */
64 dso_handle->function_list=function_list;
65 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
66 free(dso_handle); return NULL;
68 strcpy(dso_handle->filename,file);
70 mm_log((1,"DSO_open <- (0x%X)\n",dso_handle));
71 return (void*)dso_handle;
75 DSO_close(void *ptr) {
76 DSO_handle *handle=(DSO_handle*) ptr;
77 mm_log((1,"DSO_close(ptr 0x%X)\n",ptr));
78 return !shl_unload((handle->handle));
84 DSO_open(char *file, char **evalstring) {
86 func_ptr *function_list;
87 DSO_handle *dso_handle;
89 void (*f)(void *s,void *u); /* these will just have to be void for now */
91 mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );
94 if ((d_handle = LoadLibrary(file)) == NULL) {
95 mm_log((1, "DSO_open: LoadLibrary(%s) failed: %lu\n", file, GetLastError()));
98 if ( (*evalstring = (char *)GetProcAddress(d_handle, I_EVALSTR)) == NULL) {
99 mm_log((1,"DSO_open: GetProcAddress didn't fine '%s': %lu\n", I_EVALSTR, GetLastError()));
100 FreeLibrary(d_handle);
103 if ((f = (void (*)(void *, void*))GetProcAddress(d_handle, I_INSTALL_TABLES)) == NULL) {
104 mm_log((1, "DSO_open: GetProcAddress didn't find '%s': %lu\n", I_INSTALL_TABLES, GetLastError()));
105 FreeLibrary(d_handle);
108 mm_log((1, "Calling install tables\n"));
109 f(&symbol_table, &i_UTIL_table);
110 mm_log((1, "Call ok\n"));
112 if ( (function_list = (func_ptr *)GetProcAddress(d_handle, I_FUNCTION_LIST)) == NULL) {
113 mm_log((1, "DSO_open: GetProcAddress didn't find '%s': %lu\n", I_FUNCTION_LIST, GetLastError()));
114 FreeLibrary(d_handle);
117 if ( (dso_handle = (DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) { /* checked 17jul05 tonyc */
118 mm_log( (1, "DSO_Open: out of memory\n") );
119 FreeLibrary(d_handle);
122 dso_handle->handle=d_handle; /* needed to close again */
123 dso_handle->function_list=function_list;
124 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
126 FreeLibrary(d_handle);
129 strcpy(dso_handle->filename,file);
131 mm_log( (1,"DSO_open <- 0x%X\n",dso_handle) );
132 return (void*)dso_handle;
137 DSO_close(void *ptr) {
138 DSO_handle *handle = (DSO_handle *)ptr;
139 BOOL result = FreeLibrary(handle->handle);
140 free(handle->filename);
148 /* OS/2 has no dlclose; Perl doesn't provide one. */
149 #ifdef __EMX__ /* OS/2 */
151 dlclose(minthandle_t h) {
152 return DosFreeModule(h) ? -1 : 0;
158 #import <mach-o/dyld.h>
160 static char *dl_error = "unknown";
162 static char *dlopen(char *path, int mode /* mode is ignored */)
165 NSObjectFileImage ofile;
166 NSModule handle = NULL;
170 dyld_result = NSCreateObjectFileImageFromFile(path, &ofile);
171 if (dyld_result != NSObjectFileImageSuccess)
173 switch (dyld_result) {
174 case NSObjectFileImageFailure:
175 dl_error = "object file setup failure";
177 case NSObjectFileImageInappropriateFile:
178 dl_error = "not a Mach-O MH_BUNDLE file type";
180 case NSObjectFileImageArch:
181 dl_error = "no object for this architecture";
183 case NSObjectFileImageFormat:
184 dl_error = "bad object file format";
186 case NSObjectFileImageAccess:
187 dl_error = "can't read object file";
190 dl_error = "unknown error from NSCreateObjectFileImageFromFile()";
196 // NSLinkModule will cause the run to abort on any link error's
197 // not very friendly but the error recovery functionality is limited.
198 handle = NSLinkModule(ofile, path, TRUE);
205 dlsym(void *handle, char *symbol)
209 if (NSIsSymbolNameDefined(symbol))
211 addr = NSAddressOfSymbol(NSLookupAndBindSymbol(symbol));
215 dl_error = "cannot find symbol";
222 static int dlclose(void *handle) /* stub only */
227 static char *dlerror(void) /* stub only */
229 printf("Error occurred\n");
238 DSO_open(char* file,char** evalstring) {
240 func_ptr *function_list;
241 DSO_handle *dso_handle;
243 void (*f)(void *s,void *u); /* these will just have to be void for now */
247 mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );
249 if ( (d_handle = dlopen(file, RTLD_LAZY)) == NULL) {
250 mm_log( (1,"DSO_open: dlopen failed: %s.\n",dlerror()) );
254 if ( (*evalstring = (char *)dlsym(d_handle, I_EVALSTR)) == NULL) {
255 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_EVALSTR,dlerror()) );
261 I'll just leave this thing in here for now if I need it real soon
263 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_SYMBOL_TABLE ));
264 if ( (plugin_symtab = dlsym(d_handle, I_SYMBOL_TABLE)) == NULL) {
265 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_SYMBOL_TABLE,dlerror()) );
269 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_UTIL_TABLE ));
270 if ( (plugin_utiltab = dlsym(d_handle, I_UTIL_TABLE)) == NULL) {
271 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_UTIL_TABLE,dlerror()) );
277 f = (void(*)(void *s,void *u))dlsym(d_handle, I_INSTALL_TABLES);
278 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_INSTALL_TABLES ));
279 if ( (f = (void(*)(void *s,void *u))dlsym(d_handle, I_INSTALL_TABLES)) == NULL) {
280 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_INSTALL_TABLES,dlerror()) );
284 mm_log( (1,"Calling install_tables\n") );
285 f(&symbol_table,&i_UTIL_table);
286 mm_log( (1,"Call ok.\n") );
288 /* (*plugin_symtab)=&symbol_table;
289 (*plugin_utiltab)=&i_UTIL_table; */
291 mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_FUNCTION_LIST ));
292 if ( (function_list=(func_ptr *)dlsym(d_handle, I_FUNCTION_LIST)) == NULL) {
293 mm_log( (1,"DSO_open: dlsym didn't find '%s': %s.\n",I_FUNCTION_LIST,dlerror()) );
297 if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */
300 dso_handle->handle=d_handle; /* needed to close again */
301 dso_handle->function_list=function_list;
302 if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
306 strcpy(dso_handle->filename,file);
308 mm_log( (1,"DSO_open <- 0x%X\n",dso_handle) );
309 return (void*)dso_handle;
313 DSO_close(void *ptr) {
315 mm_log((1,"DSO_close(ptr 0x%X)\n",ptr));
316 handle=(DSO_handle*) ptr;
317 return !dlclose(handle->handle);