]> git.imager.perl.org - imager.git/commitdiff
rearrange dynaload code to avoid some OS X issues
authorTony Cook <tony@develop=help.com>
Thu, 6 Dec 2007 06:08:36 +0000 (06:08 +0000)
committerTony Cook <tony@develop=help.com>
Thu, 6 Dec 2007 06:08:36 +0000 (06:08 +0000)
Changes
Imager.xs
Makefile.PL
dynaload.c
dynaload.h

diff --git a/Changes b/Changes
index d8b51a8a9b63eebb05782f2b8b546683e5bf922e..723e639470955028672446965e131101fe554942 100644 (file)
--- a/Changes
+++ b/Changes
@@ -3,6 +3,10 @@ Imager release history.  Older releases can be found in Changes.old
 Imager 0.62 - unreleased
 ===========
 
+ - Makefile.PL now expands ~/path supplied to --incpath or --libpath
+   to /path under your home directory.
+   http://rt.cpan.org/Ticket/Display.html?id=29484
+
 Bug fixes:
 
  - samples/gifscale.pl sourced the base value for gif_top from
index 92cf751454ca0ad875aa93e26d2d7cb4c970851e..53162f029a8e80fb49faa1d1a0d9f3b68c32e7a0 100644 (file)
--- a/Imager.xs
+++ b/Imager.xs
@@ -3470,17 +3470,18 @@ DSO_funclist(dso_handle_v)
             PREINIT:
               int i;
               DSO_handle *dso_handle;
+              func_ptr *functions;
             PPCODE:
               dso_handle=(DSO_handle*)dso_handle_v;
+              functions = DSO_funclist(dso_handle);
               i=0;
-              while( dso_handle->function_list[i].name != NULL) {
+              while( functions[i].name != NULL) {
                 EXTEND(SP,1);
-                PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i].name,0)));
+                PUSHs(sv_2mortal(newSVpv(functions[i].name,0)));
                 EXTEND(SP,1);
-                PUSHs(sv_2mortal(newSVpv(dso_handle->function_list[i++].pcode,0)));
+                PUSHs(sv_2mortal(newSVpv(functions[i++].pcode,0)));
               }
 
-
 void
 DSO_call(handle,func_index,hv)
               void*  handle
index a5d24e67bf99501e0641817d8c8f0f1d1d1261f6..62607112e390d635ef35b1d6e148ea92d8624e0a 100644 (file)
@@ -412,8 +412,11 @@ sub init {
 
   my @definc = qw(/usr/include);
   @definc{@definc}=(1) x @definc;
-  @incs=(split(/\Q$Config{path_sep}/, $INCPATH),
-        map { split /\Q$Config{path_sep}/} @incpaths );
+  @incs=
+    (
+     split(/\Q$Config{path_sep}/, $INCPATH),
+     map _tilde_expand($_), map { split /\Q$Config{path_sep}/ } @incpaths 
+    );
   if ($Config{locincpth}) {
     push @incs, grep -d, split ' ', $Config{locincpth};
   }
@@ -437,7 +440,7 @@ sub init {
   }
 
   @libs= ( split(/\Q$Config{path_sep}/,$LIBPATH),
-    map { split /\Q$Config{path_sep}/} @libpaths );
+    map _tilde_expand($_), map { split /\Q$Config{path_sep}/} @libpaths );
   if ($Config{loclibpth}) {
     push @libs, grep -d, split ' ', $Config{loclibpth};
   }
@@ -995,6 +998,27 @@ YAML
   }
 }
 
+my $home;
+sub _tilde_expand {
+  my ($path) = @_;
+
+  if ($path =~ m!^~[/\\]!) {
+    defined $home or $home = $ENV{HOME};
+    if (!defined $home && $^O eq 'MSWin32'
+       && defined $ENV{HOMEDRIVE} && defined $ENV{HOMEPATH}) {
+      $home = $ENV{HOMEDRIVE} . $ENV{HOMEPATH};
+    }
+    unless (defined $home) {
+      $home = eval { (getpwuid($<))[7] };
+    }
+    defined $home or die "You supplied $path, but I can't find your home directory\n";
+    $path =~ s/^~//;
+    $path = File::Spec->catdir($home, $path);
+  }
+
+  $path;
+}
+
 # This isn't a module, but some broken tools, like
 # Module::Depends::Instrusive insist on treating it like one.
 #
index 4c6ce7c8a8844cc7616061442ed75a42084b2bf2..3bb74b0d1ad24373b2bc4dcbda44e6bb9be1bbe5 100644 (file)
@@ -1,3 +1,32 @@
+#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
+#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; 
+#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 */
@@ -38,6 +67,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 )
 
index 507188718e361b3cefacf4bc24b3c6069374bb49..75f55cef434b8b299d0a4d03ab1028acb7afbe32 100644 (file)
@@ -3,38 +3,13 @@
 
 #include "log.h"
 
-#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
-#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; 
-#endif 
-
 #include "EXTERN.h"
 #include "perl.h"
 #include "ppport.h"
 
 #include "ext.h"
 
-typedef struct {
-  minthandle_t handle;
-  char *filename;
-  func_ptr *function_list;
-} DSO_handle;
+typedef struct DSO_handle_tag DSO_handle;
 
 typedef struct {
   HV* hv;
@@ -50,6 +25,7 @@ int getvoid(void *hv_t,char *key,void **store);
 #endif
 
 void *DSO_open(char* file,char** evalstring);
+func_ptr *DSO_funclist(DSO_handle *handle);
 int DSO_close(void *);
 void DSO_call(DSO_handle *handle,int func_index,HV* hv);