DosGlob: Don’t use the magic 2nd arg to glob
authorFather Chrysostomos <sprout@cpan.org>
Fri, 27 Apr 2012 23:48:36 +0000 (16:48 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 10 Dec 2012 02:47:19 +0000 (18:47 -0800)
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
ext/File-DosGlob/DosGlob.xs [new file with mode: 0644]
ext/File-DosGlob/lib/File/DosGlob.pm
ext/File-DosGlob/t/DosGlob.t

index ac3aac4..a8ff0e6 100644 (file)
--- 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 (file)
index 0000000..b8a0612
--- /dev/null
@@ -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
index d7d045f..792944b 100644 (file)
@@ -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
index 8d950d7..1e4f7f3 100644 (file)
@@ -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 {