From: Father Chrysostomos Date: Fri, 27 Apr 2012 23:48:36 +0000 (-0700) Subject: DosGlob: Don’t use the magic 2nd arg to glob X-Git-Tag: upstream/5.20.0~4530 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c619428f3ddd8b400d932fe55a95dbfa57c647fc;p=platform%2Fupstream%2Fperl.git DosGlob: Don’t use the magic 2nd arg to glob Use the address of the glob op instead. This argument is going away, because it is undocumented, unused on CPAN outside of the core, and may get in the way of allowing glob() to be overridden properly. Another reason is that File::DosGlob leaks memory, because a glob op freed before iteration has finished will leave File::DosGlob still holding on to the remainder of the list of files. The easiest way to fix that will involve using an op address instead of a special index, so there will be no reason to keep it. --- diff --git a/MANIFEST b/MANIFEST index ac3aac4..a8ff0e6 100644 --- a/MANIFEST +++ b/MANIFEST @@ -3742,6 +3742,7 @@ ext/FileCache/t/04twoarg.t See if FileCache works ext/FileCache/t/05override.t See if FileCache works ext/FileCache/t/06export.t See if FileCache exporting works ext/FileCache/t/07noimport.t See if FileCache works without importing +ext/File-DosGlob/DosGlob.xs Win32 DOS-globbing module ext/File-DosGlob/lib/File/DosGlob.pm Win32 DOS-globbing module ext/File-DosGlob/t/DosGlob.t See if File::DosGlob works ext/File-Glob/bsd_glob.c File::Glob extension run time code diff --git a/ext/File-DosGlob/DosGlob.xs b/ext/File-DosGlob/DosGlob.xs new file mode 100644 index 0000000..b8a0612 --- /dev/null +++ b/ext/File-DosGlob/DosGlob.xs @@ -0,0 +1,18 @@ +#define PERL_NO_GET_CONTEXT + +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" + +MODULE = File::DosGlob PACKAGE = File::DosGlob + +PROTOTYPES: DISABLE + +SV * +_callsite(...) + CODE: + RETVAL = newSVpvn( + (char *)&cxstack[cxstack_ix].blk_sub.retop, sizeof(OP *) + ); + OUTPUT: + RETVAL diff --git a/ext/File-DosGlob/lib/File/DosGlob.pm b/ext/File-DosGlob/lib/File/DosGlob.pm index d7d045f..792944b 100644 --- a/ext/File-DosGlob/lib/File/DosGlob.pm +++ b/ext/File-DosGlob/lib/File/DosGlob.pm @@ -10,6 +10,9 @@ our $VERSION = '1.09'; use strict; use warnings; +require XSLoader; +XSLoader::load(); + sub doglob { my $cond = shift; my @retval = (); @@ -103,15 +106,12 @@ sub doglob { my %entries; sub glob { - my($pat,$cxix) = @_; + my($pat,$cxix) = ($_[0], _callsite()); my @pat; # glob without args defaults to $_ $pat = $_ unless defined $pat; - # assume global context if not provided one - $cxix = '_G_' unless defined $cxix; - # if we're just beginning, do it all first if (!$entries{$cxix}) { # extract patterns diff --git a/ext/File-DosGlob/t/DosGlob.t b/ext/File-DosGlob/t/DosGlob.t index 8d950d7..1e4f7f3 100644 --- a/ext/File-DosGlob/t/DosGlob.t +++ b/ext/File-DosGlob/t/DosGlob.t @@ -4,6 +4,9 @@ # test glob() in File::DosGlob # +# Make sure it can load before other XS extensions +use File::DosGlob; + use FindBin; use File::Spec::Functions; BEGIN {