&CORE::sysopen()
authorFather Chrysostomos <sprout@cpan.org>
Mon, 29 Aug 2011 01:23:49 +0000 (18:23 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 29 Aug 2011 04:03:52 +0000 (21:03 -0700)
This commit allows &CORE::sysopen to be called through references and
via ampersand syntax.  pp_sysopen is modified to take into account the
nulls pushed on to the stack in pp_coreargs, which happens because
pp_coreargs has no other way to tell sysopen how many arguments it’s
actually getting.  See commit 0163043a for details.

gv.c
pp_sys.c
t/op/coreamp.t

diff --git a/gv.c b/gv.c
index e269753..1c337ef 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1361,7 +1361,6 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
            case KEY_setpgrp: case KEY_shift:
            case KEY_splice:
            case KEY_stat:
-           case KEY_sysopen:
            case KEY_system:
            case KEY_tell: case KEY_tie: case KEY_tied:
            case KEY_truncate: case KEY_umask: case KEY_unlink:
index 747fd78..8454963 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1557,7 +1557,7 @@ PP(pp_sysopen)
 {
     dVAR;
     dSP;
-    const int perm = (MAXARG > 3) ? POPi : 0666;
+    const int perm = (MAXARG > 3 && (TOPs || POPs)) ? POPi : 0666;
     const int mode = POPi;
     SV * const sv = POPs;
     GV * const gv = MUTABLE_GV(POPs);
index 87273fd..50897a0 100644 (file)
@@ -690,6 +690,15 @@ is $_, 'along', 'lvalue &substr';
 
 test_proto 'symlink';
 test_proto 'syscall';
+
+test_proto 'sysopen';
+$tests +=2;
+{
+  &mysysopen(my $fh, 'test.pl', 0);
+  pass '&sysopen does not crash with 3 args';
+  ok $fh, 'sysopen autovivifies';
+}
+
 test_proto 'sysread';
 test_proto 'sysseek';
 test_proto 'syswrite';