summaryrefslogtreecommitdiff
path: root/sv.c
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-11-30 05:31:00 +1200
committerChip Salzenberg <chip@atlantic.net>1996-11-30 05:31:00 +1200
commitff68c7194e176ca1907544a3a65684b76834d0fe (patch)
tree4124d603a6b2a937f4ce1d9469426f84421f93e0 /sv.c
parenteff9c6e2f5bda63e4dc69fc15e237a9843954369 (diff)
downloadperl-ff68c7194e176ca1907544a3a65684b76834d0fe.tar.gz
[inseparable changes from patch from perl5.003_09 to perl5.003_10]
CORE LANGUAGE CHANGES Subject: Allow &{sub {...}} without warning From: Chip Salzenberg <chip@atlantic.net> Files: toke.c Subject: Make parens optional on [gs]ethost and [gs]et{pw,gr} function From: Chip Salzenberg <chip@atlantic.net> Files: toke.c Subject: Fix syntax error with "$x [0]" and "$x {y}" and "@x {y}" From: Chip Salzenberg <chip@atlantic.net> Files: toke.c DOCUMENTATION Subject: Improve documentation for sysread() and syswrite() From: Chip Salzenberg <chip@atlantic.net> Files: pod/perlfunc.pod Subject: Document how to use $SIG{ALRM} and alarm() Date: Tue, 26 Nov 1996 11:42:49 -0500 From: Roderick Schertler <roderick@ibcinc.com> Files: pod/perlfunc.pod Msg-ID: <5898.849026569@eeyore.ibcinc.com> (applied based on p5p patch as commit 5fa5e7dfc2abaaadd377c97cd1ebe78ea844da88) OTHER CORE CHANGES Subject: Hash key memory corruption fix and naming cleanup From: Chip Salzenberg <chip@atlantic.net> Files: hv.c hv.h perl.h Subject: Undo broken perf. patch (PADTMP stealing) From: Chip Salzenberg <chip@atlantic.net> Files: sv.c Subject: Make SV unstudied in sv_gets() From: Chip Salzenberg <chip@atlantic.net> Files: sv.c Subject: Better support for UVs From: Paul Marquess <pmarquess@bfsec.bt.co.uk> Files: global.sym old_global.sym perl.h pp.c pp.h proto.h sv.c sv.h Subject: Minor locale cleanups From: Chip Salzenberg <chip@atlantic.net> Files: t/lib/posix.t util.c Accept "POSIX" locale as standard like "C". Reset locale to 'C' when testing strtod() in t/lib/posix.t. Subject: Always taint result of sprintf() on float From: Chip Salzenberg <chip@atlantic.net> Files: doop.c Subject: Fix spurious warning from bitwise string ops From: Chip Salzenberg <chip@atlantic.net> Files: doop.c Subject: Eliminate warning on {,sys}read(,$newvar,) From: Chip Salzenberg <chip@atlantic.net> Files: doop.c pp_sys.c Subject: Namespace cleanup From: Chip Salzenberg <chip@atlantic.net> Files: global.sym old_global.sym perl.h Subject: Modify perl_exp.SH; create old_perl_exp.SH; document old_* From: Chip Salzenberg <chip@atlantic.net> Files: Configure INSTALL MANIFEST old_perl_exp.SH perl_exp.SH PORTABILITY Subject: Reliable signal patch Date: Tue, 26 Nov 1996 05:40:50 -0500 (EST) From: Kenneth Albanowski <kjahds@kjahds.com> Files: global.sym mg.c old_global.sym perl.h pp_sys.c proto.h util.c Msg-ID: <Pine.LNX.3.93.961126053209.294J-100000@kjahds.com> (applied based on p5p patch as commit 679728958e74b0ccd6d61567d84851f1ef994e1f) Subject: Emulate missing flock() with either fcntl() or lockf() From: Chip Salzenberg <chip@atlantic.net> Files: pp_sys.c Subject: 3_09: minor patches for OS/2 Date: Wed, 27 Nov 1996 03:30:05 -0500 (EST) From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: doio.c global.sym malloc.c old_global.sym os2/Makefile.SHs os2/OS2/ExtAttr/Makefile.PL os2/OS2/PrfDB/Makefile.PL os2/OS2/Process/Makefile.PL os2/OS2/REXX/Makefile.PL os2/os2.c os2/os2ish.h perl.h Subject: 3_09: minor patches This patches mostly enable commpilation under OS/2, and fix malloc.c. Enjoy, p5p-msgid: <199611270830.DAA04985@monk.mps.ohio-state.edu> Subject: Re: 5.003_09 and QNX Date: Wed, 27 Nov 96 13:36:06 est From: Norton Allen <nort@bottesini.harvard.edu> Files: Configure MANIFEST README.qnx hints/qnx.sh qnx/ar qnx/cpp t/TEST toke.c util.c x2p/proto.h Msg-ID: <9611271836.AA14460@bottesini.harvard.edu> (applied based on p5p patch as commit c5117498be098729dc2af28089bd130c88c8d42b)
Diffstat (limited to 'sv.c')
-rw-r--r--sv.c138
1 files changed, 110 insertions, 28 deletions
diff --git a/sv.c b/sv.c
index e9580c23e7..03d32a8242 100644
--- a/sv.c
+++ b/sv.c
@@ -1299,7 +1299,7 @@ register SV *sv;
if (SvNVX(sv) < 0.0)
SvIVX(sv) = I_V(SvNVX(sv));
else
- SvIVX(sv) = (IV) U_V(SvNVX(sv));
+ SvUVX(sv) = U_V(SvNVX(sv));
}
else if (SvPOKp(sv) && SvLEN(sv)) {
if (dowarn && !looks_like_number(sv))
@@ -1317,6 +1317,81 @@ register SV *sv;
return SvIVX(sv);
}
+UV
+sv_2uv(sv)
+register SV *sv;
+{
+ if (!sv)
+ return 0;
+ if (SvGMAGICAL(sv)) {
+ mg_get(sv);
+ if (SvIOKp(sv))
+ return SvUVX(sv);
+ if (SvNOKp(sv))
+ return U_V(SvNVX(sv));
+ if (SvPOKp(sv) && SvLEN(sv)) {
+ if (dowarn && !looks_like_number(sv))
+ not_a_number(sv);
+ return (UV)atol(SvPVX(sv));
+ }
+ if (!SvROK(sv)) {
+ return 0;
+ }
+ }
+ if (SvTHINKFIRST(sv)) {
+ if (SvROK(sv)) {
+#ifdef OVERLOAD
+ SV* tmpstr;
+ if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv, numer)))
+ return SvUV(tmpstr);
+#endif /* OVERLOAD */
+ return (UV)SvRV(sv);
+ }
+ if (SvREADONLY(sv)) {
+ if (SvNOKp(sv)) {
+ return U_V(SvNVX(sv));
+ }
+ if (SvPOKp(sv) && SvLEN(sv)) {
+ if (dowarn && !looks_like_number(sv))
+ not_a_number(sv);
+ return (UV)atol(SvPVX(sv));
+ }
+ if (dowarn)
+ warn(warn_uninit);
+ return 0;
+ }
+ }
+ switch (SvTYPE(sv)) {
+ case SVt_NULL:
+ sv_upgrade(sv, SVt_IV);
+ return SvUVX(sv);
+ case SVt_PV:
+ sv_upgrade(sv, SVt_PVIV);
+ break;
+ case SVt_NV:
+ sv_upgrade(sv, SVt_PVNV);
+ break;
+ }
+ if (SvNOKp(sv)) {
+ (void)SvIOK_on(sv);
+ SvUVX(sv) = U_V(SvNVX(sv));
+ }
+ else if (SvPOKp(sv) && SvLEN(sv)) {
+ if (dowarn && !looks_like_number(sv))
+ not_a_number(sv);
+ (void)SvIOK_on(sv);
+ SvUVX(sv) = (UV)atol(SvPVX(sv));
+ }
+ else {
+ if (dowarn && !localizing && !(SvFLAGS(sv) & SVs_PADTMP))
+ warn(warn_uninit);
+ return 0;
+ }
+ DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2uv(%lu)\n",
+ (unsigned long)sv,SvUVX(sv)));
+ return SvUVX(sv);
+}
+
double
sv_2nv(sv)
register SV *sv;
@@ -1648,22 +1723,20 @@ register SV *sstr;
(void)SvOK_off(dstr);
return;
case SVt_IV:
- if (dtype <= SVt_PV) {
+ if (dtype != SVt_IV && dtype < SVt_PVIV) {
if (dtype < SVt_IV)
sv_upgrade(dstr, SVt_IV);
else if (dtype == SVt_NV)
sv_upgrade(dstr, SVt_PVNV);
- else if (dtype <= SVt_PV)
+ else
sv_upgrade(dstr, SVt_PVIV);
}
break;
case SVt_NV:
- if (dtype <= SVt_PVIV) {
+ if (dtype != SVt_NV && dtype < SVt_PVNV) {
if (dtype < SVt_NV)
sv_upgrade(dstr, SVt_NV);
- else if (dtype == SVt_PVIV)
- sv_upgrade(dstr, SVt_PVNV);
- else if (dtype <= SVt_PV)
+ else
sv_upgrade(dstr, SVt_PVNV);
}
break;
@@ -1860,7 +1933,7 @@ register SV *sstr;
* has to be allocated and SvPVX(sstr) has to be freed.
*/
- if ((SvTEMP(sstr) || SvPADTMP(sstr)) && /* slated for free anyway? */
+ if (SvTEMP(sstr) && /* slated for free anyway? */
!(sflags & SVf_OOK)) /* and not involved in OOK hack? */
{
if (SvPVX(dstr)) { /* we know that dtype >= SVt_PV */
@@ -2796,6 +2869,7 @@ I32 append;
}
if (!SvUPGRADE(sv, SVt_PV))
return 0;
+ SvSCREAM_off(sv);
if (RsSNARF(rs)) {
rsptr = NULL;
@@ -3264,7 +3338,6 @@ newSVsv(old)
register SV *old;
{
register SV *sv;
- U32 oflags;
if (!old)
return Nullsv;
@@ -3276,11 +3349,10 @@ register SV *old;
SvANY(sv) = 0;
SvREFCNT(sv) = 1;
SvFLAGS(sv) = 0;
- oflags = SvFLAGS(old) & (SVs_TEMP|SVs_PADTMP);
- if (oflags) {
- SvFLAGS(old) &= ~(SVs_TEMP|SVs_PADTMP);
+ if (SvTEMP(old)) {
+ SvTEMP_off(old);
sv_setsv(sv,old);
- SvFLAGS(old) |= oflags;
+ SvTEMP_on(old);
}
else
sv_setsv(sv,old);
@@ -3448,30 +3520,40 @@ register SV *sv;
}
}
}
-#endif /* SvTRUE */
+#endif /* !SvTRUE */
#ifndef SvIV
-IV SvIV(Sv)
-register SV *Sv;
+IV
+SvIV(sv)
+register SV *sv;
{
- if (SvIOK(Sv))
- return SvIVX(Sv);
- return sv_2iv(Sv);
+ if (SvIOK(sv))
+ return SvIVX(sv);
+ return sv_2iv(sv);
}
-#endif /* SvIV */
+#endif /* !SvIV */
+#ifndef SvUV
+UV
+SvUV(sv)
+register SV *sv;
+{
+ if (SvIOK(sv))
+ return SvUVX(sv);
+ return sv_2uv(sv);
+}
+#endif /* !SvUV */
#ifndef SvNV
-double SvNV(Sv)
-register SV *Sv;
+double
+SvNV(sv)
+register SV *sv;
{
- if (SvNOK(Sv))
- return SvNVX(Sv);
- if (SvIOK(Sv))
- return (double)SvIVX(Sv);
- return sv_2nv(Sv);
+ if (SvNOK(sv))
+ return SvNVX(sv);
+ return sv_2nv(sv);
}
-#endif /* SvNV */
+#endif /* !SvNV */
#ifdef CRIPPLED_CC
char *