From c619428f3ddd8b400d932fe55a95dbfa57c647fc Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 27 Apr 2012 16:48:36 -0700 Subject: [PATCH] =?utf8?q?DosGlob:=20Don=E2=80=99t=20use=20the=20magic=202?= =?utf8?q?nd=20arg=20to=20glob?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- MANIFEST | 1 + ext/File-DosGlob/DosGlob.xs | 18 ++++++++++++++++++ ext/File-DosGlob/lib/File/DosGlob.pm | 8 ++++---- ext/File-DosGlob/t/DosGlob.t | 3 +++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 ext/File-DosGlob/DosGlob.xs 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 { -- 2.7.4