#include "XSUB.h"
#include "ppport.h"
+#if PERL_VERSION < 6
+# define DD_USE_OLD_ID_FORMAT
+#endif
+
static I32 num_q (const char *s, STRLEN slen);
static I32 esc_q (char *dest, const char *src, STRLEN slen);
static I32 esc_q_utf8 (pTHX_ SV *sv, const char *src, STRLEN slen);
{
char tmpbuf[128];
U32 i;
- char *c, *r, *realpack, id[128];
+ char *c, *r, *realpack;
+#ifdef DD_USE_OLD_ID_FORMAT
+ char id[128];
+#else
+ UV id_buffer;
+ char *const id = (char *)&id_buffer;
+#endif
SV **svp;
SV *sv, *ipad, *ival;
SV *blesspad = Nullsv;
if (!val)
return 0;
+ /* If the ouput buffer has less than some arbitary amount of space
+ remaining, then enlarge it. For the test case (25M of output),
+ *1.1 was slower, *2.0 was the same, so the first guess of 1.5 is
+ deemed to be good enough. */
+ if (SvTYPE(retval) >= SVt_PV && (SvLEN(retval) - SvCUR(retval)) < 42) {
+ sv_grow(retval, SvCUR(retval) * 3 / 2);
+ }
+
realtype = SvTYPE(val);
if (SvGMAGICAL(val))
ival = SvRV(val);
realtype = SvTYPE(ival);
+#ifdef DD_USE_OLD_ID_FORMAT
idlen = my_snprintf(id, sizeof(id), "0x%"UVxf, PTR2UV(ival));
+#else
+ id_buffer = PTR2UV(ival);
+ idlen = sizeof(id_buffer);
+#endif
if (SvOBJECT(ival))
realpack = HvNAME_get(SvSTASH(ival));
else
return 1;
}
else {
+#ifdef DD_USE_OLD_ID_FORMAT
warn("ref name not found for %s", id);
+#else
+ warn("ref name not found for 0x%"UVxf, PTR2UV(ival));
+#endif
return 0;
}
}
av_push(seenentry, namesv);
(void)SvREFCNT_inc(val);
av_push(seenentry, val);
- (void)hv_store(seenhv, id, strlen(id),
+ (void)hv_store(seenhv, id, idlen,
newRV_inc((SV*)seenentry), 0);
SvREFCNT_dec(seenentry);
}
(*levelp)++;
ipad = sv_x(aTHX_ Nullsv, SvPVX_const(xpad), SvCUR(xpad), *levelp);
- if (realtype <= SVt_PVBM) { /* scalar ref */
+ if (
+#if PERL_VERSION < 9
+ realtype <= SVt_PVBM
+#else
+ realtype <= SVt_PVMG
+#endif
+ ) { /* scalar ref */
SV * const namesv = newSVpvn("${", 2);
sv_catpvn(namesv, name, namelen);
sv_catpvn(namesv, "}", 1);
STRLEN i;
if (namelen) {
+#ifdef DD_USE_OLD_ID_FORMAT
idlen = my_snprintf(id, sizeof(id), "0x%"UVxf, PTR2UV(val));
+#else
+ id_buffer = PTR2UV(val);
+ idlen = sizeof(id_buffer);
+#endif
if ((svp = hv_fetch(seenhv, id, idlen, FALSE)) &&
(sv = *svp) && SvROK(sv) &&
(seenentry = (AV*)SvRV(sv)))
seenentry = newAV();
av_push(seenentry, namesv);
av_push(seenentry, newRV_inc(val));
- (void)hv_store(seenhv, id, strlen(id), newRV_inc((SV*)seenentry), 0);
+ (void)hv_store(seenhv, id, idlen, newRV_inc((SV*)seenentry), 0);
SvREFCNT_dec(seenentry);
}
}