&CORE::setpgrp()
authorFather Chrysostomos <sprout@cpan.org>
Mon, 29 Aug 2011 16:54:20 +0000 (09:54 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Mon, 29 Aug 2011 19:33:53 +0000 (12:33 -0700)
This commit allows &CORE::setpgrp to be called through references and
via ampersand syntax.  pp_setpgrp 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 setpgrp 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 1c337ef..086e398 100644 (file)
--- a/gv.c
+++ b/gv.c
@@ -1358,7 +1358,7 @@ Perl_gv_fetchpvn_flags(pTHX_ const char *nambeg, STRLEN full_len, I32 flags,
            case KEY_lstat:
            case KEY_pop:
            case KEY_push:
-           case KEY_setpgrp: case KEY_shift:
+           case KEY_shift:
            case KEY_splice:
            case KEY_stat:
            case KEY_system:
index 7ae1644..5cd9ef6 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -4342,16 +4342,12 @@ PP(pp_setpgrp)
     dVAR; dSP; dTARGET;
     Pid_t pgrp;
     Pid_t pid;
-    if (MAXARG == 1) pgrp = 0, pid = TOPi;
-    else if (MAXARG < 2) {
-       pgrp = 0;
+    pgrp = MAXARG == 2 && (TOPs||POPs) ? POPi : 0;
+    if (MAXARG > 0) pid = TOPs && TOPi;
+    else {
        pid = 0;
        XPUSHi(-1);
     }
-    else {
-       pgrp = POPi;
-       pid = TOPi;
-    }
 
     TAINT_PROPER("setpgrp");
 #ifdef BSD_SETPGRP
index 50897a0..5ef3a2b 100644 (file)
@@ -657,7 +657,18 @@ test_proto "sem$_" for qw "ctl get op";
 test_proto 'send';
 
 test_proto "set$_" for qw '
-  grent hostent netent priority protoent pwent servent sockopt
+  grent hostent netent
+';
+
+test_proto 'setpgrp';
+$tests +=2;
+eval { &mysetpgrp( 0) };
+pass "&setpgrp with one argument";
+eval { &mysetpgrp };
+pass "&setpgrp with no arguments";
+
+test_proto "set$_" for qw '
+  priority protoent pwent servent sockopt
 ';
 
 test_proto "shm$_" for qw "ctl get read write";