X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/aa833c9730468de0c7e4d05a3965d741416843e2..500888dae6ac345f223bc472079aa5ab9550fdd5:/dynaload.c diff --git a/dynaload.c b/dynaload.c index 8a6af06a..75f1b3f5 100644 --- a/dynaload.c +++ b/dynaload.c @@ -1,11 +1,48 @@ +#if defined(OS_hpux) +#include +typedef shl_t minthandle_t; +#elif defined(WIN32) +#define WIN32_LEAN_AND_MEAN +#include +typedef HMODULE minthandle_t; +#undef WIN32_LEAN_AND_MEAN +#else +#include +typedef void *minthandle_t; +#endif + +#include "plug.h" + +struct DSO_handle_tag { + minthandle_t handle; + char *filename; + func_ptr *function_list; +}; + +#include "imager.h" #include "dynaload.h" /* #include "XSUB.h" so we can compile on threaded perls */ -#include "imagei.h" +#include "imageri.h" -static symbol_table_t symbol_table={i_has_format,ICL_set_internal,ICL_info, - i_img_new,i_img_empty,i_img_empty_ch,i_img_exorcise, - i_img_info,i_img_setmask,i_img_getmask, - i_box,i_line,i_arc,i_copyto,i_copyto_trans,i_rubthru}; +static symbol_table_t symbol_table= + { + i_has_format, + ICL_set_internal, + ICL_info, + i_img_new, + i_img_empty, + i_img_empty_ch, + i_img_exorcise, + i_img_info, + i_img_setmask, + i_img_getmask, + i_box, + i_line, + i_arc, + i_copyto, + i_copyto_trans, + i_rubthru + }; /* @@ -22,6 +59,11 @@ DSO_call(DSO_handle *handle,int func_index,HV* hv) { (handle->function_list[func_index].iptr)((void*)hv); } +func_ptr * +DSO_funclist(DSO_handle *handle) { + return handle->function_list; +} + #if defined( OS_hpux ) @@ -56,11 +98,14 @@ DSO_open(char* file,char** evalstring) { mm_log( (1,"Call ok.\n") ); if ( (shl_findsym(&tt_handle, I_FUNCTION_LIST ,TYPE_UNDEFINED,(func_ptr*)&function_list))) return NULL; - if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) return NULL; + if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */ + return NULL; dso_handle->handle=tt_handle; /* needed to close again */ dso_handle->function_list=function_list; - if ( (dso_handle->filename=(char*)malloc(strlen(file))) == NULL) { free(dso_handle); return NULL; } + if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */ + free(dso_handle); return NULL; + } strcpy(dso_handle->filename,file); mm_log((1,"DSO_open <- (0x%X)\n",dso_handle)); @@ -110,14 +155,18 @@ DSO_open(char *file, char **evalstring) { FreeLibrary(d_handle); return NULL; } - if ( (dso_handle = (DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) { + if ( (dso_handle = (DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) { /* checked 17jul05 tonyc */ mm_log( (1, "DSO_Open: out of memory\n") ); FreeLibrary(d_handle); return NULL; } dso_handle->handle=d_handle; /* needed to close again */ dso_handle->function_list=function_list; - if ( (dso_handle->filename=(char*)malloc(strlen(file))) == NULL) { free(dso_handle); FreeLibrary(d_handle); return NULL; } + if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */ + free(dso_handle); + FreeLibrary(d_handle); + return NULL; + } strcpy(dso_handle->filename,file); mm_log( (1,"DSO_open <- 0x%X\n",dso_handle) ); @@ -145,87 +194,6 @@ dlclose(minthandle_t h) { } #endif /* __EMX__ */ -#ifdef OS_darwin - -#import - -static char *dl_error = "unknown"; - -static char *dlopen(char *path, int mode /* mode is ignored */) -{ - int dyld_result; - NSObjectFileImage ofile; - NSModule handle = NULL; - - - - dyld_result = NSCreateObjectFileImageFromFile(path, &ofile); - if (dyld_result != NSObjectFileImageSuccess) - { - switch (dyld_result) { - case NSObjectFileImageFailure: - dl_error = "object file setup failure"; - break; - case NSObjectFileImageInappropriateFile: - dl_error = "not a Mach-O MH_BUNDLE file type"; - break; - case NSObjectFileImageArch: - dl_error = "no object for this architecture"; - break; - case NSObjectFileImageFormat: - dl_error = "bad object file format"; - break; - case NSObjectFileImageAccess: - dl_error = "can't read object file"; - break; - default: - dl_error = "unknown error from NSCreateObjectFileImageFromFile()"; - break; - } - } - else - { - // NSLinkModule will cause the run to abort on any link error's - // not very friendly but the error recovery functionality is limited. - handle = NSLinkModule(ofile, path, TRUE); - } - - return handle; -} - -static void * -dlsym(void *handle, char *symbol) -{ - void *addr; - - if (NSIsSymbolNameDefined(symbol)) - { - addr = NSAddressOfSymbol(NSLookupAndBindSymbol(symbol)); - } - else - { - dl_error = "cannot find symbol"; - addr = NULL; - } - - return addr; -} - -static int dlclose(void *handle) /* stub only */ -{ - return 0; -} - -static char *dlerror(void) /* stub only */ -{ - printf("Error occurred\n"); - return dl_error; -} - -#define RTLD_LAZY 0 - -#endif - void* DSO_open(char* file,char** evalstring) { void *d_handle; @@ -286,11 +254,15 @@ DSO_open(char* file,char** evalstring) { return NULL; } - if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) return NULL; + if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */ + return NULL; dso_handle->handle=d_handle; /* needed to close again */ dso_handle->function_list=function_list; - if ( (dso_handle->filename=(char*)malloc(strlen(file))) == NULL) { free(dso_handle); return NULL; } + if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */ + free(dso_handle); + return NULL; + } strcpy(dso_handle->filename,file); mm_log( (1,"DSO_open <- 0x%X\n",dso_handle) );