This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Make setdefout accept only NN
authorFather Chrysostomos <sprout@cpan.org>
Thu, 24 May 2012 19:07:37 +0000 (12:07 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 7 Jun 2012 15:18:50 +0000 (08:18 -0700)
Just search through the source for GvIOp(PL_defoutgv) and you will see
that perl assumes that PL_defoutgv is never null.

I tried setting it to null from XS and got crashes, unsurprisingly.

The only CPAN user of PL_defoutgv sets it to STDOUT.

embed.fnc
pp_sys.c
proto.h

index 455a8c3..1f5047c 100644 (file)
--- a/embed.fnc
+++ b/embed.fnc
@@ -1194,7 +1194,7 @@ Apd       |NV     |scan_oct       |NN const char* start|STRLEN len|NN STRLEN* retlen
 AMpd   |OP*    |op_scope       |NULLOK OP* o
 Ap     |char*  |screaminstr    |NN SV *bigstr|NN SV *littlestr|I32 start_shift \
                                |I32 end_shift|NN I32 *old_posp|I32 last
-Apd    |void   |setdefout      |NULLOK GV* gv
+Apd    |void   |setdefout      |NN GV* gv
 Ap     |HEK*   |share_hek      |NN const char* str|I32 len|U32 hash
 #if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
 : Used in perl.c
index 5a87da5..5003282 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1227,7 +1227,8 @@ void
 Perl_setdefout(pTHX_ GV *gv)
 {
     dVAR;
-    SvREFCNT_inc_simple_void(gv);
+    PERL_ARGS_ASSERT_SETDEFOUT;
+    SvREFCNT_inc_simple_void_NN(gv);
     SvREFCNT_dec(PL_defoutgv);
     PL_defoutgv = gv;
 }
diff --git a/proto.h b/proto.h
index 539d06d..b6dbd5c 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -3638,7 +3638,11 @@ PERL_CALLCONV void       Perl_set_context(void *t)
 PERL_CALLCONV void     Perl_set_numeric_local(pTHX);
 PERL_CALLCONV void     Perl_set_numeric_radix(pTHX);
 PERL_CALLCONV void     Perl_set_numeric_standard(pTHX);
-PERL_CALLCONV void     Perl_setdefout(pTHX_ GV* gv);
+PERL_CALLCONV void     Perl_setdefout(pTHX_ GV* gv)
+                       __attribute__nonnull__(pTHX_1);
+#define PERL_ARGS_ASSERT_SETDEFOUT     \
+       assert(gv)
+
 PERL_CALLCONV HEK*     Perl_share_hek(pTHX_ const char* str, I32 len, U32 hash)
                        __attribute__nonnull__(pTHX_1);
 #define PERL_ARGS_ASSERT_SHARE_HEK     \