734417
From a6636b43dc409e4b49f369c18fedd34332fdb9ab Mon Sep 17 00:00:00 2001
734417
From: Father Chrysostomos <sprout@cpan.org>
734417
Date: Thu, 20 Sep 2012 14:25:38 -0700
734417
Subject: [PATCH] [perl #114984] Glob.xs: Extend stack when returning
734417
734417
If a pattern passed to File::Glob consists of a space-separated list
734417
of patterns, the stack will only be extended by doglob() enough for
734417
the list returned by each subpattern.  So iterate() needs to extend
734417
the stack before copying the list of files from an AV to the stack.
734417
734417
This fixes a regression introduced in 5.16.0.
734417
---
734417
 MANIFEST                   |  1 +
734417
 ext/File-Glob/Glob.xs      |  1 +
734417
 ext/File-Glob/t/rt114984.t | 25 +++++++++++++++++++++++++
734417
 3 files changed, 27 insertions(+)
734417
 create mode 100644 ext/File-Glob/t/rt114984.t
734417
734417
diff --git a/MANIFEST b/MANIFEST
734417
index a7935fc..cceb00e 100644
734417
--- a/MANIFEST
734417
+++ b/MANIFEST
734417
@@ -3748,6 +3748,7 @@ ext/File-Glob/t/basic.t		See if File::Glob works
734417
 ext/File-Glob/t/case.t		See if File::Glob works
734417
 ext/File-Glob/t/global.t	See if File::Glob works
734417
 ext/File-Glob/TODO		File::Glob extension todo list
734417
+ext/File-Glob/t/rt114984.t	See if File::Glob works
734417
 ext/File-Glob/t/taint.t		See if File::Glob works
734417
 ext/GDBM_File/GDBM_File.pm	GDBM extension Perl module
734417
 ext/GDBM_File/GDBM_File.xs	GDBM extension external subroutines
734417
diff --git a/ext/File-Glob/Glob.xs b/ext/File-Glob/Glob.xs
734417
index 3ea0590..d74e7a4 100644
734417
--- a/ext/File-Glob/Glob.xs
734417
+++ b/ext/File-Glob/Glob.xs
734417
@@ -93,6 +93,7 @@ iterate(pTHX_ bool(*globber)(pTHX_ AV *entries, SV *patsv))
734417
     /* chuck it all out, quick or slow */
734417
     if (gimme == G_ARRAY) {
734417
 	if (!on_stack) {
734417
+	    EXTEND(SP, AvFILLp(entries)+1);
734417
 	    Copy(AvARRAY(entries), SP+1, AvFILLp(entries)+1, SV *);
734417
 	    SP += AvFILLp(entries)+1;
734417
 	}
734417
diff --git a/ext/File-Glob/t/rt114984.t b/ext/File-Glob/t/rt114984.t
734417
new file mode 100644
734417
index 0000000..4229c6b
734417
--- /dev/null
734417
+++ b/ext/File-Glob/t/rt114984.t
734417
@@ -0,0 +1,25 @@
734417
+use strict;
734417
+use warnings;
734417
+use v5.16.0;
734417
+use File::Temp 'tempdir';
734417
+use File::Spec::Functions;
734417
+use Test::More tests => 1;
734417
+
734417
+my @md = (1..305);
734417
+my @mp = (1000..1205);
734417
+
734417
+my $path = tempdir uc cleanup => 1;
734417
+
734417
+foreach (@md) {
734417
+    open(my $f, ">", catfile $path, "md_$_.dat");
734417
+    close $f;
734417
+}
734417
+
734417
+foreach (@mp) {
734417
+    open(my $f, ">", catfile $path, "mp_$_.dat");
734417
+    close $f;
734417
+}
734417
+my @b = glob(qq{$path/mp_[0123456789]*.dat
734417
+                $path/md_[0123456789]*.dat});
734417
+is scalar(@b), @md+@mp,
734417
+    'File::Glob extends the stack when returning a long list';
734417
-- 
734417
1.7.11.4
734417