From d8e0c3baade733ffb5b3549bb36b900460ba615f Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Thu, 6 Dec 2007 06:08:36 +0000 Subject: [PATCH] rearrange dynaload code to avoid some OS X issues --- Changes | 4 ++++ Imager.xs | 9 +++++---- Makefile.PL | 30 +++++++++++++++++++++++++++--- dynaload.c | 34 ++++++++++++++++++++++++++++++++++ dynaload.h | 28 ++-------------------------- 5 files changed, 72 insertions(+), 33 deletions(-) diff --git a/Changes b/Changes index d8b51a8a..723e6394 100644 --- 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 diff --git a/Imager.xs b/Imager.xs index 92cf7514..53162f02 100644 --- 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 diff --git a/Makefile.PL b/Makefile.PL index a5d24e67..62607112 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -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. # diff --git a/dynaload.c b/dynaload.c index 4c6ce7c8..3bb74b0d 100644 --- a/dynaload.c +++ b/dynaload.c @@ -1,3 +1,32 @@ +#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 +#elif defined(OS_darwin) +#define DL_LOADONCEONLY +#define DLSYMUN +#undef environ +#undef bool + +#import +typedef void *minthandle_t; +#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 */ @@ -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 ) diff --git a/dynaload.h b/dynaload.h index 50718871..75f55cef 100644 --- a/dynaload.h +++ b/dynaload.h @@ -3,38 +3,13 @@ #include "log.h" -#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 -#elif defined(OS_darwin) -#define DL_LOADONCEONLY -#define DLSYMUN -#undef environ -#undef bool - -#import -typedef void *minthandle_t; -#else -#include -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); -- 2.39.5