Front page | perl.perl5.porters |
Postings from September 2006
NULL and sv_setpv vs. newSVpv
Thread Next
From:
Yitzchak Scott-Thoennes
Date:
September 10, 2006 20:31
Subject:
NULL and sv_setpv vs. newSVpv
Message ID:
8750.24.19.24.170.1157945506.squirrel@24.19.24.170
I've been seeing some coredumps in cygwin with blead for some time, and
finally got around to pinning it on:
Change 27612 by nicholas@entropy on 2006/03/26 22:12:57
Replace all sv_mortalcopy(&PL_sv_no); sv_set*(...) with
sv2mortal(newSV*(...)) to avoid needless upgrades to PVNV and needless
allocation of a copy of "".
Affected files ...
... //depot/perl/pp_sys.c#499 edit
...
/* pw_class and pw_comment are mutually exclusive--.
* see the above note for pw_change, pw_quota, and pw_age. */
- PUSHs(sv = sv_mortalcopy(&PL_sv_no));
# ifdef PWCLASS
- sv_setpv(sv, pwent->pw_class);
+ PUSHs(sv_2mortal(newSVpv(pwent->pw_class, 0)));
# else
# ifdef PWCOMMENT
- sv_setpv(sv, pwent->pw_comment);
+ PUSHs(sv_2mortal(newSVpv(pwent->pw_comment, 0)));
+# else
+ /* I think that you can never get this compiled, but just in case. */
+ PUSHs(sv_mortalcopy(&PL_sv_no));
# endif
# endif
There's a subtle difference there, in that newSVpv doesn't allow a null
pv when length is 0, while sv_setpv does (doing a SvOK_off in that case.)
And of course pwent->pw_comment is NULL for cygwin. I could just fix that,
like:
--- perl-current/pp_sys.c 2006-08-21 03:18:50.000000000 -0700
+++ perl/pp_sys.c 2006-09-10 16:23:41.843750000 -0700
@@ -5202,7 +5202,7 @@
PUSHs(sv_2mortal(newSVpv(pwent->pw_class, 0)));
# else
# ifdef PWCOMMENT
- PUSHs(sv_2mortal(newSVpv(pwent->pw_comment, 0)));
+ PUSHs(sv_2mortal(newSVpv(pwent->pw_comment ? pwent->pw_comment : "", 0)));
# else
/* I think that you can never get this compiled, but just in case. */
PUSHs(sv_mortalcopy(&PL_sv_no));
but that patch made a similar change in a lot of other cases.
Would it be better to do something like:
--- perl-current/sv.c 2006-09-05 03:44:58.000000000 -0700
+++ perl/sv.c 2006-09-10 20:25:52.656250000 -0700
@@ -6933,7 +6933,7 @@ Perl_newSVpv(pTHX_ const char *s, STRLEN
register SV *sv;
new_SV(sv);
- sv_setpvn(sv,s,len ? len : strlen(s));
+ sv_setpvn(sv,s,len || s == NULL ? len : strlen(s));
return sv;
}
Thread Next
-
NULL and sv_setpv vs. newSVpv
by Yitzchak Scott-Thoennes