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)); \
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, regsize); \
108 while (registry[i] != (a)) { \
109 if (++i >= regsize) \
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 >= (regsize >> 1))
126 SV **oldreg = registry;
127 I32 oldsize = regsize;
129 regsize = regsize ? ((regsize << 2) + 1) : 2037;
130 Newz(707, registry, regsize, SV*);
135 for (i = 0; i < oldsize; ++i) {
136 SV* oldsv = oldreg[i];
162 for (i = 0; i < regsize; ++i) {
163 SV* sv = registry[i];
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));)
359 do_clean_objs(GvSV(sv));
367 in_clean_objs = TRUE;
368 #ifndef DISABLE_DESTRUCTOR_KLUDGE
369 visit(FUNC_NAME_TO_PTR(do_clean_named_objs));
371 visit(FUNC_NAME_TO_PTR(do_clean_objs));
372 in_clean_objs = FALSE;
378 DEBUG_D((PerlIO_printf(Perl_debug_log, "Cleaning loops:\n "), sv_dump(sv));)
379 SvFLAGS(sv) |= SVf_BREAK;
387 visit(FUNC_NAME_TO_PTR(do_clean_all));
388 in_clean_all = FALSE;
397 /* Free arenas here, but be careful about fake ones. (We assume
398 contiguity of the fake ones with the corresponding real ones.) */
400 for (sva = sv_arenaroot; sva; sva = svanext) {
401 svanext = (SV*) SvANY(sva);
402 while (svanext && SvFAKE(svanext))
403 svanext = (SV*) SvANY(svanext);
406 Safefree((void *)sva);
410 Safefree(nice_chunk);
424 * See comment in more_xiv() -- RAM.
426 xiv_root = (IV**)*xiv;
427 return (XPVIV*)((char*)xiv - sizeof(XPV));
435 IV** xiv = (IV**)((char*)(p) + sizeof(XPV));
436 *xiv = (IV *)xiv_root;
444 register IV** xivend;
446 New(705, ptr, 1008/sizeof(XPV), XPV);
447 ptr->xpv_pv = (char*)xiv_arenaroot; /* linked list of xiv arenas */
448 xiv_arenaroot = ptr; /* to keep Purify happy */
451 xivend = &xiv[1008 / sizeof(IV *) - 1];
452 xiv += (sizeof(XPV) - 1) / sizeof(IV *) + 1; /* fudge by size of XPV */
454 while (xiv < xivend) {
455 *xiv = (IV *)(xiv + 1);
468 xnv_root = *(double**)xnv;
469 return (XPVNV*)((char*)xnv - sizeof(XPVIV));
477 double* xnv = (double*)((char*)(p) + sizeof(XPVIV));
478 *(double**)xnv = xnv_root;
485 register double* xnv;
486 register double* xnvend;
487 New(711, xnv, 1008/sizeof(double), double);
488 xnvend = &xnv[1008 / sizeof(double) - 1];
489 xnv += (sizeof(XPVIV) - 1) / sizeof(double) + 1; /* fudge by sizeof XPVIV */
491 while (xnv < xnvend) {
492 *(double**)xnv = (double*)(xnv + 1);
505 xrv_root = (XRV*)xrv->xrv_rv;
514 p->xrv_rv = (SV*)xrv_root;
522 register XRV* xrvend;
523 New(712, xrv_root, 1008/sizeof(XRV), XRV);
525 xrvend = &xrv[1008 / sizeof(XRV) - 1];
526 while (xrv < xrvend) {
527 xrv->xrv_rv = (SV*)(xrv + 1);
540 xpv_root = (XPV*)xpv->xpv_pv;
549 p->xpv_pv = (char*)xpv_root;
557 register XPV* xpvend;
558 New(713, xpv_root, 1008/sizeof(XPV), XPV);
560 xpvend = &xpv[1008 / sizeof(XPV) - 1];
561 while (xpv < xpvend) {
562 xpv->xpv_pv = (char*)(xpv + 1);
570 #define new_XIV() (void*)safemalloc(sizeof(XPVIV))
571 #define del_XIV(p) Safefree((char*)p)
573 #define new_XIV() (void*)new_xiv()
574 #define del_XIV(p) del_xiv((XPVIV*) p)
578 #define new_XNV() (void*)safemalloc(sizeof(XPVNV))
579 #define del_XNV(p) Safefree((char*)p)
581 #define new_XNV() (void*)new_xnv()
582 #define del_XNV(p) del_xnv((XPVNV*) p)
586 #define new_XRV() (void*)safemalloc(sizeof(XRV))
587 #define del_XRV(p) Safefree((char*)p)
589 #define new_XRV() (void*)new_xrv()
590 #define del_XRV(p) del_xrv((XRV*) p)
594 #define new_XPV() (void*)safemalloc(sizeof(XPV))
595 #define del_XPV(p) Safefree((char*)p)
597 #define new_XPV() (void*)new_xpv()
598 #define del_XPV(p) del_xpv((XPV *)p)
602 # define my_safemalloc(s) safemalloc(s)
603 # define my_safefree(s) free(s)
606 my_safemalloc(MEM_SIZE size)
609 New(717, p, size, char);
612 # define my_safefree(s) Safefree(s)
615 #define new_XPVIV() (void*)my_safemalloc(sizeof(XPVIV))
616 #define del_XPVIV(p) my_safefree((char*)p)
618 #define new_XPVNV() (void*)my_safemalloc(sizeof(XPVNV))
619 #define del_XPVNV(p) my_safefree((char*)p)
621 #define new_XPVMG() (void*)my_safemalloc(sizeof(XPVMG))
622 #define del_XPVMG(p) my_safefree((char*)p)
624 #define new_XPVLV() (void*)my_safemalloc(sizeof(XPVLV))
625 #define del_XPVLV(p) my_safefree((char*)p)
627 #define new_XPVAV() (void*)my_safemalloc(sizeof(XPVAV))
628 #define del_XPVAV(p) my_safefree((char*)p)
630 #define new_XPVHV() (void*)my_safemalloc(sizeof(XPVHV))
631 #define del_XPVHV(p) my_safefree((char*)p)
633 #define new_XPVCV() (void*)my_safemalloc(sizeof(XPVCV))
634 #define del_XPVCV(p) my_safefree((char*)p)
636 #define new_XPVGV() (void*)my_safemalloc(sizeof(XPVGV))
637 #define del_XPVGV(p) my_safefree((char*)p)
639 #define new_XPVBM() (void*)my_safemalloc(sizeof(XPVBM))
640 #define del_XPVBM(p) my_safefree((char*)p)
642 #define new_XPVFM() (void*)my_safemalloc(sizeof(XPVFM))
643 #define del_XPVFM(p) my_safefree((char*)p)
645 #define new_XPVIO() (void*)my_safemalloc(sizeof(XPVIO))
646 #define del_XPVIO(p) my_safefree((char*)p)
649 sv_upgrade(register SV *sv, U32 mt)
659 if (SvTYPE(sv) == mt)
665 switch (SvTYPE(sv)) {
680 nv = (double)SvIVX(sv);
686 else if (mt < SVt_PVIV)
703 pv = (char*)SvRV(sv);
707 nv = (double)(unsigned long)pv;
723 else if (mt == SVt_NV)
734 del_XPVIV(SvANY(sv));
744 del_XPVNV(SvANY(sv));
754 del_XPVMG(SvANY(sv));
757 croak("Can't upgrade that kind of scalar");
762 croak("Can't upgrade to undef");
764 SvANY(sv) = new_XIV();
768 SvANY(sv) = new_XNV();
772 SvANY(sv) = new_XRV();
776 SvANY(sv) = new_XPV();
782 SvANY(sv) = new_XPVIV();
792 SvANY(sv) = new_XPVNV();
800 SvANY(sv) = new_XPVMG();
810 SvANY(sv) = new_XPVLV();
824 SvANY(sv) = new_XPVAV();
839 SvANY(sv) = new_XPVHV();
855 SvANY(sv) = new_XPVCV();
856 Zero(SvANY(sv), 1, XPVCV);
866 SvANY(sv) = new_XPVGV();
881 SvANY(sv) = new_XPVBM();
894 SvANY(sv) = new_XPVFM();
895 Zero(SvANY(sv), 1, XPVFM);
905 SvANY(sv) = new_XPVIO();
906 Zero(SvANY(sv), 1, XPVIO);
917 SvFLAGS(sv) &= ~SVTYPEMASK;
926 SV *t = sv_newmortal();
936 else if (sv == (SV*)0x55555555 || SvTYPE(sv) == 'U') {
940 else if (sv == &sv_undef || sv == &sv_no || sv == &sv_yes) {
941 if (sv == &sv_undef) {
942 sv_catpv(t, "SV_UNDEF");
943 if (!(SvFLAGS(sv) & (SVf_OK|SVf_OOK|SVs_OBJECT|
944 SVs_GMG|SVs_SMG|SVs_RMG)) &&
948 else if (sv == &sv_no) {
949 sv_catpv(t, "SV_NO");
950 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
951 SVs_GMG|SVs_SMG|SVs_RMG)) &&
952 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
959 sv_catpv(t, "SV_YES");
960 if (!(SvFLAGS(sv) & (SVf_ROK|SVf_OOK|SVs_OBJECT|
961 SVs_GMG|SVs_SMG|SVs_RMG)) &&
962 !(~SvFLAGS(sv) & (SVf_POK|SVf_NOK|SVf_READONLY|
965 SvPVX(sv) && *SvPVX(sv) == '1' &&
971 else if (SvREFCNT(sv) == 0) {
977 if (SvCUR(t) + unref > 10) {
978 SvCUR(t) = unref + 3;
986 switch (SvTYPE(sv)) {
988 sv_catpv(t, "FREED");
992 sv_catpv(t, "UNDEF");
1007 sv_catpv(t, "PVIV");
1010 sv_catpv(t, "PVNV");
1013 sv_catpv(t, "PVMG");
1016 sv_catpv(t, "PVLV");
1026 sv_catpvf(t, "CV(%s)", GvNAME(CvGV(sv)));
1028 sv_catpv(t, "CV()");
1046 sv_catpv(t, "(null)");
1048 sv_catpvf(t, "(%ld+\"%.127s\")",(long)SvIVX(sv),SvPVX(sv));
1050 sv_catpvf(t, "(\"%.127s\")",SvPVX(sv));
1052 else if (SvNOKp(sv)) {
1053 SET_NUMERIC_STANDARD();
1054 sv_catpvf(t, "(%g)",SvNVX(sv));
1056 else if (SvIOKp(sv))
1057 sv_catpvf(t, "(%ld)",(long)SvIVX(sv));
1067 #else /* DEBUGGING */
1069 #endif /* DEBUGGING */
1073 sv_backoff(register SV *sv)
1077 char *s = SvPVX(sv);
1078 SvLEN(sv) += SvIVX(sv);
1079 SvPVX(sv) -= SvIVX(sv);
1081 Move(s, SvPVX(sv), SvCUR(sv)+1, char);
1083 SvFLAGS(sv) &= ~SVf_OOK;
1089 sv_grow(register SV *sv, register I32 newlen)
1091 sv_grow(SV* sv, unsigned long newlen)
1096 #ifdef HAS_64K_LIMIT
1097 if (newlen >= 0x10000) {
1098 PerlIO_printf(Perl_debug_log, "Allocation too large: %lx\n", newlen);
1101 #endif /* HAS_64K_LIMIT */
1104 if (SvTYPE(sv) < SVt_PV) {
1105 sv_upgrade(sv, SVt_PV);
1108 else if (SvOOK(sv)) { /* pv is offset? */
1111 if (newlen > SvLEN(sv))
1112 newlen += 10 * (newlen - SvCUR(sv)); /* avoid copy each time */
1113 #ifdef HAS_64K_LIMIT
1114 if (newlen >= 0x10000)
1120 if (newlen > SvLEN(sv)) { /* need more room? */
1122 Renew(s,newlen,char);
1124 New(703,s,newlen,char);
1126 SvLEN_set(sv, newlen);
1132 sv_setiv(register SV *sv, IV i)
1134 SV_CHECK_THINKFIRST(sv);
1135 switch (SvTYPE(sv)) {
1137 sv_upgrade(sv, SVt_IV);
1140 sv_upgrade(sv, SVt_PVNV);
1144 sv_upgrade(sv, SVt_PVIV);
1160 croak("Can't coerce %s to integer in %s", sv_reftype(sv,0),
1161 op_desc[op->op_type]);
1164 (void)SvIOK_only(sv); /* validate number */
1170 sv_setiv_mg(register SV *sv, IV i)
1177 sv_setuv(register SV *sv, UV u)
1182 sv_setnv(sv, (double)u);
1186 sv_setuv_mg(register SV *sv, UV u)
1193 sv_setnv(register SV *sv, double num)
1195 SV_CHECK_THINKFIRST(sv);
1196 switch (SvTYPE(sv)) {
1199 sv_upgrade(sv, SVt_NV);
1204 sv_upgrade(sv, SVt_PVNV);
1211 (void)SvOOK_off(sv);
1226 croak("Can't coerce %s to number in %s", sv_reftype(sv,0),
1227 op_name[op->op_type]);
1231 (void)SvNOK_only(sv); /* validate number */
1236 sv_setnv_mg(register SV *sv, double num)
1243 not_a_number(SV *sv)
1249 char *limit = tmpbuf + sizeof(tmpbuf) - 8;
1250 /* each *s can expand to 4 chars + "...\0",
1251 i.e. need room for 8 chars */
1253 for (s = SvPVX(sv); *s && d < limit; s++) {
1255 if (ch & 128 && !isPRINT_LC(ch)) {
1264 else if (ch == '\r') {
1268 else if (ch == '\f') {
1272 else if (ch == '\\') {
1276 else if (isPRINT_LC(ch))
1291 warn("Argument \"%s\" isn't numeric in %s", tmpbuf,
1292 op_name[op->op_type]);
1294 warn("Argument \"%s\" isn't numeric", tmpbuf);
1298 sv_2iv(register SV *sv)
1302 if (SvGMAGICAL(sv)) {
1307 if (SvNVX(sv) < 0.0)
1308 return I_V(SvNVX(sv));
1310 return (IV) U_V(SvNVX(sv));
1312 if (SvPOKp(sv) && SvLEN(sv))
1315 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1323 if (SvTHINKFIRST(sv)) {
1327 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv, numer)))
1328 return SvIV(tmpstr);
1329 #endif /* OVERLOAD */
1330 return (IV)SvRV(sv);
1332 if (SvREADONLY(sv)) {
1334 if (SvNVX(sv) < 0.0)
1335 return I_V(SvNVX(sv));
1337 return (IV) U_V(SvNVX(sv));
1339 if (SvPOKp(sv) && SvLEN(sv))
1346 switch (SvTYPE(sv)) {
1348 sv_upgrade(sv, SVt_IV);
1351 sv_upgrade(sv, SVt_PVIV);
1354 sv_upgrade(sv, SVt_PVNV);
1359 if (SvNVX(sv) < 0.0)
1360 SvIVX(sv) = I_V(SvNVX(sv));
1362 SvUVX(sv) = U_V(SvNVX(sv));
1364 else if (SvPOKp(sv) && SvLEN(sv)) {
1366 SvIVX(sv) = asIV(sv);
1370 if (dowarn && !localizing && !(SvFLAGS(sv) & SVs_PADTMP))
1374 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2iv(%ld)\n",
1375 (unsigned long)sv,(long)SvIVX(sv)));
1380 sv_2uv(register SV *sv)
1384 if (SvGMAGICAL(sv)) {
1389 return U_V(SvNVX(sv));
1390 if (SvPOKp(sv) && SvLEN(sv))
1393 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1401 if (SvTHINKFIRST(sv)) {
1405 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv, numer)))
1406 return SvUV(tmpstr);
1407 #endif /* OVERLOAD */
1408 return (UV)SvRV(sv);
1410 if (SvREADONLY(sv)) {
1412 return U_V(SvNVX(sv));
1414 if (SvPOKp(sv) && SvLEN(sv))
1421 switch (SvTYPE(sv)) {
1423 sv_upgrade(sv, SVt_IV);
1426 sv_upgrade(sv, SVt_PVIV);
1429 sv_upgrade(sv, SVt_PVNV);
1434 SvUVX(sv) = U_V(SvNVX(sv));
1436 else if (SvPOKp(sv) && SvLEN(sv)) {
1438 SvUVX(sv) = asUV(sv);
1441 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1448 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2uv(%lu)\n",
1449 (unsigned long)sv,SvUVX(sv)));
1454 sv_2nv(register SV *sv)
1458 if (SvGMAGICAL(sv)) {
1462 if (SvPOKp(sv) && SvLEN(sv)) {
1463 if (dowarn && !SvIOKp(sv) && !looks_like_number(sv))
1465 SET_NUMERIC_STANDARD();
1466 return atof(SvPVX(sv));
1469 return (double)SvIVX(sv);
1471 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1479 if (SvTHINKFIRST(sv)) {
1483 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,numer)))
1484 return SvNV(tmpstr);
1485 #endif /* OVERLOAD */
1486 return (double)(unsigned long)SvRV(sv);
1488 if (SvREADONLY(sv)) {
1489 if (SvPOKp(sv) && SvLEN(sv)) {
1490 if (dowarn && !SvIOKp(sv) && !looks_like_number(sv))
1492 SET_NUMERIC_STANDARD();
1493 return atof(SvPVX(sv));
1496 return (double)SvIVX(sv);
1502 if (SvTYPE(sv) < SVt_NV) {
1503 if (SvTYPE(sv) == SVt_IV)
1504 sv_upgrade(sv, SVt_PVNV);
1506 sv_upgrade(sv, SVt_NV);
1507 DEBUG_c(SET_NUMERIC_STANDARD());
1508 DEBUG_c(PerlIO_printf(Perl_debug_log,
1509 "0x%lx num(%g)\n",(unsigned long)sv,SvNVX(sv)));
1511 else if (SvTYPE(sv) < SVt_PVNV)
1512 sv_upgrade(sv, SVt_PVNV);
1514 (!SvPOKp(sv) || !strchr(SvPVX(sv),'.') || !looks_like_number(sv)))
1516 SvNVX(sv) = (double)SvIVX(sv);
1518 else if (SvPOKp(sv) && SvLEN(sv)) {
1519 if (dowarn && !SvIOKp(sv) && !looks_like_number(sv))
1521 SET_NUMERIC_STANDARD();
1522 SvNVX(sv) = atof(SvPVX(sv));
1526 if (dowarn && !localizing && !(SvFLAGS(sv) & SVs_PADTMP))
1531 DEBUG_c(SET_NUMERIC_STANDARD());
1532 DEBUG_c(PerlIO_printf(Perl_debug_log,
1533 "0x%lx 2nv(%g)\n",(unsigned long)sv,SvNVX(sv)));
1540 I32 numtype = looks_like_number(sv);
1544 return atol(SvPVX(sv));
1545 if (!numtype && dowarn)
1547 SET_NUMERIC_STANDARD();
1548 d = atof(SvPVX(sv));
1558 I32 numtype = looks_like_number(sv);
1562 return strtoul(SvPVX(sv), Null(char**), 10);
1564 if (!numtype && dowarn)
1566 SET_NUMERIC_STANDARD();
1567 return U_V(atof(SvPVX(sv)));
1571 looks_like_number(SV *sv)
1574 register char *send;
1575 register char *sbegin;
1583 else if (SvPOKp(sv))
1584 sbegin = SvPV(sv, len);
1587 send = sbegin + len;
1592 if (*s == '+' || *s == '-')
1595 /* next must be digit or '.' */
1599 } while (isDIGIT(*s));
1602 while (isDIGIT(*s)) /* optional digits after "." */
1606 else if (*s == '.') {
1608 /* no digits before '.' means we need digits after it */
1612 } while (isDIGIT(*s));
1621 * we return 1 if the number can be converted to _integer_ with atol()
1622 * and 2 if you need (int)atof().
1626 /* we can have an optional exponent part */
1627 if (*s == 'e' || *s == 'E') {
1630 if (*s == '+' || *s == '-')
1635 } while (isDIGIT(*s));
1644 if (len == 10 && memEQ(sbegin, "0 but true", 10))
1650 sv_2pv(register SV *sv, STRLEN *lp)
1655 char tmpbuf[64]; /* Must fit sprintf/Gconvert of longest IV/NV */
1661 if (SvGMAGICAL(sv)) {
1668 (void)sprintf(tmpbuf,"%ld",(long)SvIVX(sv));
1673 SET_NUMERIC_STANDARD();
1674 Gconvert(SvNVX(sv), DBL_DIG, 0, tmpbuf);
1679 if (dowarn && !(SvFLAGS(sv) & SVs_PADTMP)) {
1688 if (SvTHINKFIRST(sv)) {
1692 if (SvAMAGIC(sv) && (tmpstr=AMG_CALLun(sv,string)))
1693 return SvPV(tmpstr,*lp);
1694 #endif /* OVERLOAD */
1701 switch (SvTYPE(sv)) {
1703 if ( ((SvFLAGS(sv) &
1704 (SVs_OBJECT|SVf_OK|SVs_GMG|SVs_SMG|SVs_RMG))
1705 == (SVs_OBJECT|SVs_RMG))
1706 && strEQ(s=HvNAME(SvSTASH(sv)), "Regexp")
1707 && (mg = mg_find(sv, 'r'))) {
1708 regexp *re = (regexp *)mg->mg_obj;
1721 case SVt_PVBM: s = "SCALAR"; break;
1722 case SVt_PVLV: s = "LVALUE"; break;
1723 case SVt_PVAV: s = "ARRAY"; break;
1724 case SVt_PVHV: s = "HASH"; break;
1725 case SVt_PVCV: s = "CODE"; break;
1726 case SVt_PVGV: s = "GLOB"; break;
1727 case SVt_PVFM: s = "FORMAT"; break;
1728 case SVt_PVIO: s = "IO"; break;
1729 default: s = "UNKNOWN"; break;
1733 sv_setpvf(tsv, "%s=%s", HvNAME(SvSTASH(sv)), s);
1736 sv_catpvf(tsv, "(0x%lx)", (unsigned long)sv);
1742 if (SvREADONLY(sv)) {
1744 SET_NUMERIC_STANDARD();
1745 Gconvert(SvNVX(sv), DBL_DIG, 0, tmpbuf);
1750 (void)sprintf(tmpbuf,"%ld",(long)SvIVX(sv));
1760 (void)SvUPGRADE(sv, SVt_PV);
1762 if (SvTYPE(sv) < SVt_PVNV)
1763 sv_upgrade(sv, SVt_PVNV);
1766 olderrno = errno; /* some Xenix systems wipe out errno here */
1768 if (SvNVX(sv) == 0.0)
1769 (void)strcpy(s,"0");
1773 SET_NUMERIC_STANDARD();
1774 Gconvert(SvNVX(sv), DBL_DIG, 0, s);
1777 #ifdef FIXNEGATIVEZERO
1778 if (*s == '-' && s[1] == '0' && !s[2])
1787 else if (SvIOKp(sv)) {
1788 U32 oldIOK = SvIOK(sv);
1789 if (SvTYPE(sv) < SVt_PVIV)
1790 sv_upgrade(sv, SVt_PVIV);
1791 olderrno = errno; /* some Xenix systems wipe out errno here */
1792 sv_setpviv(sv, SvIVX(sv));
1802 if (dowarn && !localizing && !(SvFLAGS(sv) & SVs_PADTMP))
1807 *lp = s - SvPVX(sv);
1810 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2pv(%s)\n",(unsigned long)sv,SvPVX(sv)));
1814 if (SvROK(sv)) { /* XXX Skip this when sv_pvn_force calls */
1815 /* Sneaky stuff here */
1819 tsv = newSVpv(tmpbuf, 0);
1835 len = strlen(tmpbuf);
1837 #ifdef FIXNEGATIVEZERO
1838 if (len == 2 && t[0] == '-' && t[1] == '0') {
1843 (void)SvUPGRADE(sv, SVt_PV);
1845 s = SvGROW(sv, len + 1);
1853 /* This function is only called on magical items */
1855 sv_2bool(register SV *sv)
1867 if (SvAMAGIC(sv) && (tmpsv = AMG_CALLun(sv,bool_)))
1868 return SvTRUE(tmpsv);
1870 #endif /* OVERLOAD */
1871 return SvRV(sv) != 0;
1874 register XPV* Xpvtmp;
1875 if ((Xpvtmp = (XPV*)SvANY(sv)) &&
1876 (*Xpvtmp->xpv_pv > '0' ||
1877 Xpvtmp->xpv_cur > 1 ||
1878 (Xpvtmp->xpv_cur && *Xpvtmp->xpv_pv != '0')))
1885 return SvIVX(sv) != 0;
1888 return SvNVX(sv) != 0.0;
1895 /* Note: sv_setsv() should not be called with a source string that needs
1896 * to be reused, since it may destroy the source string if it is marked
1901 sv_setsv(SV *dstr, register SV *sstr)
1904 register U32 sflags;
1910 SV_CHECK_THINKFIRST(dstr);
1913 stype = SvTYPE(sstr);
1914 dtype = SvTYPE(dstr);
1916 if (dtype == SVt_PVGV && (SvFLAGS(dstr) & SVf_FAKE)) {
1917 sv_unglob(dstr); /* so fake GLOB won't perpetuate */
1918 sv_setpvn(dstr, "", 0);
1919 (void)SvPOK_only(dstr);
1920 dtype = SvTYPE(dstr);
1925 #endif /* OVERLOAD */
1926 /* There's a lot of redundancy below but we're going for speed here */
1930 if (dtype != SVt_PVGV) {
1931 (void)SvOK_off(dstr);
1936 if (dtype != SVt_IV && dtype < SVt_PVIV) {
1938 sv_upgrade(dstr, SVt_IV);
1939 else if (dtype == SVt_NV)
1940 sv_upgrade(dstr, SVt_PVNV);
1942 sv_upgrade(dstr, SVt_PVIV);
1946 if (dtype != SVt_NV && dtype < SVt_PVNV) {
1948 sv_upgrade(dstr, SVt_NV);
1950 sv_upgrade(dstr, SVt_PVNV);
1955 sv_upgrade(dstr, SVt_RV);
1956 else if (dtype == SVt_PVGV &&
1957 SvTYPE(SvRV(sstr)) == SVt_PVGV) {
1960 if (curcop->cop_stash != GvSTASH(dstr))
1961 GvIMPORTED_on(dstr);
1971 sv_upgrade(dstr, SVt_PV);
1974 if (dtype < SVt_PVIV)
1975 sv_upgrade(dstr, SVt_PVIV);
1978 if (dtype < SVt_PVNV)
1979 sv_upgrade(dstr, SVt_PVNV);
1986 croak("Bizarre copy of %s in %s", sv_reftype(sstr, 0),
1987 op_name[op->op_type]);
1989 croak("Bizarre copy of %s", sv_reftype(sstr, 0));
1993 if (dtype <= SVt_PVGV) {
1995 if (dtype != SVt_PVGV) {
1996 char *name = GvNAME(sstr);
1997 STRLEN len = GvNAMELEN(sstr);
1998 sv_upgrade(dstr, SVt_PVGV);
1999 sv_magic(dstr, dstr, '*', name, len);
2000 GvSTASH(dstr) = (HV*)SvREFCNT_inc(GvSTASH(sstr));
2001 GvNAME(dstr) = savepvn(name, len);
2002 GvNAMELEN(dstr) = len;
2003 SvFAKE_on(dstr); /* can coerce to non-glob */
2005 /* ahem, death to those who redefine active sort subs */
2006 else if (curstackinfo->si_type == SI_SORT
2007 && GvCV(dstr) && sortcop == CvSTART(GvCV(dstr)))
2008 croak("Can't redefine active sort subroutine %s",
2010 (void)SvOK_off(dstr);
2011 GvINTRO_off(dstr); /* one-shot flag */
2013 GvGP(dstr) = gp_ref(GvGP(sstr));
2015 if (curcop->cop_stash != GvSTASH(dstr))
2016 GvIMPORTED_on(dstr);
2023 if (SvGMAGICAL(sstr)) {
2025 if (SvTYPE(sstr) != stype) {
2026 stype = SvTYPE(sstr);
2027 if (stype == SVt_PVGV && dtype <= SVt_PVGV)
2031 if (stype == SVt_PVLV)
2032 SvUPGRADE(dstr, SVt_PVNV);
2034 SvUPGRADE(dstr, stype);
2037 sflags = SvFLAGS(sstr);
2039 if (sflags & SVf_ROK) {
2040 if (dtype >= SVt_PV) {
2041 if (dtype == SVt_PVGV) {
2043 SV *sref = SvREFCNT_inc(SvRV(sstr));
2045 int intro = GvINTRO(dstr);
2049 GvGP(dstr)->gp_refcnt--;
2050 GvINTRO_off(dstr); /* one-shot flag */
2051 Newz(602,gp, 1, GP);
2052 GvGP(dstr) = gp_ref(gp);
2053 GvSV(dstr) = NEWSV(72,0);
2054 GvLINE(dstr) = curcop->cop_line;
2055 GvEGV(dstr) = (GV*)dstr;
2058 switch (SvTYPE(sref)) {
2061 SAVESPTR(GvAV(dstr));
2063 dref = (SV*)GvAV(dstr);
2064 GvAV(dstr) = (AV*)sref;
2065 if (curcop->cop_stash != GvSTASH(dstr))
2066 GvIMPORTED_AV_on(dstr);
2070 SAVESPTR(GvHV(dstr));
2072 dref = (SV*)GvHV(dstr);
2073 GvHV(dstr) = (HV*)sref;
2074 if (curcop->cop_stash != GvSTASH(dstr))
2075 GvIMPORTED_HV_on(dstr);
2079 if (GvCVGEN(dstr) && GvCV(dstr) != (CV*)sref) {
2080 SvREFCNT_dec(GvCV(dstr));
2081 GvCV(dstr) = Nullcv;
2082 GvCVGEN(dstr) = 0; /* Switch off cacheness. */
2085 SAVESPTR(GvCV(dstr));
2088 dref = (SV*)GvCV(dstr);
2089 if (GvCV(dstr) != (CV*)sref) {
2090 CV* cv = GvCV(dstr);
2092 if (!GvCVGEN((GV*)dstr) &&
2093 (CvROOT(cv) || CvXSUB(cv)))
2095 SV *const_sv = cv_const_sv(cv);
2096 bool const_changed = TRUE;
2098 const_changed = sv_cmp(const_sv,
2099 op_const_sv(CvSTART((CV*)sref),
2101 /* ahem, death to those who redefine
2102 * active sort subs */
2103 if (curstackinfo->si_type == SI_SORT &&
2104 sortcop == CvSTART(cv))
2106 "Can't redefine active sort subroutine %s",
2107 GvENAME((GV*)dstr));
2108 if (dowarn || (const_changed && const_sv)) {
2109 if (!(CvGV(cv) && GvSTASH(CvGV(cv))
2110 && HvNAME(GvSTASH(CvGV(cv)))
2111 && strEQ(HvNAME(GvSTASH(CvGV(cv))),
2114 "Constant subroutine %s redefined"
2115 : "Subroutine %s redefined",
2116 GvENAME((GV*)dstr));
2119 cv_ckproto(cv, (GV*)dstr,
2120 SvPOK(sref) ? SvPVX(sref) : Nullch);
2122 GvCV(dstr) = (CV*)sref;
2123 GvCVGEN(dstr) = 0; /* Switch off cacheness. */
2124 GvASSUMECV_on(dstr);
2127 if (curcop->cop_stash != GvSTASH(dstr))
2128 GvIMPORTED_CV_on(dstr);
2132 SAVESPTR(GvIOp(dstr));
2134 dref = (SV*)GvIOp(dstr);
2135 GvIOp(dstr) = (IO*)sref;
2139 SAVESPTR(GvSV(dstr));
2141 dref = (SV*)GvSV(dstr);
2143 if (curcop->cop_stash != GvSTASH(dstr))
2144 GvIMPORTED_SV_on(dstr);
2155 (void)SvOOK_off(dstr); /* backoff */
2156 Safefree(SvPVX(dstr));
2157 SvLEN(dstr)=SvCUR(dstr)=0;
2160 (void)SvOK_off(dstr);
2161 SvRV(dstr) = SvREFCNT_inc(SvRV(sstr));
2163 if (sflags & SVp_NOK) {
2165 SvNVX(dstr) = SvNVX(sstr);
2167 if (sflags & SVp_IOK) {
2168 (void)SvIOK_on(dstr);
2169 SvIVX(dstr) = SvIVX(sstr);
2172 if (SvAMAGIC(sstr)) {
2175 #endif /* OVERLOAD */
2177 else if (sflags & SVp_POK) {
2180 * Check to see if we can just swipe the string. If so, it's a
2181 * possible small lose on short strings, but a big win on long ones.
2182 * It might even be a win on short strings if SvPVX(dstr)
2183 * has to be allocated and SvPVX(sstr) has to be freed.
2186 if (SvTEMP(sstr) && /* slated for free anyway? */
2187 SvREFCNT(sstr) == 1 && /* and no other references to it? */
2188 !(sflags & SVf_OOK)) /* and not involved in OOK hack? */
2190 if (SvPVX(dstr)) { /* we know that dtype >= SVt_PV */
2192 SvFLAGS(dstr) &= ~SVf_OOK;
2193 Safefree(SvPVX(dstr) - SvIVX(dstr));
2196 Safefree(SvPVX(dstr));
2198 (void)SvPOK_only(dstr);
2199 SvPV_set(dstr, SvPVX(sstr));
2200 SvLEN_set(dstr, SvLEN(sstr));
2201 SvCUR_set(dstr, SvCUR(sstr));
2203 (void)SvOK_off(sstr);
2204 SvPV_set(sstr, Nullch);
2209 else { /* have to copy actual string */
2210 STRLEN len = SvCUR(sstr);
2212 SvGROW(dstr, len + 1); /* inlined from sv_setpvn */
2213 Move(SvPVX(sstr),SvPVX(dstr),len,char);
2214 SvCUR_set(dstr, len);
2215 *SvEND(dstr) = '\0';
2216 (void)SvPOK_only(dstr);
2219 if (sflags & SVp_NOK) {
2221 SvNVX(dstr) = SvNVX(sstr);
2223 if (sflags & SVp_IOK) {
2224 (void)SvIOK_on(dstr);
2225 SvIVX(dstr) = SvIVX(sstr);
2228 else if (sflags & SVp_NOK) {
2229 SvNVX(dstr) = SvNVX(sstr);
2230 (void)SvNOK_only(dstr);
2232 (void)SvIOK_on(dstr);
2233 SvIVX(dstr) = SvIVX(sstr);
2236 else if (sflags & SVp_IOK) {
2237 (void)SvIOK_only(dstr);
2238 SvIVX(dstr) = SvIVX(sstr);
2241 if (dtype == SVt_PVGV) {
2243 warn("Undefined value assigned to typeglob");
2246 (void)SvOK_off(dstr);
2252 sv_setsv_mg(SV *dstr, register SV *sstr)
2254 sv_setsv(dstr,sstr);
2259 sv_setpvn(register SV *sv, register const char *ptr, register STRLEN len)
2261 register char *dptr;
2262 assert(len >= 0); /* STRLEN is probably unsigned, so this may
2263 elicit a warning, but it won't hurt. */
2264 SV_CHECK_THINKFIRST(sv);
2269 if (SvTYPE(sv) >= SVt_PV) {
2270 if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV)
2274 sv_upgrade(sv, SVt_PV);
2276 SvGROW(sv, len + 1);
2278 Move(ptr,dptr,len,char);
2281 (void)SvPOK_only(sv); /* validate pointer */
2286 sv_setpvn_mg(register SV *sv, register const char *ptr, register STRLEN len)
2288 sv_setpvn(sv,ptr,len);
2293 sv_setpv(register SV *sv, register const char *ptr)
2295 register STRLEN len;
2297 SV_CHECK_THINKFIRST(sv);
2303 if (SvTYPE(sv) >= SVt_PV) {
2304 if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV)
2308 sv_upgrade(sv, SVt_PV);
2310 SvGROW(sv, len + 1);
2311 Move(ptr,SvPVX(sv),len+1,char);
2313 (void)SvPOK_only(sv); /* validate pointer */
2318 sv_setpv_mg(register SV *sv, register const char *ptr)
2325 sv_usepvn(register SV *sv, register char *ptr, register STRLEN len)
2327 SV_CHECK_THINKFIRST(sv);
2328 (void)SvUPGRADE(sv, SVt_PV);
2334 Safefree(SvPVX(sv));
2335 Renew(ptr, len+1, char);
2338 SvLEN_set(sv, len+1);
2340 (void)SvPOK_only(sv); /* validate pointer */
2345 sv_usepvn_mg(register SV *sv, register char *ptr, register STRLEN len)
2347 sv_usepvn(sv,ptr,len);
2352 sv_check_thinkfirst(register SV *sv)
2354 if (SvREADONLY(sv)) {
2356 if (curcop != &compiling)
2364 sv_chop(register SV *sv, register char *ptr) /* like set but assuming ptr is in sv */
2368 register STRLEN delta;
2370 if (!ptr || !SvPOKp(sv))
2372 SV_CHECK_THINKFIRST(sv);
2373 if (SvTYPE(sv) < SVt_PVIV)
2374 sv_upgrade(sv,SVt_PVIV);
2378 SvFLAGS(sv) |= SVf_OOK;
2380 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVp_IOK|SVp_NOK);
2381 delta = ptr - SvPVX(sv);
2389 sv_catpvn(register SV *sv, register char *ptr, register STRLEN len)
2394 junk = SvPV_force(sv, tlen);
2395 SvGROW(sv, tlen + len + 1);
2398 Move(ptr,SvPVX(sv)+tlen,len,char);
2401 (void)SvPOK_only(sv); /* validate pointer */
2406 sv_catpvn_mg(register SV *sv, register char *ptr, register STRLEN len)
2408 sv_catpvn(sv,ptr,len);
2413 sv_catsv(SV *dstr, register SV *sstr)
2419 if (s = SvPV(sstr, len))
2420 sv_catpvn(dstr,s,len);
2424 sv_catsv_mg(SV *dstr, register SV *sstr)
2426 sv_catsv(dstr,sstr);
2431 sv_catpv(register SV *sv, register char *ptr)
2433 register STRLEN len;
2439 junk = SvPV_force(sv, tlen);
2441 SvGROW(sv, tlen + len + 1);
2444 Move(ptr,SvPVX(sv)+tlen,len+1,char);
2446 (void)SvPOK_only(sv); /* validate pointer */
2451 sv_catpv_mg(register SV *sv, register char *ptr)
2467 sv_upgrade(sv, SVt_PV);
2468 SvGROW(sv, len + 1);
2473 /* name is assumed to contain an SV* if (name && namelen == HEf_SVKEY) */
2476 sv_magic(register SV *sv, SV *obj, int how, char *name, I32 namlen)
2480 if (SvREADONLY(sv)) {
2482 if (curcop != &compiling && !strchr("gBf", how))
2485 if (SvMAGICAL(sv) || (how == 't' && SvTYPE(sv) >= SVt_PVMG)) {
2486 if (SvMAGIC(sv) && (mg = mg_find(sv, how))) {
2493 (void)SvUPGRADE(sv, SVt_PVMG);
2495 Newz(702,mg, 1, MAGIC);
2496 mg->mg_moremagic = SvMAGIC(sv);
2499 if (!obj || obj == sv || how == '#' || how == 'r')
2503 mg->mg_obj = SvREFCNT_inc(obj);
2504 mg->mg_flags |= MGf_REFCOUNTED;
2507 mg->mg_len = namlen;
2510 mg->mg_ptr = savepvn(name, namlen);
2511 else if (namlen == HEf_SVKEY)
2512 mg->mg_ptr = (char*)SvREFCNT_inc((SV*)name);
2516 mg->mg_virtual = &vtbl_sv;
2520 mg->mg_virtual = &vtbl_amagic;
2523 mg->mg_virtual = &vtbl_amagicelem;
2528 #endif /* OVERLOAD */
2530 mg->mg_virtual = &vtbl_bm;
2533 mg->mg_virtual = &vtbl_env;
2536 mg->mg_virtual = &vtbl_fm;
2539 mg->mg_virtual = &vtbl_envelem;
2542 mg->mg_virtual = &vtbl_mglob;
2545 mg->mg_virtual = &vtbl_isa;
2548 mg->mg_virtual = &vtbl_isaelem;
2551 mg->mg_virtual = &vtbl_nkeys;
2558 mg->mg_virtual = &vtbl_dbline;
2562 mg->mg_virtual = &vtbl_mutex;
2564 #endif /* USE_THREADS */
2565 #ifdef USE_LOCALE_COLLATE
2567 mg->mg_virtual = &vtbl_collxfrm;
2569 #endif /* USE_LOCALE_COLLATE */
2571 mg->mg_virtual = &vtbl_pack;
2575 mg->mg_virtual = &vtbl_packelem;
2579 mg->mg_virtual = &vtbl_regexp;
2582 mg->mg_virtual = &vtbl_sig;
2585 mg->mg_virtual = &vtbl_sigelem;
2588 mg->mg_virtual = &vtbl_taint;
2592 mg->mg_virtual = &vtbl_uvar;
2595 mg->mg_virtual = &vtbl_vec;
2598 mg->mg_virtual = &vtbl_substr;
2601 mg->mg_virtual = &vtbl_defelem;
2604 mg->mg_virtual = &vtbl_glob;
2607 mg->mg_virtual = &vtbl_arylen;
2610 mg->mg_virtual = &vtbl_pos;
2612 case '~': /* Reserved for use by extensions not perl internals. */
2613 /* Useful for attaching extension internal data to perl vars. */
2614 /* Note that multiple extensions may clash if magical scalars */
2615 /* etc holding private data from one are passed to another. */
2619 croak("Don't know how to handle magic of type '%c'", how);
2623 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
2627 sv_unmagic(SV *sv, int type)
2631 if (SvTYPE(sv) < SVt_PVMG || !SvMAGIC(sv))
2634 for (mg = *mgp; mg; mg = *mgp) {
2635 if (mg->mg_type == type) {
2636 MGVTBL* vtbl = mg->mg_virtual;
2637 *mgp = mg->mg_moremagic;
2638 if (vtbl && (vtbl->svt_free != NULL))
2639 (VTBL->svt_free)(sv, mg);
2640 if (mg->mg_ptr && mg->mg_type != 'g')
2641 if (mg->mg_len >= 0)
2642 Safefree(mg->mg_ptr);
2643 else if (mg->mg_len == HEf_SVKEY)
2644 SvREFCNT_dec((SV*)mg->mg_ptr);
2645 if (mg->mg_flags & MGf_REFCOUNTED)
2646 SvREFCNT_dec(mg->mg_obj);
2650 mgp = &mg->mg_moremagic;
2654 SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
2661 sv_insert(SV *bigstr, STRLEN offset, STRLEN len, char *little, STRLEN littlelen)
2665 register char *midend;
2666 register char *bigend;
2672 croak("Can't modify non-existent substring");
2673 SvPV_force(bigstr, curlen);
2674 if (offset + len > curlen) {
2675 SvGROW(bigstr, offset+len+1);
2676 Zero(SvPVX(bigstr)+curlen, offset+len-curlen, char);
2677 SvCUR_set(bigstr, offset+len);
2680 i = littlelen - len;
2681 if (i > 0) { /* string might grow */
2682 big = SvGROW(bigstr, SvCUR(bigstr) + i + 1);
2683 mid = big + offset + len;
2684 midend = bigend = big + SvCUR(bigstr);
2687 while (midend > mid) /* shove everything down */
2688 *--bigend = *--midend;
2689 Move(little,big+offset,littlelen,char);
2695 Move(little,SvPVX(bigstr)+offset,len,char);
2700 big = SvPVX(bigstr);
2703 bigend = big + SvCUR(bigstr);
2705 if (midend > bigend)
2706 croak("panic: sv_insert");
2708 if (mid - big > bigend - midend) { /* faster to shorten from end */
2710 Move(little, mid, littlelen,char);
2713 i = bigend - midend;
2715 Move(midend, mid, i,char);
2719 SvCUR_set(bigstr, mid - big);
2722 else if (i = mid - big) { /* faster from front */
2723 midend -= littlelen;
2725 sv_chop(bigstr,midend-i);
2730 Move(little, mid, littlelen,char);
2732 else if (littlelen) {
2733 midend -= littlelen;
2734 sv_chop(bigstr,midend);
2735 Move(little,midend,littlelen,char);
2738 sv_chop(bigstr,midend);
2743 /* make sv point to what nstr did */
2746 sv_replace(register SV *sv, register SV *nsv)
2748 U32 refcnt = SvREFCNT(sv);
2749 SV_CHECK_THINKFIRST(sv);
2750 if (SvREFCNT(nsv) != 1)
2751 warn("Reference miscount in sv_replace()");
2752 if (SvMAGICAL(sv)) {
2756 sv_upgrade(nsv, SVt_PVMG);
2757 SvMAGIC(nsv) = SvMAGIC(sv);
2758 SvFLAGS(nsv) |= SvMAGICAL(sv);
2764 assert(!SvREFCNT(sv));
2765 StructCopy(nsv,sv,SV);
2766 SvREFCNT(sv) = refcnt;
2767 SvFLAGS(nsv) |= SVTYPEMASK; /* Mark as freed */
2772 sv_clear(register SV *sv)
2776 assert(SvREFCNT(sv) == 0);
2780 if (defstash) { /* Still have a symbol table? */
2785 Zero(&tmpref, 1, SV);
2786 sv_upgrade(&tmpref, SVt_RV);
2788 SvREADONLY_on(&tmpref); /* DESTROY() could be naughty */
2789 SvREFCNT(&tmpref) = 1;
2792 stash = SvSTASH(sv);
2793 destructor = gv_fetchmethod(SvSTASH(sv), "DESTROY");
2796 PUSHSTACK(SI_DESTROY);
2797 SvRV(&tmpref) = SvREFCNT_inc(sv);
2802 perl_call_sv((SV*)GvCV(destructor),
2803 G_DISCARD|G_EVAL|G_KEEPERR);
2808 } while (SvOBJECT(sv) && SvSTASH(sv) != stash);
2810 del_XRV(SvANY(&tmpref));
2814 SvREFCNT_dec(SvSTASH(sv)); /* possibly of changed persuasion */
2815 SvOBJECT_off(sv); /* Curse the object. */
2816 if (SvTYPE(sv) != SVt_PVIO)
2817 --sv_objcount; /* XXX Might want something more general */
2821 croak("DESTROY created new reference to dead object");
2822 /* DESTROY gave object new lease on life */
2826 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv))
2829 switch (SvTYPE(sv)) {
2831 if (IoIFP(sv) != PerlIO_stdin() &&
2832 IoIFP(sv) != PerlIO_stdout() &&
2833 IoIFP(sv) != PerlIO_stderr())
2835 Safefree(IoTOP_NAME(sv));
2836 Safefree(IoFMT_NAME(sv));
2837 Safefree(IoBOTTOM_NAME(sv));
2853 Safefree(GvNAME(sv));
2854 /* cannot decrease stash refcount yet, as we might recursively delete
2855 ourselves when the refcnt drops to zero. Delay SvREFCNT_dec
2856 of stash until current sv is completely gone.
2857 -- JohnPC, 27 Mar 1998 */
2858 stash = GvSTASH(sv);
2865 (void)SvOOK_off(sv);
2870 SvREFCNT_dec(SvRV(sv));
2871 else if (SvPVX(sv) && SvLEN(sv))
2872 Safefree(SvPVX(sv));
2882 switch (SvTYPE(sv)) {
2898 del_XPVIV(SvANY(sv));
2901 del_XPVNV(SvANY(sv));
2904 del_XPVMG(SvANY(sv));
2907 del_XPVLV(SvANY(sv));
2910 del_XPVAV(SvANY(sv));
2913 del_XPVHV(SvANY(sv));
2916 del_XPVCV(SvANY(sv));
2919 del_XPVGV(SvANY(sv));
2920 /* code duplication for increased performance. */
2921 SvFLAGS(sv) &= SVf_BREAK;
2922 SvFLAGS(sv) |= SVTYPEMASK;
2923 /* decrease refcount of the stash that owns this GV, if any */
2925 SvREFCNT_dec(stash);
2926 return; /* not break, SvFLAGS reset already happened */
2928 del_XPVBM(SvANY(sv));
2931 del_XPVFM(SvANY(sv));
2934 del_XPVIO(SvANY(sv));
2937 SvFLAGS(sv) &= SVf_BREAK;
2938 SvFLAGS(sv) |= SVTYPEMASK;
2945 ATOMIC_INC(SvREFCNT(sv));
2952 int refcount_is_zero;
2956 if (SvREADONLY(sv)) {
2957 if (sv == &sv_undef || sv == &sv_yes || sv == &sv_no)
2960 if (SvREFCNT(sv) == 0) {
2961 if (SvFLAGS(sv) & SVf_BREAK)
2963 if (in_clean_all) /* All is fair */
2965 warn("Attempt to free unreferenced scalar");
2968 ATOMIC_DEC_AND_TEST(refcount_is_zero, SvREFCNT(sv));
2969 if (!refcount_is_zero)
2973 warn("Attempt to free temp prematurely: %s", SvPEEK(sv));
2983 sv_len(register SV *sv)
2992 len = mg_length(sv);
2994 junk = SvPV(sv, len);
2999 sv_eq(register SV *str1, register SV *str2)
3011 pv1 = SvPV(str1, cur1);
3016 pv2 = SvPV(str2, cur2);
3021 return memEQ(pv1, pv2, cur1);
3025 sv_cmp(register SV *str1, register SV *str2)
3028 char *pv1 = str1 ? SvPV(str1, cur1) : (char *) NULL;
3030 char *pv2 = str2 ? SvPV(str2, cur2) : (char *) NULL;
3034 return cur2 ? -1 : 0;
3039 retval = memcmp((void*)pv1, (void*)pv2, cur1 < cur2 ? cur1 : cur2);
3042 return retval < 0 ? -1 : 1;
3047 return cur1 < cur2 ? -1 : 1;
3051 sv_cmp_locale(register SV *sv1, register SV *sv2)
3053 #ifdef USE_LOCALE_COLLATE
3059 if (collation_standard)
3063 pv1 = sv1 ? sv_collxfrm(sv1, &len1) : (char *) NULL;
3065 pv2 = sv2 ? sv_collxfrm(sv2, &len2) : (char *) NULL;
3067 if (!pv1 || !len1) {
3078 retval = memcmp((void*)pv1, (void*)pv2, len1 < len2 ? len1 : len2);
3081 return retval < 0 ? -1 : 1;
3084 * When the result of collation is equality, that doesn't mean
3085 * that there are no differences -- some locales exclude some
3086 * characters from consideration. So to avoid false equalities,
3087 * we use the raw string as a tiebreaker.
3093 #endif /* USE_LOCALE_COLLATE */
3095 return sv_cmp(sv1, sv2);
3098 #ifdef USE_LOCALE_COLLATE
3100 * Any scalar variable may carry an 'o' magic that contains the
3101 * scalar data of the variable transformed to such a format that
3102 * a normal memory comparison can be used to compare the data
3103 * according to the locale settings.
3106 sv_collxfrm(SV *sv, STRLEN *nxp)
3110 mg = SvMAGICAL(sv) ? mg_find(sv, 'o') : (MAGIC *) NULL;
3111 if (!mg || !mg->mg_ptr || *(U32*)mg->mg_ptr != collation_ix) {
3116 Safefree(mg->mg_ptr);
3118 if ((xf = mem_collxfrm(s, len, &xlen))) {
3119 if (SvREADONLY(sv)) {
3122 return xf + sizeof(collation_ix);
3125 sv_magic(sv, 0, 'o', 0, 0);
3126 mg = mg_find(sv, 'o');
3139 if (mg && mg->mg_ptr) {
3141 return mg->mg_ptr + sizeof(collation_ix);
3149 #endif /* USE_LOCALE_COLLATE */
3152 sv_gets(register SV *sv, register PerlIO *fp, I32 append)
3157 register STDCHAR rslast;
3158 register STDCHAR *bp;
3162 SV_CHECK_THINKFIRST(sv);
3163 (void)SvUPGRADE(sv, SVt_PV);
3170 else if (RsRECORD(rs)) {
3171 I32 recsize, bytesread;
3174 /* Grab the size of the record we're getting */
3175 recsize = SvIV(SvRV(rs));
3176 (void)SvPOK_only(sv); /* Validate pointer */
3177 /* Make sure we've got the room to yank in the whole thing */
3178 if (SvLEN(sv) <= recsize + 3) {
3179 /* No, so make it bigger */
3180 SvGROW(sv, recsize + 3);
3182 buffer = SvPVX(sv); /* Get the location of the final buffer */
3185 /* VMS wants read instead of fread, because fread doesn't respect */
3186 /* RMS record boundaries. This is not necessarily a good thing to be */
3187 /* doing, but we've got no other real choice */
3188 bytesread = PerlLIO_read(PerlIO_fileno(fp), buffer, recsize);
3190 bytesread = PerlIO_read(fp, buffer, recsize);
3192 SvCUR_set(sv, bytesread);
3193 return(SvCUR(sv) ? SvPVX(sv) : Nullch);
3195 else if (RsPARA(rs)) {
3200 rsptr = SvPV(rs, rslen);
3201 rslast = rslen ? rsptr[rslen - 1] : '\0';
3203 if (RsPARA(rs)) { /* have to do this both before and after */
3204 do { /* to make sure file boundaries work right */
3207 i = PerlIO_getc(fp);
3211 PerlIO_ungetc(fp,i);
3217 /* See if we know enough about I/O mechanism to cheat it ! */
3219 /* This used to be #ifdef test - it is made run-time test for ease
3220 of abstracting out stdio interface. One call should be cheap
3221 enough here - and may even be a macro allowing compile
3225 if (PerlIO_fast_gets(fp)) {
3228 * We're going to steal some values from the stdio struct
3229 * and put EVERYTHING in the innermost loop into registers.
3231 register STDCHAR *ptr;
3235 #if defined(VMS) && defined(PERLIO_IS_STDIO)
3236 /* An ungetc()d char is handled separately from the regular
3237 * buffer, so we getc() it back out and stuff it in the buffer.
3239 i = PerlIO_getc(fp);
3240 if (i == EOF) return 0;
3241 *(--((*fp)->_ptr)) = (unsigned char) i;
3245 /* Here is some breathtakingly efficient cheating */
3247 cnt = PerlIO_get_cnt(fp); /* get count into register */
3248 (void)SvPOK_only(sv); /* validate pointer */
3249 if (SvLEN(sv) - append <= cnt + 1) { /* make sure we have the room */
3250 if (cnt > 80 && SvLEN(sv) > append) {
3251 shortbuffered = cnt - SvLEN(sv) + append + 1;
3252 cnt -= shortbuffered;
3256 /* remember that cnt can be negative */
3257 SvGROW(sv, append + (cnt <= 0 ? 2 : (cnt + 1)));
3262 bp = (STDCHAR*)SvPVX(sv) + append; /* move these two too to registers */
3263 ptr = (STDCHAR*)PerlIO_get_ptr(fp);
3264 DEBUG_P(PerlIO_printf(Perl_debug_log,
3265 "Screamer: entering, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3266 DEBUG_P(PerlIO_printf(Perl_debug_log,
3267 "Screamer: entering: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3268 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3269 (long)(PerlIO_has_base(fp) ? PerlIO_get_base(fp) : 0)));
3274 while (cnt > 0) { /* this | eat */
3276 if ((*bp++ = *ptr++) == rslast) /* really | dust */
3277 goto thats_all_folks; /* screams | sed :-) */
3281 Copy(ptr, bp, cnt, char); /* this | eat */
3282 bp += cnt; /* screams | dust */
3283 ptr += cnt; /* louder | sed :-) */
3288 if (shortbuffered) { /* oh well, must extend */
3289 cnt = shortbuffered;
3291 bpx = bp - (STDCHAR*)SvPVX(sv); /* box up before relocation */
3293 SvGROW(sv, SvLEN(sv) + append + cnt + 2);
3294 bp = (STDCHAR*)SvPVX(sv) + bpx; /* unbox after relocation */
3298 DEBUG_P(PerlIO_printf(Perl_debug_log,
3299 "Screamer: going to getc, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3300 PerlIO_set_ptrcnt(fp, ptr, cnt); /* deregisterize cnt and ptr */
3301 DEBUG_P(PerlIO_printf(Perl_debug_log,
3302 "Screamer: pre: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3303 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3304 (long)(PerlIO_has_base (fp) ? PerlIO_get_base(fp) : 0)));
3305 /* This used to call 'filbuf' in stdio form, but as that behaves like
3306 getc when cnt <= 0 we use PerlIO_getc here to avoid introducing
3307 another abstraction. */
3308 i = PerlIO_getc(fp); /* get more characters */
3309 DEBUG_P(PerlIO_printf(Perl_debug_log,
3310 "Screamer: post: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3311 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3312 (long)(PerlIO_has_base (fp) ? PerlIO_get_base(fp) : 0)));
3313 cnt = PerlIO_get_cnt(fp);
3314 ptr = (STDCHAR*)PerlIO_get_ptr(fp); /* reregisterize cnt and ptr */
3315 DEBUG_P(PerlIO_printf(Perl_debug_log,
3316 "Screamer: after getc, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3318 if (i == EOF) /* all done for ever? */
3319 goto thats_really_all_folks;
3321 bpx = bp - (STDCHAR*)SvPVX(sv); /* box up before relocation */
3323 SvGROW(sv, bpx + cnt + 2);
3324 bp = (STDCHAR*)SvPVX(sv) + bpx; /* unbox after relocation */
3326 *bp++ = i; /* store character from PerlIO_getc */
3328 if (rslen && (STDCHAR)i == rslast) /* all done for now? */
3329 goto thats_all_folks;
3333 if ((rslen > 1 && (bp - (STDCHAR*)SvPVX(sv) < rslen)) ||
3334 memNE((char*)bp - rslen, rsptr, rslen))
3335 goto screamer; /* go back to the fray */
3336 thats_really_all_folks:
3338 cnt += shortbuffered;
3339 DEBUG_P(PerlIO_printf(Perl_debug_log,
3340 "Screamer: quitting, ptr=%ld, cnt=%ld\n",(long)ptr,(long)cnt));
3341 PerlIO_set_ptrcnt(fp, ptr, cnt); /* put these back or we're in trouble */
3342 DEBUG_P(PerlIO_printf(Perl_debug_log,
3343 "Screamer: end: FILE * thinks ptr=%ld, cnt=%ld, base=%ld\n",
3344 (long)PerlIO_get_ptr(fp), (long)PerlIO_get_cnt(fp),
3345 (long)(PerlIO_has_base (fp) ? PerlIO_get_base(fp) : 0)));
3347 SvCUR_set(sv, bp - (STDCHAR*)SvPVX(sv)); /* set length */
3348 DEBUG_P(PerlIO_printf(Perl_debug_log,
3349 "Screamer: done, len=%ld, string=|%.*s|\n",
3350 (long)SvCUR(sv),(int)SvCUR(sv),SvPVX(sv)));
3354 /*The big, slow, and stupid way */
3359 register STDCHAR *bpe = buf + sizeof(buf);
3361 while ((i = PerlIO_getc(fp)) != EOF && (*bp++ = i) != rslast && bp < bpe)
3362 ; /* keep reading */
3366 cnt = PerlIO_read(fp,(char*)buf, sizeof(buf));
3367 /* Accomodate broken VAXC compiler, which applies U8 cast to
3368 * both args of ?: operator, causing EOF to change into 255
3370 if (cnt) { i = (U8)buf[cnt - 1]; } else { i = EOF; }
3374 sv_catpvn(sv, (char *) buf, cnt);
3376 sv_setpvn(sv, (char *) buf, cnt);
3378 if (i != EOF && /* joy */
3380 SvCUR(sv) < rslen ||
3381 memNE(SvPVX(sv) + SvCUR(sv) - rslen, rsptr, rslen)))
3385 * If we're reading from a TTY and we get a short read,
3386 * indicating that the user hit his EOF character, we need
3387 * to notice it now, because if we try to read from the TTY
3388 * again, the EOF condition will disappear.
3390 * The comparison of cnt to sizeof(buf) is an optimization
3391 * that prevents unnecessary calls to feof().
3395 if (!(cnt < sizeof(buf) && PerlIO_eof(fp)))
3400 if (RsPARA(rs)) { /* have to do this both before and after */
3401 while (i != EOF) { /* to make sure file boundaries work right */
3402 i = PerlIO_getc(fp);
3404 PerlIO_ungetc(fp,i);
3411 win32_strip_return(sv);
3414 return (SvCUR(sv) - append) ? SvPVX(sv) : Nullch;
3419 sv_inc(register SV *sv)
3426 if (SvTHINKFIRST(sv)) {
3427 if (SvREADONLY(sv)) {
3429 if (curcop != &compiling)
3434 if (SvAMAGIC(sv) && AMG_CALLun(sv,inc)) return;
3435 #endif /* OVERLOAD */
3441 flags = SvFLAGS(sv);
3442 if (flags & SVp_NOK) {
3443 (void)SvNOK_only(sv);
3447 if (flags & SVp_IOK) {
3448 if (SvIVX(sv) == IV_MAX)
3449 sv_setnv(sv, (double)IV_MAX + 1.0);
3451 (void)SvIOK_only(sv);
3456 if (!(flags & SVp_POK) || !*SvPVX(sv)) {
3457 if ((flags & SVTYPEMASK) < SVt_PVNV)
3458 sv_upgrade(sv, SVt_NV);
3460 (void)SvNOK_only(sv);
3464 while (isALPHA(*d)) d++;
3465 while (isDIGIT(*d)) d++;
3467 SET_NUMERIC_STANDARD();
3468 sv_setnv(sv,atof(SvPVX(sv)) + 1.0); /* punt */
3472 while (d >= SvPVX(sv)) {
3482 *(d--) -= 'z' - 'a' + 1;
3485 /* oh,oh, the number grew */
3486 SvGROW(sv, SvCUR(sv) + 2);
3488 for (d = SvPVX(sv) + SvCUR(sv); d > SvPVX(sv); d--)
3497 sv_dec(register SV *sv)
3503 if (SvTHINKFIRST(sv)) {
3504 if (SvREADONLY(sv)) {
3506 if (curcop != &compiling)
3511 if (SvAMAGIC(sv) && AMG_CALLun(sv,dec)) return;
3512 #endif /* OVERLOAD */
3518 flags = SvFLAGS(sv);
3519 if (flags & SVp_NOK) {
3521 (void)SvNOK_only(sv);
3524 if (flags & SVp_IOK) {
3525 if (SvIVX(sv) == IV_MIN)
3526 sv_setnv(sv, (double)IV_MIN - 1.0);
3528 (void)SvIOK_only(sv);
3533 if (!(flags & SVp_POK)) {
3534 if ((flags & SVTYPEMASK) < SVt_PVNV)
3535 sv_upgrade(sv, SVt_NV);
3537 (void)SvNOK_only(sv);
3540 SET_NUMERIC_STANDARD();
3541 sv_setnv(sv,atof(SvPVX(sv)) - 1.0); /* punt */
3544 /* Make a string that will exist for the duration of the expression
3545 * evaluation. Actually, it may have to last longer than that, but
3546 * hopefully we won't free it until it has been assigned to a
3547 * permanent location. */
3553 tmps_max += (tmps_max < 512) ? 128 : 512;
3554 Renew(tmps_stack, tmps_max, SV*);
3558 sv_mortalcopy(SV *oldstr)
3567 sv_setsv(sv,oldstr);
3568 if (++tmps_ix >= tmps_max)
3570 tmps_stack[tmps_ix] = sv;
3584 SvFLAGS(sv) = SVs_TEMP;
3585 if (++tmps_ix >= tmps_max)
3587 tmps_stack[tmps_ix] = sv;
3591 /* same thing without the copying */
3594 sv_2mortal(register SV *sv)
3599 if (SvREADONLY(sv) && curcop != &compiling)
3601 if (++tmps_ix >= tmps_max)
3603 tmps_stack[tmps_ix] = sv;
3609 newSVpv(char *s, STRLEN len)
3619 sv_setpvn(sv,s,len);
3624 newSVpvn(char *s, STRLEN len)
3632 sv_setpvn(sv,s,len);
3637 newSVpvf(const char* pat, ...)
3646 va_start(args, pat);
3647 sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
3689 sv_upgrade(sv, SVt_RV);
3691 SvRV(sv) = SvREFCNT_inc(tmpRef);
3699 Perl_newRV_noinc(SV *tmpRef)
3704 SvREFCNT_dec(tmpRef);
3708 /* make an exact duplicate of old */
3711 newSVsv(register SV *old)
3717 if (SvTYPE(old) == SVTYPEMASK) {
3718 warn("semi-panic: attempt to dup freed string");
3736 sv_reset(register char *s, HV *stash)
3749 if (!*s) { /* reset ?? searches */
3750 for (pm = HvPMROOT(stash); pm; pm = pm->op_pmnext) {
3751 pm->op_pmdynflags &= ~PMdf_USED;
3756 /* reset variables */
3758 if (!HvARRAY(stash))
3761 Zero(todo, 256, char);
3768 for ( ; i <= max; i++) {
3771 for (i = 0; i <= (I32) HvMAX(stash); i++) {
3772 for (entry = HvARRAY(stash)[i];
3774 entry = HeNEXT(entry)) {
3775 if (!todo[(U8)*HeKEY(entry)])
3777 gv = (GV*)HeVAL(entry);
3780 if (SvTYPE(sv) >= SVt_PV) {
3782 if (SvPVX(sv) != Nullch)
3789 if (GvHV(gv) && !HvNAME(GvHV(gv))) {
3791 #ifndef VMS /* VMS has no environ array */
3793 environ[0] = Nullch;
3807 switch (SvTYPE(sv)) {
3815 croak("Bad filehandle: %s", GvNAME(gv));
3819 croak(no_usym, "filehandle");
3821 return sv_2io(SvRV(sv));
3822 gv = gv_fetchpv(SvPV(sv,na), FALSE, SVt_PVIO);
3828 croak("Bad filehandle: %s", SvPV(sv,na));
3835 sv_2cv(SV *sv, HV **st, GV **gvp, I32 lref)
3841 return *gvp = Nullgv, Nullcv;
3842 switch (SvTYPE(sv)) {
3862 if (SvTYPE(cv) != SVt_PVCV)
3863 croak("Not a subroutine reference");
3871 gv = gv_fetchpv(SvPV(sv, na), lref, SVt_PVCV);
3877 if (lref && !GvCVu(gv)) {
3880 tmpsv = NEWSV(704,0);
3881 gv_efullname3(tmpsv, gv, Nullch);
3882 newSUB(start_subparse(FALSE, 0),
3883 newSVOP(OP_CONST, 0, tmpsv),
3888 croak("Unable to create sub named \"%s\"", SvPV(sv,na));
3895 sv_true(register SV *sv)
3902 if ((tXpv = (XPV*)SvANY(sv)) &&
3903 (*tXpv->xpv_pv > '0' ||
3904 tXpv->xpv_cur > 1 ||
3905 (tXpv->xpv_cur && *tXpv->xpv_pv != '0')))
3912 return SvIVX(sv) != 0;
3915 return SvNVX(sv) != 0.0;
3917 return sv_2bool(sv);
3923 sv_iv(register SV *sv)
3931 sv_uv(register SV *sv)
3939 sv_nv(register SV *sv)
3947 sv_pvn(SV *sv, STRLEN *lp)
3953 return sv_2pv(sv, lp);
3957 sv_pvn_force(SV *sv, STRLEN *lp)
3961 if (SvREADONLY(sv)) {
3963 if (curcop != &compiling)
3971 if (SvTYPE(sv) > SVt_PVLV && SvTYPE(sv) != SVt_PVFM) {
3972 if (SvFAKE(sv) && SvTYPE(sv) == SVt_PVGV) {
3979 croak("Can't coerce %s to string in %s", sv_reftype(sv,0),
3980 op_name[op->op_type]);
3985 if (s != SvPVX(sv)) { /* Almost, but not quite, sv_setpvn() */
3990 (void)SvUPGRADE(sv, SVt_PV); /* Never FALSE */
3991 SvGROW(sv, len + 1);
3992 Move(s,SvPVX(sv),len,char);
3997 SvPOK_on(sv); /* validate pointer */
3999 DEBUG_c(PerlIO_printf(Perl_debug_log, "0x%lx 2pv(%s)\n",
4000 (unsigned long)sv,SvPVX(sv)));
4007 sv_reftype(SV *sv, int ob)
4009 if (ob && SvOBJECT(sv))
4010 return HvNAME(SvSTASH(sv));
4012 switch (SvTYPE(sv)) {
4026 case SVt_PVLV: return "LVALUE";
4027 case SVt_PVAV: return "ARRAY";
4028 case SVt_PVHV: return "HASH";
4029 case SVt_PVCV: return "CODE";
4030 case SVt_PVGV: return "GLOB";
4031 case SVt_PVFM: return "FORMAT";
4032 default: return "UNKNOWN";
4053 sv_isa(SV *sv, char *name)
4065 return strEQ(HvNAME(SvSTASH(sv)), name);
4069 newSVrv(SV *rv, char *classname)
4079 SV_CHECK_THINKFIRST(rv);
4082 #endif /* OVERLOAD */
4084 if (SvTYPE(rv) < SVt_RV)
4085 sv_upgrade(rv, SVt_RV);
4088 SvRV(rv) = SvREFCNT_inc(sv);
4092 HV* stash = gv_stashpv(classname, TRUE);
4093 (void)sv_bless(rv, stash);
4099 sv_setref_pv(SV *rv, char *classname, void *pv)
4102 sv_setsv(rv, &sv_undef);
4106 sv_setiv(newSVrv(rv,classname), (IV)pv);
4111 sv_setref_iv(SV *rv, char *classname, IV iv)
4113 sv_setiv(newSVrv(rv,classname), iv);
4118 sv_setref_nv(SV *rv, char *classname, double nv)
4120 sv_setnv(newSVrv(rv,classname), nv);
4125 sv_setref_pvn(SV *rv, char *classname, char *pv, I32 n)
4127 sv_setpvn(newSVrv(rv,classname), pv, n);
4132 sv_bless(SV *sv, HV *stash)
4137 croak("Can't bless non-reference value");
4139 if (SvFLAGS(tmpRef) & (SVs_OBJECT|SVf_READONLY)) {
4140 if (SvREADONLY(tmpRef))
4142 if (SvOBJECT(tmpRef)) {
4143 if (SvTYPE(tmpRef) != SVt_PVIO)
4145 SvREFCNT_dec(SvSTASH(tmpRef));
4148 SvOBJECT_on(tmpRef);
4149 if (SvTYPE(tmpRef) != SVt_PVIO)
4151 (void)SvUPGRADE(tmpRef, SVt_PVMG);
4152 SvSTASH(tmpRef) = (HV*)SvREFCNT_inc(stash);
4159 #endif /* OVERLOAD */
4167 assert(SvTYPE(sv) == SVt_PVGV);
4172 SvREFCNT_dec(GvSTASH(sv));
4173 GvSTASH(sv) = Nullhv;
4175 sv_unmagic(sv, '*');
4176 Safefree(GvNAME(sv));
4178 SvFLAGS(sv) &= ~SVTYPEMASK;
4179 SvFLAGS(sv) |= SVt_PVMG;
4189 if (SvREFCNT(rv) != 1 || SvREADONLY(rv))
4192 sv_2mortal(rv); /* Schedule for freeing later */
4198 sv_magic((sv), Nullsv, 't', Nullch, 0);
4204 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
4205 MAGIC *mg = mg_find(sv, 't');
4214 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv)) {
4215 MAGIC *mg = mg_find(sv, 't');
4216 if (mg && ((mg->mg_len & 1) || (mg->mg_len & 2) && mg->mg_obj == sv))
4223 sv_setpviv(SV *sv, IV iv)
4226 char buf[TYPE_DIGITS(UV)];
4227 char *ptr = buf + sizeof(buf);
4232 sv_setpvn(sv, "", 0);
4241 *--ptr = '0' + (uv % 10);
4243 len = (buf + sizeof(buf)) - ptr;
4244 /* taking advantage of SvCUR(sv) == 0 */
4245 SvGROW(sv, sign + len + 1);
4249 memcpy(p, ptr, len);
4252 SvCUR(sv) = p - SvPVX(sv);
4257 sv_setpviv_mg(SV *sv, IV iv)
4264 sv_setpvf(SV *sv, const char* pat, ...)
4267 va_start(args, pat);
4268 sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4274 sv_setpvf_mg(SV *sv, const char* pat, ...)
4277 va_start(args, pat);
4278 sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4284 sv_catpvf(SV *sv, const char* pat, ...)
4287 va_start(args, pat);
4288 sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4293 sv_catpvf_mg(SV *sv, const char* pat, ...)
4296 va_start(args, pat);
4297 sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*));
4303 sv_vsetpvfn(SV *sv, const char *pat, STRLEN patlen, va_list *args, SV **svargs, I32 svmax, bool *used_locale)
4305 sv_setpvn(sv, "", 0);
4306 sv_vcatpvfn(sv, pat, patlen, args, svargs, svmax, used_locale);
4310 sv_vcatpvfn(SV *sv, const char *pat, STRLEN patlen, va_list *args, SV **svargs, I32 svmax, bool *used_locale)
4318 static char nullstr[] = "(null)";
4320 /* no matter what, this is a string now */
4321 (void)SvPV_force(sv, origlen);
4323 /* special-case "", "%s", and "%_" */
4326 if (patlen == 2 && pat[0] == '%') {
4330 char *s = va_arg(*args, char*);
4331 sv_catpv(sv, s ? s : nullstr);
4333 else if (svix < svmax)
4334 sv_catsv(sv, *svargs);
4338 sv_catsv(sv, va_arg(*args, SV*));
4341 /* See comment on '_' below */
4346 patend = (char*)pat + patlen;
4347 for (p = (char*)pat; p < patend; p = q) {
4355 bool has_precis = FALSE;
4359 STRLEN esignlen = 0;
4361 char *eptr = Nullch;
4363 char ebuf[TYPE_DIGITS(int) * 2 + 16]; /* large enough for "%#.#f" */
4365 static char *efloatbuf = Nullch;
4366 static STRLEN efloatsize = 0;
4378 for (q = p; q < patend && *q != '%'; ++q) ;
4380 sv_catpvn(sv, p, q - p);
4418 case '1': case '2': case '3':
4419 case '4': case '5': case '6':
4420 case '7': case '8': case '9':
4423 width = width * 10 + (*q++ - '0');
4428 i = va_arg(*args, int);
4430 i = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4432 width = (i < 0) ? -i : i;
4443 i = va_arg(*args, int);
4445 i = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4446 precis = (i < 0) ? 0 : i;
4452 precis = precis * 10 + (*q++ - '0');
4461 #if 0 /* when quads have better support within Perl */
4462 if (*(q + 1) == 'l') {
4488 c = va_arg(*args, int);
4490 c = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4497 eptr = va_arg(*args, char*);
4499 elen = strlen(eptr);
4502 elen = sizeof nullstr - 1;
4505 else if (svix < svmax)
4506 eptr = SvPVx(svargs[svix++], elen);
4511 * The "%_" hack might have to be changed someday,
4512 * if ISO or ANSI decide to use '_' for something.
4513 * So we keep it hidden from users' code.
4517 eptr = SvPVx(va_arg(*args, SV*), elen);
4520 if (has_precis && elen > precis)
4528 uv = (UV)va_arg(*args, void*);
4530 uv = (svix < svmax) ? (UV)svargs[svix++] : 0;
4541 case 'h': iv = (short)va_arg(*args, int); break;
4542 default: iv = va_arg(*args, int); break;
4543 case 'l': iv = va_arg(*args, long); break;
4544 case 'V': iv = va_arg(*args, IV); break;
4548 iv = (svix < svmax) ? SvIVx(svargs[svix++]) : 0;
4550 case 'h': iv = (short)iv; break;
4551 default: iv = (int)iv; break;
4552 case 'l': iv = (long)iv; break;
4559 esignbuf[esignlen++] = plus;
4563 esignbuf[esignlen++] = '-';
4589 case 'h': uv = (unsigned short)va_arg(*args, unsigned); break;
4590 default: uv = va_arg(*args, unsigned); break;
4591 case 'l': uv = va_arg(*args, unsigned long); break;
4592 case 'V': uv = va_arg(*args, UV); break;
4596 uv = (svix < svmax) ? SvUVx(svargs[svix++]) : 0;
4598 case 'h': uv = (unsigned short)uv; break;
4599 default: uv = (unsigned)uv; break;
4600 case 'l': uv = (unsigned long)uv; break;
4606 eptr = ebuf + sizeof ebuf;
4612 p = (c == 'X') ? "0123456789ABCDEF" : "0123456789abcdef";
4618 esignbuf[esignlen++] = '0';
4619 esignbuf[esignlen++] = c; /* 'x' or 'X' */
4625 *--eptr = '0' + dig;
4627 if (alt && *eptr != '0')
4630 default: /* it had better be ten or less */
4633 *--eptr = '0' + dig;
4634 } while (uv /= base);
4637 elen = (ebuf + sizeof ebuf) - eptr;
4640 zeros = precis - elen;
4641 else if (precis == 0 && elen == 1 && *eptr == '0')
4646 /* FLOATING POINT */
4649 c = 'f'; /* maybe %F isn't supported here */
4655 /* This is evil, but floating point is even more evil */
4658 nv = va_arg(*args, double);
4660 nv = (svix < svmax) ? SvNVx(svargs[svix++]) : 0.0;
4663 if (c != 'e' && c != 'E') {
4665 (void)frexp(nv, &i);
4666 if (i == PERL_INT_MIN)
4667 die("panic: frexp");
4669 need = BIT_DIGITS(i);
4671 need += has_precis ? precis : 6; /* known default */
4675 need += 20; /* fudge factor */
4676 if (efloatsize < need) {
4677 Safefree(efloatbuf);
4678 efloatsize = need + 20; /* more fudge */
4679 New(906, efloatbuf, efloatsize, char);
4682 eptr = ebuf + sizeof ebuf;
4687 do { *--eptr = '0' + (base % 10); } while (base /= 10);
4692 do { *--eptr = '0' + (base % 10); } while (base /= 10);
4704 (void)sprintf(efloatbuf, eptr, nv);
4707 elen = strlen(efloatbuf);
4711 * User-defined locales may include arbitrary characters.
4712 * And, unfortunately, some system may alloc the "C" locale
4713 * to be overridden by a malicious user.
4716 *used_locale = TRUE;
4717 #endif /* LC_NUMERIC */
4724 i = SvCUR(sv) - origlen;
4727 case 'h': *(va_arg(*args, short*)) = i; break;
4728 default: *(va_arg(*args, int*)) = i; break;
4729 case 'l': *(va_arg(*args, long*)) = i; break;
4730 case 'V': *(va_arg(*args, IV*)) = i; break;
4733 else if (svix < svmax)
4734 sv_setuv(svargs[svix++], (UV)i);
4735 continue; /* not "break" */
4741 if (!args && dowarn &&
4742 (op->op_type == OP_PRTF || op->op_type == OP_SPRINTF)) {
4743 SV *msg = sv_newmortal();
4744 sv_setpvf(msg, "Invalid conversion in %s: ",
4745 (op->op_type == OP_PRTF) ? "printf" : "sprintf");
4747 sv_catpvf(msg, isPRINT(c) ? "\"%%%c\"" : "\"%%\\%03o\"",
4750 sv_catpv(msg, "end of string");
4751 warn("%_", msg); /* yes, this is reentrant */
4754 /* output mangled stuff ... */
4760 /* ... right here, because formatting flags should not apply */
4761 SvGROW(sv, SvCUR(sv) + elen + 1);
4763 memcpy(p, eptr, elen);
4766 SvCUR(sv) = p - SvPVX(sv);
4767 continue; /* not "break" */
4770 have = esignlen + zeros + elen;
4771 need = (have > width ? have : width);
4774 SvGROW(sv, SvCUR(sv) + need + 1);
4776 if (esignlen && fill == '0') {
4777 for (i = 0; i < esignlen; i++)
4781 memset(p, fill, gap);
4784 if (esignlen && fill != '0') {
4785 for (i = 0; i < esignlen; i++)
4789 for (i = zeros; i; i--)
4793 memcpy(p, eptr, elen);
4797 memset(p, ' ', gap);
4801 SvCUR(sv) = p - SvPVX(sv);
4809 SV *d = sv_newmortal();
4815 PerlIO_printf(Perl_debug_log, "SV = 0\n");
4819 flags = SvFLAGS(sv);
4822 sv_setpvf(d, "(0x%lx)\n REFCNT = %ld\n FLAGS = (",
4823 (unsigned long)SvANY(sv), (long)SvREFCNT(sv));
4824 if (flags & SVs_PADBUSY) sv_catpv(d, "PADBUSY,");
4825 if (flags & SVs_PADTMP) sv_catpv(d, "PADTMP,");
4826 if (flags & SVs_PADMY) sv_catpv(d, "PADMY,");
4827 if (flags & SVs_TEMP) sv_catpv(d, "TEMP,");
4828 if (flags & SVs_OBJECT) sv_catpv(d, "OBJECT,");
4829 if (flags & SVs_GMG) sv_catpv(d, "GMG,");
4830 if (flags & SVs_SMG) sv_catpv(d, "SMG,");
4831 if (flags & SVs_RMG) sv_catpv(d, "RMG,");
4833 if (flags & SVf_IOK) sv_catpv(d, "IOK,");
4834 if (flags & SVf_NOK) sv_catpv(d, "NOK,");
4835 if (flags & SVf_POK) sv_catpv(d, "POK,");
4836 if (flags & SVf_ROK) sv_catpv(d, "ROK,");
4837 if (flags & SVf_OOK) sv_catpv(d, "OOK,");
4838 if (flags & SVf_FAKE) sv_catpv(d, "FAKE,");
4839 if (flags & SVf_READONLY) sv_catpv(d, "READONLY,");
4842 if (flags & SVf_AMAGIC) sv_catpv(d, "OVERLOAD,");
4843 #endif /* OVERLOAD */
4844 if (flags & SVp_IOK) sv_catpv(d, "pIOK,");
4845 if (flags & SVp_NOK) sv_catpv(d, "pNOK,");
4846 if (flags & SVp_POK) sv_catpv(d, "pPOK,");
4847 if (flags & SVp_SCREAM) sv_catpv(d, "SCREAM,");
4852 if (CvANON(sv)) sv_catpv(d, "ANON,");
4853 if (CvUNIQUE(sv)) sv_catpv(d, "UNIQUE,");
4854 if (CvCLONE(sv)) sv_catpv(d, "CLONE,");
4855 if (CvCLONED(sv)) sv_catpv(d, "CLONED,");
4856 if (CvNODEBUG(sv)) sv_catpv(d, "NODEBUG,");
4859 if (HvSHAREKEYS(sv)) sv_catpv(d, "SHAREKEYS,");
4860 if (HvLAZYDEL(sv)) sv_catpv(d, "LAZYDEL,");
4863 if (GvINTRO(sv)) sv_catpv(d, "INTRO,");
4864 if (GvMULTI(sv)) sv_catpv(d, "MULTI,");
4865 if (GvASSUMECV(sv)) sv_catpv(d, "ASSUMECV,");
4866 if (GvIMPORTED(sv)) {
4867 sv_catpv(d, "IMPORT");
4868 if (GvIMPORTED(sv) == GVf_IMPORTED)
4869 sv_catpv(d, "ALL,");
4872 if (GvIMPORTED_SV(sv)) sv_catpv(d, " SV");
4873 if (GvIMPORTED_AV(sv)) sv_catpv(d, " AV");
4874 if (GvIMPORTED_HV(sv)) sv_catpv(d, " HV");
4875 if (GvIMPORTED_CV(sv)) sv_catpv(d, " CV");
4880 if (SvTAIL(sv)) sv_catpv(d, "TAIL,");
4881 if (SvCOMPILED(sv)) sv_catpv(d, "COMPILED,");
4885 if (*(SvEND(d) - 1) == ',')
4886 SvPVX(d)[--SvCUR(d)] = '\0';
4890 PerlIO_printf(Perl_debug_log, "SV = ");
4893 PerlIO_printf(Perl_debug_log, "NULL%s\n", s);
4896 PerlIO_printf(Perl_debug_log, "IV%s\n", s);
4899 PerlIO_printf(Perl_debug_log, "NV%s\n", s);
4902 PerlIO_printf(Perl_debug_log, "RV%s\n", s);
4905 PerlIO_printf(Perl_debug_log, "PV%s\n", s);
4908 PerlIO_printf(Perl_debug_log, "PVIV%s\n", s);
4911 PerlIO_printf(Perl_debug_log, "PVNV%s\n", s);
4914 PerlIO_printf(Perl_debug_log, "PVBM%s\n", s);
4917 PerlIO_printf(Perl_debug_log, "PVMG%s\n", s);
4920 PerlIO_printf(Perl_debug_log, "PVLV%s\n", s);
4923 PerlIO_printf(Perl_debug_log, "PVAV%s\n", s);
4926 PerlIO_printf(Perl_debug_log, "PVHV%s\n", s);
4929 PerlIO_printf(Perl_debug_log, "PVCV%s\n", s);
4932 PerlIO_printf(Perl_debug_log, "PVGV%s\n", s);
4935 PerlIO_printf(Perl_debug_log, "PVFM%s\n", s);
4938 PerlIO_printf(Perl_debug_log, "PVIO%s\n", s);
4941 PerlIO_printf(Perl_debug_log, "UNKNOWN%s\n", s);
4944 if (type >= SVt_PVIV || type == SVt_IV)
4945 PerlIO_printf(Perl_debug_log, " IV = %ld\n", (long)SvIVX(sv));
4946 if (type >= SVt_PVNV || type == SVt_NV) {
4947 SET_NUMERIC_STANDARD();
4948 PerlIO_printf(Perl_debug_log, " NV = %.*g\n", DBL_DIG, SvNVX(sv));
4951 PerlIO_printf(Perl_debug_log, " RV = 0x%lx\n", (long)SvRV(sv));
4957 if (type <= SVt_PVLV) {
4959 PerlIO_printf(Perl_debug_log, " PV = 0x%lx \"%s\"\n CUR = %ld\n LEN = %ld\n",
4960 (long)SvPVX(sv), SvPVX(sv), (long)SvCUR(sv), (long)SvLEN(sv));
4962 PerlIO_printf(Perl_debug_log, " PV = 0\n");
4964 if (type >= SVt_PVMG) {
4966 PerlIO_printf(Perl_debug_log, " MAGIC = 0x%lx\n", (long)SvMAGIC(sv));
4969 PerlIO_printf(Perl_debug_log, " STASH = \"%s\"\n", HvNAME(SvSTASH(sv)));
4973 PerlIO_printf(Perl_debug_log, " TYPE = %c\n", LvTYPE(sv));
4974 PerlIO_printf(Perl_debug_log, " TARGOFF = %ld\n", (long)LvTARGOFF(sv));
4975 PerlIO_printf(Perl_debug_log, " TARGLEN = %ld\n", (long)LvTARGLEN(sv));
4976 PerlIO_printf(Perl_debug_log, " TARG = 0x%lx\n", (long)LvTARG(sv));
4977 sv_dump(LvTARG(sv));
4980 PerlIO_printf(Perl_debug_log, " ARRAY = 0x%lx\n", (long)AvARRAY(sv));
4981 PerlIO_printf(Perl_debug_log, " ALLOC = 0x%lx\n", (long)AvALLOC(sv));
4982 PerlIO_printf(Perl_debug_log, " FILL = %ld\n", (long)AvFILLp(sv));
4983 PerlIO_printf(Perl_debug_log, " MAX = %ld\n", (long)AvMAX(sv));
4984 PerlIO_printf(Perl_debug_log, " ARYLEN = 0x%lx\n", (long)AvARYLEN(sv));
4985 flags = AvFLAGS(sv);
4987 if (flags & AVf_REAL) sv_catpv(d, ",REAL");
4988 if (flags & AVf_REIFY) sv_catpv(d, ",REIFY");
4989 if (flags & AVf_REUSED) sv_catpv(d, ",REUSED");
4990 PerlIO_printf(Perl_debug_log, " FLAGS = (%s)\n",
4991 SvCUR(d) ? SvPVX(d) + 1 : "");
4994 PerlIO_printf(Perl_debug_log, " ARRAY = 0x%lx\n",(long)HvARRAY(sv));
4995 PerlIO_printf(Perl_debug_log, " KEYS = %ld\n", (long)HvKEYS(sv));
4996 PerlIO_printf(Perl_debug_log, " FILL = %ld\n", (long)HvFILL(sv));
4997 PerlIO_printf(Perl_debug_log, " MAX = %ld\n", (long)HvMAX(sv));
4998 PerlIO_printf(Perl_debug_log, " RITER = %ld\n", (long)HvRITER(sv));
4999 PerlIO_printf(Perl_debug_log, " EITER = 0x%lx\n",(long) HvEITER(sv));
5001 PerlIO_printf(Perl_debug_log, " PMROOT = 0x%lx\n",(long)HvPMROOT(sv));
5003 PerlIO_printf(Perl_debug_log, " NAME = \"%s\"\n", HvNAME(sv));
5007 PerlIO_printf(Perl_debug_log, " PROTOTYPE = \"%s\"\n", SvPV(sv,na));
5010 PerlIO_printf(Perl_debug_log, " STASH = 0x%lx\n", (long)CvSTASH(sv));
5011 PerlIO_printf(Perl_debug_log, " START = 0x%lx\n", (long)CvSTART(sv));
5012 PerlIO_printf(Perl_debug_log, " ROOT = 0x%lx\n", (long)CvROOT(sv));
5013 PerlIO_printf(Perl_debug_log, " XSUB = 0x%lx\n", (long)CvXSUB(sv));
5014 PerlIO_printf(Perl_debug_log, " XSUBANY = %ld\n", (long)CvXSUBANY(sv).any_i32);
5015 PerlIO_printf(Perl_debug_log, " GV = 0x%lx", (long)CvGV(sv));
5016 if (CvGV(sv) && GvNAME(CvGV(sv))) {
5017 PerlIO_printf(Perl_debug_log, " \"%s\"\n", GvNAME(CvGV(sv)));
5019 PerlIO_printf(Perl_debug_log, "\n");
5021 PerlIO_printf(Perl_debug_log, " FILEGV = 0x%lx\n", (long)CvFILEGV(sv));
5022 PerlIO_printf(Perl_debug_log, " DEPTH = %ld\n", (long)CvDEPTH(sv));
5023 PerlIO_printf(Perl_debug_log, " PADLIST = 0x%lx\n", (long)CvPADLIST(sv));
5024 PerlIO_printf(Perl_debug_log, " OUTSIDE = 0x%lx\n", (long)CvOUTSIDE(sv));
5026 PerlIO_printf(Perl_debug_log, " MUTEXP = 0x%lx\n", (long)CvMUTEXP(sv));
5027 PerlIO_printf(Perl_debug_log, " OWNER = 0x%lx\n", (long)CvOWNER(sv));
5028 #endif /* USE_THREADS */
5029 PerlIO_printf(Perl_debug_log, " FLAGS = 0x%lx\n",
5030 (unsigned long)CvFLAGS(sv));
5031 if (type == SVt_PVFM)
5032 PerlIO_printf(Perl_debug_log, " LINES = %ld\n", (long)FmLINES(sv));
5035 PerlIO_printf(Perl_debug_log, " NAME = \"%s\"\n", GvNAME(sv));
5036 PerlIO_printf(Perl_debug_log, " NAMELEN = %ld\n", (long)GvNAMELEN(sv));
5037 PerlIO_printf(Perl_debug_log, " STASH = \"%s\"\n",
5038 SvTYPE(GvSTASH(sv)) == SVt_PVHV ? HvNAME(GvSTASH(sv)) : "(deleted)");
5039 PerlIO_printf(Perl_debug_log, " GP = 0x%lx\n", (long)GvGP(sv));
5040 PerlIO_printf(Perl_debug_log, " SV = 0x%lx\n", (long)GvSV(sv));
5041 PerlIO_printf(Perl_debug_log, " REFCNT = %ld\n", (long)GvREFCNT(sv));
5042 PerlIO_printf(Perl_debug_log, " IO = 0x%lx\n", (long)GvIOp(sv));
5043 PerlIO_printf(Perl_debug_log, " FORM = 0x%lx\n", (long)GvFORM(sv));
5044 PerlIO_printf(Perl_debug_log, " AV = 0x%lx\n", (long)GvAV(sv));
5045 PerlIO_printf(Perl_debug_log, " HV = 0x%lx\n", (long)GvHV(sv));
5046 PerlIO_printf(Perl_debug_log, " CV = 0x%lx\n", (long)GvCV(sv));
5047 PerlIO_printf(Perl_debug_log, " CVGEN = 0x%lx\n", (long)GvCVGEN(sv));
5048 PerlIO_printf(Perl_debug_log, " LASTEXPR = %ld\n", (long)GvLASTEXPR(sv));
5049 PerlIO_printf(Perl_debug_log, " LINE = %ld\n", (long)GvLINE(sv));
5050 PerlIO_printf(Perl_debug_log, " FILEGV = 0x%lx\n", (long)GvFILEGV(sv));
5051 PerlIO_printf(Perl_debug_log, " EGV = 0x%lx\n", (long)GvEGV(sv));
5054 PerlIO_printf(Perl_debug_log, " IFP = 0x%lx\n", (long)IoIFP(sv));
5055 PerlIO_printf(Perl_debug_log, " OFP = 0x%lx\n", (long)IoOFP(sv));
5056 PerlIO_printf(Perl_debug_log, " DIRP = 0x%lx\n", (long)IoDIRP(sv));
5057 PerlIO_printf(Perl_debug_log, " LINES = %ld\n", (long)IoLINES(sv));
5058 PerlIO_printf(Perl_debug_log, " PAGE = %ld\n", (long)IoPAGE(sv));
5059 PerlIO_printf(Perl_debug_log, " PAGE_LEN = %ld\n", (long)IoPAGE_LEN(sv));
5060 PerlIO_printf(Perl_debug_log, " LINES_LEFT = %ld\n", (long)IoLINES_LEFT(sv));
5061 PerlIO_printf(Perl_debug_log, " TOP_NAME = \"%s\"\n", IoTOP_NAME(sv));
5062 PerlIO_printf(Perl_debug_log, " TOP_GV = 0x%lx\n", (long)IoTOP_GV(sv));
5063 PerlIO_printf(Perl_debug_log, " FMT_NAME = \"%s\"\n", IoFMT_NAME(sv));
5064 PerlIO_printf(Perl_debug_log, " FMT_GV = 0x%lx\n", (long)IoFMT_GV(sv));
5065 PerlIO_printf(Perl_debug_log, " BOTTOM_NAME = \"%s\"\n", IoBOTTOM_NAME(sv));
5066 PerlIO_printf(Perl_debug_log, " BOTTOM_GV = 0x%lx\n", (long)IoBOTTOM_GV(sv));
5067 PerlIO_printf(Perl_debug_log, " SUBPROCESS = %ld\n", (long)IoSUBPROCESS(sv));
5068 PerlIO_printf(Perl_debug_log, " TYPE = %c\n", IoTYPE(sv));
5069 PerlIO_printf(Perl_debug_log, " FLAGS = 0x%lx\n", (long)IoFLAGS(sv));
5072 #endif /* DEBUGGING */