]> git.imager.perl.org - imager.git/blobdiff - dynaload.c
WIP, it compiles
[imager.git] / dynaload.c
index 4c6ce7c8a8844cc7616061442ed75a42084b2bf2..faa605daa68b2cee038fa38a7472d6b40c40a0f0 100644 (file)
@@ -1,16 +1,41 @@
+#if defined(OS_hpux)
+#include <dl.h>
+typedef shl_t minthandle_t;
+#elif defined(WIN32)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+typedef HMODULE minthandle_t;
+#undef WIN32_LEAN_AND_MEAN
+#else 
+#include <dlfcn.h>
+typedef void *minthandle_t; 
+#endif 
+
+#include "ext.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 "imageri.h"
 
+static im_context_t
+do_get_context(void) {
+  return im_get_context();
+}
+
 static symbol_table_t symbol_table=
   {
     i_has_format,
     ICL_set_internal,
     ICL_info,
-    i_img_new,
-    i_img_empty,
-    i_img_empty_ch,
+    do_get_context,
+    im_img_empty_ch,
     i_img_exorcise,
     i_img_info,
     i_img_setmask,
@@ -34,10 +59,16 @@ static symbol_table_t symbol_table=
 
 void
 DSO_call(DSO_handle *handle,int func_index,HV* hv) {
-  mm_log((1,"DSO_call(handle 0x%X, func_index %d, hv 0x%X)\n",handle,func_index,hv));
+  mm_log((1,"DSO_call(handle %p, func_index %d, hv %p)\n",
+         handle, func_index, hv));
   (handle->function_list[func_index].iptr)((void*)hv);
 }
 
+func_ptr *
+DSO_funclist(DSO_handle *handle) {
+  return handle->function_list;
+}
+
 
 #if defined( OS_hpux )
 
@@ -103,7 +134,7 @@ DSO_open(char *file, char **evalstring) {
   
   void (*f)(void *s,void *u); /* these will just have to be void for now */
 
-  mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );
+  mm_log( (1,"DSO_open(file '%s' (%p), evalstring %p)\n",file,file,evalstring) );
 
   *evalstring = NULL;
   if ((d_handle = LoadLibrary(file)) == NULL) {
@@ -143,7 +174,7 @@ DSO_open(char *file, char **evalstring) {
   }
   strcpy(dso_handle->filename,file);
 
-  mm_log( (1,"DSO_open <- 0x%X\n",dso_handle) );
+  mm_log( (1,"DSO_open <- %p\n",dso_handle) );
   return (void*)dso_handle;
 
 }
@@ -168,87 +199,6 @@ dlclose(minthandle_t h) {
 }
 #endif /* __EMX__ */
 
-#ifdef OS_darwin
-
-#import <mach-o/dyld.h>
-
-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;
@@ -259,7 +209,8 @@ DSO_open(char* file,char** evalstring) {
   
   *evalstring=NULL;
 
-  mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );
+  mm_log( (1,"DSO_open(file '%s' (%p), evalstring %p)\n",
+          file, file, evalstring) );
 
   if ( (d_handle = dlopen(file, RTLD_LAZY)) == NULL) {
     mm_log( (1,"DSO_open: dlopen failed: %s.\n",dlerror()) );
@@ -320,14 +271,14 @@ DSO_open(char* file,char** evalstring) {
   }
   strcpy(dso_handle->filename,file);
 
-  mm_log( (1,"DSO_open <- 0x%X\n",dso_handle) );
+  mm_log( (1,"DSO_open <- %p\n",dso_handle) );
   return (void*)dso_handle;
 }
 
 undef_int
 DSO_close(void *ptr) {
   DSO_handle *handle;
-  mm_log((1,"DSO_close(ptr 0x%X)\n",ptr));
+  mm_log((1,"DSO_close(ptr %p)\n",ptr));
   handle=(DSO_handle*) ptr;
   return !dlclose(handle->handle);
 }