added Artur's OSX dlload() emulation, with minor changes
authorTony Cook <tony@develop=help.com>
Sun, 3 Feb 2002 12:19:22 +0000 (12:19 +0000)
committerTony Cook <tony@develop=help.com>
Sun, 3 Feb 2002 12:19:22 +0000 (12:19 +0000)
modified _color() to work around a 5.6.0 bug

Changes
Imager.pm
dynaload.c
dynaload.h
image.c

diff --git a/Changes b/Changes
index 5451e8df2b583f498804759ebf3ec18e0d52675e..6b5ea5d1872b87d1c3794644bf3e88f87ff29592 100644 (file)
--- a/Changes
+++ b/Changes
@@ -598,6 +598,8 @@ Revision history for Perl extension Imager.
        - Added lib/Imager/Filters.pod, draft of Filters pod.
        - Added lib/Imager/Engines.pod, draft of Engines pod.
         - added getpixel() and setpixel() methods
+        - added Artur's OSX dlload() emulation, with minor changes
+        - modified _color() to work around a 5.6.0 bug
 
 
 =================================================================
index d536fc05ccc0aa9790406e1996b357ee6cb72e0c..f485bd544a44d2a63d1440d879c5491e45176331 100644 (file)
--- a/Imager.pm
+++ b/Imager.pm
@@ -456,6 +456,11 @@ sub _error_as_msg {
 
 sub _color {
   my $arg = shift;
+  # perl 5.6.0 seems to do weird things to $arg if we don't make an 
+  # explicitly stringified copy
+  # I vaguely remember a bug on this on p5p, but couldn't find it
+  # through bugs.perl.org (I had trouble getting it to find any bugs)
+  my $copy = $arg . "";
   my $result;
 
   if (ref $arg) {
@@ -464,10 +469,10 @@ sub _color {
       $result = $arg;
     }
     else {
-      if ($arg =~ /^HASH\(/) {
+      if ($copy =~ /^HASH\(/) {
         $result = Imager::Color->new(%$arg);
       }
-      elsif ($arg =~ /^ARRAY\(/) {
+      elsif ($copy =~ /^ARRAY\(/) {
         if (grep $_ > 1, @$arg) {
           $result = Imager::Color->new(@$arg);
         }
index b5486a53f12a2dfe67c949d57e45add606c495c6..4ebd3c08663a92c8ac59fcafd792aed159493809 100644 (file)
@@ -1,6 +1,12 @@
 #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 */
 
 
@@ -80,7 +86,6 @@ int getobj(void *hv_t,char *key,char *type,void **store) {
 
 
 UTIL_table_t UTIL_table={getstr,getint,getdouble,getvoid,getobj};
-extern symbol_table_t symbol_table;
 
 /*
   Dynamic loading works like this:
@@ -217,6 +222,90 @@ 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;
+}
+
+void *
+dlsym(handle, symbol)
+     void *handle;
+     char *symbol;
+{
+  void *addr;
+
+  if (NSIsSymbolNameDefined(symbol))
+  {
+    addr = NSAddressOfSymbol(NSLookupAndBindSymbol(symbol));
+  }
+  else
+  {
+    dl_error = "cannot find symbol";
+    addr = NULL;
+  }
+
+  return addr;
+}
+
+int dlclose(handle) /* stub only */
+     void *handle;
+{
+  return 0;
+}
+
+char *dlerror(handle) /* stub only */
+     void *handle;
+{
+  printf("Error occured\n");
+  return dl_error; 
+}
+
+#define RTLD_LAZY 0
+
+#endif 
 
 void*
 DSO_open(char* file,char** evalstring) {
index 2007b93b8938aadfed0a3273b04d7b2afddb1455..40f83b7932ae245c59200eb3f99cf50b4ba9110b 100644 (file)
@@ -11,6 +11,14 @@ typedef shl_t minthandle_t;
 #include <windows.h>
 typedef HMODULE minthandle_t;
 #undef WIN32_LEAN_AND_MEAN
+#elif defined(OS_darwin)
+#define DL_LOADONCEONLY
+#define DLSYMUN
+#undef environ
+#undef bool
+
+#import <mach-o/dyld.h>
+typedef void *minthandle_t; 
 #else 
 #include <dlfcn.h>
 typedef void *minthandle_t; 
diff --git a/image.c b/image.c
index e97cd5bfdd2f92255a38af761b665b79c360830c..9e9482c43583568a186908a089db985ba68c9d7e 100644 (file)
--- a/image.c
+++ b/image.c
@@ -1241,13 +1241,6 @@ i_count_colors(i_img *im,int maxc) {
   return colorcnt;
 }
 
-
-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};
-
-
 /*
 =back