3 * Copyright (c) 1991-1997, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "I wonder what the Entish is for 'yes' and 'no'," he thought.
18 /* Use an overridden DBL_DIG */
22 # define DBL_DIG OVR_DBL_DIG
24 /* The following is all to get DBL_DIG, in order to pick a nice
25 default value for printing floating point numbers in Gconvert.
35 #define DBL_DIG 15 /* A guess that works lots of places */
39 #if defined(USE_STDIO_PTR) && defined(STDIO_PTR_LVALUE) && defined(STDIO_CNT_LVALUE) && !defined(__QNX__)
43 static IV asIV _((SV* sv));
44 static UV asUV _((SV* sv));
45 static SV *more_sv _((void));
46 static XPVIV *more_xiv _((void));
47 static XPVNV *more_xnv _((void));
48 static XPV *more_xpv _((void));
49 static XRV *more_xrv _((void));
50 static XPVIV *new_xiv _((void));
51 static XPVNV *new_xnv _((void));
52 static XPV *new_xpv _((void));
53 static XRV *new_xrv _((void));
54 static void del_xiv _((XPVIV* p));
55 static void del_xnv _((XPVNV* p));
56 static void del_xpv _((XPV* p));
57 static void del_xrv _((XRV* p));
58 static void sv_mortalgrow _((void));
59 static void sv_unglob _((SV* sv));
60 static void sv_check_thinkfirst _((SV *sv));
62 #define SV_CHECK_THINKFIRST(sv) if (SvTHINKFIRST(sv)) sv_check_thinkfirst(sv)
65 static void *my_safemalloc(MEM_SIZE size);
68 typedef void (*SVFUNC) _((SV*));
75 (p) = (SV*)safemalloc(sizeof(SV)); \
84 Safefree((char*)(p)); \
91 #define REGHASH(sv,size) ((((U32)(sv)) >> 2) % (size))
93 #define REG_REPLACE(sv,a,b) \
95 void* p = sv->sv_any; \
96 I32 h = REGHASH(sv, regsize); \
98 while (registry[i] != (a)) { \
102 die("SV registry bug"); \
107 #define REG_ADD(sv) REG_REPLACE(sv,Nullsv,sv)
108 #define REG_REMOVE(sv) REG_REPLACE(sv,sv,Nullsv)
114 if (sv_count >= (regsize >> 1))
116 SV **oldreg = registry;
117 I32 oldsize = regsize;
119 regsize = regsize ? ((regsize << 2) + 1) : 2037;
120 Newz(707, registry, regsize, SV*);
125 for (i = 0; i < oldsize; ++i) {
126 SV* oldsv = oldreg[i];
152 for (i = 0; i < regsize; ++i) {
153 SV* sv = registry[i];
160 sv_add_arena(ptr, size, flags)
165 if (!(flags & SVf_FAKE))
172 * "A time to plant, and a time to uproot what was planted..."
175 #define plant_SV(p) \
177 SvANY(p) = (void *)sv_root; \
178 SvFLAGS(p) = SVTYPEMASK; \
183 /* sv_mutex must be held while calling uproot_SV() */
184 #define uproot_SV(p) \
187 sv_root = (SV*)SvANY(p); \
191 #define new_SV(p) do { \
202 #define del_SV(p) do { \
219 for (sva = sv_arenaroot; sva; sva = (SV *) SvANY(sva)) {
221 svend = &sva[SvREFCNT(sva)];
222 if (p >= sv && p < svend)
226 warn("Attempt to free non-arena SV: 0x%lx", (unsigned long)p);
233 #else /* ! DEBUGGING */
235 #define del_SV(p) plant_SV(p)
237 #endif /* DEBUGGING */
240 sv_add_arena(char *ptr, U32 size, U32 flags)
245 Zero(sva, size, char);
247 /* The first SV in an arena isn't an SV. */
248 SvANY(sva) = (void *) sv_arenaroot; /* ptr to next arena */
249 SvREFCNT(sva) = size / sizeof(SV); /* number of SV slots */
250 SvFLAGS(sva) = flags; /* FAKE if not to be freed */
255 svend = &sva[SvREFCNT(sva) - 1];
258 SvANY(sv) = (void *)(SV*)(sv + 1);
259 SvFLAGS(sv) = SVTYPEMASK;
263 SvFLAGS(sv) = SVTYPEMASK;
266 /* sv_mutex must be held while calling more_sv() */
273 sv_add_arena(nice_chunk, nice_chunk_size, 0);
277 char *chunk; /* must use New here to match call to */
278 New(704,chunk,1008,char); /* Safefree() in sv_free_arenas() */
279 sv_add_arena(chunk, 1008, 0);
292 for (sva = sv_arenaroot; sva; sva = (SV*)SvANY(sva)) {
293 svend = &sva[SvREFCNT(sva)];
294 for (sv = sva + 1; sv < svend; ++sv) {
295 if (SvTYPE(sv) != SVTYPEMASK)
304 do_report_used(SV *sv)
306 if (SvTYPE(sv) != SVTYPEMASK) {
307 /* XXX Perhaps this ought to go to Perl_debug_log, if DEBUGGING. */
308 PerlIO_printf(PerlIO_stderr(), "****\n");
316 visit(do_report_used);
320 do_clean_objs(SV *sv)
324 if (SvROK(sv) && SvOBJECT(rv = SvRV(sv))) {
325 DEBUG_D((PerlIO_printf(Perl_debug_log, "Cleaning object ref:\n "), sv_dump(sv));)
331 /* XXX Might want to check arrays, etc. */
334 #ifndef DISABLE_DESTRUCTOR_KLUDGE
336 do_clean_named_objs(SV *sv)
338 if (SvTYPE(sv) == SVt_PVGV && GvSV(sv))
339 do_clean_objs(GvSV(sv));
343 static bool in_clean_objs = FALSE;
348 in_clean_objs = TRUE;
349 #ifndef DISABLE_DESTRUCTOR_KLUDGE
350 visit(do_clean_named_objs);
352 visit(do_clean_objs);
353 in_clean_objs = FALSE;
359 DEBUG_D((PerlIO_printf(Perl_debug_log, "Cleaning loops:\n "), sv_dump(sv));)
360 SvFLAGS(sv) |= SVf_BREAK;
364 static bool in_clean_all = FALSE;
371 in_clean_all = FALSE;
380 /* Free arenas here, but be careful about fake ones. (We assume
381 contiguity of the fake ones with the corresponding real ones.) */
383 for (sva = sv_arenaroot; sva; sva = svanext) {
384 svanext = (SV*) SvANY(sva);
385 while (svanext && SvFAKE(svanext))
386 svanext = (SV*) SvANY(svanext);
389 Safefree((void *)sva);
403 * See comment in more_xiv() -- RAM.
405 xiv_root = (IV**)*xiv;
406 return (XPVIV*)((char*)xiv - sizeof(XPV));
414 IV** xiv = (IV**)((char*)(p) + sizeof(XPV));
415 *xiv = (IV *)xiv_root;
423 register IV** xivend;
425 New(705, ptr, 1008/sizeof(XPV), XPV);
426 ptr->xpv_pv = (char*)xiv_arenaroot; /* linked list of xiv arenas */
427 xiv_arenaroot = ptr; /* to keep Purify happy */
430 xivend = &xiv[1008 / sizeof(IV *) - 1];
431 xiv += (sizeof(XPV) - 1) / sizeof(IV *) + 1; /* fudge by size of XPV */
433 while (xiv < xivend) {
434 *xiv = (IV *)(xiv + 1);
447 xnv_root = *(double**)xnv;
448 return (XPVNV*)((char*)xnv - sizeof(XPVIV));
456 double* xnv = (double*)((char*)(p) + sizeof(XPVIV));
457 *(double**)xnv = xnv_root;
464 register double* xnv;
465 register double* xnvend;
466 New(711, xnv, 1008/sizeof(double), double);
467 xnvend = &xnv[1008 / sizeof(double) - 1];
468 xnv += (sizeof(XPVIV) - 1) / sizeof(double) + 1; /* fudge by sizeof XPVIV */
470 while (xnv < xnvend) {
471 *(double**)xnv = (double*)(xnv + 1);
484 xrv_root = (XRV*)xrv->xrv_rv;
493 p->xrv_rv = (SV*)xrv_root;
501 register XRV* xrvend;
502 New(712, xrv_root, 1008/sizeof(XRV), XRV);
504 xrvend = &xrv[1008 / sizeof(XRV) - 1];
505 while (xrv < xrvend) {
506 xrv->xrv_rv = (SV*)(xrv + 1);
519 xpv_root = (XPV*)xpv->xpv_pv;
528 p->xpv_pv = (char*)xpv_root;
536 register XPV* xpvend;
537 New(713, xpv_root, 1008/sizeof(XPV), XPV);
539 xpvend = &xpv[1008 / sizeof(XPV) - 1];
540 while (xpv < xpvend) {
541 xpv->xpv_pv = (char*)(xpv + 1);
549 #define new_XIV() (void*)safemalloc(sizeof(XPVIV))
550 #define del_XIV(p) Safefree((char*)p)
552 #define new_XIV() (void*)new_xiv()
553 #define del_XIV(p) del_xiv((XPVIV*) p)
557 #define new_XNV() (void*)safemalloc(sizeof(XPVNV))
558 #define del_XNV(p) Safefree((char*)p)
560 #define new_XNV() (void*)new_xnv()
561 #define del_XNV(p) del_xnv((XPVNV*) p)
565 #define new_XRV() (void*)safemalloc(sizeof(XRV))
566 #define del_XRV(p) Safefree((char*)p)
568 #define new_XRV() (void*)new_xrv()
569 #define del_XRV(p) del_xrv((XRV*) p)
573 #define new_XPV() (void*)safemalloc(sizeof(XPV))
574 #define del_XPV(p) Safefree((char*)p)
576 #define new_XPV() (void*)new_xpv()
577 #define del_XPV(p) del_xpv((XPV *)p)
581 # define my_safemalloc(s) safemalloc(s)
582 # define my_safefree(s) free(s)
585 my_safemalloc(MEM_SIZE size)
588 New(717, p, size, char);
591 # define my_safefree(s) Safefree(s)
594 #define new_XPVIV() (void*)my_safemalloc(sizeof(XPVIV))
595 #define del_XPVIV(p) my_safefree((char*)p)
597 #define new_XPVNV() (void*)my_safemalloc(sizeof(XPVNV))
598 #define del_XPVNV(p) my_safefree((char*)p)
600 #define new_XPVMG() (void*)my_safemalloc(sizeof(XPVMG))
601 #define del_XPVMG(p) my_safefree((char*)p)
603 #define new_XPVLV() (void*)my_safemalloc(sizeof(XPVLV))
604 #define del_XPVLV(p) my_safefree((char*)p)
606 #define new_XPVAV() (void*)my_safemalloc(sizeof(XPVAV))
607 #define del_XPVAV(p) my_safefree((char*)p)
609 #define new_XPVHV() (void*)my_safemalloc(sizeof(XPVHV))
610 #define del_XPVHV(p) my_safefree((char*)p)
612 #define new_XPVCV() (void*)my_safemalloc(sizeof(XPVCV))
613 #define del_XPVCV(p) my_safefree((char*)p)
615 #define new_XPVGV() (void*)my_safemalloc(sizeof(XPVGV))
616 #define del_XPVGV(p) my_safefree((char*)p)
618 #define new_XPVBM() (void*)my_safemalloc(sizeof(XPVBM))
619 #define del_XPVBM(p) my_safefree((char*)p)
621 #define new_XPVFM() (void*)my_safemalloc(sizeof(XPVFM))
622 #define del_XPVFM(p) my_safefree((char*)p)
624 #define new_XPVIO() (void*)my_safemalloc(sizeof(XPVIO))
625 #define del_XPVIO(p) my_safefree((char*)p)
628 sv_upgrade(register SV *sv, U32 mt)
638 if (SvTYPE(sv) == mt)
644 switch (SvTYPE(sv)) {
659 nv = (double)SvIVX(sv);
665 else if (mt < SVt_PVIV)
682 pv = (char*)SvRV(sv);
686 nv = (double)(unsigned long)pv;
702 else if (mt == SVt_NV)
713 del_XPVIV(SvANY(sv));
723 del_XPVNV(SvANY(sv));
733 del_XPVMG(SvANY(sv));
736 croak("Can't upgrade that kind of scalar");
741 croak("Can't upgrade to undef");
743 SvANY(sv) = new_XIV();
747 SvANY(sv) = new_XNV();
751 SvANY(sv) = new_XRV();
755 SvANY(sv) = new_XPV();
761 SvANY(sv) = new_XPVIV();
771 SvANY(sv) = new_XPVNV();
779 SvANY(sv) = new_XPVMG();
789 SvANY(sv) = new_XPVLV();
803 SvANY(sv) = new_XPVAV();
818 SvANY(sv) = new_XPVHV();
834 SvANY(sv) = new_XPVCV();
835 Zero(SvANY(sv), 1, XPVCV);
845 SvANY(sv) = new_XPVGV();
860 SvANY(sv) = new_XPVBM();
873 SvANY(sv) = new_XPVFM();
874 Zero(SvANY(sv), 1, XPVFM);
884 SvANY(sv) = new_XPVIO();
885 Zero(SvANY(sv), 1, XPVIO);
896 SvFLAGS(sv) &= ~SVTYPEMASK;
905 SV *t = sv_newmortal();
915 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
919 else if (sv == &sv_undef || sv == &sv_no || sv == &sv_yes) {
920 if (sv == &sv_undef) {
921 sv_catpv(t, "SV_UNDEF");
922 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
923 SVs_GMG|SVs_SMG|SVs_RMG)) &&
927 else if (sv == &sv_no) {
928 sv_catpv(t, "SV_NO");
929 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
930 SVs_GMG|SVs_SMG|SVs_RMG)) &&
931 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
938 sv_catpv(t, "SV_YES");
939 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
940 SVs_GMG|SVs_SMG|SVs_RMG)) &&
941 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
944 SvPVX(sv) && *SvPVX(sv) == '1' &&
950 else if (SvREFCNT(sv) == 0) {
956 if (SvCUR(t) + unref > 10) {
957 SvCUR(t) = unref + 3;
965 switch (SvTYPE(sv)) {
967 sv_catpv(t, "FREED");
971 sv_catpv(t, "UNDEF");
1005 sv_catpvf(t, "CV(%s)", GvNAME(CvGV(sv)));
1007 sv_catpv(t, "CV()");
1025 sv_catpv(t, "(null)");
1027 sv_catpvf(t, "(%ld+\"%.127s\")",(long)SvIVX(sv),SvPVX(sv));
1029 sv_catpvf(t, "(\"%.127s\")",SvPVX(sv));
1031 else if (SvNOKp(sv)) {
1032 SET_NUMERIC_STANDARD();
1033 sv_catpvf(t, "(%g)",SvNVX(sv));
1035 else if (SvIOKp(sv))
1036 sv_catpvf(t, "(%ld)",(long)SvIVX(sv));
1050 sv_backoff(register SV *sv)
1054 char *s = SvPVX(sv);
1055 SvLEN(sv) += SvIVX(sv);
1056 SvPVX(sv) -= SvIVX(sv);
1058 Move(s, SvPVX(sv), SvCUR(sv)+1, char);
1060 SvFLAGS(sv) &= ~SVf_OOK;
1066 sv_grow(register SV *sv, register I32 newlen)
1068 sv_grow(SV* sv, unsigned long newlen)
1073 #ifdef HAS_64K_LIMIT
1074 if (newlen >= 0x10000) {
1075 PerlIO_printf(Perl_debug_log, "Allocation too large: %lx\n", newlen);
1078 #endif /* HAS_64K_LIMIT */
1081 if (SvTYPE(sv) < SVt_PV) {
1082 sv_upgrade(sv, SVt_PV);
1085 else if (SvOOK(sv)) { /* pv is offset? */
1088 if (newlen > SvLEN(sv))
1089 newlen += 10 * (newlen - SvCUR(sv)); /* avoid copy each time */
1090 #ifdef HAS_64K_LIMIT
1091 if (newlen >= 0x10000)
1097 if (newlen > SvLEN(sv)) { /* need more room? */
1099 Renew(s,newlen,char);
1101 New(703,s,newlen,char);
1103 SvLEN_set(sv, newlen);
1109 sv_setiv(register SV *sv, IV i)
1111 SV_CHECK_THINKFIRST(sv);
1112 switch (SvTYPE(sv)) {
1114 sv_upgrade(sv, SVt_IV);
1117 sv_upgrade(sv, SVt_PVNV);
1121 sv_upgrade(sv, SVt_PVIV);
1137 croak("Can't coerce %s to integer in %s", sv_reftype(sv,0),
1138 op_desc[op->op_type]);
1141 (void)SvIOK_only(sv); /* validate number */
1147 sv_setiv_mg(register SV *sv, IV i)
1154 sv_setuv(register SV *sv, UV u)
1159 sv_setnv(sv, (double)u);
1163 sv_setuv_mg(register SV *sv, UV u)
1170 sv_setnv(register SV *sv, double num)
1172 SV_CHECK_THINKFIRST(sv);
1173 switch (SvTYPE(sv)) {
1176 sv_upgrade(sv, SVt_NV);
1181 sv_upgrade(sv, SVt_PVNV);
1188 (void)SvOOK_off(sv);
1203 croak("Can't coerce %s to number in %s", sv_reftype(sv,0),
1204 op_name[op->op_type]);
1208 (void)SvNOK_only(sv); /* validate number */
1213 sv_setnv_mg(register SV *sv, double num)
1220 not_a_number(SV *sv)
1226 char *limit = tmpbuf + sizeof(tmpbuf) - 8;
1227 /* each *s can expand to 4 chars + "...\0",
1228 i.e. need room for 8 chars */
1230 for (s = SvPVX(sv); *s && d < limit; s++) {
1232 if (ch & 128 && !isPRINT_LC(ch)) {
1241 else if (ch == '\r') {
1245 else if (ch == '\f') {
1249 else if (ch == '\\') {
1253 else if (isPRINT_LC(ch))
1268 warn("Argument \"%s\" isn't numeric in %s", tmpbuf,
1269 op_name[op->op_type]);
1271 warn("Argument \"%s\" isn't numeric", tmpbuf);
1275 sv_2iv(register SV *sv)
1279 if (SvGMAGICAL(sv)) {
1284 if (SvNVX(sv) < 0.0)
1285 return I_V(SvNVX(sv));
1287 return (IV) U_V(SvNVX(sv));
1289 if (SvPOKp(sv) && SvLEN(sv))
1292 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1300 if (SvTHINKFIRST(sv)) {
1304 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv, numer)))
1305 return SvIV(tmpstr);
1306 #endif /* OVERLOAD */
1307 return (IV)SvRV(sv);
1309 if (SvREADONLY(sv)) {
1311 if (SvNVX(sv) < 0.0)
1312 return I_V(SvNVX(sv));
1314 return (IV) U_V(SvNVX(sv));
1316 if (SvPOKp(sv) && SvLEN(sv))
1323 switch (SvTYPE(sv)) {
1325 sv_upgrade(sv, SVt_IV);
1328 sv_upgrade(sv, SVt_PVIV);
1331 sv_upgrade(sv, SVt_PVNV);
1336 if (SvNVX(sv) < 0.0)
1337 SvIVX(sv) = I_V(SvNVX(sv));
1339 SvUVX(sv) = U_V(SvNVX(sv));
1341 else if (SvPOKp(sv) && SvLEN(sv)) {
1343 SvIVX(sv) = asIV(sv);
1347 if (dowarn && !localizing && !(SvFLAGS(sv) & SVs_PADTMP))
1351 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2iv(%ld)\n",
1352 (unsigned long)sv,(long)SvIVX(sv)));
1357 sv_2uv(register SV *sv)
1361 if (SvGMAGICAL(sv)) {
1366 return U_V(SvNVX(sv));
1367 if (SvPOKp(sv) && SvLEN(sv))
1370 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1378 if (SvTHINKFIRST(sv)) {
1382 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv, numer)))
1383 return SvUV(tmpstr);
1384 #endif /* OVERLOAD */
1385 return (UV)SvRV(sv);
1387 if (SvREADONLY(sv)) {
1389 return U_V(SvNVX(sv));
1391 if (SvPOKp(sv) && SvLEN(sv))
1398 switch (SvTYPE(sv)) {
1400 sv_upgrade(sv, SVt_IV);
1403 sv_upgrade(sv, SVt_PVIV);
1406 sv_upgrade(sv, SVt_PVNV);
1411 SvUVX(sv) = U_V(SvNVX(sv));
1413 else if (SvPOKp(sv) && SvLEN(sv)) {
1415 SvUVX(sv) = asUV(sv);
1418 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1425 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2uv(%lu)\n",
1426 (unsigned long)sv,SvUVX(sv)));
1431 sv_2nv(register SV *sv)
1435 if (SvGMAGICAL(sv)) {
1439 if (SvPOKp(sv) && SvLEN(sv)) {
1440 if (dowarn && !SvIOKp(sv) && !looks_like_number(sv))
1442 SET_NUMERIC_STANDARD();
1443 return atof(SvPVX(sv));
1446 return (double)SvIVX(sv);
1448 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1456 if (SvTHINKFIRST(sv)) {
1460 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,numer)))
1461 return SvNV(tmpstr);
1462 #endif /* OVERLOAD */
1463 return (double)(unsigned long)SvRV(sv);
1465 if (SvREADONLY(sv)) {
1466 if (SvPOKp(sv) && SvLEN(sv)) {
1467 if (dowarn && !SvIOKp(sv) && !looks_like_number(sv))
1469 SET_NUMERIC_STANDARD();
1470 return atof(SvPVX(sv));
1473 return (double)SvIVX(sv);
1479 if (SvTYPE(sv) < SVt_NV) {
1480 if (SvTYPE(sv) == SVt_IV)
1481 sv_upgrade(sv, SVt_PVNV);
1483 sv_upgrade(sv, SVt_NV);
1484 DEBUG_c(SET_NUMERIC_STANDARD());
1485 DEBUG_c(PerlIO_printf(Perl_debug_log,
1486 "0x%lx num(%g)\n",(unsigned long)sv,SvNVX(sv)));
1488 else if (SvTYPE(sv) < SVt_PVNV)
1489 sv_upgrade(sv, SVt_PVNV);
1491 (!SvPOKp(sv) || !strchr(SvPVX(sv),'.') || !looks_like_number(sv)))
1493 SvNVX(sv) = (double)SvIVX(sv);
1495 else if (SvPOKp(sv) && SvLEN(sv)) {
1496 if (dowarn && !SvIOKp(sv) && !looks_like_number(sv))
1498 SET_NUMERIC_STANDARD();
1499 SvNVX(sv) = atof(SvPVX(sv));
1503 if (dowarn && !localizing && !(SvFLAGS(sv) & SVs_PADTMP))
1508 DEBUG_c(SET_NUMERIC_STANDARD());
1509 DEBUG_c(PerlIO_printf(Perl_debug_log,
1510 "0x%lx 2nv(%g)\n",(unsigned long)sv,SvNVX(sv)));
1517 I32 numtype = looks_like_number(sv);
1521 return atol(SvPVX(sv));
1522 if (!numtype && dowarn)
1524 SET_NUMERIC_STANDARD();
1525 d = atof(SvPVX(sv));
1535 I32 numtype = looks_like_number(sv);
1539 return strtoul(SvPVX(sv), Null(char**), 10);
1541 if (!numtype && dowarn)
1543 SET_NUMERIC_STANDARD();
1544 return U_V(atof(SvPVX(sv)));
1548 looks_like_number(SV *sv)
1551 register char *send;
1552 register char *sbegin;
1560 else if (SvPOKp(sv))
1561 sbegin = SvPV(sv, len);
1564 send = sbegin + len;
1569 if (*s == '+' || *s == '-')
1572 /* next must be digit or '.' */
1576 } while (isDIGIT(*s));
1579 while (isDIGIT(*s)) /* optional digits after "." */
1583 else if (*s == '.') {
1585 /* no digits before '.' means we need digits after it */
1589 } while (isDIGIT(*s));
1598 * we return 1 if the number can be converted to _integer_ with atol()
1599 * and 2 if you need (int)atof().
1603 /* we can have an optional exponent part */
1604 if (*s == 'e' || *s == 'E') {
1607 if (*s == '+' || *s == '-')
1612 } while (isDIGIT(*s));
1621 if (len == 10 && memEQ(sbegin, "0 but true", 10))
1627 sv_2pv(register SV *sv, STRLEN *lp)
1632 char tmpbuf[64]; /* Must fit sprintf/Gconvert of longest IV/NV */
1638 if (SvGMAGICAL(sv)) {
1645 (void)sprintf(tmpbuf,"%ld",(long)SvIVX(sv));
1650 SET_NUMERIC_STANDARD();
1651 Gconvert(SvNVX(sv), DBL_DIG, 0, tmpbuf);
1656 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1665 if (SvTHINKFIRST(sv)) {
1669 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,string)))
1670 return SvPV(tmpstr,*lp);
1671 #endif /* OVERLOAD */
1676 switch (SvTYPE(sv)) {
1685 case SVt_PVMG: s = "SCALAR"; break;
1686 case SVt_PVLV: s = "LVALUE"; break;
1687 case SVt_PVAV: s = "ARRAY"; break;
1688 case SVt_PVHV: s = "HASH"; break;
1689 case SVt_PVCV: s = "CODE"; break;
1690 case SVt_PVGV: s = "GLOB"; break;
1691 case SVt_PVFM: s = "FORMLINE"; break;
1692 case SVt_PVIO: s = "IO"; break;
1693 default: s = "UNKNOWN"; break;
1697 sv_setpvf(tsv, "%s=%s", HvNAME(SvSTASH(sv)), s);
1700 sv_catpvf(tsv, "(0x%lx)", (unsigned long)sv);
1706 if (SvREADONLY(sv)) {
1708 SET_NUMERIC_STANDARD();
1709 Gconvert(SvNVX(sv), DBL_DIG, 0, tmpbuf);
1714 (void)sprintf(tmpbuf,"%ld",(long)SvIVX(sv));
1724 (void)SvUPGRADE(sv, SVt_PV);
1726 if (SvTYPE(sv) < SVt_PVNV)
1727 sv_upgrade(sv, SVt_PVNV);
1730 olderrno = errno; /* some Xenix systems wipe out errno here */
1732 if (SvNVX(sv) == 0.0)
1733 (void)strcpy(s,"0");
1737 SET_NUMERIC_STANDARD();
1738 Gconvert(SvNVX(sv), DBL_DIG, 0, s);
1741 #ifdef FIXNEGATIVEZERO
1742 if (*s == '-' && s[1] == '0' && !s[2])
1751 else if (SvIOKp(sv)) {
1752 U32 oldIOK = SvIOK(sv);
1753 if (SvTYPE(sv) < SVt_PVIV)
1754 sv_upgrade(sv, SVt_PVIV);
1755 olderrno = errno; /* some Xenix systems wipe out errno here */
1756 sv_setpviv(sv, SvIVX(sv));
1766 if (dowarn && !localizing && !(SvFLAGS(sv) & SVs_PADTMP))
1771 *lp = s - SvPVX(sv);
1774 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2pv(%s)\n",(unsigned long)sv,SvPVX(sv)));
1778 if (SvROK(sv)) { /* XXX Skip this when sv_pvn_force calls */
1779 /* Sneaky stuff here */
1783 tsv = newSVpv(tmpbuf, 0);
1799 len = strlen(tmpbuf);
1801 #ifdef FIXNEGATIVEZERO
1802 if (len == 2 && t[0] == '-' && t[1] == '0') {
1807 (void)SvUPGRADE(sv, SVt_PV);
1809 s = SvGROW(sv, len + 1);
1817 /* This function is only called on magical items */
1819 sv_2bool(register SV *sv)
1831 if (SvAMAGIC(sv) && (tmpsv = AMG_CALLun(sv,bool_)))
1832 return SvTRUE(tmpsv);
1834 #endif /* OVERLOAD */
1835 return SvRV(sv) != 0;
1838 register XPV* Xpvtmp;
1839 if ((Xpvtmp = (XPV*)SvANY(sv)) &&
1840 (*Xpvtmp->xpv_pv > '0' ||
1841 Xpvtmp->xpv_cur > 1 ||
1842 (Xpvtmp->xpv_cur && *Xpvtmp->xpv_pv != '0')))
1849 return SvIVX(sv) != 0;
1852 return SvNVX(sv) != 0.0;
1859 /* Note: sv_setsv() should not be called with a source string that needs
1860 * to be reused, since it may destroy the source string if it is marked
1865 sv_setsv(SV *dstr, register SV *sstr)
1868 register U32 sflags;
1874 SV_CHECK_THINKFIRST(dstr);
1877 stype = SvTYPE(sstr);
1878 dtype = SvTYPE(dstr);
1880 if (dtype == SVt_PVGV && (SvFLAGS(dstr) & SVf_FAKE)) {
1881 sv_unglob(dstr); /* so fake GLOB won't perpetuate */
1882 sv_setpvn(dstr, "", 0);
1883 (void)SvPOK_only(dstr);
1884 dtype = SvTYPE(dstr);
1889 #endif /* OVERLOAD */
1890 /* There's a lot of redundancy below but we're going for speed here */
1894 (void)SvOK_off(dstr);
1897 if (dtype != SVt_IV && dtype < SVt_PVIV) {
1899 sv_upgrade(dstr, SVt_IV);
1900 else if (dtype == SVt_NV)
1901 sv_upgrade(dstr, SVt_PVNV);
1903 sv_upgrade(dstr, SVt_PVIV);
1907 if (dtype != SVt_NV && dtype < SVt_PVNV) {
1909 sv_upgrade(dstr, SVt_NV);
1911 sv_upgrade(dstr, SVt_PVNV);
1916 sv_upgrade(dstr, SVt_RV);
1917 else if (dtype == SVt_PVGV &&
1918 SvTYPE(SvRV(sstr)) == SVt_PVGV) {
1921 if (curcop->cop_stash != GvSTASH(dstr))
1922 GvIMPORTED_on(dstr);
1932 sv_upgrade(dstr, SVt_PV);
1935 if (dtype < SVt_PVIV)
1936 sv_upgrade(dstr, SVt_PVIV);
1939 if (dtype < SVt_PVNV)
1940 sv_upgrade(dstr, SVt_PVNV);
1948 croak("Bizarre copy of %s in %s", sv_reftype(sstr, 0),
1949 op_name[op->op_type]);
1951 croak("Bizarre copy of %s", sv_reftype(sstr, 0));
1955 if (dtype <= SVt_PVGV) {
1957 if (dtype != SVt_PVGV) {
1958 char *name = GvNAME(sstr);
1959 STRLEN len = GvNAMELEN(sstr);
1960 sv_upgrade(dstr, SVt_PVGV);
1961 sv_magic(dstr, dstr, '*', name, len);
1962 GvSTASH(dstr) = (HV*)SvREFCNT_inc(GvSTASH(sstr));
1963 GvNAME(dstr) = savepvn(name, len);
1964 GvNAMELEN(dstr) = len;
1965 SvFAKE_on(dstr); /* can coerce to non-glob */
1967 /* ahem, death to those who redefine active sort subs */
1968 else if (curstack == sortstack
1969 && GvCV(dstr) && sortcop == CvSTART(GvCV(dstr)))
1970 croak("Can't redefine active sort subroutine %s",
1972 (void)SvOK_off(dstr);
1973 GvINTRO_off(dstr); /* one-shot flag */
1975 GvGP(dstr) = gp_ref(GvGP(sstr));
1977 if (curcop->cop_stash != GvSTASH(dstr))
1978 GvIMPORTED_on(dstr);
1985 if (SvGMAGICAL(sstr)) {
1987 if (SvTYPE(sstr) != stype) {
1988 stype = SvTYPE(sstr);
1989 if (stype == SVt_PVGV && dtype <= SVt_PVGV)
1994 sv_upgrade(dstr, stype);
1997 sflags = SvFLAGS(sstr);
1999 if (sflags & SVf_ROK) {
2000 if (dtype >= SVt_PV) {
2001 if (dtype == SVt_PVGV) {
2003 SV *sref = SvREFCNT_inc(SvRV(sstr));
2005 int intro = GvINTRO(dstr);
2009 GvGP(dstr)->gp_refcnt--;
2010 GvINTRO_off(dstr); /* one-shot flag */
2011 Newz(602,gp, 1, GP);
2012 GvGP(dstr) = gp_ref(gp);
2013 GvSV(dstr) = NEWSV(72,0);
2014 GvLINE(dstr) = curcop->cop_line;
2015 GvEGV(dstr) = (GV*)dstr;
2018 switch (SvTYPE(sref)) {
2021 SAVESPTR(GvAV(dstr));
2023 dref = (SV*)GvAV(dstr);
2024 GvAV(dstr) = (AV*)sref;
2025 if (curcop->cop_stash != GvSTASH(dstr))
2026 GvIMPORTED_AV_on(dstr);
2030 SAVESPTR(GvHV(dstr));
2032 dref = (SV*)GvHV(dstr);
2033 GvHV(dstr) = (HV*)sref;
2034 if (curcop->cop_stash != GvSTASH(dstr))
2035 GvIMPORTED_HV_on(dstr);
2039 if (GvCVGEN(dstr) && GvCV(dstr) != (CV*)sref) {
2040 SvREFCNT_dec(GvCV(dstr));
2041 GvCV(dstr) = Nullcv;
2042 GvCVGEN(dstr) = 0; /* Switch off cacheness. */
2045 SAVESPTR(GvCV(dstr));
2048 dref = (SV*)GvCV(dstr);
2049 if (GvCV(dstr) != (CV*)sref) {
2050 CV* cv = GvCV(dstr);
2052 if (!GvCVGEN((GV*)dstr) &&
2053 (CvROOT(cv) || CvXSUB(cv)))
2055 /* ahem, death to those who redefine
2056 * active sort subs */
2057 if (curstack == sortstack &&
2058 sortcop == CvSTART(cv))
2060 "Can't redefine active sort subroutine %s",
2061 GvENAME((GV*)dstr));
2062 if (cv_const_sv(cv))
2063 warn("Constant subroutine %s redefined",
2064 GvENAME((GV*)dstr));
2066 warn("Subroutine %s redefined",
2067 GvENAME((GV*)dstr));
2069 cv_ckproto(cv, (GV*)dstr,
2070 SvPOK(sref) ? SvPVX(sref) : Nullch);
2072 GvCV(dstr) = (CV*)sref;
2073 GvCVGEN(dstr) = 0; /* Switch off cacheness. */
2074 GvASSUMECV_on(dstr);
2077 if (curcop->cop_stash != GvSTASH(dstr))
2078 GvIMPORTED_CV_on(dstr);
2082 SAVESPTR(GvIOp(dstr));
2084 dref = (SV*)GvIOp(dstr);
2085 GvIOp(dstr) = (IO*)sref;
2089 SAVESPTR(GvSV(dstr));
2091 dref = (SV*)GvSV(dstr);
2093 if (curcop->cop_stash != GvSTASH(dstr))
2094 GvIMPORTED_SV_on(dstr);
2105 (void)SvOOK_off(dstr); /* backoff */
2106 Safefree(SvPVX(dstr));
2107 SvLEN(dstr)=SvCUR(dstr)=0;
2110 (void)SvOK_off(dstr);
2111 SvRV(dstr) = SvREFCNT_inc(SvRV(sstr));
2113 if (sflags & SVp_NOK) {
2115 SvNVX(dstr) = SvNVX(sstr);
2117 if (sflags & SVp_IOK) {
2118 (void)SvIOK_on(dstr);
2119 SvIVX(dstr) = SvIVX(sstr);
2122 if (SvAMAGIC(sstr)) {
2125 #endif /* OVERLOAD */
2127 else if (sflags & SVp_POK) {
2130 * Check to see if we can just swipe the string. If so, it's a
2131 * possible small lose on short strings, but a big win on long ones.
2132 * It might even be a win on short strings if SvPVX(dstr)
2133 * has to be allocated and SvPVX(sstr) has to be freed.
2136 if (SvTEMP(sstr) && /* slated for free anyway? */
2137 SvREFCNT(sstr) == 1 && /* and no other references to it? */
2138 !(sflags & SVf_OOK)) /* and not involved in OOK hack? */
2140 if (SvPVX(dstr)) { /* we know that dtype >= SVt_PV */
2142 SvFLAGS(dstr) &= ~SVf_OOK;
2143 Safefree(SvPVX(dstr) - SvIVX(dstr));
2146 Safefree(SvPVX(dstr));
2148 (void)SvPOK_only(dstr);
2149 SvPV_set(dstr, SvPVX(sstr));
2150 SvLEN_set(dstr, SvLEN(sstr));
2151 SvCUR_set(dstr, SvCUR(sstr));
2153 (void)SvOK_off(sstr);
2154 SvPV_set(sstr, Nullch);
2159 else { /* have to copy actual string */
2160 STRLEN len = SvCUR(sstr);
2162 SvGROW(dstr, len + 1); /* inlined from sv_setpvn */
2163 Move(SvPVX(sstr),SvPVX(dstr),len,char);
2164 SvCUR_set(dstr, len);
2165 *SvEND(dstr) = '\0';
2166 (void)SvPOK_only(dstr);
2169 if (sflags & SVp_NOK) {
2171 SvNVX(dstr) = SvNVX(sstr);
2173 if (sflags & SVp_IOK) {
2174 (void)SvIOK_on(dstr);
2175 SvIVX(dstr) = SvIVX(sstr);
2178 else if (sflags & SVp_NOK) {
2179 SvNVX(dstr) = SvNVX(sstr);
2180 (void)SvNOK_only(dstr);
2182 (void)SvIOK_on(dstr);
2183 SvIVX(dstr) = SvIVX(sstr);
2186 else if (sflags & SVp_IOK) {
2187 (void)SvIOK_only(dstr);
2188 SvIVX(dstr) = SvIVX(sstr);
2191 (void)SvOK_off(dstr);
2197 sv_setsv_mg(SV *dstr, register SV *sstr)
2199 sv_setsv(dstr,sstr);
2204 sv_setpvn(register SV *sv, register const char *ptr, register STRLEN len)
2206 register char *dptr;
2207 assert(len >= 0); /* STRLEN is probably unsigned, so this may
2208 elicit a warning, but it won't hurt. */
2209 SV_CHECK_THINKFIRST(sv);
2214 if (SvTYPE(sv) >= SVt_PV) {
2215 if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV)
2219 sv_upgrade(sv, SVt_PV);
2221 SvGROW(sv, len + 1);
2223 Move(ptr,dptr,len,char);
2226 (void)SvPOK_only(sv); /* validate pointer */
2231 sv_setpvn_mg(register SV *sv, register const char *ptr, register STRLEN len)
2233 sv_setpvn(sv,ptr,len);
2238 sv_setpv(register SV *sv, register const char *ptr)
2240 register STRLEN len;
2242 SV_CHECK_THINKFIRST(sv);
2248 if (SvTYPE(sv) >= SVt_PV) {
2249 if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV)
2253 sv_upgrade(sv, SVt_PV);
2255 SvGROW(sv, len + 1);
2256 Move(ptr,SvPVX(sv),len+1,char);
2258 (void)SvPOK_only(sv); /* validate pointer */
2263 sv_setpv_mg(register SV *sv, register const char *ptr)
2270 sv_usepvn(register SV *sv, register char *ptr, register STRLEN len)
2272 SV_CHECK_THINKFIRST(sv);
2273 (void)SvUPGRADE(sv, SVt_PV);
2279 Safefree(SvPVX(sv));
2280 Renew(ptr, len+1, char);
2283 SvLEN_set(sv, len+1);
2285 (void)SvPOK_only(sv); /* validate pointer */
2290 sv_usepvn_mg(register SV *sv, register char *ptr, register STRLEN len)
2292 sv_usepvn_mg(sv,ptr,len);
2297 sv_check_thinkfirst(register SV *sv)
2299 if (SvREADONLY(sv)) {
2301 if (curcop != &compiling)
2309 sv_chop(register SV *sv, register char *ptr) /* like set but assuming ptr is in sv */
2313 register STRLEN delta;
2315 if (!ptr || !SvPOKp(sv))
2317 SV_CHECK_THINKFIRST(sv);
2318 if (SvTYPE(sv) < SVt_PVIV)
2319 sv_upgrade(sv,SVt_PVIV);
2323 SvFLAGS(sv) |= SVf_OOK;
2325 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVp_IOK|SVp_NOK);
2326 delta = ptr - SvPVX(sv);
2334 sv_catpvn(register SV *sv, register char *ptr, register STRLEN len)
2339 junk = SvPV_force(sv, tlen);
2340 SvGROW(sv, tlen + len + 1);
2343 Move(ptr,SvPVX(sv)+tlen,len,char);
2346 (void)SvPOK_only(sv); /* validate pointer */
2351 sv_catpvn_mg(register SV *sv, register char *ptr, register STRLEN len)
2353 sv_catpvn(sv,ptr,len);
2358 sv_catsv(SV *dstr, register SV *sstr)
2364 if (s = SvPV(sstr, len))
2365 sv_catpvn(dstr,s,len);
2369 sv_catsv_mg(SV *dstr, register SV *sstr)
2371 sv_catsv(dstr,sstr);
2376 sv_catpv(register SV *sv, register char *ptr)
2378 register STRLEN len;
2384 junk = SvPV_force(sv, tlen);
2386 SvGROW(sv, tlen + len + 1);
2389 Move(ptr,SvPVX(sv)+tlen,len+1,char);
2391 (void)SvPOK_only(sv); /* validate pointer */
2396 sv_catpv_mg(register SV *sv, register char *ptr)
2398 sv_catpv_mg(sv,ptr);
2404 newSV(I32 x, STRLEN len)
2416 sv_upgrade(sv, SVt_PV);
2417 SvGROW(sv, len + 1);
2422 /* name is assumed to contain an SV* if (name && namelen == HEf_SVKEY) */
2425 sv_magic(register SV *sv, SV *obj, int how, char *name, I32 namlen)
2429 if (SvREADONLY(sv)) {
2431 if (curcop != &compiling && !strchr("gBf", how))
2434 if (SvMAGICAL(sv) || (how == 't' && SvTYPE(sv) >= SVt_PVMG)) {
2435 if (SvMAGIC(sv) && (mg = mg_find(sv, how))) {
2442 (void)SvUPGRADE(sv, SVt_PVMG);
2444 Newz(702,mg, 1, MAGIC);
2445 mg->mg_moremagic = SvMAGIC(sv);
2448 if (!obj || obj == sv || how == '#' || how == 'r')
2452 mg->mg_obj = SvREFCNT_inc(obj);
2453 mg->mg_flags |= MGf_REFCOUNTED;
2456 mg->mg_len = namlen;
2459 mg->mg_ptr = savepvn(name, namlen);
2460 else if (namlen == HEf_SVKEY)
2461 mg->mg_ptr = (char*)SvREFCNT_inc((SV*)name);
2465 mg->mg_virtual = &vtbl_sv;
2469 mg->mg_virtual = &vtbl_amagic;
2472 mg->mg_virtual = &vtbl_amagicelem;
2477 #endif /* OVERLOAD */
2479 mg->mg_virtual = &vtbl_bm;
2482 mg->mg_virtual = &vtbl_env;
2485 mg->mg_virtual = &vtbl_fm;
2488 mg->mg_virtual = &vtbl_envelem;
2491 mg->mg_virtual = &vtbl_mglob;
2494 mg->mg_virtual = &vtbl_isa;
2497 mg->mg_virtual = &vtbl_isaelem;
2500 mg->mg_virtual = &vtbl_nkeys;
2507 mg->mg_virtual = &vtbl_dbline;
2511 mg->mg_virtual = &vtbl_mutex;
2513 #endif /* USE_THREADS */
2514 #ifdef USE_LOCALE_COLLATE
2516 mg->mg_virtual = &vtbl_collxfrm;
2518 #endif /* USE_LOCALE_COLLATE */
2520 mg->mg_virtual = &vtbl_pack;
2524 mg->mg_virtual = &vtbl_packelem;
2527 mg->mg_virtual = &vtbl_regexp;
2530 mg->mg_virtual = &vtbl_sig;
2533 mg->mg_virtual = &vtbl_sigelem;
2536 mg->mg_virtual = &vtbl_taint;
2540 mg->mg_virtual = &vtbl_uvar;
2543 mg->mg_virtual = &vtbl_vec;
2546 mg->mg_virtual = &vtbl_substr;
2549 mg->mg_virtual = &vtbl_defelem;
2552 mg->mg_virtual = &vtbl_glob;
2555 mg->mg_virtual = &vtbl_arylen;
2558 mg->mg_virtual = &vtbl_pos;
2560 case '~': /* Reserved for use by extensions not perl internals. */
2561 /* Useful for attaching extension internal data to perl vars. */
2562 /* Note that multiple extensions may clash if magical scalars */
2563 /* etc holding private data from one are passed to another. */
2567 croak("Don't know how to handle magic of type '%c'", how);
2571 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
2575 sv_unmagic(SV *sv, int type)
2579 if (SvTYPE(sv) < SVt_PVMG || !SvMAGIC(sv))
2582 for (mg = *mgp; mg; mg = *mgp) {
2583 if (mg->mg_type == type) {
2584 MGVTBL* vtbl = mg->mg_virtual;
2585 *mgp = mg->mg_moremagic;
2586 if (vtbl && vtbl->svt_free)
2587 (*vtbl->svt_free)(sv, mg);
2588 if (mg->mg_ptr && mg->mg_type != 'g')
2589 if (mg->mg_len >= 0)
2590 Safefree(mg->mg_ptr);
2591 else if (mg->mg_len == HEf_SVKEY)
2592 SvREFCNT_dec((SV*)mg->mg_ptr);
2593 if (mg->mg_flags & MGf_REFCOUNTED)
2594 SvREFCNT_dec(mg->mg_obj);
2598 mgp = &mg->mg_moremagic;
2602 SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
2609 sv_insert(SV *bigstr, STRLEN offset, STRLEN len, char *little, STRLEN littlelen)
2613 register char *midend;
2614 register char *bigend;
2618 croak("Can't modify non-existent substring");
2619 SvPV_force(bigstr, na);
2621 i = littlelen - len;
2622 if (i > 0) { /* string might grow */
2623 big = SvGROW(bigstr, SvCUR(bigstr) + i + 1);
2624 mid = big + offset + len;
2625 midend = bigend = big + SvCUR(bigstr);
2628 while (midend > mid) /* shove everything down */
2629 *--bigend = *--midend;
2630 Move(little,big+offset,littlelen,char);
2636 Move(little,SvPVX(bigstr)+offset,len,char);
2641 big = SvPVX(bigstr);
2644 bigend = big + SvCUR(bigstr);
2646 if (midend > bigend)
2647 croak("panic: sv_insert");
2649 if (mid - big > bigend - midend) { /* faster to shorten from end */
2651 Move(little, mid, littlelen,char);
2654 i = bigend - midend;
2656 Move(midend, mid, i,char);
2660 SvCUR_set(bigstr, mid - big);
2663 else if (i = mid - big) { /* faster from front */
2664 midend -= littlelen;
2666 sv_chop(bigstr,midend-i);
2671 Move(little, mid, littlelen,char);
2673 else if (littlelen) {
2674 midend -= littlelen;
2675 sv_chop(bigstr,midend);
2676 Move(little,midend,littlelen,char);
2679 sv_chop(bigstr,midend);
2684 /* make sv point to what nstr did */
2687 sv_replace(register SV *sv, register SV *nsv)
2689 U32 refcnt = SvREFCNT(sv);
2690 SV_CHECK_THINKFIRST(sv);
2691 if (SvREFCNT(nsv) != 1)
2692 warn("Reference miscount in sv_replace()");
2693 if (SvMAGICAL(sv)) {
2697 sv_upgrade(nsv, SVt_PVMG);
2698 SvMAGIC(nsv) = SvMAGIC(sv);
2699 SvFLAGS(nsv) |= SvMAGICAL(sv);
2705 assert(!SvREFCNT(sv));
2706 StructCopy(nsv,sv,SV);
2707 SvREFCNT(sv) = refcnt;
2708 SvFLAGS(nsv) |= SVTYPEMASK; /* Mark as freed */
2713 sv_clear(register SV *sv)
2716 assert(SvREFCNT(sv) == 0);
2720 if (defstash) { /* Still have a symbol table? */
2727 sv_upgrade(&ref, SVt_RV);
2729 SvREADONLY_on(&ref); /* DESTROY() could be naughty */
2733 stash = SvSTASH(sv);
2734 destructor = gv_fetchmethod(SvSTASH(sv), "DESTROY");
2737 SvRV(&ref) = SvREFCNT_inc(sv);
2742 perl_call_sv((SV*)GvCV(destructor),
2743 G_DISCARD|G_EVAL|G_KEEPERR);
2747 } while (SvOBJECT(sv) && SvSTASH(sv) != stash);
2749 del_XRV(SvANY(&ref));
2753 SvREFCNT_dec(SvSTASH(sv)); /* possibly of changed persuasion */
2754 SvOBJECT_off(sv); /* Curse the object. */
2755 if (SvTYPE(sv) != SVt_PVIO)
2756 --sv_objcount; /* XXX Might want something more general */
2760 croak("DESTROY created new reference to dead object");
2761 /* DESTROY gave object new lease on life */
2765 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv))
2767 switch (SvTYPE(sv)) {
2769 if (IoIFP(sv) != PerlIO_stdin() &&
2770 IoIFP(sv) != PerlIO_stdout() &&
2771 IoIFP(sv) != PerlIO_stderr())
2773 Safefree(IoTOP_NAME(sv));
2774 Safefree(IoFMT_NAME(sv));
2775 Safefree(IoBOTTOM_NAME(sv));
2791 Safefree(GvNAME(sv));
2792 SvREFCNT_dec(GvSTASH(sv));
2799 (void)SvOOK_off(sv);
2804 SvREFCNT_dec(SvRV(sv));
2805 else if (SvPVX(sv) && SvLEN(sv))
2806 Safefree(SvPVX(sv));
2816 switch (SvTYPE(sv)) {
2832 del_XPVIV(SvANY(sv));
2835 del_XPVNV(SvANY(sv));
2838 del_XPVMG(SvANY(sv));
2841 del_XPVLV(SvANY(sv));
2844 del_XPVAV(SvANY(sv));
2847 del_XPVHV(SvANY(sv));
2850 del_XPVCV(SvANY(sv));
2853 del_XPVGV(SvANY(sv));
2856 del_XPVBM(SvANY(sv));
2859 del_XPVFM(SvANY(sv));
2862 del_XPVIO(SvANY(sv));
2865 SvFLAGS(sv) &= SVf_BREAK;
2866 SvFLAGS(sv) |= SVTYPEMASK;
2882 if (SvREADONLY(sv)) {
2883 if (sv == &sv_undef || sv == &sv_yes || sv == &sv_no)
2886 if (SvREFCNT(sv) == 0) {
2887 if (SvFLAGS(sv) & SVf_BREAK)
2889 if (in_clean_all) /* All is fair */
2891 warn("Attempt to free unreferenced scalar");
2894 if (--SvREFCNT(sv) > 0)
2898 warn("Attempt to free temp prematurely: %s", SvPEEK(sv));
2908 sv_len(register SV *sv)
2919 junk = SvPV(sv, len);
2924 sv_eq(register SV *str1, register SV *str2)
2936 pv1 = SvPV(str1, cur1);
2941 pv2 = SvPV(str2, cur2);
2946 return memEQ(pv1, pv2, cur1);
2950 sv_cmp(register SV *str1, register SV *str2)
2953 char *pv1 = str1 ? SvPV(str1, cur1) : (char *) NULL;
2955 char *pv2 = str2 ? SvPV(str2, cur2) : (char *) NULL;
2959 return cur2 ? -1 : 0;
2964 retval = memcmp((void*)pv1, (void*)pv2, cur1 < cur2 ? cur1 : cur2);
2967 return retval < 0 ? -1 : 1;
2972 return cur1 < cur2 ? -1 : 1;
2976 sv_cmp_locale(register SV *sv1, register SV *sv2)
2978 #ifdef USE_LOCALE_COLLATE
2984 if (collation_standard)
2988 pv1 = sv1 ? sv_collxfrm(sv1, &len1) : (char *) NULL;
2990 pv2 = sv2 ? sv_collxfrm(sv2, &len2) : (char *) NULL;
2992 if (!pv1 || !len1) {
3003 retval = memcmp((void*)pv1, (void*)pv2, len1 < len2 ? len1 : len2);
3006 return retval < 0 ? -1 : 1;
3009 * When the result of collation is equality, that doesn't mean
3010 * that there are no differences -- some locales exclude some
3011 * characters from consideration. So to avoid false equalities,
3012 * we use the raw string as a tiebreaker.
3018 #endif /* USE_LOCALE_COLLATE */
3020 return sv_cmp(sv1, sv2);
3023 #ifdef USE_LOCALE_COLLATE
3025 * Any scalar variable may carry an 'o' magic that contains the
3026 * scalar data of the variable transformed to such a format that
3027 * a normal memory comparison can be used to compare the data
3028 * according to the locale settings.
3031 sv_collxfrm(SV *sv, STRLEN *nxp)
3035 mg = SvMAGICAL(sv) ? mg_find(sv, 'o') : (MAGIC *) NULL;
3036 if (!mg || !mg->mg_ptr || *(U32*)mg->mg_ptr != collation_ix) {
3041 Safefree(mg->mg_ptr);
3043 if ((xf = mem_collxfrm(s, len, &xlen))) {
3044 if (SvREADONLY(sv)) {
3047 return xf + sizeof(collation_ix);
3050 sv_magic(sv, 0, 'o', 0, 0);
3051 mg = mg_find(sv, 'o');
3064 if (mg && mg->mg_ptr) {
3066 return mg->mg_ptr + sizeof(collation_ix);
3074 #endif /* USE_LOCALE_COLLATE */
3077 sv_gets(register SV *sv, register PerlIO *fp, I32 append)
3082 register STDCHAR rslast;
3083 register STDCHAR *bp;
3087 SV_CHECK_THINKFIRST(sv);
3088 (void)SvUPGRADE(sv, SVt_PV);
3095 else if (RsPARA(rs)) {
3100 rsptr = SvPV(rs, rslen);
3101 rslast = rslen ? rsptr[rslen - 1] : '\0';
3103 if (RsPARA(rs)) { /* have to do this both before and after */
3104 do { /* to make sure file boundaries work right */
3107 i = PerlIO_getc(fp);
3111 PerlIO_ungetc(fp,i);
3117 /* See if we know enough about I/O mechanism to cheat it ! */
3119 /* This used to be #ifdef test - it is made run-time test for ease
3120 of abstracting out stdio interface. One call should be cheap
3121 enough here - and may even be a macro allowing compile
3125 if (PerlIO_fast_gets(fp)) {
3128 * We're going to steal some values from the stdio struct
3129 * and put EVERYTHING in the innermost loop into registers.
3131 register STDCHAR *ptr;
3135 #if defined(VMS) && defined(PERLIO_IS_STDIO)
3136 /* An ungetc()d char is handled separately from the regular
3137 * buffer, so we getc() it back out and stuff it in the buffer.
3139 i = PerlIO_getc(fp);
3140 if (i == EOF) return 0;
3141 *(--((*fp)->_ptr)) = (unsigned char) i;
3145 /* Here is some breathtakingly efficient cheating */
3147 cnt = PerlIO_get_cnt(fp); /* get count into register */
3148 (void)SvPOK_only(sv); /* validate pointer */
3149 if (SvLEN(sv) - append <= cnt + 1) { /* make sure we have the room */
3150 if (cnt > 80 && SvLEN(sv) > append) {
3151 shortbuffered = cnt - SvLEN(sv) + append + 1;
3152 cnt -= shortbuffered;
3156 /* remember that cnt can be negative */
3157 SvGROW(sv, append + (cnt <= 0 ? 2 : (cnt + 1)));
3162 bp = (STDCHAR*)SvPVX(sv) + append; /* move these two too to registers */
3163 ptr = (STDCHAR*)PerlIO_get_ptr(fp);
3164 DEBUG_P(PerlIO_printf(Perl_debug_log,
3165 "Screamer: entering, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3166 DEBUG_P(PerlIO_printf(Perl_debug_log,
3167 "Screamer: entering: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3168 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3169 (long)(PerlIO_has_base(fp) ? PerlIO_get_base(fp) : 0)));
3174 while (cnt > 0) { /* this | eat */
3176 if ((*bp++ = *ptr++) == rslast) /* really | dust */
3177 goto thats_all_folks; /* screams | sed :-) */
3181 Copy(ptr, bp, cnt, char); /* this | eat */
3182 bp += cnt; /* screams | dust */
3183 ptr += cnt; /* louder | sed :-) */
3188 if (shortbuffered) { /* oh well, must extend */
3189 cnt = shortbuffered;
3191 bpx = bp - (STDCHAR*)SvPVX(sv); /* box up before relocation */
3193 SvGROW(sv, SvLEN(sv) + append + cnt + 2);
3194 bp = (STDCHAR*)SvPVX(sv) + bpx; /* unbox after relocation */
3198 DEBUG_P(PerlIO_printf(Perl_debug_log,
3199 "Screamer: going to getc, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3200 PerlIO_set_ptrcnt(fp, ptr, cnt); /* deregisterize cnt and ptr */
3201 DEBUG_P(PerlIO_printf(Perl_debug_log,
3202 "Screamer: pre: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3203 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3204 (long)(PerlIO_has_base (fp) ? PerlIO_get_base(fp) : 0)));
3205 /* This used to call 'filbuf' in stdio form, but as that behaves like
3206 getc when cnt <= 0 we use PerlIO_getc here to avoid introducing
3207 another abstraction. */
3208 i = PerlIO_getc(fp); /* get more characters */
3209 DEBUG_P(PerlIO_printf(Perl_debug_log,
3210 "Screamer: post: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3211 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3212 (long)(PerlIO_has_base (fp) ? PerlIO_get_base(fp) : 0)));
3213 cnt = PerlIO_get_cnt(fp);
3214 ptr = (STDCHAR*)PerlIO_get_ptr(fp); /* reregisterize cnt and ptr */
3215 DEBUG_P(PerlIO_printf(Perl_debug_log,
3216 "Screamer: after getc, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3218 if (i == EOF) /* all done for ever? */
3219 goto thats_really_all_folks;
3221 bpx = bp - (STDCHAR*)SvPVX(sv); /* box up before relocation */
3223 SvGROW(sv, bpx + cnt + 2);
3224 bp = (STDCHAR*)SvPVX(sv) + bpx; /* unbox after relocation */
3226 *bp++ = i; /* store character from PerlIO_getc */
3228 if (rslen && (STDCHAR)i == rslast) /* all done for now? */
3229 goto thats_all_folks;
3233 if ((rslen > 1 && (bp - (STDCHAR*)SvPVX(sv) < rslen)) ||
3234 memNE((char*)bp - rslen, rsptr, rslen))
3235 goto screamer; /* go back to the fray */
3236 thats_really_all_folks:
3238 cnt += shortbuffered;
3239 DEBUG_P(PerlIO_printf(Perl_debug_log,
3240 "Screamer: quitting, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3241 PerlIO_set_ptrcnt(fp, ptr, cnt); /* put these back or we're in trouble */
3242 DEBUG_P(PerlIO_printf(Perl_debug_log,
3243 "Screamer: end: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3244 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3245 (long)(PerlIO_has_base (fp) ? PerlIO_get_base(fp) : 0)));
3247 SvCUR_set(sv, bp - (STDCHAR*)SvPVX(sv)); /* set length */
3248 DEBUG_P(PerlIO_printf(Perl_debug_log,
3249 "Screamer: done, len=%ld, string=|%.*s|\n",
3250 (long)SvCUR(sv),(int)SvCUR(sv),SvPVX(sv)));
3254 /*The big, slow, and stupid way */
3259 register STDCHAR *bpe = buf + sizeof(buf);
3261 while ((i = PerlIO_getc(fp)) != EOF && (*bp++ = i) != rslast && bp < bpe)
3262 ; /* keep reading */
3266 cnt = PerlIO_read(fp,(char*)buf, sizeof(buf));
3267 /* Accomodate broken VAXC compiler, which applies U8 cast to
3268 * both args of ?: operator, causing EOF to change into 255
3270 if (cnt) { i = (U8)buf[cnt - 1]; } else { i = EOF; }
3274 sv_catpvn(sv, (char *) buf, cnt);
3276 sv_setpvn(sv, (char *) buf, cnt);
3278 if (i != EOF && /* joy */
3280 SvCUR(sv) < rslen ||
3281 memNE(SvPVX(sv) + SvCUR(sv) - rslen, rsptr, rslen)))
3285 * If we're reading from a TTY and we get a short read,
3286 * indicating that the user hit his EOF character, we need
3287 * to notice it now, because if we try to read from the TTY
3288 * again, the EOF condition will disappear.
3290 * The comparison of cnt to sizeof(buf) is an optimization
3291 * that prevents unnecessary calls to feof().
3295 if (!(cnt < sizeof(buf) && PerlIO_eof(fp)))
3300 if (RsPARA(rs)) { /* have to do this both before and after */
3301 while (i != EOF) { /* to make sure file boundaries work right */
3302 i = PerlIO_getc(fp);
3304 PerlIO_ungetc(fp,i);
3311 win32_strip_return(sv);
3314 return (SvCUR(sv) - append) ? SvPVX(sv) : Nullch;
3319 sv_inc(register SV *sv)
3326 if (SvTHINKFIRST(sv)) {
3327 if (SvREADONLY(sv)) {
3329 if (curcop != &compiling)
3334 if (SvAMAGIC(sv) && AMG_CALLun(sv,inc)) return;
3335 #endif /* OVERLOAD */
3341 flags = SvFLAGS(sv);
3342 if (flags & SVp_NOK) {
3343 (void)SvNOK_only(sv);
3347 if (flags & SVp_IOK) {
3348 if (SvIVX(sv) == IV_MAX)
3349 sv_setnv(sv, (double)IV_MAX + 1.0);
3351 (void)SvIOK_only(sv);
3356 if (!(flags & SVp_POK) || !*SvPVX(sv)) {
3357 if ((flags & SVTYPEMASK) < SVt_PVNV)
3358 sv_upgrade(sv, SVt_NV);
3360 (void)SvNOK_only(sv);
3364 while (isALPHA(*d)) d++;
3365 while (isDIGIT(*d)) d++;
3367 SET_NUMERIC_STANDARD();
3368 sv_setnv(sv,atof(SvPVX(sv)) + 1.0); /* punt */
3372 while (d >= SvPVX(sv)) {
3382 *(d--) -= 'z' - 'a' + 1;
3385 /* oh,oh, the number grew */
3386 SvGROW(sv, SvCUR(sv) + 2);
3388 for (d = SvPVX(sv) + SvCUR(sv); d > SvPVX(sv); d--)
3397 sv_dec(register SV *sv)
3403 if (SvTHINKFIRST(sv)) {
3404 if (SvREADONLY(sv)) {
3406 if (curcop != &compiling)
3411 if (SvAMAGIC(sv) && AMG_CALLun(sv,dec)) return;
3412 #endif /* OVERLOAD */
3418 flags = SvFLAGS(sv);
3419 if (flags & SVp_NOK) {
3421 (void)SvNOK_only(sv);
3424 if (flags & SVp_IOK) {
3425 if (SvIVX(sv) == IV_MIN)
3426 sv_setnv(sv, (double)IV_MIN - 1.0);
3428 (void)SvIOK_only(sv);
3433 if (!(flags & SVp_POK)) {
3434 if ((flags & SVTYPEMASK) < SVt_PVNV)
3435 sv_upgrade(sv, SVt_NV);
3437 (void)SvNOK_only(sv);
3440 SET_NUMERIC_STANDARD();
3441 sv_setnv(sv,atof(SvPVX(sv)) - 1.0); /* punt */
3444 /* Make a string that will exist for the duration of the expression
3445 * evaluation. Actually, it may have to last longer than that, but
3446 * hopefully we won't free it until it has been assigned to a
3447 * permanent location. */
3453 tmps_max += (tmps_max < 512) ? 128 : 512;
3454 Renew(tmps_stack, tmps_max, SV*);
3458 sv_mortalcopy(SV *oldstr)
3467 sv_setsv(sv,oldstr);
3468 if (++tmps_ix >= tmps_max)
3470 tmps_stack[tmps_ix] = sv;
3484 SvFLAGS(sv) = SVs_TEMP;
3485 if (++tmps_ix >= tmps_max)
3487 tmps_stack[tmps_ix] = sv;
3491 /* same thing without the copying */
3494 sv_2mortal(register SV *sv)
3499 if (SvREADONLY(sv) && curcop != &compiling)
3501 if (++tmps_ix >= tmps_max)
3503 tmps_stack[tmps_ix] = sv;
3509 newSVpv(char *s, STRLEN len)
3519 sv_setpvn(sv,s,len);
3534 sv_setpvn(sv,s,len);
3540 newSVpvf(const char* pat, ...)
3544 newSVpvf(pat, va_alist)
3557 va_start(args, pat);
3561 sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
3603 sv_upgrade(sv, SVt_RV);
3605 SvRV(sv) = SvREFCNT_inc(ref);
3613 Perl_newRV_noinc(SV *ref)
3622 /* make an exact duplicate of old */
3625 newSVsv(register SV *old)
3631 if (SvTYPE(old) == SVTYPEMASK) {
3632 warn("semi-panic: attempt to dup freed string");
3650 sv_reset(register char *s, HV *stash)
3663 if (!*s) { /* reset ?? searches */
3664 for (pm = HvPMROOT(stash); pm; pm = pm->op_pmnext) {
3665 pm->op_pmflags &= ~PMf_USED;
3670 /* reset variables */
3672 if (!HvARRAY(stash))
3675 Zero(todo, 256, char);
3682 for ( ; i <= max; i++) {
3685 for (i = 0; i <= (I32) HvMAX(stash); i++) {
3686 for (entry = HvARRAY(stash)[i];
3688 entry = HeNEXT(entry)) {
3689 if (!todo[(U8)*HeKEY(entry)])
3691 gv = (GV*)HeVAL(entry);
3694 if (SvTYPE(sv) >= SVt_PV) {
3696 if (SvPVX(sv) != Nullch)
3703 if (GvHV(gv) && !HvNAME(GvHV(gv))) {
3705 #ifndef VMS /* VMS has no environ array */
3707 environ[0] = Nullch;
3721 switch (SvTYPE(sv)) {
3729 croak("Bad filehandle: %s", GvNAME(gv));
3733 croak(no_usym, "filehandle");
3735 return sv_2io(SvRV(sv));
3736 gv = gv_fetchpv(SvPV(sv,na), FALSE, SVt_PVIO);
3742 croak("Bad filehandle: %s", SvPV(sv,na));
3749 sv_2cv(SV *sv, HV **st, GV **gvp, I32 lref)
3755 return *gvp = Nullgv, Nullcv;
3756 switch (SvTYPE(sv)) {
3776 if (SvTYPE(cv) != SVt_PVCV)
3777 croak("Not a subroutine reference");
3785 gv = gv_fetchpv(SvPV(sv, na), lref, SVt_PVCV);
3791 if (lref && !GvCVu(gv)) {
3794 tmpsv = NEWSV(704,0);
3795 gv_efullname3(tmpsv, gv, Nullch);
3796 newSUB(start_subparse(FALSE, 0),
3797 newSVOP(OP_CONST, 0, tmpsv),
3802 croak("Unable to create sub named \"%s\"", SvPV(sv,na));
3809 sv_true(register SV *sv)
3816 if ((tXpv = (XPV*)SvANY(sv)) &&
3817 (*tXpv->xpv_pv > '0' ||
3818 tXpv->xpv_cur > 1 ||
3819 (tXpv->xpv_cur && *tXpv->xpv_pv != '0')))
3826 return SvIVX(sv) != 0;
3829 return SvNVX(sv) != 0.0;
3831 return sv_2bool(sv);
3837 sv_iv(register SV *sv)
3845 sv_uv(register SV *sv)
3853 sv_nv(register SV *sv)
3861 sv_pvn(SV *sv, STRLEN *lp)
3867 return sv_2pv(sv, lp);
3871 sv_pvn_force(SV *sv, STRLEN *lp)
3875 if (SvREADONLY(sv)) {
3877 if (curcop != &compiling)
3885 if (SvTYPE(sv) > SVt_PVLV && SvTYPE(sv) != SVt_PVFM) {
3886 if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV) {
3893 croak("Can't coerce %s to string in %s", sv_reftype(sv,0),
3894 op_name[op->op_type]);
3899 if (s != SvPVX(sv)) { /* Almost, but not quite, sv_setpvn() */
3904 (void)SvUPGRADE(sv, SVt_PV); /* Never FALSE */
3905 SvGROW(sv, len + 1);
3906 Move(s,SvPVX(sv),len,char);
3911 SvPOK_on(sv); /* validate pointer */
3913 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2pv(%s)\n",
3914 (unsigned long)sv,SvPVX(sv)));
3921 sv_reftype(SV *sv, int ob)
3923 if (ob && SvOBJECT(sv))
3924 return HvNAME(SvSTASH(sv));
3926 switch (SvTYPE(sv)) {
3940 case SVt_PVLV: return "LVALUE";
3941 case SVt_PVAV: return "ARRAY";
3942 case SVt_PVHV: return "HASH";
3943 case SVt_PVCV: return "CODE";
3944 case SVt_PVGV: return "GLOB";
3945 case SVt_PVFM: return "FORMLINE";
3946 default: return "UNKNOWN";
3967 sv_isa(SV *sv, char *name)
3979 return strEQ(HvNAME(SvSTASH(sv)), name);
3983 newSVrv(SV *rv, char *classname)
3993 SV_CHECK_THINKFIRST(rv);
3996 #endif /* OVERLOAD */
3998 if (SvTYPE(rv) < SVt_RV)
3999 sv_upgrade(rv, SVt_RV);
4002 SvRV(rv) = SvREFCNT_inc(sv);
4006 HV* stash = gv_stashpv(classname, TRUE);
4007 (void)sv_bless(rv, stash);
4013 sv_setref_pv(SV *rv, char *classname, void *pv)
4016 sv_setsv(rv, &sv_undef);
4020 sv_setiv(newSVrv(rv,classname), (IV)pv);
4025 sv_setref_iv(SV *rv, char *classname, IV iv)
4027 sv_setiv(newSVrv(rv,classname), iv);
4032 sv_setref_nv(SV *rv, char *classname, double nv)
4034 sv_setnv(newSVrv(rv,classname), nv);
4039 sv_setref_pvn(SV *rv, char *classname, char *pv, I32 n)
4041 sv_setpvn(newSVrv(rv,classname), pv, n);
4046 sv_bless(SV *sv, HV *stash)
4051 croak("Can't bless non-reference value");
4053 if (SvFLAGS(ref) & (SVs_OBJECT|SVf_READONLY)) {
4054 if (SvREADONLY(ref))
4056 if (SvOBJECT(ref)) {
4057 if (SvTYPE(ref) != SVt_PVIO)
4059 SvREFCNT_dec(SvSTASH(ref));
4063 if (SvTYPE(ref) != SVt_PVIO)
4065 (void)SvUPGRADE(ref, SVt_PVMG);
4066 SvSTASH(ref) = (HV*)SvREFCNT_inc(stash);
4073 #endif /* OVERLOAD */
4081 assert(SvTYPE(sv) == SVt_PVGV);
4085 sv_unmagic(sv, '*');
4086 Safefree(GvNAME(sv));
4088 SvFLAGS(sv) &= ~SVTYPEMASK;
4089 SvFLAGS(sv) |= SVt_PVMG;
4099 if (SvREFCNT(rv) != 1 || SvREADONLY(rv))
4102 sv_2mortal(rv); /* Schedule for freeing later */
4108 sv_magic((sv), Nullsv, 't', Nullch, 0);
4114 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
4115 MAGIC *mg = mg_find(sv, 't');
4124 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
4125 MAGIC *mg = mg_find(sv, 't');
4126 if (mg && ((mg->mg_len & 1) || (mg->mg_len & 2) && mg->mg_obj == sv))
4133 sv_setpviv(SV *sv, IV iv)
4136 char buf[TYPE_DIGITS(UV)];
4137 char *ptr = buf + sizeof(buf);
4142 sv_setpvn(sv, "", 0);
4151 *--ptr = '0' + (uv % 10);
4153 len = (buf + sizeof(buf)) - ptr;
4154 /* taking advantage of SvCUR(sv) == 0 */
4155 SvGROW(sv, sign + len + 1);
4159 memcpy(p, ptr, len);
4162 SvCUR(sv) = p - SvPVX(sv);
4167 sv_setpviv_mg(SV *sv, IV iv)
4175 sv_setpvf(SV *sv, const char* pat, ...)
4179 sv_setpvf(sv, pat, va_alist)
4187 va_start(args, pat);
4191 sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4198 sv_setpvf_mg(SV *sv, const char* pat, ...)
4202 sv_setpvf_mg(sv, pat, va_alist)
4210 va_start(args, pat);
4214 sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4221 sv_catpvf(SV *sv, const char* pat, ...)
4225 sv_catpvf(sv, pat, va_alist)
4233 va_start(args, pat);
4237 sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4243 sv_catpvf_mg(SV *sv, const char* pat, ...)
4247 sv_catpvf_mg(sv, pat, va_alist)
4255 va_start(args, pat);
4259 sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4265 sv_vsetpvfn(SV *sv, const char *pat, STRLEN patlen, va_list *args, SV **svargs, I32 svmax, bool *used_locale)
4267 sv_setpvn(sv, "", 0);
4268 sv_vcatpvfn(sv, pat, patlen, args, svargs, svmax, used_locale);
4272 sv_vcatpvfn(SV *sv, const char *pat, STRLEN patlen, va_list *args, SV **svargs, I32 svmax, bool *used_locale)
4280 static char nullstr[] = "(null)";
4282 /* no matter what, this is a string now */
4283 (void)SvPV_force(sv, origlen);
4285 /* special-case "", "%s", and "%_" */
4288 if (patlen == 2 && pat[0] == '%') {
4292 char *s = va_arg(*args, char*);
4293 sv_catpv(sv, s ? s : nullstr);
4295 else if (svix < svmax)
4296 sv_catsv(sv, *svargs);
4300 sv_catsv(sv, va_arg(*args, SV*));
4303 /* See comment on '_' below */
4308 patend = (char*)pat + patlen;
4309 for (p = (char*)pat; p < patend; p = q) {
4317 bool has_precis = FALSE;
4321 STRLEN esignlen = 0;
4323 char *eptr = Nullch;
4325 char ebuf[TYPE_DIGITS(int) * 2 + 16]; /* large enough for "%#.#f" */
4327 static char *efloatbuf = Nullch;
4328 static STRLEN efloatsize = 0;
4340 for (q = p; q < patend && *q != '%'; ++q) ;
4342 sv_catpvn(sv, p, q - p);
4380 case '1': case '2': case '3':
4381 case '4': case '5': case '6':
4382 case '7': case '8': case '9':
4385 width = width * 10 + (*q++ - '0');
4390 i = va_arg(*args, int);
4392 i = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4394 width = (i < 0) ? -i : i;
4405 i = va_arg(*args, int);
4407 i = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4408 precis = (i < 0) ? 0 : i;
4414 precis = precis * 10 + (*q++ - '0');
4423 #if 0 /* when quads have better support within Perl */
4424 if (*(q + 1) == 'l') {
4450 c = va_arg(*args, int);
4452 c = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4459 eptr = va_arg(*args, char*);
4461 elen = strlen(eptr);
4464 elen = sizeof nullstr - 1;
4467 else if (svix < svmax)
4468 eptr = SvPVx(svargs[svix++], elen);
4473 * The "%_" hack might have to be changed someday,
4474 * if ISO or ANSI decide to use '_' for something.
4475 * So we keep it hidden from users' code.
4479 eptr = SvPVx(va_arg(*args, SV*), elen);
4482 if (has_precis && elen > precis)
4490 uv = (UV)va_arg(*args, void*);
4492 uv = (svix < svmax) ? (UV)svargs[svix++] : 0;
4503 case 'h': iv = (short)va_arg(*args, int); break;
4504 default: iv = va_arg(*args, int); break;
4505 case 'l': iv = va_arg(*args, long); break;
4506 case 'V': iv = va_arg(*args, IV); break;
4510 iv = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4512 case 'h': iv = (short)iv; break;
4513 default: iv = (int)iv; break;
4514 case 'l': iv = (long)iv; break;
4521 esignbuf[esignlen++] = plus;
4525 esignbuf[esignlen++] = '-';
4551 case 'h': uv = (unsigned short)va_arg(*args, unsigned); break;
4552 default: uv = va_arg(*args, unsigned); break;
4553 case 'l': uv = va_arg(*args, unsigned long); break;
4554 case 'V': uv = va_arg(*args, UV); break;
4558 uv = (svix < svmax) ? SvUVx(svargs[svix++]) : 0;
4560 case 'h': uv = (unsigned short)uv; break;
4561 default: uv = (unsigned)uv; break;
4562 case 'l': uv = (unsigned long)uv; break;
4568 eptr = ebuf + sizeof ebuf;
4572 p = (c == 'X') ? "0123456789ABCDEF" : "0123456789abcdef";
4578 esignbuf[esignlen++] = '0';
4579 esignbuf[esignlen++] = c; /* 'x' or 'X' */
4585 *--eptr = '0' + dig;
4587 if (alt && *eptr != '0')
4590 default: /* it had better be ten or less */
4593 *--eptr = '0' + dig;
4594 } while (uv /= base);
4597 elen = (ebuf + sizeof ebuf) - eptr;
4598 if (has_precis && precis > elen)
4599 zeros = precis - elen;
4602 /* FLOATING POINT */
4605 c = 'f'; /* maybe %F isn't supported here */
4611 /* This is evil, but floating point is even more evil */
4614 nv = va_arg(*args, double);
4616 nv = (svix < svmax) ? SvNVx(svargs[svix++]) : 0.0;
4619 if (c != 'e' && c != 'E') {
4621 (void)frexp(nv, &i);
4622 if (i == PERL_INT_MIN)
4623 die("panic: frexp");
4625 need = BIT_DIGITS(i);
4627 need += has_precis ? precis : 6; /* known default */
4631 need += 20; /* fudge factor */
4632 if (efloatsize < need) {
4633 Safefree(efloatbuf);
4634 efloatsize = need + 20; /* more fudge */
4635 New(906, efloatbuf, efloatsize, char);
4638 eptr = ebuf + sizeof ebuf;
4643 do { *--eptr = '0' + (base % 10); } while (base /= 10);
4648 do { *--eptr = '0' + (base % 10); } while (base /= 10);
4660 (void)sprintf(efloatbuf, eptr, nv);
4663 elen = strlen(efloatbuf);
4667 * User-defined locales may include arbitrary characters.
4668 * And, unfortunately, some system may alloc the "C" locale
4669 * to be overridden by a malicious user.
4672 *used_locale = TRUE;
4673 #endif /* LC_NUMERIC */
4680 i = SvCUR(sv) - origlen;
4683 case 'h': *(va_arg(*args, short*)) = i; break;
4684 default: *(va_arg(*args, int*)) = i; break;
4685 case 'l': *(va_arg(*args, long*)) = i; break;
4686 case 'V': *(va_arg(*args, IV*)) = i; break;
4689 else if (svix < svmax)
4690 sv_setuv(svargs[svix++], (UV)i);
4691 continue; /* not "break" */
4697 if (!args && dowarn &&
4698 (op->op_type == OP_PRTF || op->op_type == OP_SPRINTF)) {
4699 SV *msg = sv_newmortal();
4700 sv_setpvf(msg, "Invalid conversion in %s: ",
4701 (op->op_type == OP_PRTF) ? "printf" : "sprintf");
4703 sv_catpvf(msg, isPRINT(c) ? "\"%%%c\"" : "\"%%\\%03o\"",
4706 sv_catpv(msg, "end of string");
4707 warn("%_", msg); /* yes, this is reentrant */
4710 /* output mangled stuff ... */
4716 /* ... right here, because formatting flags should not apply */
4717 SvGROW(sv, SvCUR(sv) + elen + 1);
4719 memcpy(p, eptr, elen);
4722 SvCUR(sv) = p - SvPVX(sv);
4723 continue; /* not "break" */
4726 have = esignlen + zeros + elen;
4727 need = (have > width ? have : width);
4730 SvGROW(sv, SvCUR(sv) + need + 1);
4732 if (esignlen && fill == '0') {
4733 for (i = 0; i < esignlen; i++)
4737 memset(p, fill, gap);
4740 if (esignlen && fill != '0') {
4741 for (i = 0; i < esignlen; i++)
4745 for (i = zeros; i; i--)
4749 memcpy(p, eptr, elen);
4753 memset(p, ' ', gap);
4757 SvCUR(sv) = p - SvPVX(sv);
4765 SV *d = sv_newmortal();
4771 PerlIO_printf(Perl_debug_log, "SV = 0\n");
4775 flags = SvFLAGS(sv);
4778 sv_setpvf(d, "(0x%lx)\n REFCNT = %ld\n FLAGS = (",
4779 (unsigned long)SvANY(sv), (long)SvREFCNT(sv));
4780 if (flags & SVs_PADBUSY) sv_catpv(d, "PADBUSY,");
4781 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
4782 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
4783 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
4784 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
4785 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
4786 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
4787 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
4789 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
4790 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
4791 if (flags & SVf_POK) sv_catpv(d, "POK,");
4792 if (flags & SVf_ROK) sv_catpv(d, "ROK,");
4793 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
4794 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
4795 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
4798 if (flags & SVf_AMAGIC) sv_catpv(d, "OVERLOAD,");
4799 #endif /* OVERLOAD */
4800 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
4801 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
4802 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
4803 if (flags & SVp_SCREAM) sv_catpv(d, "SCREAM,");
4808 if (CvANON(sv)) sv_catpv(d, "ANON,");
4809 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
4810 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
4811 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
4812 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
4815 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
4816 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
4819 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
4820 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
4821 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
4822 if (GvIMPORTED(sv)) {
4823 sv_catpv(d, "IMPORT");
4824 if (GvIMPORTED(sv) == GVf_IMPORTED)
4825 sv_catpv(d, "ALL,");
4828 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
4829 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
4830 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
4831 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
4836 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
4837 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
4841 if (*(SvEND(d) - 1) == ',')
4842 SvPVX(d)[--SvCUR(d)] = '\0';
4846 PerlIO_printf(Perl_debug_log, "SV = ");
4849 PerlIO_printf(Perl_debug_log, "NULL%s\n", s);
4852 PerlIO_printf(Perl_debug_log, "IV%s\n", s);
4855 PerlIO_printf(Perl_debug_log, "NV%s\n", s);
4858 PerlIO_printf(Perl_debug_log, "RV%s\n", s);
4861 PerlIO_printf(Perl_debug_log, "PV%s\n", s);
4864 PerlIO_printf(Perl_debug_log, "PVIV%s\n", s);
4867 PerlIO_printf(Perl_debug_log, "PVNV%s\n", s);
4870 PerlIO_printf(Perl_debug_log, "PVBM%s\n", s);
4873 PerlIO_printf(Perl_debug_log, "PVMG%s\n", s);
4876 PerlIO_printf(Perl_debug_log, "PVLV%s\n", s);
4879 PerlIO_printf(Perl_debug_log, "PVAV%s\n", s);
4882 PerlIO_printf(Perl_debug_log, "PVHV%s\n", s);
4885 PerlIO_printf(Perl_debug_log, "PVCV%s\n", s);
4888 PerlIO_printf(Perl_debug_log, "PVGV%s\n", s);
4891 PerlIO_printf(Perl_debug_log, "PVFM%s\n", s);
4894 PerlIO_printf(Perl_debug_log, "PVIO%s\n", s);
4897 PerlIO_printf(Perl_debug_log, "UNKNOWN%s\n", s);
4900 if (type >= SVt_PVIV || type == SVt_IV)
4901 PerlIO_printf(Perl_debug_log, " IV = %ld\n", (long)SvIVX(sv));
4902 if (type >= SVt_PVNV || type == SVt_NV) {
4903 SET_NUMERIC_STANDARD();
4904 PerlIO_printf(Perl_debug_log, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
4907 PerlIO_printf(Perl_debug_log, " RV = 0x%lx\n", (long)SvRV(sv));
4913 if (type <= SVt_PVLV) {
4915 PerlIO_printf(Perl_debug_log, " PV = 0x%lx \"%s\"\n CUR = %ld\n LEN = %ld\n",
4916 (long)SvPVX(sv), SvPVX(sv), (long)SvCUR(sv), (long)SvLEN(sv));
4918 PerlIO_printf(Perl_debug_log, " PV = 0\n");
4920 if (type >= SVt_PVMG) {
4922 PerlIO_printf(Perl_debug_log, " MAGIC = 0x%lx\n", (long)SvMAGIC(sv));
4925 PerlIO_printf(Perl_debug_log, " STASH = \"%s\"\n", HvNAME(SvSTASH(sv)));
4929 PerlIO_printf(Perl_debug_log, " TYPE = %c\n", LvTYPE(sv));
4930 PerlIO_printf(Perl_debug_log, " TARGOFF = %ld\n", (long)LvTARGOFF(sv));
4931 PerlIO_printf(Perl_debug_log, " TARGLEN = %ld\n", (long)LvTARGLEN(sv));
4932 PerlIO_printf(Perl_debug_log, " TARG = 0x%lx\n", (long)LvTARG(sv));
4933 sv_dump(LvTARG(sv));
4936 PerlIO_printf(Perl_debug_log, " ARRAY = 0x%lx\n", (long)AvARRAY(sv));
4937 PerlIO_printf(Perl_debug_log, " ALLOC = 0x%lx\n", (long)AvALLOC(sv));
4938 PerlIO_printf(Perl_debug_log, " FILL = %ld\n", (long)AvFILLp(sv));
4939 PerlIO_printf(Perl_debug_log, " MAX = %ld\n", (long)AvMAX(sv));
4940 PerlIO_printf(Perl_debug_log, " ARYLEN = 0x%lx\n", (long)AvARYLEN(sv));
4941 flags = AvFLAGS(sv);
4943 if (flags & AVf_REAL) sv_catpv(d, ",REAL");
4944 if (flags & AVf_REIFY) sv_catpv(d, ",REIFY");
4945 if (flags & AVf_REUSED) sv_catpv(d, ",REUSED");
4946 PerlIO_printf(Perl_debug_log, " FLAGS = (%s)\n",
4947 SvCUR(d) ? SvPVX(d) + 1 : "");
4950 PerlIO_printf(Perl_debug_log, " ARRAY = 0x%lx\n",(long)HvARRAY(sv));
4951 PerlIO_printf(Perl_debug_log, " KEYS = %ld\n", (long)HvKEYS(sv));
4952 PerlIO_printf(Perl_debug_log, " FILL = %ld\n", (long)HvFILL(sv));
4953 PerlIO_printf(Perl_debug_log, " MAX = %ld\n", (long)HvMAX(sv));
4954 PerlIO_printf(Perl_debug_log, " RITER = %ld\n", (long)HvRITER(sv));
4955 PerlIO_printf(Perl_debug_log, " EITER = 0x%lx\n",(long) HvEITER(sv));
4957 PerlIO_printf(Perl_debug_log, " PMROOT = 0x%lx\n",(long)HvPMROOT(sv));
4959 PerlIO_printf(Perl_debug_log, " NAME = \"%s\"\n", HvNAME(sv));
4963 PerlIO_printf(Perl_debug_log, " PROTOTYPE = \"%s\"\n", SvPV(sv,na));
4966 PerlIO_printf(Perl_debug_log, " STASH = 0x%lx\n", (long)CvSTASH(sv));
4967 PerlIO_printf(Perl_debug_log, " START = 0x%lx\n", (long)CvSTART(sv));
4968 PerlIO_printf(Perl_debug_log, " ROOT = 0x%lx\n", (long)CvROOT(sv));
4969 PerlIO_printf(Perl_debug_log, " XSUB = 0x%lx\n", (long)CvXSUB(sv));
4970 PerlIO_printf(Perl_debug_log, " XSUBANY = %ld\n", (long)CvXSUBANY(sv).any_i32);
4971 PerlIO_printf(Perl_debug_log, " GV = 0x%lx", (long)CvGV(sv));
4972 if (CvGV(sv) && GvNAME(CvGV(sv))) {
4973 PerlIO_printf(Perl_debug_log, " \"%s\"\n", GvNAME(CvGV(sv)));
4975 PerlIO_printf(Perl_debug_log, "\n");
4977 PerlIO_printf(Perl_debug_log, " FILEGV = 0x%lx\n", (long)CvFILEGV(sv));
4978 PerlIO_printf(Perl_debug_log, " DEPTH = %ld\n", (long)CvDEPTH(sv));
4979 PerlIO_printf(Perl_debug_log, " PADLIST = 0x%lx\n", (long)CvPADLIST(sv));
4980 PerlIO_printf(Perl_debug_log, " OUTSIDE = 0x%lx\n", (long)CvOUTSIDE(sv));
4982 PerlIO_printf(Perl_debug_log, " MUTEXP = 0x%lx\n", (long)CvMUTEXP(sv));
4983 PerlIO_printf(Perl_debug_log, " OWNER = 0x%lx\n", (long)CvOWNER(sv));
4984 #endif /* USE_THREADS */
4985 PerlIO_printf(Perl_debug_log, " FLAGS = 0x%lx\n",
4986 (unsigned long)CvFLAGS(sv));
4987 if (type == SVt_PVFM)
4988 PerlIO_printf(Perl_debug_log, " LINES = %ld\n", (long)FmLINES(sv));
4991 PerlIO_printf(Perl_debug_log, " NAME = \"%s\"\n", GvNAME(sv));
4992 PerlIO_printf(Perl_debug_log, " NAMELEN = %ld\n", (long)GvNAMELEN(sv));
4993 PerlIO_printf(Perl_debug_log, " STASH = \"%s\"\n", HvNAME(GvSTASH(sv)));
4994 PerlIO_printf(Perl_debug_log, " GP = 0x%lx\n", (long)GvGP(sv));
4995 PerlIO_printf(Perl_debug_log, " SV = 0x%lx\n", (long)GvSV(sv));
4996 PerlIO_printf(Perl_debug_log, " REFCNT = %ld\n", (long)GvREFCNT(sv));
4997 PerlIO_printf(Perl_debug_log, " IO = 0x%lx\n", (long)GvIOp(sv));
4998 PerlIO_printf(Perl_debug_log, " FORM = 0x%lx\n", (long)GvFORM(sv));
4999 PerlIO_printf(Perl_debug_log, " AV = 0x%lx\n", (long)GvAV(sv));
5000 PerlIO_printf(Perl_debug_log, " HV = 0x%lx\n", (long)GvHV(sv));
5001 PerlIO_printf(Perl_debug_log, " CV = 0x%lx\n", (long)GvCV(sv));
5002 PerlIO_printf(Perl_debug_log, " CVGEN = 0x%lx\n", (long)GvCVGEN(sv));
5003 PerlIO_printf(Perl_debug_log, " LASTEXPR = %ld\n", (long)GvLASTEXPR(sv));
5004 PerlIO_printf(Perl_debug_log, " LINE = %ld\n", (long)GvLINE(sv));
5005 PerlIO_printf(Perl_debug_log, " FILEGV = 0x%lx\n", (long)GvFILEGV(sv));
5006 PerlIO_printf(Perl_debug_log, " EGV = 0x%lx\n", (long)GvEGV(sv));
5009 PerlIO_printf(Perl_debug_log, " IFP = 0x%lx\n", (long)IoIFP(sv));
5010 PerlIO_printf(Perl_debug_log, " OFP = 0x%lx\n", (long)IoOFP(sv));
5011 PerlIO_printf(Perl_debug_log, " DIRP = 0x%lx\n", (long)IoDIRP(sv));
5012 PerlIO_printf(Perl_debug_log, " LINES = %ld\n", (long)IoLINES(sv));
5013 PerlIO_printf(Perl_debug_log, " PAGE = %ld\n", (long)IoPAGE(sv));
5014 PerlIO_printf(Perl_debug_log, " PAGE_LEN = %ld\n", (long)IoPAGE_LEN(sv));
5015 PerlIO_printf(Perl_debug_log, " LINES_LEFT = %ld\n", (long)IoLINES_LEFT(sv));
5016 PerlIO_printf(Perl_debug_log, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
5017 PerlIO_printf(Perl_debug_log, " TOP_GV = 0x%lx\n", (long)IoTOP_GV(sv));
5018 PerlIO_printf(Perl_debug_log, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
5019 PerlIO_printf(Perl_debug_log, " FMT_GV = 0x%lx\n", (long)IoFMT_GV(sv));
5020 PerlIO_printf(Perl_debug_log, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
5021 PerlIO_printf(Perl_debug_log, " BOTTOM_GV = 0x%lx\n", (long)IoBOTTOM_GV(sv));
5022 PerlIO_printf(Perl_debug_log, " SUBPROCESS = %ld\n", (long)IoSUBPROCESS(sv));
5023 PerlIO_printf(Perl_debug_log, " TYPE = %c\n", IoTYPE(sv));
5024 PerlIO_printf(Perl_debug_log, " FLAGS = 0x%lx\n", (long)IoFLAGS(sv));