summaryrefslogtreecommitdiff
path: root/ext/File-DosGlob
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-04-27 16:48:36 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-12-09 18:47:19 -0800
commitc619428f3ddd8b400d932fe55a95dbfa57c647fc (patch)
treeacb7c49f88ef67423ceada493aa9b7da0fe8d547 /ext/File-DosGlob
parente2f137a79fc59f85f7323ded9b1a55055d085f0c (diff)
downloadperl-c619428f3ddd8b400d932fe55a95dbfa57c647fc.tar.gz
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.
Diffstat (limited to 'ext/File-DosGlob')
-rw-r--r--ext/File-DosGlob/DosGlob.xs18
-rw-r--r--ext/File-DosGlob/lib/File/DosGlob.pm8
-rw-r--r--ext/File-DosGlob/t/DosGlob.t3
3 files changed, 25 insertions, 4 deletions
diff --git a/ext/File-DosGlob/DosGlob.xs b/ext/File-DosGlob/DosGlob.xs
new file mode 100644
index 0000000000..b8a061255f
--- /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 d7d045fc9f..792944b045 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 8d950d76d3..1e4f7f3dab 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 {