From: Gisle Aas Date: Sat, 7 Feb 1998 00:21:57 +0000 (+0100) Subject: Assorted patches to sv.c: X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c6f8c383310e5d7c972fc8614c9ce784e00b7bc7;p=p5sagit%2Fp5-mst-13.2.git Assorted patches to sv.c: Subject: [PATCH] sv_grow can fail for HAS_64K_LIMIT systems Date: 07 Feb 1998 00:21:57 +0100 Subject: [PATCH] sv_setnv will upgrade SVt_NV to SVt_PVNV Date: 07 Feb 1998 00:29:45 +0100 Subject: [PATCH] sv_upgrade() always returns TRUE Date: 09 Feb 1998 15:44:01 +0100 p4raw-id: //depot/perl@502 --- diff --git a/sv.c b/sv.c index 1ab0e31..f3ca97c 100644 --- a/sv.c +++ b/sv.c @@ -1085,6 +1085,10 @@ sv_grow(SV* sv, unsigned long newlen) s = SvPVX(sv); if (newlen > SvLEN(sv)) newlen += 10 * (newlen - SvCUR(sv)); /* avoid copy each time */ +#ifdef HAS_64K_LIMIT + if (newlen >= 0x10000) + newlen = 0xFFFF; +#endif } else s = SvPVX(sv); @@ -1169,7 +1173,6 @@ sv_setnv(register SV *sv, double num) case SVt_IV: sv_upgrade(sv, SVt_NV); break; - case SVt_NV: case SVt_RV: case SVt_PV: case SVt_PVIV: @@ -1716,8 +1719,7 @@ sv_2pv(register SV *sv, STRLEN *lp) return ""; } } - if (!SvUPGRADE(sv, SVt_PV)) - return 0; + (void)SvUPGRADE(sv, SVt_PV); if (SvNOKp(sv)) { if (SvTYPE(sv) < SVt_PVNV) sv_upgrade(sv, SVt_PVNV); @@ -2199,6 +2201,7 @@ sv_setsv_mg(SV *dstr, register SV *sstr) void sv_setpvn(register SV *sv, register const char *ptr, register STRLEN len) { + register char *dptr; assert(len >= 0); /* STRLEN is probably unsigned, so this may elicit a warning, but it won't hurt. */ sv_check_thinkfirst(sv); @@ -2210,12 +2213,14 @@ sv_setpvn(register SV *sv, register const char *ptr, register STRLEN len) if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV) sv_unglob(sv); } - else if (!sv_upgrade(sv, SVt_PV)) - return; + else + sv_upgrade(sv, SVt_PV); + SvGROW(sv, len + 1); - Move(ptr,SvPVX(sv),len,char); + dptr = SvPVX(sv); + Move(ptr,dptr,len,char); + dptr[len] = '\0'; SvCUR_set(sv, len); - *SvEND(sv) = '\0'; (void)SvPOK_only(sv); /* validate pointer */ SvTAINT(sv); } @@ -2242,8 +2247,9 @@ sv_setpv(register SV *sv, register const char *ptr) if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV) sv_unglob(sv); } - else if (!sv_upgrade(sv, SVt_PV)) - return; + else + sv_upgrade(sv, SVt_PV); + SvGROW(sv, len + 1); Move(ptr,SvPVX(sv),len+1,char); SvCUR_set(sv, len); @@ -2262,8 +2268,7 @@ void sv_usepvn(register SV *sv, register char *ptr, register STRLEN len) { sv_check_thinkfirst(sv); - if (!SvUPGRADE(sv, SVt_PV)) - return; + (void)SvUPGRADE(sv, SVt_PV); if (!ptr) { (void)SvOK_off(sv); return; @@ -2434,8 +2439,7 @@ sv_magic(register SV *sv, SV *obj, int how, char *name, I32 namlen) } } else { - if (!SvUPGRADE(sv, SVt_PVMG)) - return; + (void)SvUPGRADE(sv, SVt_PVMG); } Newz(702,mg, 1, MAGIC); mg->mg_moremagic = SvMAGIC(sv); @@ -3081,8 +3085,7 @@ sv_gets(register SV *sv, register PerlIO *fp, I32 append) I32 i; sv_check_thinkfirst(sv); - if (!SvUPGRADE(sv, SVt_PV)) - return 0; + (void)SvUPGRADE(sv, SVt_PV); SvSCREAM_off(sv); if (RsSNARF(rs)) {