From: Nicholas Clark Date: Fri, 6 May 2005 22:17:04 +0000 (+0000) Subject: Get the correct refcount on the temporary assignment to PL_sigwarn so X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9cfa90c07dda2bbf7df20096eab1b9057035d586;p=p5sagit%2Fp5-mst-13.2.git Get the correct refcount on the temporary assignment to PL_sigwarn so that other code assigning to $SIG{__WARN__} doesn't cause a premature free. p4raw-id: //depot/perl@24410 --- diff --git a/perlio.c b/perlio.c index fbe8da2..f437222 100644 --- a/perlio.c +++ b/perlio.c @@ -762,7 +762,8 @@ PerlIO_find_layer(pTHX_ const char *name, STRLEN len, int load) ENTER; SAVEINT(PL_in_load_module); if (cv) { - SAVESPTR(PL_warnhook); + SAVEGENERICSV(PL_warnhook); + SvREFCNT_inc(cv); PL_warnhook = (SV *) cv; } PL_in_load_module++; @@ -5039,3 +5040,13 @@ PerlIO_sprintf(char *s, int n, const char *fmt, ...) return result; } #endif + +/* + * Local variables: + * c-indentation-style: bsd + * c-basic-offset: 4 + * indent-tabs-mode: t + * End: + * + * vim: shiftwidth=4: +*/ diff --git a/t/io/layers.t b/t/io/layers.t index 79800dc..41c44c4 100644 --- a/t/io/layers.t +++ b/t/io/layers.t @@ -41,7 +41,7 @@ if (${^UNICODE} & 1) { $UNICODE_STDIN = 1; } } -my $NTEST = 43 - (($DOSISH || !$FASTSTDIO) ? 7 : 0) - ($DOSISH ? 5 : 0) +my $NTEST = 44 - (($DOSISH || !$FASTSTDIO) ? 7 : 0) - ($DOSISH ? 5 : 0) + $UNICODE_STDIN; sub PerlIO::F_UTF8 () { 0x00008000 } # from perliol.h @@ -212,5 +212,12 @@ SKIP: { close G; } + # Check that PL_sigwarn's reference count is correct, and that + # &PerlIO::Layer::NoWarnings isn't prematurely freed. + fresh_perl_like (<<'EOT', qr/^CODE/); +open(UTF, "<:raw:encoding(utf8)", $^X) or die $!; +print ref *PerlIO::Layer::NoWarnings{CODE}; +EOT + 1 while unlink "afile"; }