X-Git-Url: http://git.imager.perl.org/imager.git/blobdiff_plain/4ede8fe20a85a96a4e0fefccf7b8a3477e75c705..4db4acaac20ba27a08193d52642f5595bccf97f0:/dynaload.c?ds=sidebyside diff --git a/dynaload.c b/dynaload.c index cdbf3d95..4c6ce7c8 100644 --- a/dynaload.c +++ b/dynaload.c @@ -1,91 +1,28 @@ +#include "imager.h" #include "dynaload.h" -#include "XSUB.h" /* so we can compile on threaded perls */ - -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_draw,i_arc,i_copyto,i_copyto_trans,i_rubthru}; - - -/* These functions are all shared - then comes platform dependant code */ - - -int getstr(void *hv_t,char *key,char **store) { - SV** svpp; - HV* hv=(HV*)hv_t; - - mm_log((1,"getstr(hv_t 0x%X, key %s, store 0x%X)\n",hv_t,key,store)); - - if ( !hv_exists(hv,key,strlen(key)) ) return 0; - - svpp=hv_fetch(hv, key, strlen(key), 0); - *store=SvPV(*svpp, PL_na ); - - return 1; -} - -int getint(void *hv_t,char *key,int *store) { - SV** svpp; - HV* hv=(HV*)hv_t; - - mm_log((1,"getint(hv_t 0x%X, key %s, store 0x%X)\n",hv_t,key,store)); - - if ( !hv_exists(hv,key,strlen(key)) ) return 0; - - svpp=hv_fetch(hv, key, strlen(key), 0); - *store=(int)SvIV(*svpp); - return 1; -} - -int getdouble(void *hv_t,char* key,double *store) { - SV** svpp; - HV* hv=(HV*)hv_t; - - mm_log((1,"getdouble(hv_t 0x%X, key %s, store 0x%X)\n",hv_t,key,store)); - - if ( !hv_exists(hv,key,strlen(key)) ) return 0; - svpp=hv_fetch(hv, key, strlen(key), 0); - *store=(float)SvNV(*svpp); - return 1; -} - -int getvoid(void *hv_t,char* key,void **store) { - SV** svpp; - HV* hv=(HV*)hv_t; - - mm_log((1,"getvoid(hv_t 0x%X, key %s, store 0x%X)\n",hv_t,key,store)); - - if ( !hv_exists(hv,key,strlen(key)) ) return 0; - - svpp=hv_fetch(hv, key, strlen(key), 0); - *store=(void*)SvIV(*svpp); - - return 1; -} - -int getobj(void *hv_t,char *key,char *type,void **store) { - SV** svpp; - HV* hv=(HV*)hv_t; - - mm_log((1,"getobj(hv_t 0x%X, key %s,type %s, store 0x%X)\n",hv_t,key,type,store)); - - if ( !hv_exists(hv,key,strlen(key)) ) return 0; - - svpp=hv_fetch(hv, key, strlen(key), 0); - - if (sv_derived_from(*svpp,type)) { - IV tmp = SvIV((SV*)SvRV(*svpp)); - *store = (void*) tmp; - } else { - mm_log((1,"getobj: key exists in hash but is not of correct type")); - return 0; - } - - return 1; -} +/* #include "XSUB.h" so we can compile on threaded perls */ +#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 + }; -UTIL_table_t UTIL_table={getstr,getint,getdouble,getvoid,getobj}; /* Dynamic loading works like this: @@ -125,21 +62,24 @@ DSO_open(char* file,char** evalstring) { if ( (shl_findsym(&tt_handle, "symbol_table",TYPE_UNDEFINED,(void*)&plugin_symtab))) return NULL; if ( (shl_findsym(&tt_handle, "util_table",TYPE_UNDEFINED,&plugin_utiltab))) return NULL; (*plugin_symtab)=&symbol_table; - (*plugin_utiltab)=&UTIL_table; + (*plugin_utiltab)=&i_UTIL_table; */ if ( (shl_findsym(&tt_handle, I_INSTALL_TABLES ,TYPE_UNDEFINED, &f ))) return NULL; mm_log( (1,"Calling install_tables\n") ); - f(&symbol_table,&UTIL_table); + f(&symbol_table,&i_UTIL_table); 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)); @@ -181,7 +121,7 @@ DSO_open(char *file, char **evalstring) { return NULL; } mm_log((1, "Calling install tables\n")); - f(&symbol_table, &UTIL_table); + f(&symbol_table, &i_UTIL_table); mm_log((1, "Call ok\n")); if ( (function_list = (func_ptr *)GetProcAddress(d_handle, I_FUNCTION_LIST)) == NULL) { @@ -189,14 +129,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) ); @@ -207,9 +151,11 @@ DSO_open(char *file, char **evalstring) { undef_int DSO_close(void *ptr) { DSO_handle *handle = (DSO_handle *)ptr; - FreeLibrary(handle->handle); + BOOL result = FreeLibrary(handle->handle); free(handle->filename); free(handle); + + return result; } #else @@ -351,11 +297,11 @@ DSO_open(char* file,char** evalstring) { } mm_log( (1,"Calling install_tables\n") ); - f(&symbol_table,&UTIL_table); + f(&symbol_table,&i_UTIL_table); mm_log( (1,"Call ok.\n") ); /* (*plugin_symtab)=&symbol_table; - (*plugin_utiltab)=&UTIL_table; */ + (*plugin_utiltab)=&i_UTIL_table; */ mm_log( (1,"DSO_open: going to dlsym '%s'\n", I_FUNCTION_LIST )); if ( (function_list=(func_ptr *)dlsym(d_handle, I_FUNCTION_LIST)) == NULL) { @@ -363,11 +309,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) );