Change 33182 by [EMAIL PROTECTED] on 2008/02/02 11:05:17
In XS_PerlIO_get_layers() take advantage of the implementation of
PerlIO_get_layers(), by co-opting the new SVs it creates, rather than
copying them.
Affected files ...
... //depot/perl/perlio.c#376 edit
... //depot/perl/universal.c#187 edit
Differences ...
==== //depot/perl/perlio.c#376 (text) ====
Index: perl/perlio.c
--- perl/perlio.c#375~32235~ 2007-11-07 04:12:29.000000000 -0800
+++ perl/perlio.c 2008-02-02 03:05:17.000000000 -0800
@@ -759,6 +759,11 @@
PerlIOl *l = PerlIOBase(f);
while (l) {
+ /* There is some collusion in the implementation of
+ XS_PerlIO_get_layers - it knows that name and flags are
+ generated as fresh SVs here, and takes advantage of that to
+ "copy" them by taking a reference. If it changes here, it needs
+ to change there too. */
SV * const name = l->tab && l->tab->name ?
newSVpv(l->tab->name, 0) : &PL_sv_undef;
SV * const arg = l->tab && l->tab->Getarg ?
==== //depot/perl/universal.c#187 (text) ====
Index: perl/universal.c
--- perl/universal.c#186~33181~ 2008-02-01 16:16:02.000000000 -0800
+++ perl/universal.c 2008-02-02 03:05:17.000000000 -0800
@@ -969,16 +969,22 @@
const bool flgok = flgsvp && *flgsvp && SvIOK(*flgsvp);
if (details) {
+ /* Indents of 5? Yuck. */
+ /* We know that PerlIO_get_layers creates a new SV for
+ the name and flags, so we can just take a reference
+ and "steal" it when we free the AV below. */
XPUSHs(namok
- ? sv_2mortal(newSVpvn(SvPVX_const(*namsvp),
SvCUR(*namsvp)))
+ ? sv_2mortal(SvREFCNT_inc_simple_NN(*namsvp))
: &PL_sv_undef);
XPUSHs(argok
- ? sv_2mortal(newSVpvn(SvPVX_const(*argsvp),
SvCUR(*argsvp)))
+ ? newSVpvn_flags(SvPVX_const(*argsvp),
+ SvCUR(*argsvp),
+ (SvUTF8(*argsvp) ? SVf_UTF8 : 0)
+ | SVs_TEMP)
+ : &PL_sv_undef);
+ XPUSHs(namok
+ ? sv_2mortal(SvREFCNT_inc_simple_NN(*flgsvp))
: &PL_sv_undef);
- if (flgok)
- mXPUSHi(SvIVX(*flgsvp));
- else
- XPUSHs(&PL_sv_undef);
nitem += 3;
}
else {
@@ -987,8 +993,7 @@
SVfARG(*namsvp),
SVfARG(*argsvp))));
else if (namok)
- XPUSHs(sv_2mortal(Perl_newSVpvf(aTHX_ "%"SVf,
- SVfARG(*namsvp))));
+ XPUSHs(sv_2mortal(SvREFCNT_inc_simple_NN(*namsvp)));
else
XPUSHs(&PL_sv_undef);
nitem++;
End of Patch.