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__)
44 #define FCALL this->*f
45 #define VTBL this->*vtbl
47 #else /* !PERL_OBJECT */
49 static IV asIV _((SV* sv));
50 static UV asUV _((SV* sv));
51 static SV *more_sv _((void));
52 static XPVIV *more_xiv _((void));
53 static XPVNV *more_xnv _((void));
54 static XPV *more_xpv _((void));
55 static XRV *more_xrv _((void));
56 static XPVIV *new_xiv _((void));
57 static XPVNV *new_xnv _((void));
58 static XPV *new_xpv _((void));
59 static XRV *new_xrv _((void));
60 static void del_xiv _((XPVIV* p));
61 static void del_xnv _((XPVNV* p));
62 static void del_xpv _((XPV* p));
63 static void del_xrv _((XRV* p));
64 static void sv_mortalgrow _((void));
65 static void sv_unglob _((SV* sv));
66 static void sv_check_thinkfirst _((SV *sv));
69 static void *my_safemalloc(MEM_SIZE size);
72 typedef void (*SVFUNC) _((SV*));
76 #endif /* PERL_OBJECT */
78 #define SV_CHECK_THINKFIRST(sv) if (SvTHINKFIRST(sv)) sv_check_thinkfirst(sv)
85 (p) = (SV*)safemalloc(sizeof(SV)); \
94 Safefree((char*)(p)); \
99 static I32 registry_size;
101 #define REGHASH(sv,size) ((((U32)(sv)) >> 2) % (size))
103 #define REG_REPLACE(sv,a,b) \
105 void* p = sv->sv_any; \
106 I32 h = REGHASH(sv, registry_size); \
108 while (registry[i] != (a)) { \
109 if (++i >= registry_size) \
112 die("SV registry bug"); \
117 #define REG_ADD(sv) REG_REPLACE(sv,Nullsv,sv)
118 #define REG_REMOVE(sv) REG_REPLACE(sv,sv,Nullsv)
124 if (sv_count >= (registry_size >> 1))
126 SV **oldreg = registry;
127 I32 oldsize = registry_size;
129 registry_size = registry_size ? ((registry_size << 2) + 1) : 2037;
130 Newz(707, registry, registry_size, SV*);
135 for (i = 0; i < oldsize; ++i) {
136 SV* oldsv = oldreg[i];
162 for (i = 0; i < registry_size; ++i) {
163 SV* sv = registry[i];
164 if (sv && SvTYPE(sv) != SVTYPEMASK)
170 sv_add_arena(ptr, size, flags)
175 if (!(flags & SVf_FAKE))
182 * "A time to plant, and a time to uproot what was planted..."
185 #define plant_SV(p) \
187 SvANY(p) = (void *)sv_root; \
188 SvFLAGS(p) = SVTYPEMASK; \
193 /* sv_mutex must be held while calling uproot_SV() */
194 #define uproot_SV(p) \
197 sv_root = (SV*)SvANY(p); \
201 #define new_SV(p) do { \
212 #define del_SV(p) do { \
229 for (sva = sv_arenaroot; sva; sva = (SV *) SvANY(sva)) {
231 svend = &sva[SvREFCNT(sva)];
232 if (p >= sv && p < svend)
236 warn("Attempt to free non-arena SV: 0x%lx", (unsigned long)p);
243 #else /* ! DEBUGGING */
245 #define del_SV(p) plant_SV(p)
247 #endif /* DEBUGGING */
250 sv_add_arena(char *ptr, U32 size, U32 flags)
255 Zero(sva, size, char);
257 /* The first SV in an arena isn't an SV. */
258 SvANY(sva) = (void *) sv_arenaroot; /* ptr to next arena */
259 SvREFCNT(sva) = size / sizeof(SV); /* number of SV slots */
260 SvFLAGS(sva) = flags; /* FAKE if not to be freed */
265 svend = &sva[SvREFCNT(sva) - 1];
268 SvANY(sv) = (void *)(SV*)(sv + 1);
269 SvFLAGS(sv) = SVTYPEMASK;
273 SvFLAGS(sv) = SVTYPEMASK;
276 /* sv_mutex must be held while calling more_sv() */
283 sv_add_arena(nice_chunk, nice_chunk_size, 0);
287 char *chunk; /* must use New here to match call to */
288 New(704,chunk,1008,char); /* Safefree() in sv_free_arenas() */
289 sv_add_arena(chunk, 1008, 0);
302 for (sva = sv_arenaroot; sva; sva = (SV*)SvANY(sva)) {
303 svend = &sva[SvREFCNT(sva)];
304 for (sv = sva + 1; sv < svend; ++sv) {
305 if (SvTYPE(sv) != SVTYPEMASK)
314 do_report_used(SV *sv)
316 if (SvTYPE(sv) != SVTYPEMASK) {
317 /* XXX Perhaps this ought to go to Perl_debug_log, if DEBUGGING. */
318 PerlIO_printf(PerlIO_stderr(), "****\n");
326 visit(FUNC_NAME_TO_PTR(do_report_used));
330 do_clean_objs(SV *sv)
334 if (SvROK(sv) && SvOBJECT(rv = SvRV(sv))) {
335 DEBUG_D((PerlIO_printf(Perl_debug_log, "Cleaning object ref:\n "), sv_dump(sv));)
341 /* XXX Might want to check arrays, etc. */
344 #ifndef DISABLE_DESTRUCTOR_KLUDGE
346 do_clean_named_objs(SV *sv)
348 if (SvTYPE(sv) == SVt_PVGV) {
349 if ( SvOBJECT(GvSV(sv)) ||
350 GvAV(sv) && SvOBJECT(GvAV(sv)) ||
351 GvHV(sv) && SvOBJECT(GvHV(sv)) ||
352 GvIO(sv) && SvOBJECT(GvIO(sv)) ||
353 GvCV(sv) && SvOBJECT(GvCV(sv)) )
355 DEBUG_D((PerlIO_printf(Perl_debug_log, "Cleaning named glob object:\n "), sv_dump(sv));)
365 in_clean_objs = TRUE;
366 visit(FUNC_NAME_TO_PTR(do_clean_objs));
367 #ifndef DISABLE_DESTRUCTOR_KLUDGE
368 /* some barnacles may yet remain, clinging to typeglobs */
369 visit(FUNC_NAME_TO_PTR(do_clean_named_objs));
371 in_clean_objs = FALSE;
377 DEBUG_D((PerlIO_printf(Perl_debug_log, "Cleaning loops:\n "), sv_dump(sv));)
378 SvFLAGS(sv) |= SVf_BREAK;
386 visit(FUNC_NAME_TO_PTR(do_clean_all));
387 in_clean_all = FALSE;
396 /* Free arenas here, but be careful about fake ones. (We assume
397 contiguity of the fake ones with the corresponding real ones.) */
399 for (sva = sv_arenaroot; sva; sva = svanext) {
400 svanext = (SV*) SvANY(sva);
401 while (svanext && SvFAKE(svanext))
402 svanext = (SV*) SvANY(svanext);
405 Safefree((void *)sva);
409 Safefree(nice_chunk);
423 * See comment in more_xiv() -- RAM.
425 xiv_root = *(IV**)xiv;
426 return (XPVIV*)((char*)xiv - STRUCT_OFFSET(XPVIV, xiv_iv));
434 IV* xiv = (IV*)((char*)(p) + STRUCT_OFFSET(XPVIV, xiv_iv));
435 *(IV**)xiv = xiv_root;
445 New(705, ptr, 1008/sizeof(XPV), XPV);
446 ptr->xpv_pv = (char*)xiv_arenaroot; /* linked list of xiv arenas */
447 xiv_arenaroot = ptr; /* to keep Purify happy */
450 xivend = &xiv[1008 / sizeof(IV) - 1];
451 xiv += (sizeof(XPV) - 1) / sizeof(IV) + 1; /* fudge by size of XPV */
453 while (xiv < xivend) {
454 *(IV**)xiv = (IV *)(xiv + 1);
467 xnv_root = *(double**)xnv;
468 return (XPVNV*)((char*)xnv - STRUCT_OFFSET(XPVNV, xnv_nv));
476 double* xnv = (double*)((char*)(p) + STRUCT_OFFSET(XPVNV, xnv_nv));
477 *(double**)xnv = xnv_root;
484 register double* xnv;
485 register double* xnvend;
486 New(711, xnv, 1008/sizeof(double), double);
487 xnvend = &xnv[1008 / sizeof(double) - 1];
488 xnv += (sizeof(XPVIV) - 1) / sizeof(double) + 1; /* fudge by sizeof XPVIV */
490 while (xnv < xnvend) {
491 *(double**)xnv = (double*)(xnv + 1);
504 xrv_root = (XRV*)xrv->xrv_rv;
513 p->xrv_rv = (SV*)xrv_root;
521 register XRV* xrvend;
522 New(712, xrv_root, 1008/sizeof(XRV), XRV);
524 xrvend = &xrv[1008 / sizeof(XRV) - 1];
525 while (xrv < xrvend) {
526 xrv->xrv_rv = (SV*)(xrv + 1);
539 xpv_root = (XPV*)xpv->xpv_pv;
548 p->xpv_pv = (char*)xpv_root;
556 register XPV* xpvend;
557 New(713, xpv_root, 1008/sizeof(XPV), XPV);
559 xpvend = &xpv[1008 / sizeof(XPV) - 1];
560 while (xpv < xpvend) {
561 xpv->xpv_pv = (char*)(xpv + 1);
569 #define new_XIV() (void*)safemalloc(sizeof(XPVIV))
570 #define del_XIV(p) Safefree((char*)p)
572 #define new_XIV() (void*)new_xiv()
573 #define del_XIV(p) del_xiv((XPVIV*) p)
577 #define new_XNV() (void*)safemalloc(sizeof(XPVNV))
578 #define del_XNV(p) Safefree((char*)p)
580 #define new_XNV() (void*)new_xnv()
581 #define del_XNV(p) del_xnv((XPVNV*) p)
585 #define new_XRV() (void*)safemalloc(sizeof(XRV))
586 #define del_XRV(p) Safefree((char*)p)
588 #define new_XRV() (void*)new_xrv()
589 #define del_XRV(p) del_xrv((XRV*) p)
593 #define new_XPV() (void*)safemalloc(sizeof(XPV))
594 #define del_XPV(p) Safefree((char*)p)
596 #define new_XPV() (void*)new_xpv()
597 #define del_XPV(p) del_xpv((XPV *)p)
601 # define my_safemalloc(s) safemalloc(s)
602 # define my_safefree(s) free(s)
605 my_safemalloc(MEM_SIZE size)
608 New(717, p, size, char);
611 # define my_safefree(s) Safefree(s)
614 #define new_XPVIV() (void*)my_safemalloc(sizeof(XPVIV))
615 #define del_XPVIV(p) my_safefree((char*)p)
617 #define new_XPVNV() (void*)my_safemalloc(sizeof(XPVNV))
618 #define del_XPVNV(p) my_safefree((char*)p)
620 #define new_XPVMG() (void*)my_safemalloc(sizeof(XPVMG))
621 #define del_XPVMG(p) my_safefree((char*)p)
623 #define new_XPVLV() (void*)my_safemalloc(sizeof(XPVLV))
624 #define del_XPVLV(p) my_safefree((char*)p)
626 #define new_XPVAV() (void*)my_safemalloc(sizeof(XPVAV))
627 #define del_XPVAV(p) my_safefree((char*)p)
629 #define new_XPVHV() (void*)my_safemalloc(sizeof(XPVHV))
630 #define del_XPVHV(p) my_safefree((char*)p)
632 #define new_XPVCV() (void*)my_safemalloc(sizeof(XPVCV))
633 #define del_XPVCV(p) my_safefree((char*)p)
635 #define new_XPVGV() (void*)my_safemalloc(sizeof(XPVGV))
636 #define del_XPVGV(p) my_safefree((char*)p)
638 #define new_XPVBM() (void*)my_safemalloc(sizeof(XPVBM))
639 #define del_XPVBM(p) my_safefree((char*)p)
641 #define new_XPVFM() (void*)my_safemalloc(sizeof(XPVFM))
642 #define del_XPVFM(p) my_safefree((char*)p)
644 #define new_XPVIO() (void*)my_safemalloc(sizeof(XPVIO))
645 #define del_XPVIO(p) my_safefree((char*)p)
648 sv_upgrade(register SV *sv, U32 mt)
658 if (SvTYPE(sv) == mt)
664 switch (SvTYPE(sv)) {
679 nv = (double)SvIVX(sv);
685 else if (mt < SVt_PVIV)
702 pv = (char*)SvRV(sv);
706 nv = (double)(unsigned long)pv;
722 else if (mt == SVt_NV)
733 del_XPVIV(SvANY(sv));
743 del_XPVNV(SvANY(sv));
753 del_XPVMG(SvANY(sv));
756 croak("Can't upgrade that kind of scalar");
761 croak("Can't upgrade to undef");
763 SvANY(sv) = new_XIV();
767 SvANY(sv) = new_XNV();
771 SvANY(sv) = new_XRV();
775 SvANY(sv) = new_XPV();
781 SvANY(sv) = new_XPVIV();
791 SvANY(sv) = new_XPVNV();
799 SvANY(sv) = new_XPVMG();
809 SvANY(sv) = new_XPVLV();
823 SvANY(sv) = new_XPVAV();
838 SvANY(sv) = new_XPVHV();
854 SvANY(sv) = new_XPVCV();
855 Zero(SvANY(sv), 1, XPVCV);
865 SvANY(sv) = new_XPVGV();
880 SvANY(sv) = new_XPVBM();
893 SvANY(sv) = new_XPVFM();
894 Zero(SvANY(sv), 1, XPVFM);
904 SvANY(sv) = new_XPVIO();
905 Zero(SvANY(sv), 1, XPVIO);
916 SvFLAGS(sv) &= ~SVTYPEMASK;
925 SV *t = sv_newmortal();
935 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
939 else if (sv == &sv_undef || sv == &sv_no || sv == &sv_yes) {
940 if (sv == &sv_undef) {
941 sv_catpv(t, "SV_UNDEF");
942 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
943 SVs_GMG|SVs_SMG|SVs_RMG)) &&
947 else if (sv == &sv_no) {
948 sv_catpv(t, "SV_NO");
949 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
950 SVs_GMG|SVs_SMG|SVs_RMG)) &&
951 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
958 sv_catpv(t, "SV_YES");
959 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
960 SVs_GMG|SVs_SMG|SVs_RMG)) &&
961 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
964 SvPVX(sv) && *SvPVX(sv) == '1' &&
970 else if (SvREFCNT(sv) == 0) {
976 if (SvCUR(t) + unref > 10) {
977 SvCUR(t) = unref + 3;
985 switch (SvTYPE(sv)) {
987 sv_catpv(t, "FREED");
991 sv_catpv(t, "UNDEF");
1006 sv_catpv(t, "PVIV");
1009 sv_catpv(t, "PVNV");
1012 sv_catpv(t, "PVMG");
1015 sv_catpv(t, "PVLV");
1025 sv_catpvf(t, "CV(%s)", GvNAME(CvGV(sv)));
1027 sv_catpv(t, "CV()");
1045 sv_catpv(t, "(null)");
1047 sv_catpvf(t, "(%ld+\"%.127s\")",(long)SvIVX(sv),SvPVX(sv));
1049 sv_catpvf(t, "(\"%.127s\")",SvPVX(sv));
1051 else if (SvNOKp(sv)) {
1052 SET_NUMERIC_STANDARD();
1053 sv_catpvf(t, "(%g)",SvNVX(sv));
1055 else if (SvIOKp(sv))
1056 sv_catpvf(t, "(%ld)",(long)SvIVX(sv));
1066 #else /* DEBUGGING */
1068 #endif /* DEBUGGING */
1072 sv_backoff(register SV *sv)
1076 char *s = SvPVX(sv);
1077 SvLEN(sv) += SvIVX(sv);
1078 SvPVX(sv) -= SvIVX(sv);
1080 Move(s, SvPVX(sv), SvCUR(sv)+1, char);
1082 SvFLAGS(sv) &= ~SVf_OOK;
1088 sv_grow(register SV *sv, register I32 newlen)
1090 sv_grow(SV* sv, unsigned long newlen)
1095 #ifdef HAS_64K_LIMIT
1096 if (newlen >= 0x10000) {
1097 PerlIO_printf(Perl_debug_log, "Allocation too large: %lx\n", newlen);
1100 #endif /* HAS_64K_LIMIT */
1103 if (SvTYPE(sv) < SVt_PV) {
1104 sv_upgrade(sv, SVt_PV);
1107 else if (SvOOK(sv)) { /* pv is offset? */
1110 if (newlen > SvLEN(sv))
1111 newlen += 10 * (newlen - SvCUR(sv)); /* avoid copy each time */
1112 #ifdef HAS_64K_LIMIT
1113 if (newlen >= 0x10000)
1119 if (newlen > SvLEN(sv)) { /* need more room? */
1120 if (SvLEN(sv) && s) {
1121 #if defined(MYMALLOC) && !defined(PURIFY)
1122 STRLEN l = malloced_size((void*)SvPVX(sv));
1128 Renew(s,newlen,char);
1131 New(703,s,newlen,char);
1133 SvLEN_set(sv, newlen);
1139 sv_setiv(register SV *sv, IV i)
1141 SV_CHECK_THINKFIRST(sv);
1142 switch (SvTYPE(sv)) {
1144 sv_upgrade(sv, SVt_IV);
1147 sv_upgrade(sv, SVt_PVNV);
1151 sv_upgrade(sv, SVt_PVIV);
1167 croak("Can't coerce %s to integer in %s", sv_reftype(sv,0),
1168 op_desc[op->op_type]);
1171 (void)SvIOK_only(sv); /* validate number */
1177 sv_setiv_mg(register SV *sv, IV i)
1184 sv_setuv(register SV *sv, UV u)
1189 sv_setnv(sv, (double)u);
1193 sv_setuv_mg(register SV *sv, UV u)
1200 sv_setnv(register SV *sv, double num)
1202 SV_CHECK_THINKFIRST(sv);
1203 switch (SvTYPE(sv)) {
1206 sv_upgrade(sv, SVt_NV);
1211 sv_upgrade(sv, SVt_PVNV);
1227 croak("Can't coerce %s to number in %s", sv_reftype(sv,0),
1228 op_name[op->op_type]);
1232 (void)SvNOK_only(sv); /* validate number */
1237 sv_setnv_mg(register SV *sv, double num)
1244 not_a_number(SV *sv)
1250 char *limit = tmpbuf + sizeof(tmpbuf) - 8;
1251 /* each *s can expand to 4 chars + "...\0",
1252 i.e. need room for 8 chars */
1254 for (s = SvPVX(sv); *s && d < limit; s++) {
1256 if (ch & 128 && !isPRINT_LC(ch)) {
1265 else if (ch == '\r') {
1269 else if (ch == '\f') {
1273 else if (ch == '\\') {
1277 else if (isPRINT_LC(ch))
1292 warn("Argument \"%s\" isn't numeric in %s", tmpbuf,
1293 op_name[op->op_type]);
1295 warn("Argument \"%s\" isn't numeric", tmpbuf);
1299 sv_2iv(register SV *sv)
1303 if (SvGMAGICAL(sv)) {
1308 if (SvNVX(sv) < 0.0)
1309 return I_V(SvNVX(sv));
1311 return (IV) U_V(SvNVX(sv));
1313 if (SvPOKp(sv) && SvLEN(sv))
1316 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1324 if (SvTHINKFIRST(sv)) {
1328 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv, numer)))
1329 return SvIV(tmpstr);
1330 #endif /* OVERLOAD */
1331 return (IV)SvRV(sv);
1333 if (SvREADONLY(sv)) {
1335 if (SvNVX(sv) < 0.0)
1336 return I_V(SvNVX(sv));
1338 return (IV) U_V(SvNVX(sv));
1340 if (SvPOKp(sv) && SvLEN(sv))
1347 switch (SvTYPE(sv)) {
1349 sv_upgrade(sv, SVt_IV);
1352 sv_upgrade(sv, SVt_PVIV);
1355 sv_upgrade(sv, SVt_PVNV);
1360 if (SvNVX(sv) < 0.0)
1361 SvIVX(sv) = I_V(SvNVX(sv));
1363 SvUVX(sv) = U_V(SvNVX(sv));
1365 else if (SvPOKp(sv) && SvLEN(sv)) {
1367 SvIVX(sv) = asIV(sv);
1371 if (dowarn && !localizing && !(SvFLAGS(sv) & SVs_PADTMP))
1375 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2iv(%ld)\n",
1376 (unsigned long)sv,(long)SvIVX(sv)));
1381 sv_2uv(register SV *sv)
1385 if (SvGMAGICAL(sv)) {
1390 return U_V(SvNVX(sv));
1391 if (SvPOKp(sv) && SvLEN(sv))
1394 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1402 if (SvTHINKFIRST(sv)) {
1406 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv, numer)))
1407 return SvUV(tmpstr);
1408 #endif /* OVERLOAD */
1409 return (UV)SvRV(sv);
1411 if (SvREADONLY(sv)) {
1413 return U_V(SvNVX(sv));
1415 if (SvPOKp(sv) && SvLEN(sv))
1422 switch (SvTYPE(sv)) {
1424 sv_upgrade(sv, SVt_IV);
1427 sv_upgrade(sv, SVt_PVIV);
1430 sv_upgrade(sv, SVt_PVNV);
1435 SvUVX(sv) = U_V(SvNVX(sv));
1437 else if (SvPOKp(sv) && SvLEN(sv)) {
1439 SvUVX(sv) = asUV(sv);
1442 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1449 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2uv(%lu)\n",
1450 (unsigned long)sv,SvUVX(sv)));
1455 sv_2nv(register SV *sv)
1459 if (SvGMAGICAL(sv)) {
1463 if (SvPOKp(sv) && SvLEN(sv)) {
1464 if (dowarn && !SvIOKp(sv) && !looks_like_number(sv))
1466 SET_NUMERIC_STANDARD();
1467 return atof(SvPVX(sv));
1470 return (double)SvIVX(sv);
1472 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1480 if (SvTHINKFIRST(sv)) {
1484 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,numer)))
1485 return SvNV(tmpstr);
1486 #endif /* OVERLOAD */
1487 return (double)(unsigned long)SvRV(sv);
1489 if (SvREADONLY(sv)) {
1490 if (SvPOKp(sv) && SvLEN(sv)) {
1491 if (dowarn && !SvIOKp(sv) && !looks_like_number(sv))
1493 SET_NUMERIC_STANDARD();
1494 return atof(SvPVX(sv));
1497 return (double)SvIVX(sv);
1503 if (SvTYPE(sv) < SVt_NV) {
1504 if (SvTYPE(sv) == SVt_IV)
1505 sv_upgrade(sv, SVt_PVNV);
1507 sv_upgrade(sv, SVt_NV);
1508 DEBUG_c(SET_NUMERIC_STANDARD());
1509 DEBUG_c(PerlIO_printf(Perl_debug_log,
1510 "0x%lx num(%g)\n",(unsigned long)sv,SvNVX(sv)));
1512 else if (SvTYPE(sv) < SVt_PVNV)
1513 sv_upgrade(sv, SVt_PVNV);
1515 (!SvPOKp(sv) || !strchr(SvPVX(sv),'.') || !looks_like_number(sv)))
1517 SvNVX(sv) = (double)SvIVX(sv);
1519 else if (SvPOKp(sv) && SvLEN(sv)) {
1520 if (dowarn && !SvIOKp(sv) && !looks_like_number(sv))
1522 SET_NUMERIC_STANDARD();
1523 SvNVX(sv) = atof(SvPVX(sv));
1527 if (dowarn && !localizing && !(SvFLAGS(sv) & SVs_PADTMP))
1532 DEBUG_c(SET_NUMERIC_STANDARD());
1533 DEBUG_c(PerlIO_printf(Perl_debug_log,
1534 "0x%lx 2nv(%g)\n",(unsigned long)sv,SvNVX(sv)));
1541 I32 numtype = looks_like_number(sv);
1545 return atol(SvPVX(sv));
1546 if (!numtype && dowarn)
1548 SET_NUMERIC_STANDARD();
1549 d = atof(SvPVX(sv));
1559 I32 numtype = looks_like_number(sv);
1563 return strtoul(SvPVX(sv), Null(char**), 10);
1565 if (!numtype && dowarn)
1567 SET_NUMERIC_STANDARD();
1568 return U_V(atof(SvPVX(sv)));
1572 looks_like_number(SV *sv)
1575 register char *send;
1576 register char *sbegin;
1584 else if (SvPOKp(sv))
1585 sbegin = SvPV(sv, len);
1588 send = sbegin + len;
1593 if (*s == '+' || *s == '-')
1596 /* next must be digit or '.' */
1600 } while (isDIGIT(*s));
1603 while (isDIGIT(*s)) /* optional digits after "." */
1607 else if (*s == '.') {
1609 /* no digits before '.' means we need digits after it */
1613 } while (isDIGIT(*s));
1622 * we return 1 if the number can be converted to _integer_ with atol()
1623 * and 2 if you need (int)atof().
1627 /* we can have an optional exponent part */
1628 if (*s == 'e' || *s == 'E') {
1631 if (*s == '+' || *s == '-')
1636 } while (isDIGIT(*s));
1645 if (len == 10 && memEQ(sbegin, "0 but true", 10))
1651 sv_2pv(register SV *sv, STRLEN *lp)
1656 char tmpbuf[64]; /* Must fit sprintf/Gconvert of longest IV/NV */
1662 if (SvGMAGICAL(sv)) {
1669 (void)sprintf(tmpbuf,"%ld",(long)SvIVX(sv));
1674 SET_NUMERIC_STANDARD();
1675 Gconvert(SvNVX(sv), DBL_DIG, 0, tmpbuf);
1680 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1689 if (SvTHINKFIRST(sv)) {
1693 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,string)))
1694 return SvPV(tmpstr,*lp);
1695 #endif /* OVERLOAD */
1702 switch (SvTYPE(sv)) {
1704 if ( ((SvFLAGS(sv) &
1705 (SVs_OBJECT|SVf_OK|SVs_GMG|SVs_SMG|SVs_RMG))
1706 == (SVs_OBJECT|SVs_RMG))
1707 && strEQ(s=HvNAME(SvSTASH(sv)), "Regexp")
1708 && (mg = mg_find(sv, 'r'))) {
1710 regexp *re = (regexp *)mg->mg_obj;
1713 char *fptr = "msix";
1718 U16 reganch = (re->reganch & PMf_COMPILETIME) >> 12;
1720 while(ch = *fptr++) {
1722 reflags[left++] = ch;
1725 reflags[right--] = ch;
1730 reflags[left] = '-';
1734 mg->mg_len = re->prelen + 4 + left;
1735 New(616, mg->mg_ptr, mg->mg_len + 1 + left, char);
1736 Copy("(?", mg->mg_ptr, 2, char);
1737 Copy(reflags, mg->mg_ptr+2, left, char);
1738 Copy(":", mg->mg_ptr+left+2, 1, char);
1739 Copy(re->precomp, mg->mg_ptr+3+left, re->prelen, char);
1740 mg->mg_ptr[mg->mg_len - 1] = ')';
1741 mg->mg_ptr[mg->mg_len] = 0;
1743 reginterp_cnt += re->program[0].next_off;
1755 case SVt_PVBM: s = "SCALAR"; break;
1756 case SVt_PVLV: s = "LVALUE"; break;
1757 case SVt_PVAV: s = "ARRAY"; break;
1758 case SVt_PVHV: s = "HASH"; break;
1759 case SVt_PVCV: s = "CODE"; break;
1760 case SVt_PVGV: s = "GLOB"; break;
1761 case SVt_PVFM: s = "FORMAT"; break;
1762 case SVt_PVIO: s = "IO"; break;
1763 default: s = "UNKNOWN"; break;
1767 sv_setpvf(tsv, "%s=%s", HvNAME(SvSTASH(sv)), s);
1770 sv_catpvf(tsv, "(0x%lx)", (unsigned long)sv);
1776 if (SvREADONLY(sv)) {
1778 SET_NUMERIC_STANDARD();
1779 Gconvert(SvNVX(sv), DBL_DIG, 0, tmpbuf);
1784 (void)sprintf(tmpbuf,"%ld",(long)SvIVX(sv));
1794 (void)SvUPGRADE(sv, SVt_PV);
1796 if (SvTYPE(sv) < SVt_PVNV)
1797 sv_upgrade(sv, SVt_PVNV);
1800 olderrno = errno; /* some Xenix systems wipe out errno here */
1802 if (SvNVX(sv) == 0.0)
1803 (void)strcpy(s,"0");
1807 SET_NUMERIC_STANDARD();
1808 Gconvert(SvNVX(sv), DBL_DIG, 0, s);
1811 #ifdef FIXNEGATIVEZERO
1812 if (*s == '-' && s[1] == '0' && !s[2])
1821 else if (SvIOKp(sv)) {
1822 U32 oldIOK = SvIOK(sv);
1823 if (SvTYPE(sv) < SVt_PVIV)
1824 sv_upgrade(sv, SVt_PVIV);
1825 olderrno = errno; /* some Xenix systems wipe out errno here */
1826 sv_setpviv(sv, SvIVX(sv));
1836 if (dowarn && !localizing && !(SvFLAGS(sv) & SVs_PADTMP))
1841 *lp = s - SvPVX(sv);
1844 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2pv(%s)\n",(unsigned long)sv,SvPVX(sv)));
1848 if (SvROK(sv)) { /* XXX Skip this when sv_pvn_force calls */
1849 /* Sneaky stuff here */
1853 tsv = newSVpv(tmpbuf, 0);
1869 len = strlen(tmpbuf);
1871 #ifdef FIXNEGATIVEZERO
1872 if (len == 2 && t[0] == '-' && t[1] == '0') {
1877 (void)SvUPGRADE(sv, SVt_PV);
1879 s = SvGROW(sv, len + 1);
1887 /* This function is only called on magical items */
1889 sv_2bool(register SV *sv)
1901 if (SvAMAGIC(sv) && (tmpsv = AMG_CALLun(sv,bool_)))
1902 return SvTRUE(tmpsv);
1904 #endif /* OVERLOAD */
1905 return SvRV(sv) != 0;
1908 register XPV* Xpvtmp;
1909 if ((Xpvtmp = (XPV*)SvANY(sv)) &&
1910 (*Xpvtmp->xpv_pv > '0' ||
1911 Xpvtmp->xpv_cur > 1 ||
1912 (Xpvtmp->xpv_cur && *Xpvtmp->xpv_pv != '0')))
1919 return SvIVX(sv) != 0;
1922 return SvNVX(sv) != 0.0;
1929 /* Note: sv_setsv() should not be called with a source string that needs
1930 * to be reused, since it may destroy the source string if it is marked
1935 sv_setsv(SV *dstr, register SV *sstr)
1938 register U32 sflags;
1944 SV_CHECK_THINKFIRST(dstr);
1947 stype = SvTYPE(sstr);
1948 dtype = SvTYPE(dstr);
1950 if (dtype == SVt_PVGV && (SvFLAGS(dstr) & SVf_FAKE)) {
1951 sv_unglob(dstr); /* so fake GLOB won't perpetuate */
1952 sv_setpvn(dstr, "", 0);
1953 (void)SvPOK_only(dstr);
1954 dtype = SvTYPE(dstr);
1959 #endif /* OVERLOAD */
1960 /* There's a lot of redundancy below but we're going for speed here */
1965 if (dtype != SVt_PVGV) {
1966 (void)SvOK_off(dstr);
1974 sv_upgrade(dstr, SVt_IV);
1977 sv_upgrade(dstr, SVt_PVNV);
1981 sv_upgrade(dstr, SVt_PVIV);
1984 (void)SvIOK_only(dstr);
1985 SvIVX(dstr) = SvIVX(sstr);
1996 sv_upgrade(dstr, SVt_NV);
2001 sv_upgrade(dstr, SVt_PVNV);
2004 SvNVX(dstr) = SvNVX(sstr);
2005 (void)SvNOK_only(dstr);
2013 sv_upgrade(dstr, SVt_RV);
2014 else if (dtype == SVt_PVGV &&
2015 SvTYPE(SvRV(sstr)) == SVt_PVGV) {
2018 if (curcop->cop_stash != GvSTASH(dstr))
2019 GvIMPORTED_on(dstr);
2029 sv_upgrade(dstr, SVt_PV);
2032 if (dtype < SVt_PVIV)
2033 sv_upgrade(dstr, SVt_PVIV);
2036 if (dtype < SVt_PVNV)
2037 sv_upgrade(dstr, SVt_PVNV);
2044 croak("Bizarre copy of %s in %s", sv_reftype(sstr, 0),
2045 op_name[op->op_type]);
2047 croak("Bizarre copy of %s", sv_reftype(sstr, 0));
2051 if (dtype <= SVt_PVGV) {
2053 if (dtype != SVt_PVGV) {
2054 char *name = GvNAME(sstr);
2055 STRLEN len = GvNAMELEN(sstr);
2056 sv_upgrade(dstr, SVt_PVGV);
2057 sv_magic(dstr, dstr, '*', name, len);
2058 GvSTASH(dstr) = (HV*)SvREFCNT_inc(GvSTASH(sstr));
2059 GvNAME(dstr) = savepvn(name, len);
2060 GvNAMELEN(dstr) = len;
2061 SvFAKE_on(dstr); /* can coerce to non-glob */
2063 /* ahem, death to those who redefine active sort subs */
2064 else if (curstackinfo->si_type == PERLSI_SORT
2065 && GvCV(dstr) && sortcop == CvSTART(GvCV(dstr)))
2066 croak("Can't redefine active sort subroutine %s",
2068 (void)SvOK_off(dstr);
2069 GvINTRO_off(dstr); /* one-shot flag */
2071 GvGP(dstr) = gp_ref(GvGP(sstr));
2073 if (curcop->cop_stash != GvSTASH(dstr))
2074 GvIMPORTED_on(dstr);
2081 if (SvGMAGICAL(sstr)) {
2083 if (SvTYPE(sstr) != stype) {
2084 stype = SvTYPE(sstr);
2085 if (stype == SVt_PVGV && dtype <= SVt_PVGV)
2089 if (stype == SVt_PVLV)
2090 SvUPGRADE(dstr, SVt_PVNV);
2092 SvUPGRADE(dstr, stype);
2095 sflags = SvFLAGS(sstr);
2097 if (sflags & SVf_ROK) {
2098 if (dtype >= SVt_PV) {
2099 if (dtype == SVt_PVGV) {
2101 SV *sref = SvREFCNT_inc(SvRV(sstr));
2103 int intro = GvINTRO(dstr);
2107 GvGP(dstr)->gp_refcnt--;
2108 GvINTRO_off(dstr); /* one-shot flag */
2109 Newz(602,gp, 1, GP);
2110 GvGP(dstr) = gp_ref(gp);
2111 GvSV(dstr) = NEWSV(72,0);
2112 GvLINE(dstr) = curcop->cop_line;
2113 GvEGV(dstr) = (GV*)dstr;
2116 switch (SvTYPE(sref)) {
2119 SAVESPTR(GvAV(dstr));
2121 dref = (SV*)GvAV(dstr);
2122 GvAV(dstr) = (AV*)sref;
2123 if (curcop->cop_stash != GvSTASH(dstr))
2124 GvIMPORTED_AV_on(dstr);
2128 SAVESPTR(GvHV(dstr));
2130 dref = (SV*)GvHV(dstr);
2131 GvHV(dstr) = (HV*)sref;
2132 if (curcop->cop_stash != GvSTASH(dstr))
2133 GvIMPORTED_HV_on(dstr);
2137 if (GvCVGEN(dstr) && GvCV(dstr) != (CV*)sref) {
2138 SvREFCNT_dec(GvCV(dstr));
2139 GvCV(dstr) = Nullcv;
2140 GvCVGEN(dstr) = 0; /* Switch off cacheness. */
2143 SAVESPTR(GvCV(dstr));
2146 dref = (SV*)GvCV(dstr);
2147 if (GvCV(dstr) != (CV*)sref) {
2148 CV* cv = GvCV(dstr);
2150 if (!GvCVGEN((GV*)dstr) &&
2151 (CvROOT(cv) || CvXSUB(cv)))
2153 SV *const_sv = cv_const_sv(cv);
2154 bool const_changed = TRUE;
2156 const_changed = sv_cmp(const_sv,
2157 op_const_sv(CvSTART((CV*)sref),
2159 /* ahem, death to those who redefine
2160 * active sort subs */
2161 if (curstackinfo->si_type == PERLSI_SORT &&
2162 sortcop == CvSTART(cv))
2164 "Can't redefine active sort subroutine %s",
2165 GvENAME((GV*)dstr));
2166 if (dowarn || (const_changed && const_sv)) {
2167 if (!(CvGV(cv) && GvSTASH(CvGV(cv))
2168 && HvNAME(GvSTASH(CvGV(cv)))
2169 && strEQ(HvNAME(GvSTASH(CvGV(cv))),
2172 "Constant subroutine %s redefined"
2173 : "Subroutine %s redefined",
2174 GvENAME((GV*)dstr));
2177 cv_ckproto(cv, (GV*)dstr,
2178 SvPOK(sref) ? SvPVX(sref) : Nullch);
2180 GvCV(dstr) = (CV*)sref;
2181 GvCVGEN(dstr) = 0; /* Switch off cacheness. */
2182 GvASSUMECV_on(dstr);
2185 if (curcop->cop_stash != GvSTASH(dstr))
2186 GvIMPORTED_CV_on(dstr);
2190 SAVESPTR(GvIOp(dstr));
2192 dref = (SV*)GvIOp(dstr);
2193 GvIOp(dstr) = (IO*)sref;
2197 SAVESPTR(GvSV(dstr));
2199 dref = (SV*)GvSV(dstr);
2201 if (curcop->cop_stash != GvSTASH(dstr))
2202 GvIMPORTED_SV_on(dstr);
2213 (void)SvOOK_off(dstr); /* backoff */
2214 Safefree(SvPVX(dstr));
2215 SvLEN(dstr)=SvCUR(dstr)=0;
2218 (void)SvOK_off(dstr);
2219 SvRV(dstr) = SvREFCNT_inc(SvRV(sstr));
2221 if (sflags & SVp_NOK) {
2223 SvNVX(dstr) = SvNVX(sstr);
2225 if (sflags & SVp_IOK) {
2226 (void)SvIOK_on(dstr);
2227 SvIVX(dstr) = SvIVX(sstr);
2230 if (SvAMAGIC(sstr)) {
2233 #endif /* OVERLOAD */
2235 else if (sflags & SVp_POK) {
2238 * Check to see if we can just swipe the string. If so, it's a
2239 * possible small lose on short strings, but a big win on long ones.
2240 * It might even be a win on short strings if SvPVX(dstr)
2241 * has to be allocated and SvPVX(sstr) has to be freed.
2244 if (SvTEMP(sstr) && /* slated for free anyway? */
2245 SvREFCNT(sstr) == 1 && /* and no other references to it? */
2246 !(sflags & SVf_OOK)) /* and not involved in OOK hack? */
2248 if (SvPVX(dstr)) { /* we know that dtype >= SVt_PV */
2250 SvFLAGS(dstr) &= ~SVf_OOK;
2251 Safefree(SvPVX(dstr) - SvIVX(dstr));
2254 Safefree(SvPVX(dstr));
2256 (void)SvPOK_only(dstr);
2257 SvPV_set(dstr, SvPVX(sstr));
2258 SvLEN_set(dstr, SvLEN(sstr));
2259 SvCUR_set(dstr, SvCUR(sstr));
2261 (void)SvOK_off(sstr);
2262 SvPV_set(sstr, Nullch);
2267 else { /* have to copy actual string */
2268 STRLEN len = SvCUR(sstr);
2270 SvGROW(dstr, len + 1); /* inlined from sv_setpvn */
2271 Move(SvPVX(sstr),SvPVX(dstr),len,char);
2272 SvCUR_set(dstr, len);
2273 *SvEND(dstr) = '\0';
2274 (void)SvPOK_only(dstr);
2277 if (sflags & SVp_NOK) {
2279 SvNVX(dstr) = SvNVX(sstr);
2281 if (sflags & SVp_IOK) {
2282 (void)SvIOK_on(dstr);
2283 SvIVX(dstr) = SvIVX(sstr);
2286 else if (sflags & SVp_NOK) {
2287 SvNVX(dstr) = SvNVX(sstr);
2288 (void)SvNOK_only(dstr);
2290 (void)SvIOK_on(dstr);
2291 SvIVX(dstr) = SvIVX(sstr);
2294 else if (sflags & SVp_IOK) {
2295 (void)SvIOK_only(dstr);
2296 SvIVX(dstr) = SvIVX(sstr);
2299 if (dtype == SVt_PVGV) {
2301 warn("Undefined value assigned to typeglob");
2304 (void)SvOK_off(dstr);
2310 sv_setsv_mg(SV *dstr, register SV *sstr)
2312 sv_setsv(dstr,sstr);
2317 sv_setpvn(register SV *sv, register const char *ptr, register STRLEN len)
2319 register char *dptr;
2320 assert(len >= 0); /* STRLEN is probably unsigned, so this may
2321 elicit a warning, but it won't hurt. */
2322 SV_CHECK_THINKFIRST(sv);
2327 if (SvTYPE(sv) >= SVt_PV) {
2328 if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV)
2332 sv_upgrade(sv, SVt_PV);
2334 SvGROW(sv, len + 1);
2336 Move(ptr,dptr,len,char);
2339 (void)SvPOK_only(sv); /* validate pointer */
2344 sv_setpvn_mg(register SV *sv, register const char *ptr, register STRLEN len)
2346 sv_setpvn(sv,ptr,len);
2351 sv_setpv(register SV *sv, register const char *ptr)
2353 register STRLEN len;
2355 SV_CHECK_THINKFIRST(sv);
2361 if (SvTYPE(sv) >= SVt_PV) {
2362 if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV)
2366 sv_upgrade(sv, SVt_PV);
2368 SvGROW(sv, len + 1);
2369 Move(ptr,SvPVX(sv),len+1,char);
2371 (void)SvPOK_only(sv); /* validate pointer */
2376 sv_setpv_mg(register SV *sv, register const char *ptr)
2383 sv_usepvn(register SV *sv, register char *ptr, register STRLEN len)
2385 SV_CHECK_THINKFIRST(sv);
2386 (void)SvUPGRADE(sv, SVt_PV);
2392 Safefree(SvPVX(sv));
2393 Renew(ptr, len+1, char);
2396 SvLEN_set(sv, len+1);
2398 (void)SvPOK_only(sv); /* validate pointer */
2403 sv_usepvn_mg(register SV *sv, register char *ptr, register STRLEN len)
2405 sv_usepvn(sv,ptr,len);
2410 sv_check_thinkfirst(register SV *sv)
2412 if (SvREADONLY(sv)) {
2414 if (curcop != &compiling)
2422 sv_chop(register SV *sv, register char *ptr) /* like set but assuming ptr is in sv */
2426 register STRLEN delta;
2428 if (!ptr || !SvPOKp(sv))
2430 SV_CHECK_THINKFIRST(sv);
2431 if (SvTYPE(sv) < SVt_PVIV)
2432 sv_upgrade(sv,SVt_PVIV);
2436 SvFLAGS(sv) |= SVf_OOK;
2438 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVp_IOK|SVp_NOK);
2439 delta = ptr - SvPVX(sv);
2447 sv_catpvn(register SV *sv, register char *ptr, register STRLEN len)
2452 junk = SvPV_force(sv, tlen);
2453 SvGROW(sv, tlen + len + 1);
2456 Move(ptr,SvPVX(sv)+tlen,len,char);
2459 (void)SvPOK_only(sv); /* validate pointer */
2464 sv_catpvn_mg(register SV *sv, register char *ptr, register STRLEN len)
2466 sv_catpvn(sv,ptr,len);
2471 sv_catsv(SV *dstr, register SV *sstr)
2477 if (s = SvPV(sstr, len))
2478 sv_catpvn(dstr,s,len);
2482 sv_catsv_mg(SV *dstr, register SV *sstr)
2484 sv_catsv(dstr,sstr);
2489 sv_catpv(register SV *sv, register char *ptr)
2491 register STRLEN len;
2497 junk = SvPV_force(sv, tlen);
2499 SvGROW(sv, tlen + len + 1);
2502 Move(ptr,SvPVX(sv)+tlen,len+1,char);
2504 (void)SvPOK_only(sv); /* validate pointer */
2509 sv_catpv_mg(register SV *sv, register char *ptr)
2525 sv_upgrade(sv, SVt_PV);
2526 SvGROW(sv, len + 1);
2531 /* name is assumed to contain an SV* if (name && namelen == HEf_SVKEY) */
2534 sv_magic(register SV *sv, SV *obj, int how, char *name, I32 namlen)
2538 if (SvREADONLY(sv)) {
2540 if (curcop != &compiling && !strchr("gBf", how))
2543 if (SvMAGICAL(sv) || (how == 't' && SvTYPE(sv) >= SVt_PVMG)) {
2544 if (SvMAGIC(sv) && (mg = mg_find(sv, how))) {
2551 (void)SvUPGRADE(sv, SVt_PVMG);
2553 Newz(702,mg, 1, MAGIC);
2554 mg->mg_moremagic = SvMAGIC(sv);
2557 if (!obj || obj == sv || how == '#' || how == 'r')
2561 mg->mg_obj = SvREFCNT_inc(obj);
2562 mg->mg_flags |= MGf_REFCOUNTED;
2565 mg->mg_len = namlen;
2568 mg->mg_ptr = savepvn(name, namlen);
2569 else if (namlen == HEf_SVKEY)
2570 mg->mg_ptr = (char*)SvREFCNT_inc((SV*)name);
2574 mg->mg_virtual = &vtbl_sv;
2578 mg->mg_virtual = &vtbl_amagic;
2581 mg->mg_virtual = &vtbl_amagicelem;
2586 #endif /* OVERLOAD */
2588 mg->mg_virtual = &vtbl_bm;
2591 mg->mg_virtual = &vtbl_env;
2594 mg->mg_virtual = &vtbl_fm;
2597 mg->mg_virtual = &vtbl_envelem;
2600 mg->mg_virtual = &vtbl_mglob;
2603 mg->mg_virtual = &vtbl_isa;
2606 mg->mg_virtual = &vtbl_isaelem;
2609 mg->mg_virtual = &vtbl_nkeys;
2616 mg->mg_virtual = &vtbl_dbline;
2620 mg->mg_virtual = &vtbl_mutex;
2622 #endif /* USE_THREADS */
2623 #ifdef USE_LOCALE_COLLATE
2625 mg->mg_virtual = &vtbl_collxfrm;
2627 #endif /* USE_LOCALE_COLLATE */
2629 mg->mg_virtual = &vtbl_pack;
2633 mg->mg_virtual = &vtbl_packelem;
2636 mg->mg_virtual = &vtbl_regexp;
2639 mg->mg_virtual = &vtbl_sig;
2642 mg->mg_virtual = &vtbl_sigelem;
2645 mg->mg_virtual = &vtbl_taint;
2649 mg->mg_virtual = &vtbl_uvar;
2652 mg->mg_virtual = &vtbl_vec;
2655 mg->mg_virtual = &vtbl_substr;
2658 mg->mg_virtual = &vtbl_defelem;
2661 mg->mg_virtual = &vtbl_glob;
2664 mg->mg_virtual = &vtbl_arylen;
2667 mg->mg_virtual = &vtbl_pos;
2669 case '~': /* Reserved for use by extensions not perl internals. */
2670 /* Useful for attaching extension internal data to perl vars. */
2671 /* Note that multiple extensions may clash if magical scalars */
2672 /* etc holding private data from one are passed to another. */
2676 croak("Don't know how to handle magic of type '%c'", how);
2680 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
2684 sv_unmagic(SV *sv, int type)
2688 if (SvTYPE(sv) < SVt_PVMG || !SvMAGIC(sv))
2691 for (mg = *mgp; mg; mg = *mgp) {
2692 if (mg->mg_type == type) {
2693 MGVTBL* vtbl = mg->mg_virtual;
2694 *mgp = mg->mg_moremagic;
2695 if (vtbl && (vtbl->svt_free != NULL))
2696 (VTBL->svt_free)(sv, mg);
2697 if (mg->mg_ptr && mg->mg_type != 'g')
2698 if (mg->mg_len >= 0)
2699 Safefree(mg->mg_ptr);
2700 else if (mg->mg_len == HEf_SVKEY)
2701 SvREFCNT_dec((SV*)mg->mg_ptr);
2702 if (mg->mg_flags & MGf_REFCOUNTED)
2703 SvREFCNT_dec(mg->mg_obj);
2707 mgp = &mg->mg_moremagic;
2711 SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
2718 sv_insert(SV *bigstr, STRLEN offset, STRLEN len, char *little, STRLEN littlelen)
2722 register char *midend;
2723 register char *bigend;
2729 croak("Can't modify non-existent substring");
2730 SvPV_force(bigstr, curlen);
2731 if (offset + len > curlen) {
2732 SvGROW(bigstr, offset+len+1);
2733 Zero(SvPVX(bigstr)+curlen, offset+len-curlen, char);
2734 SvCUR_set(bigstr, offset+len);
2737 i = littlelen - len;
2738 if (i > 0) { /* string might grow */
2739 big = SvGROW(bigstr, SvCUR(bigstr) + i + 1);
2740 mid = big + offset + len;
2741 midend = bigend = big + SvCUR(bigstr);
2744 while (midend > mid) /* shove everything down */
2745 *--bigend = *--midend;
2746 Move(little,big+offset,littlelen,char);
2752 Move(little,SvPVX(bigstr)+offset,len,char);
2757 big = SvPVX(bigstr);
2760 bigend = big + SvCUR(bigstr);
2762 if (midend > bigend)
2763 croak("panic: sv_insert");
2765 if (mid - big > bigend - midend) { /* faster to shorten from end */
2767 Move(little, mid, littlelen,char);
2770 i = bigend - midend;
2772 Move(midend, mid, i,char);
2776 SvCUR_set(bigstr, mid - big);
2779 else if (i = mid - big) { /* faster from front */
2780 midend -= littlelen;
2782 sv_chop(bigstr,midend-i);
2787 Move(little, mid, littlelen,char);
2789 else if (littlelen) {
2790 midend -= littlelen;
2791 sv_chop(bigstr,midend);
2792 Move(little,midend,littlelen,char);
2795 sv_chop(bigstr,midend);
2800 /* make sv point to what nstr did */
2803 sv_replace(register SV *sv, register SV *nsv)
2805 U32 refcnt = SvREFCNT(sv);
2806 SV_CHECK_THINKFIRST(sv);
2807 if (SvREFCNT(nsv) != 1)
2808 warn("Reference miscount in sv_replace()");
2809 if (SvMAGICAL(sv)) {
2813 sv_upgrade(nsv, SVt_PVMG);
2814 SvMAGIC(nsv) = SvMAGIC(sv);
2815 SvFLAGS(nsv) |= SvMAGICAL(sv);
2821 assert(!SvREFCNT(sv));
2822 StructCopy(nsv,sv,SV);
2823 SvREFCNT(sv) = refcnt;
2824 SvFLAGS(nsv) |= SVTYPEMASK; /* Mark as freed */
2829 sv_clear(register SV *sv)
2833 assert(SvREFCNT(sv) == 0);
2837 if (defstash) { /* Still have a symbol table? */
2842 Zero(&tmpref, 1, SV);
2843 sv_upgrade(&tmpref, SVt_RV);
2845 SvREADONLY_on(&tmpref); /* DESTROY() could be naughty */
2846 SvREFCNT(&tmpref) = 1;
2849 stash = SvSTASH(sv);
2850 destructor = gv_fetchmethod(SvSTASH(sv), "DESTROY");
2853 PUSHSTACKi(PERLSI_DESTROY);
2854 SvRV(&tmpref) = SvREFCNT_inc(sv);
2859 perl_call_sv((SV*)GvCV(destructor),
2860 G_DISCARD|G_EVAL|G_KEEPERR);
2865 } while (SvOBJECT(sv) && SvSTASH(sv) != stash);
2867 del_XRV(SvANY(&tmpref));
2871 SvREFCNT_dec(SvSTASH(sv)); /* possibly of changed persuasion */
2872 SvOBJECT_off(sv); /* Curse the object. */
2873 if (SvTYPE(sv) != SVt_PVIO)
2874 --sv_objcount; /* XXX Might want something more general */
2878 croak("DESTROY created new reference to dead object");
2879 /* DESTROY gave object new lease on life */
2883 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv))
2886 switch (SvTYPE(sv)) {
2888 if (IoIFP(sv) != PerlIO_stdin() &&
2889 IoIFP(sv) != PerlIO_stdout() &&
2890 IoIFP(sv) != PerlIO_stderr())
2892 Safefree(IoTOP_NAME(sv));
2893 Safefree(IoFMT_NAME(sv));
2894 Safefree(IoBOTTOM_NAME(sv));
2910 Safefree(GvNAME(sv));
2911 /* cannot decrease stash refcount yet, as we might recursively delete
2912 ourselves when the refcnt drops to zero. Delay SvREFCNT_dec
2913 of stash until current sv is completely gone.
2914 -- JohnPC, 27 Mar 1998 */
2915 stash = GvSTASH(sv);
2922 (void)SvOOK_off(sv);
2927 SvREFCNT_dec(SvRV(sv));
2928 else if (SvPVX(sv) && SvLEN(sv))
2929 Safefree(SvPVX(sv));
2939 switch (SvTYPE(sv)) {
2955 del_XPVIV(SvANY(sv));
2958 del_XPVNV(SvANY(sv));
2961 del_XPVMG(SvANY(sv));
2964 del_XPVLV(SvANY(sv));
2967 del_XPVAV(SvANY(sv));
2970 del_XPVHV(SvANY(sv));
2973 del_XPVCV(SvANY(sv));
2976 del_XPVGV(SvANY(sv));
2977 /* code duplication for increased performance. */
2978 SvFLAGS(sv) &= SVf_BREAK;
2979 SvFLAGS(sv) |= SVTYPEMASK;
2980 /* decrease refcount of the stash that owns this GV, if any */
2982 SvREFCNT_dec(stash);
2983 return; /* not break, SvFLAGS reset already happened */
2985 del_XPVBM(SvANY(sv));
2988 del_XPVFM(SvANY(sv));
2991 del_XPVIO(SvANY(sv));
2994 SvFLAGS(sv) &= SVf_BREAK;
2995 SvFLAGS(sv) |= SVTYPEMASK;
3002 ATOMIC_INC(SvREFCNT(sv));
3009 int refcount_is_zero;
3013 if (SvREFCNT(sv) == 0) {
3014 if (SvFLAGS(sv) & SVf_BREAK)
3016 if (in_clean_all) /* All is fair */
3018 if (SvREADONLY(sv) && SvIMMORTAL(sv)) {
3019 /* make sure SvREFCNT(sv)==0 happens very seldom */
3020 SvREFCNT(sv) = (~(U32)0)/2;
3023 warn("Attempt to free unreferenced scalar");
3026 ATOMIC_DEC_AND_TEST(refcount_is_zero, SvREFCNT(sv));
3027 if (!refcount_is_zero)
3031 warn("Attempt to free temp prematurely: %s", SvPEEK(sv));
3035 if (SvREADONLY(sv) && SvIMMORTAL(sv)) {
3036 /* make sure SvREFCNT(sv)==0 happens very seldom */
3037 SvREFCNT(sv) = (~(U32)0)/2;
3046 sv_len(register SV *sv)
3055 len = mg_length(sv);
3057 junk = SvPV(sv, len);
3062 sv_eq(register SV *str1, register SV *str2)
3074 pv1 = SvPV(str1, cur1);
3079 pv2 = SvPV(str2, cur2);
3084 return memEQ(pv1, pv2, cur1);
3088 sv_cmp(register SV *str1, register SV *str2)
3091 char *pv1 = str1 ? SvPV(str1, cur1) : (char *) NULL;
3093 char *pv2 = str2 ? SvPV(str2, cur2) : (char *) NULL;
3097 return cur2 ? -1 : 0;
3102 retval = memcmp((void*)pv1, (void*)pv2, cur1 < cur2 ? cur1 : cur2);
3105 return retval < 0 ? -1 : 1;
3110 return cur1 < cur2 ? -1 : 1;
3114 sv_cmp_locale(register SV *sv1, register SV *sv2)
3116 #ifdef USE_LOCALE_COLLATE
3122 if (collation_standard)
3126 pv1 = sv1 ? sv_collxfrm(sv1, &len1) : (char *) NULL;
3128 pv2 = sv2 ? sv_collxfrm(sv2, &len2) : (char *) NULL;
3130 if (!pv1 || !len1) {
3141 retval = memcmp((void*)pv1, (void*)pv2, len1 < len2 ? len1 : len2);
3144 return retval < 0 ? -1 : 1;
3147 * When the result of collation is equality, that doesn't mean
3148 * that there are no differences -- some locales exclude some
3149 * characters from consideration. So to avoid false equalities,
3150 * we use the raw string as a tiebreaker.
3156 #endif /* USE_LOCALE_COLLATE */
3158 return sv_cmp(sv1, sv2);
3161 #ifdef USE_LOCALE_COLLATE
3163 * Any scalar variable may carry an 'o' magic that contains the
3164 * scalar data of the variable transformed to such a format that
3165 * a normal memory comparison can be used to compare the data
3166 * according to the locale settings.
3169 sv_collxfrm(SV *sv, STRLEN *nxp)
3173 mg = SvMAGICAL(sv) ? mg_find(sv, 'o') : (MAGIC *) NULL;
3174 if (!mg || !mg->mg_ptr || *(U32*)mg->mg_ptr != collation_ix) {
3179 Safefree(mg->mg_ptr);
3181 if ((xf = mem_collxfrm(s, len, &xlen))) {
3182 if (SvREADONLY(sv)) {
3185 return xf + sizeof(collation_ix);
3188 sv_magic(sv, 0, 'o', 0, 0);
3189 mg = mg_find(sv, 'o');
3202 if (mg && mg->mg_ptr) {
3204 return mg->mg_ptr + sizeof(collation_ix);
3212 #endif /* USE_LOCALE_COLLATE */
3215 sv_gets(register SV *sv, register PerlIO *fp, I32 append)
3220 register STDCHAR rslast;
3221 register STDCHAR *bp;
3225 SV_CHECK_THINKFIRST(sv);
3226 (void)SvUPGRADE(sv, SVt_PV);
3233 else if (RsRECORD(rs)) {
3234 I32 recsize, bytesread;
3237 /* Grab the size of the record we're getting */
3238 recsize = SvIV(SvRV(rs));
3239 (void)SvPOK_only(sv); /* Validate pointer */
3240 /* Make sure we've got the room to yank in the whole thing */
3241 if (SvLEN(sv) <= recsize + 3) {
3242 /* No, so make it bigger */
3243 SvGROW(sv, recsize + 3);
3245 buffer = SvPVX(sv); /* Get the location of the final buffer */
3248 /* VMS wants read instead of fread, because fread doesn't respect */
3249 /* RMS record boundaries. This is not necessarily a good thing to be */
3250 /* doing, but we've got no other real choice */
3251 bytesread = PerlLIO_read(PerlIO_fileno(fp), buffer, recsize);
3253 bytesread = PerlIO_read(fp, buffer, recsize);
3255 SvCUR_set(sv, bytesread);
3256 return(SvCUR(sv) ? SvPVX(sv) : Nullch);
3258 else if (RsPARA(rs)) {
3263 rsptr = SvPV(rs, rslen);
3264 rslast = rslen ? rsptr[rslen - 1] : '\0';
3266 if (RsPARA(rs)) { /* have to do this both before and after */
3267 do { /* to make sure file boundaries work right */
3270 i = PerlIO_getc(fp);
3274 PerlIO_ungetc(fp,i);
3280 /* See if we know enough about I/O mechanism to cheat it ! */
3282 /* This used to be #ifdef test - it is made run-time test for ease
3283 of abstracting out stdio interface. One call should be cheap
3284 enough here - and may even be a macro allowing compile
3288 if (PerlIO_fast_gets(fp)) {
3291 * We're going to steal some values from the stdio struct
3292 * and put EVERYTHING in the innermost loop into registers.
3294 register STDCHAR *ptr;
3298 #if defined(VMS) && defined(PERLIO_IS_STDIO)
3299 /* An ungetc()d char is handled separately from the regular
3300 * buffer, so we getc() it back out and stuff it in the buffer.
3302 i = PerlIO_getc(fp);
3303 if (i == EOF) return 0;
3304 *(--((*fp)->_ptr)) = (unsigned char) i;
3308 /* Here is some breathtakingly efficient cheating */
3310 cnt = PerlIO_get_cnt(fp); /* get count into register */
3311 (void)SvPOK_only(sv); /* validate pointer */
3312 if (SvLEN(sv) - append <= cnt + 1) { /* make sure we have the room */
3313 if (cnt > 80 && SvLEN(sv) > append) {
3314 shortbuffered = cnt - SvLEN(sv) + append + 1;
3315 cnt -= shortbuffered;
3319 /* remember that cnt can be negative */
3320 SvGROW(sv, append + (cnt <= 0 ? 2 : (cnt + 1)));
3325 bp = (STDCHAR*)SvPVX(sv) + append; /* move these two too to registers */
3326 ptr = (STDCHAR*)PerlIO_get_ptr(fp);
3327 DEBUG_P(PerlIO_printf(Perl_debug_log,
3328 "Screamer: entering, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3329 DEBUG_P(PerlIO_printf(Perl_debug_log,
3330 "Screamer: entering: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3331 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3332 (long)(PerlIO_has_base(fp) ? PerlIO_get_base(fp) : 0)));
3337 while (cnt > 0) { /* this | eat */
3339 if ((*bp++ = *ptr++) == rslast) /* really | dust */
3340 goto thats_all_folks; /* screams | sed :-) */
3344 Copy(ptr, bp, cnt, char); /* this | eat */
3345 bp += cnt; /* screams | dust */
3346 ptr += cnt; /* louder | sed :-) */
3351 if (shortbuffered) { /* oh well, must extend */
3352 cnt = shortbuffered;
3354 bpx = bp - (STDCHAR*)SvPVX(sv); /* box up before relocation */
3356 SvGROW(sv, SvLEN(sv) + append + cnt + 2);
3357 bp = (STDCHAR*)SvPVX(sv) + bpx; /* unbox after relocation */
3361 DEBUG_P(PerlIO_printf(Perl_debug_log,
3362 "Screamer: going to getc, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3363 PerlIO_set_ptrcnt(fp, ptr, cnt); /* deregisterize cnt and ptr */
3364 DEBUG_P(PerlIO_printf(Perl_debug_log,
3365 "Screamer: pre: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3366 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3367 (long)(PerlIO_has_base (fp) ? PerlIO_get_base(fp) : 0)));
3368 /* This used to call 'filbuf' in stdio form, but as that behaves like
3369 getc when cnt <= 0 we use PerlIO_getc here to avoid introducing
3370 another abstraction. */
3371 i = PerlIO_getc(fp); /* get more characters */
3372 DEBUG_P(PerlIO_printf(Perl_debug_log,
3373 "Screamer: post: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3374 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3375 (long)(PerlIO_has_base (fp) ? PerlIO_get_base(fp) : 0)));
3376 cnt = PerlIO_get_cnt(fp);
3377 ptr = (STDCHAR*)PerlIO_get_ptr(fp); /* reregisterize cnt and ptr */
3378 DEBUG_P(PerlIO_printf(Perl_debug_log,
3379 "Screamer: after getc, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3381 if (i == EOF) /* all done for ever? */
3382 goto thats_really_all_folks;
3384 bpx = bp - (STDCHAR*)SvPVX(sv); /* box up before relocation */
3386 SvGROW(sv, bpx + cnt + 2);
3387 bp = (STDCHAR*)SvPVX(sv) + bpx; /* unbox after relocation */
3389 *bp++ = i; /* store character from PerlIO_getc */
3391 if (rslen && (STDCHAR)i == rslast) /* all done for now? */
3392 goto thats_all_folks;
3396 if ((rslen > 1 && (bp - (STDCHAR*)SvPVX(sv) < rslen)) ||
3397 memNE((char*)bp - rslen, rsptr, rslen))
3398 goto screamer; /* go back to the fray */
3399 thats_really_all_folks:
3401 cnt += shortbuffered;
3402 DEBUG_P(PerlIO_printf(Perl_debug_log,
3403 "Screamer: quitting, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3404 PerlIO_set_ptrcnt(fp, ptr, cnt); /* put these back or we're in trouble */
3405 DEBUG_P(PerlIO_printf(Perl_debug_log,
3406 "Screamer: end: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3407 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3408 (long)(PerlIO_has_base (fp) ? PerlIO_get_base(fp) : 0)));
3410 SvCUR_set(sv, bp - (STDCHAR*)SvPVX(sv)); /* set length */
3411 DEBUG_P(PerlIO_printf(Perl_debug_log,
3412 "Screamer: done, len=%ld, string=|%.*s|\n",
3413 (long)SvCUR(sv),(int)SvCUR(sv),SvPVX(sv)));
3417 /*The big, slow, and stupid way */
3422 register STDCHAR *bpe = buf + sizeof(buf);
3424 while ((i = PerlIO_getc(fp)) != EOF && (*bp++ = i) != rslast && bp < bpe)
3425 ; /* keep reading */
3429 cnt = PerlIO_read(fp,(char*)buf, sizeof(buf));
3430 /* Accomodate broken VAXC compiler, which applies U8 cast to
3431 * both args of ?: operator, causing EOF to change into 255
3433 if (cnt) { i = (U8)buf[cnt - 1]; } else { i = EOF; }
3437 sv_catpvn(sv, (char *) buf, cnt);
3439 sv_setpvn(sv, (char *) buf, cnt);
3441 if (i != EOF && /* joy */
3443 SvCUR(sv) < rslen ||
3444 memNE(SvPVX(sv) + SvCUR(sv) - rslen, rsptr, rslen)))
3448 * If we're reading from a TTY and we get a short read,
3449 * indicating that the user hit his EOF character, we need
3450 * to notice it now, because if we try to read from the TTY
3451 * again, the EOF condition will disappear.
3453 * The comparison of cnt to sizeof(buf) is an optimization
3454 * that prevents unnecessary calls to feof().
3458 if (!(cnt < sizeof(buf) && PerlIO_eof(fp)))
3463 if (RsPARA(rs)) { /* have to do this both before and after */
3464 while (i != EOF) { /* to make sure file boundaries work right */
3465 i = PerlIO_getc(fp);
3467 PerlIO_ungetc(fp,i);
3474 win32_strip_return(sv);
3477 return (SvCUR(sv) - append) ? SvPVX(sv) : Nullch;
3482 sv_inc(register SV *sv)
3489 if (SvTHINKFIRST(sv)) {
3490 if (SvREADONLY(sv)) {
3492 if (curcop != &compiling)
3498 if (SvAMAGIC(sv) && AMG_CALLun(sv,inc)) return;
3499 #endif /* OVERLOAD */
3507 flags = SvFLAGS(sv);
3508 if (flags & SVp_NOK) {
3509 (void)SvNOK_only(sv);
3513 if (flags & SVp_IOK) {
3514 if (SvIVX(sv) == IV_MAX)
3515 sv_setnv(sv, (double)IV_MAX + 1.0);
3517 (void)SvIOK_only(sv);
3522 if (!(flags & SVp_POK) || !*SvPVX(sv)) {
3523 if ((flags & SVTYPEMASK) < SVt_PVNV)
3524 sv_upgrade(sv, SVt_NV);
3526 (void)SvNOK_only(sv);
3530 while (isALPHA(*d)) d++;
3531 while (isDIGIT(*d)) d++;
3533 SET_NUMERIC_STANDARD();
3534 sv_setnv(sv,atof(SvPVX(sv)) + 1.0); /* punt */
3538 while (d >= SvPVX(sv)) {
3548 *(d--) -= 'z' - 'a' + 1;
3551 /* oh,oh, the number grew */
3552 SvGROW(sv, SvCUR(sv) + 2);
3554 for (d = SvPVX(sv) + SvCUR(sv); d > SvPVX(sv); d--)
3563 sv_dec(register SV *sv)
3569 if (SvTHINKFIRST(sv)) {
3570 if (SvREADONLY(sv)) {
3572 if (curcop != &compiling)
3578 if (SvAMAGIC(sv) && AMG_CALLun(sv,dec)) return;
3579 #endif /* OVERLOAD */
3587 flags = SvFLAGS(sv);
3588 if (flags & SVp_NOK) {
3590 (void)SvNOK_only(sv);
3593 if (flags & SVp_IOK) {
3594 if (SvIVX(sv) == IV_MIN)
3595 sv_setnv(sv, (double)IV_MIN - 1.0);
3597 (void)SvIOK_only(sv);
3602 if (!(flags & SVp_POK)) {
3603 if ((flags & SVTYPEMASK) < SVt_PVNV)
3604 sv_upgrade(sv, SVt_NV);
3606 (void)SvNOK_only(sv);
3609 SET_NUMERIC_STANDARD();
3610 sv_setnv(sv,atof(SvPVX(sv)) - 1.0); /* punt */
3613 /* Make a string that will exist for the duration of the expression
3614 * evaluation. Actually, it may have to last longer than that, but
3615 * hopefully we won't free it until it has been assigned to a
3616 * permanent location. */
3622 tmps_max += (tmps_max < 512) ? 128 : 512;
3623 Renew(tmps_stack, tmps_max, SV*);
3627 sv_mortalcopy(SV *oldstr)
3636 sv_setsv(sv,oldstr);
3637 if (++tmps_ix >= tmps_max)
3639 tmps_stack[tmps_ix] = sv;
3653 SvFLAGS(sv) = SVs_TEMP;
3654 if (++tmps_ix >= tmps_max)
3656 tmps_stack[tmps_ix] = sv;
3660 /* same thing without the copying */
3663 sv_2mortal(register SV *sv)
3668 if (SvREADONLY(sv) && SvIMMORTAL(sv))
3670 if (++tmps_ix >= tmps_max)
3672 tmps_stack[tmps_ix] = sv;
3678 newSVpv(char *s, STRLEN len)
3688 sv_setpvn(sv,s,len);
3693 newSVpvn(char *s, STRLEN len)
3701 sv_setpvn(sv,s,len);
3706 newSVpvf(const char* pat, ...)
3715 va_start(args, pat);
3716 sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
3749 newRV_noinc(SV *tmpRef)
3758 sv_upgrade(sv, SVt_RV);
3768 return newRV_noinc(SvREFCNT_inc(tmpRef));
3771 /* make an exact duplicate of old */
3774 newSVsv(register SV *old)
3780 if (SvTYPE(old) == SVTYPEMASK) {
3781 warn("semi-panic: attempt to dup freed string");
3799 sv_reset(register char *s, HV *stash)
3812 if (!*s) { /* reset ?? searches */
3813 for (pm = HvPMROOT(stash); pm; pm = pm->op_pmnext) {
3814 pm->op_pmdynflags &= ~PMdf_USED;
3819 /* reset variables */
3821 if (!HvARRAY(stash))
3824 Zero(todo, 256, char);
3831 for ( ; i <= max; i++) {
3834 for (i = 0; i <= (I32) HvMAX(stash); i++) {
3835 for (entry = HvARRAY(stash)[i];
3837 entry = HeNEXT(entry)) {
3838 if (!todo[(U8)*HeKEY(entry)])
3840 gv = (GV*)HeVAL(entry);
3843 if (SvTYPE(sv) >= SVt_PV) {
3845 if (SvPVX(sv) != Nullch)
3852 if (GvHV(gv) && !HvNAME(GvHV(gv))) {
3854 #ifndef VMS /* VMS has no environ array */
3856 environ[0] = Nullch;
3870 switch (SvTYPE(sv)) {
3878 croak("Bad filehandle: %s", GvNAME(gv));
3882 croak(no_usym, "filehandle");
3884 return sv_2io(SvRV(sv));
3885 gv = gv_fetchpv(SvPV(sv,na), FALSE, SVt_PVIO);
3891 croak("Bad filehandle: %s", SvPV(sv,na));
3898 sv_2cv(SV *sv, HV **st, GV **gvp, I32 lref)
3904 return *gvp = Nullgv, Nullcv;
3905 switch (SvTYPE(sv)) {
3925 if (SvTYPE(cv) != SVt_PVCV)
3926 croak("Not a subroutine reference");
3934 gv = gv_fetchpv(SvPV(sv, na), lref, SVt_PVCV);
3940 if (lref && !GvCVu(gv)) {
3943 tmpsv = NEWSV(704,0);
3944 gv_efullname3(tmpsv, gv, Nullch);
3945 newSUB(start_subparse(FALSE, 0),
3946 newSVOP(OP_CONST, 0, tmpsv),
3951 croak("Unable to create sub named \"%s\"", SvPV(sv,na));
3958 sv_true(register SV *sv)
3965 if ((tXpv = (XPV*)SvANY(sv)) &&
3966 (*tXpv->xpv_pv > '0' ||
3967 tXpv->xpv_cur > 1 ||
3968 (tXpv->xpv_cur && *tXpv->xpv_pv != '0')))
3975 return SvIVX(sv) != 0;
3978 return SvNVX(sv) != 0.0;
3980 return sv_2bool(sv);
3986 sv_iv(register SV *sv)
3994 sv_uv(register SV *sv)
4002 sv_nv(register SV *sv)
4010 sv_pvn(SV *sv, STRLEN *lp)
4016 return sv_2pv(sv, lp);
4020 sv_pvn_force(SV *sv, STRLEN *lp)
4024 if (SvREADONLY(sv)) {
4026 if (curcop != &compiling)
4034 if (SvTYPE(sv) > SVt_PVLV && SvTYPE(sv) != SVt_PVFM) {
4035 if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV) {
4042 croak("Can't coerce %s to string in %s", sv_reftype(sv,0),
4043 op_name[op->op_type]);
4048 if (s != SvPVX(sv)) { /* Almost, but not quite, sv_setpvn() */
4053 (void)SvUPGRADE(sv, SVt_PV); /* Never FALSE */
4054 SvGROW(sv, len + 1);
4055 Move(s,SvPVX(sv),len,char);
4060 SvPOK_on(sv); /* validate pointer */
4062 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2pv(%s)\n",
4063 (unsigned long)sv,SvPVX(sv)));
4070 sv_reftype(SV *sv, int ob)
4072 if (ob && SvOBJECT(sv))
4073 return HvNAME(SvSTASH(sv));
4075 switch (SvTYPE(sv)) {
4089 case SVt_PVLV: return "LVALUE";
4090 case SVt_PVAV: return "ARRAY";
4091 case SVt_PVHV: return "HASH";
4092 case SVt_PVCV: return "CODE";
4093 case SVt_PVGV: return "GLOB";
4094 case SVt_PVFM: return "FORMAT";
4095 default: return "UNKNOWN";
4116 sv_isa(SV *sv, char *name)
4128 return strEQ(HvNAME(SvSTASH(sv)), name);
4132 newSVrv(SV *rv, char *classname)
4142 SV_CHECK_THINKFIRST(rv);
4145 #endif /* OVERLOAD */
4147 if (SvTYPE(rv) < SVt_RV)
4148 sv_upgrade(rv, SVt_RV);
4151 SvRV(rv) = SvREFCNT_inc(sv);
4155 HV* stash = gv_stashpv(classname, TRUE);
4156 (void)sv_bless(rv, stash);
4162 sv_setref_pv(SV *rv, char *classname, void *pv)
4165 sv_setsv(rv, &sv_undef);
4169 sv_setiv(newSVrv(rv,classname), (IV)pv);
4174 sv_setref_iv(SV *rv, char *classname, IV iv)
4176 sv_setiv(newSVrv(rv,classname), iv);
4181 sv_setref_nv(SV *rv, char *classname, double nv)
4183 sv_setnv(newSVrv(rv,classname), nv);
4188 sv_setref_pvn(SV *rv, char *classname, char *pv, I32 n)
4190 sv_setpvn(newSVrv(rv,classname), pv, n);
4195 sv_bless(SV *sv, HV *stash)
4200 croak("Can't bless non-reference value");
4202 if (SvFLAGS(tmpRef) & (SVs_OBJECT|SVf_READONLY)) {
4203 if (SvREADONLY(tmpRef))
4205 if (SvOBJECT(tmpRef)) {
4206 if (SvTYPE(tmpRef) != SVt_PVIO)
4208 SvREFCNT_dec(SvSTASH(tmpRef));
4211 SvOBJECT_on(tmpRef);
4212 if (SvTYPE(tmpRef) != SVt_PVIO)
4214 (void)SvUPGRADE(tmpRef, SVt_PVMG);
4215 SvSTASH(tmpRef) = (HV*)SvREFCNT_inc(stash);
4222 #endif /* OVERLOAD */
4230 assert(SvTYPE(sv) == SVt_PVGV);
4235 SvREFCNT_dec(GvSTASH(sv));
4236 GvSTASH(sv) = Nullhv;
4238 sv_unmagic(sv, '*');
4239 Safefree(GvNAME(sv));
4241 SvFLAGS(sv) &= ~SVTYPEMASK;
4242 SvFLAGS(sv) |= SVt_PVMG;
4252 if (SvREFCNT(rv) != 1 || SvREADONLY(rv))
4255 sv_2mortal(rv); /* Schedule for freeing later */
4261 sv_magic((sv), Nullsv, 't', Nullch, 0);
4267 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
4268 MAGIC *mg = mg_find(sv, 't');
4277 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
4278 MAGIC *mg = mg_find(sv, 't');
4279 if (mg && ((mg->mg_len & 1) || (mg->mg_len & 2) && mg->mg_obj == sv))
4286 sv_setpviv(SV *sv, IV iv)
4289 char buf[TYPE_DIGITS(UV)];
4290 char *ptr = buf + sizeof(buf);
4295 sv_setpvn(sv, "", 0);
4304 *--ptr = '0' + (uv % 10);
4306 len = (buf + sizeof(buf)) - ptr;
4307 /* taking advantage of SvCUR(sv) == 0 */
4308 SvGROW(sv, sign + len + 1);
4312 memcpy(p, ptr, len);
4315 SvCUR(sv) = p - SvPVX(sv);
4320 sv_setpviv_mg(SV *sv, IV iv)
4327 sv_setpvf(SV *sv, const char* pat, ...)
4330 va_start(args, pat);
4331 sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4337 sv_setpvf_mg(SV *sv, const char* pat, ...)
4340 va_start(args, pat);
4341 sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4347 sv_catpvf(SV *sv, const char* pat, ...)
4350 va_start(args, pat);
4351 sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4356 sv_catpvf_mg(SV *sv, const char* pat, ...)
4359 va_start(args, pat);
4360 sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4366 sv_vsetpvfn(SV *sv, const char *pat, STRLEN patlen, va_list *args, SV **svargs, I32 svmax, bool *used_locale)
4368 sv_setpvn(sv, "", 0);
4369 sv_vcatpvfn(sv, pat, patlen, args, svargs, svmax, used_locale);
4373 sv_vcatpvfn(SV *sv, const char *pat, STRLEN patlen, va_list *args, SV **svargs, I32 svmax, bool *used_locale)
4381 static char nullstr[] = "(null)";
4383 /* no matter what, this is a string now */
4384 (void)SvPV_force(sv, origlen);
4386 /* special-case "", "%s", and "%_" */
4389 if (patlen == 2 && pat[0] == '%') {
4393 char *s = va_arg(*args, char*);
4394 sv_catpv(sv, s ? s : nullstr);
4396 else if (svix < svmax)
4397 sv_catsv(sv, *svargs);
4401 sv_catsv(sv, va_arg(*args, SV*));
4404 /* See comment on '_' below */
4409 patend = (char*)pat + patlen;
4410 for (p = (char*)pat; p < patend; p = q) {
4418 bool has_precis = FALSE;
4422 STRLEN esignlen = 0;
4424 char *eptr = Nullch;
4426 char ebuf[TYPE_DIGITS(int) * 2 + 16]; /* large enough for "%#.#f" */
4428 static char *efloatbuf = Nullch;
4429 static STRLEN efloatsize = 0;
4441 for (q = p; q < patend && *q != '%'; ++q) ;
4443 sv_catpvn(sv, p, q - p);
4481 case '1': case '2': case '3':
4482 case '4': case '5': case '6':
4483 case '7': case '8': case '9':
4486 width = width * 10 + (*q++ - '0');
4491 i = va_arg(*args, int);
4493 i = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4495 width = (i < 0) ? -i : i;
4506 i = va_arg(*args, int);
4508 i = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4509 precis = (i < 0) ? 0 : i;
4515 precis = precis * 10 + (*q++ - '0');
4524 #if 0 /* when quads have better support within Perl */
4525 if (*(q + 1) == 'l') {
4551 c = va_arg(*args, int);
4553 c = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4560 eptr = va_arg(*args, char*);
4562 elen = strlen(eptr);
4565 elen = sizeof nullstr - 1;
4568 else if (svix < svmax)
4569 eptr = SvPVx(svargs[svix++], elen);
4574 * The "%_" hack might have to be changed someday,
4575 * if ISO or ANSI decide to use '_' for something.
4576 * So we keep it hidden from users' code.
4580 eptr = SvPVx(va_arg(*args, SV*), elen);
4583 if (has_precis && elen > precis)
4591 uv = (UV)va_arg(*args, void*);
4593 uv = (svix < svmax) ? (UV)svargs[svix++] : 0;
4604 case 'h': iv = (short)va_arg(*args, int); break;
4605 default: iv = va_arg(*args, int); break;
4606 case 'l': iv = va_arg(*args, long); break;
4607 case 'V': iv = va_arg(*args, IV); break;
4611 iv = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4613 case 'h': iv = (short)iv; break;
4614 default: iv = (int)iv; break;
4615 case 'l': iv = (long)iv; break;
4622 esignbuf[esignlen++] = plus;
4626 esignbuf[esignlen++] = '-';
4652 case 'h': uv = (unsigned short)va_arg(*args, unsigned); break;
4653 default: uv = va_arg(*args, unsigned); break;
4654 case 'l': uv = va_arg(*args, unsigned long); break;
4655 case 'V': uv = va_arg(*args, UV); break;
4659 uv = (svix < svmax) ? SvUVx(svargs[svix++]) : 0;
4661 case 'h': uv = (unsigned short)uv; break;
4662 default: uv = (unsigned)uv; break;
4663 case 'l': uv = (unsigned long)uv; break;
4669 eptr = ebuf + sizeof ebuf;
4675 p = (c == 'X') ? "0123456789ABCDEF" : "0123456789abcdef";
4681 esignbuf[esignlen++] = '0';
4682 esignbuf[esignlen++] = c; /* 'x' or 'X' */
4688 *--eptr = '0' + dig;
4690 if (alt && *eptr != '0')
4693 default: /* it had better be ten or less */
4696 *--eptr = '0' + dig;
4697 } while (uv /= base);
4700 elen = (ebuf + sizeof ebuf) - eptr;
4703 zeros = precis - elen;
4704 else if (precis == 0 && elen == 1 && *eptr == '0')
4709 /* FLOATING POINT */
4712 c = 'f'; /* maybe %F isn't supported here */
4718 /* This is evil, but floating point is even more evil */
4721 nv = va_arg(*args, double);
4723 nv = (svix < svmax) ? SvNVx(svargs[svix++]) : 0.0;
4726 if (c != 'e' && c != 'E') {
4728 (void)frexp(nv, &i);
4729 if (i == PERL_INT_MIN)
4730 die("panic: frexp");
4732 need = BIT_DIGITS(i);
4734 need += has_precis ? precis : 6; /* known default */
4738 need += 20; /* fudge factor */
4739 if (efloatsize < need) {
4740 Safefree(efloatbuf);
4741 efloatsize = need + 20; /* more fudge */
4742 New(906, efloatbuf, efloatsize, char);
4745 eptr = ebuf + sizeof ebuf;
4750 do { *--eptr = '0' + (base % 10); } while (base /= 10);
4755 do { *--eptr = '0' + (base % 10); } while (base /= 10);
4767 (void)sprintf(efloatbuf, eptr, nv);
4770 elen = strlen(efloatbuf);
4774 * User-defined locales may include arbitrary characters.
4775 * And, unfortunately, some system may alloc the "C" locale
4776 * to be overridden by a malicious user.
4779 *used_locale = TRUE;
4780 #endif /* LC_NUMERIC */
4787 i = SvCUR(sv) - origlen;
4790 case 'h': *(va_arg(*args, short*)) = i; break;
4791 default: *(va_arg(*args, int*)) = i; break;
4792 case 'l': *(va_arg(*args, long*)) = i; break;
4793 case 'V': *(va_arg(*args, IV*)) = i; break;
4796 else if (svix < svmax)
4797 sv_setuv(svargs[svix++], (UV)i);
4798 continue; /* not "break" */
4804 if (!args && dowarn &&
4805 (op->op_type == OP_PRTF || op->op_type == OP_SPRINTF)) {
4806 SV *msg = sv_newmortal();
4807 sv_setpvf(msg, "Invalid conversion in %s: ",
4808 (op->op_type == OP_PRTF) ? "printf" : "sprintf");
4810 sv_catpvf(msg, isPRINT(c) ? "\"%%%c\"" : "\"%%\\%03o\"",
4813 sv_catpv(msg, "end of string");
4814 warn("%_", msg); /* yes, this is reentrant */
4817 /* output mangled stuff ... */
4823 /* ... right here, because formatting flags should not apply */
4824 SvGROW(sv, SvCUR(sv) + elen + 1);
4826 memcpy(p, eptr, elen);
4829 SvCUR(sv) = p - SvPVX(sv);
4830 continue; /* not "break" */
4833 have = esignlen + zeros + elen;
4834 need = (have > width ? have : width);
4837 SvGROW(sv, SvCUR(sv) + need + 1);
4839 if (esignlen && fill == '0') {
4840 for (i = 0; i < esignlen; i++)
4844 memset(p, fill, gap);
4847 if (esignlen && fill != '0') {
4848 for (i = 0; i < esignlen; i++)
4852 for (i = zeros; i; i--)
4856 memcpy(p, eptr, elen);
4860 memset(p, ' ', gap);
4864 SvCUR(sv) = p - SvPVX(sv);
4872 SV *d = sv_newmortal();
4878 PerlIO_printf(Perl_debug_log, "SV = 0\n");
4882 flags = SvFLAGS(sv);
4885 sv_setpvf(d, "(0x%lx)\n REFCNT = %ld\n FLAGS = (",
4886 (unsigned long)SvANY(sv), (long)SvREFCNT(sv));
4887 if (flags & SVs_PADBUSY) sv_catpv(d, "PADBUSY,");
4888 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
4889 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
4890 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
4891 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
4892 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
4893 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
4894 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
4896 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
4897 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
4898 if (flags & SVf_POK) sv_catpv(d, "POK,");
4899 if (flags & SVf_ROK) sv_catpv(d, "ROK,");
4900 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
4901 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
4902 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
4905 if (flags & SVf_AMAGIC) sv_catpv(d, "OVERLOAD,");
4906 #endif /* OVERLOAD */
4907 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
4908 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
4909 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
4910 if (flags & SVp_SCREAM) sv_catpv(d, "SCREAM,");
4915 if (CvANON(sv)) sv_catpv(d, "ANON,");
4916 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
4917 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
4918 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
4919 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
4922 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
4923 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
4926 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
4927 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
4928 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
4929 if (GvIMPORTED(sv)) {
4930 sv_catpv(d, "IMPORT");
4931 if (GvIMPORTED(sv) == GVf_IMPORTED)
4932 sv_catpv(d, "ALL,");
4935 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
4936 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
4937 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
4938 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
4943 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
4944 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
4948 if (*(SvEND(d) - 1) == ',')
4949 SvPVX(d)[--SvCUR(d)] = '\0';
4953 PerlIO_printf(Perl_debug_log, "SV = ");
4956 PerlIO_printf(Perl_debug_log, "NULL%s\n", s);
4959 PerlIO_printf(Perl_debug_log, "IV%s\n", s);
4962 PerlIO_printf(Perl_debug_log, "NV%s\n", s);
4965 PerlIO_printf(Perl_debug_log, "RV%s\n", s);
4968 PerlIO_printf(Perl_debug_log, "PV%s\n", s);
4971 PerlIO_printf(Perl_debug_log, "PVIV%s\n", s);
4974 PerlIO_printf(Perl_debug_log, "PVNV%s\n", s);
4977 PerlIO_printf(Perl_debug_log, "PVBM%s\n", s);
4980 PerlIO_printf(Perl_debug_log, "PVMG%s\n", s);
4983 PerlIO_printf(Perl_debug_log, "PVLV%s\n", s);
4986 PerlIO_printf(Perl_debug_log, "PVAV%s\n", s);
4989 PerlIO_printf(Perl_debug_log, "PVHV%s\n", s);
4992 PerlIO_printf(Perl_debug_log, "PVCV%s\n", s);
4995 PerlIO_printf(Perl_debug_log, "PVGV%s\n", s);
4998 PerlIO_printf(Perl_debug_log, "PVFM%s\n", s);
5001 PerlIO_printf(Perl_debug_log, "PVIO%s\n", s);
5004 PerlIO_printf(Perl_debug_log, "UNKNOWN%s\n", s);
5007 if (type >= SVt_PVIV || type == SVt_IV)
5008 PerlIO_printf(Perl_debug_log, " IV = %ld\n", (long)SvIVX(sv));
5009 if (type >= SVt_PVNV || type == SVt_NV) {
5010 SET_NUMERIC_STANDARD();
5011 PerlIO_printf(Perl_debug_log, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
5014 PerlIO_printf(Perl_debug_log, " RV = 0x%lx\n", (long)SvRV(sv));
5020 if (type <= SVt_PVLV) {
5022 PerlIO_printf(Perl_debug_log, " PV = 0x%lx \"%s\"\n CUR = %ld\n LEN = %ld\n",
5023 (long)SvPVX(sv), SvPVX(sv), (long)SvCUR(sv), (long)SvLEN(sv));
5025 PerlIO_printf(Perl_debug_log, " PV = 0\n");
5027 if (type >= SVt_PVMG) {
5029 PerlIO_printf(Perl_debug_log, " MAGIC = 0x%lx\n", (long)SvMAGIC(sv));
5032 PerlIO_printf(Perl_debug_log, " STASH = \"%s\"\n", HvNAME(SvSTASH(sv)));
5036 PerlIO_printf(Perl_debug_log, " TYPE = %c\n", LvTYPE(sv));
5037 PerlIO_printf(Perl_debug_log, " TARGOFF = %ld\n", (long)LvTARGOFF(sv));
5038 PerlIO_printf(Perl_debug_log, " TARGLEN = %ld\n", (long)LvTARGLEN(sv));
5039 PerlIO_printf(Perl_debug_log, " TARG = 0x%lx\n", (long)LvTARG(sv));
5040 sv_dump(LvTARG(sv));
5043 PerlIO_printf(Perl_debug_log, " ARRAY = 0x%lx\n", (long)AvARRAY(sv));
5044 PerlIO_printf(Perl_debug_log, " ALLOC = 0x%lx\n", (long)AvALLOC(sv));
5045 PerlIO_printf(Perl_debug_log, " FILL = %ld\n", (long)AvFILLp(sv));
5046 PerlIO_printf(Perl_debug_log, " MAX = %ld\n", (long)AvMAX(sv));
5047 PerlIO_printf(Perl_debug_log, " ARYLEN = 0x%lx\n", (long)AvARYLEN(sv));
5048 flags = AvFLAGS(sv);
5050 if (flags & AVf_REAL) sv_catpv(d, ",REAL");
5051 if (flags & AVf_REIFY) sv_catpv(d, ",REIFY");
5052 if (flags & AVf_REUSED) sv_catpv(d, ",REUSED");
5053 PerlIO_printf(Perl_debug_log, " FLAGS = (%s)\n",
5054 SvCUR(d) ? SvPVX(d) + 1 : "");
5057 PerlIO_printf(Perl_debug_log, " ARRAY = 0x%lx\n",(long)HvARRAY(sv));
5058 PerlIO_printf(Perl_debug_log, " KEYS = %ld\n", (long)HvKEYS(sv));
5059 PerlIO_printf(Perl_debug_log, " FILL = %ld\n", (long)HvFILL(sv));
5060 PerlIO_printf(Perl_debug_log, " MAX = %ld\n", (long)HvMAX(sv));
5061 PerlIO_printf(Perl_debug_log, " RITER = %ld\n", (long)HvRITER(sv));
5062 PerlIO_printf(Perl_debug_log, " EITER = 0x%lx\n",(long) HvEITER(sv));
5064 PerlIO_printf(Perl_debug_log, " PMROOT = 0x%lx\n",(long)HvPMROOT(sv));
5066 PerlIO_printf(Perl_debug_log, " NAME = \"%s\"\n", HvNAME(sv));
5070 PerlIO_printf(Perl_debug_log, " PROTOTYPE = \"%s\"\n", SvPV(sv,na));
5073 PerlIO_printf(Perl_debug_log, " STASH = 0x%lx\n", (long)CvSTASH(sv));
5074 PerlIO_printf(Perl_debug_log, " START = 0x%lx\n", (long)CvSTART(sv));
5075 PerlIO_printf(Perl_debug_log, " ROOT = 0x%lx\n", (long)CvROOT(sv));
5076 PerlIO_printf(Perl_debug_log, " XSUB = 0x%lx\n", (long)CvXSUB(sv));
5077 PerlIO_printf(Perl_debug_log, " XSUBANY = %ld\n", (long)CvXSUBANY(sv).any_i32);
5078 PerlIO_printf(Perl_debug_log, " GV = 0x%lx", (long)CvGV(sv));
5079 if (CvGV(sv) && GvNAME(CvGV(sv))) {
5080 PerlIO_printf(Perl_debug_log, " \"%s\"\n", GvNAME(CvGV(sv)));
5082 PerlIO_printf(Perl_debug_log, "\n");
5084 PerlIO_printf(Perl_debug_log, " FILEGV = 0x%lx\n", (long)CvFILEGV(sv));
5085 PerlIO_printf(Perl_debug_log, " DEPTH = %ld\n", (long)CvDEPTH(sv));
5086 PerlIO_printf(Perl_debug_log, " PADLIST = 0x%lx\n", (long)CvPADLIST(sv));
5087 PerlIO_printf(Perl_debug_log, " OUTSIDE = 0x%lx\n", (long)CvOUTSIDE(sv));
5089 PerlIO_printf(Perl_debug_log, " MUTEXP = 0x%lx\n", (long)CvMUTEXP(sv));
5090 PerlIO_printf(Perl_debug_log, " OWNER = 0x%lx\n", (long)CvOWNER(sv));
5091 #endif /* USE_THREADS */
5092 PerlIO_printf(Perl_debug_log, " FLAGS = 0x%lx\n",
5093 (unsigned long)CvFLAGS(sv));
5094 if (type == SVt_PVFM)
5095 PerlIO_printf(Perl_debug_log, " LINES = %ld\n", (long)FmLINES(sv));
5098 PerlIO_printf(Perl_debug_log, " NAME = \"%s\"\n", GvNAME(sv));
5099 PerlIO_printf(Perl_debug_log, " NAMELEN = %ld\n", (long)GvNAMELEN(sv));
5100 PerlIO_printf(Perl_debug_log, " STASH = \"%s\"\n",
5101 SvTYPE(GvSTASH(sv)) == SVt_PVHV ? HvNAME(GvSTASH(sv)) : "(deleted)");
5102 PerlIO_printf(Perl_debug_log, " GP = 0x%lx\n", (long)GvGP(sv));
5103 PerlIO_printf(Perl_debug_log, " SV = 0x%lx\n", (long)GvSV(sv));
5104 PerlIO_printf(Perl_debug_log, " REFCNT = %ld\n", (long)GvREFCNT(sv));
5105 PerlIO_printf(Perl_debug_log, " IO = 0x%lx\n", (long)GvIOp(sv));
5106 PerlIO_printf(Perl_debug_log, " FORM = 0x%lx\n", (long)GvFORM(sv));
5107 PerlIO_printf(Perl_debug_log, " AV = 0x%lx\n", (long)GvAV(sv));
5108 PerlIO_printf(Perl_debug_log, " HV = 0x%lx\n", (long)GvHV(sv));
5109 PerlIO_printf(Perl_debug_log, " CV = 0x%lx\n", (long)GvCV(sv));
5110 PerlIO_printf(Perl_debug_log, " CVGEN = 0x%lx\n", (long)GvCVGEN(sv));
5111 PerlIO_printf(Perl_debug_log, " LASTEXPR = %ld\n", (long)GvLASTEXPR(sv));
5112 PerlIO_printf(Perl_debug_log, " LINE = %ld\n", (long)GvLINE(sv));
5113 PerlIO_printf(Perl_debug_log, " FILEGV = 0x%lx\n", (long)GvFILEGV(sv));
5114 PerlIO_printf(Perl_debug_log, " EGV = 0x%lx\n", (long)GvEGV(sv));
5117 PerlIO_printf(Perl_debug_log, " IFP = 0x%lx\n", (long)IoIFP(sv));
5118 PerlIO_printf(Perl_debug_log, " OFP = 0x%lx\n", (long)IoOFP(sv));
5119 PerlIO_printf(Perl_debug_log, " DIRP = 0x%lx\n", (long)IoDIRP(sv));
5120 PerlIO_printf(Perl_debug_log, " LINES = %ld\n", (long)IoLINES(sv));
5121 PerlIO_printf(Perl_debug_log, " PAGE = %ld\n", (long)IoPAGE(sv));
5122 PerlIO_printf(Perl_debug_log, " PAGE_LEN = %ld\n", (long)IoPAGE_LEN(sv));
5123 PerlIO_printf(Perl_debug_log, " LINES_LEFT = %ld\n", (long)IoLINES_LEFT(sv));
5124 PerlIO_printf(Perl_debug_log, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
5125 PerlIO_printf(Perl_debug_log, " TOP_GV = 0x%lx\n", (long)IoTOP_GV(sv));
5126 PerlIO_printf(Perl_debug_log, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
5127 PerlIO_printf(Perl_debug_log, " FMT_GV = 0x%lx\n", (long)IoFMT_GV(sv));
5128 PerlIO_printf(Perl_debug_log, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
5129 PerlIO_printf(Perl_debug_log, " BOTTOM_GV = 0x%lx\n", (long)IoBOTTOM_GV(sv));
5130 PerlIO_printf(Perl_debug_log, " SUBPROCESS = %ld\n", (long)IoSUBPROCESS(sv));
5131 PerlIO_printf(Perl_debug_log, " TYPE = %c\n", IoTYPE(sv));
5132 PerlIO_printf(Perl_debug_log, " FLAGS = 0x%lx\n", (long)IoFLAGS(sv));
5135 #endif /* DEBUGGING */