pat = group_end(pat, patend, ']') + 1;
}
Perl_croak(aTHX_ "No group ending character `%c' found", ender);
+ return 0;
}
#define TYPE_IS_SHRIEKING 0x100
Perl_croak(aTHX_ "%s not allowed in length fields", buf);
case ',': /* grandfather in commas but with a warning */
if (commas++ == 0 && ckWARN(WARN_UNPACK))
- Perl_warner(aTHX_ WARN_UNPACK,
+ Perl_warner(aTHX_ packWARN(WARN_UNPACK),
"Invalid type in unpack: '%c'", (int)datumtype);
/* FALL THROUGH */
case '%':
case 'I':
size = sizeof(unsigned int);
break;
+ case 'j':
+ size = IVSIZE;
+ break;
+ case 'J':
+ size = UVSIZE;
+ break;
case 'l':
#if LONGSIZE == SIZE32
size = SIZE32;
break;
#endif
case 'f':
- case 'F':
size = sizeof(float);
break;
case 'd':
- case 'D':
size = sizeof(double);
break;
+ case 'F':
+ size = NVSIZE;
+ break;
+#if defined(HAS_LONG_DOUBLE) && defined(USE_LONG_DOUBLE)
+ case 'D':
+ size = LONG_DOUBLESIZE;
+ break;
+#endif
}
total += len * size;
}
float afloat;
double adouble;
I32 checksum = 0;
- UV culong = 0;
+ UV cuv = 0;
NV cdouble = 0.0;
- const int bits_in_uv = 8 * sizeof(culong);
+ const int bits_in_uv = 8 * sizeof(cuv);
int commas = 0;
int star; /* 1 if count is *, -1 if no count given, -2 for / */
#ifdef PERL_NATINT_PACK
int natint; /* native integer */
int unatint; /* unsigned native integer */
#endif
+ IV aiv;
+ UV auv;
+ NV anv;
+#if defined(HAS_LONG_DOUBLE) && defined(USE_LONG_DOUBLE)
+ long double aldouble;
+#endif
bool do_utf8 = flags & UNPACK_DO_UTF8;
while ((pat = next_symbol(pat, patend)) < patend) {
Perl_croak(aTHX_ "Invalid type in unpack: '%c'", (int)datumtype);
case ',': /* grandfather in commas but with a warning */
if (commas++ == 0 && ckWARN(WARN_UNPACK))
- Perl_warner(aTHX_ WARN_UNPACK,
+ Perl_warner(aTHX_ packWARN(WARN_UNPACK),
"Invalid type in unpack: '%c'", (int)datumtype);
break;
case '%':
if (len == 1 && pat[-1] != '1' && pat[-1] != ']')
len = 16; /* len is not specified */
checksum = len;
- culong = 0;
+ cuv = 0;
cdouble = 0;
continue;
break;
}
}
while (len >= 8) {
- culong += PL_bitcount[*(unsigned char*)s++];
+ cuv += PL_bitcount[*(unsigned char*)s++];
len -= 8;
}
if (len) {
bits = *s;
if (datumtype == 'b') {
while (len-- > 0) {
- if (bits & 1) culong++;
+ if (bits & 1) cuv++;
bits >>= 1;
}
}
else {
while (len-- > 0) {
- if (bits & 128) culong++;
+ if (bits & 128) cuv++;
bits <<= 1;
}
}
if (checksum > bits_in_uv)
cdouble += (NV)aint;
else
- culong += aint;
+ cuv += aint;
}
}
else {
uchar_checksum:
while (len-- > 0) {
auint = *s++ & 255;
- culong += auint;
+ cuv += auint;
}
}
else {
if (checksum > bits_in_uv)
cdouble += (NV)auint;
else
- culong += auint;
+ cuv += auint;
}
}
else {
if (checksum > bits_in_uv)
cdouble += (NV)ashort;
else
- culong += ashort;
+ cuv += ashort;
}
}
if (checksum > bits_in_uv)
cdouble += (NV)ashort;
else
- culong += ashort;
+ cuv += ashort;
}
}
}
if (checksum > bits_in_uv)
cdouble += (NV)aushort;
else
- culong += aushort;
+ cuv += aushort;
}
}
else
if (checksum > bits_in_uv)
cdouble += (NV)aushort;
else
- culong += aushort;
+ cuv += aushort;
}
}
}
if (checksum > bits_in_uv)
cdouble += (NV)aint;
else
- culong += aint;
+ cuv += aint;
}
}
else {
if (checksum > bits_in_uv)
cdouble += (NV)auint;
else
- culong += auint;
+ cuv += auint;
}
}
else {
}
}
break;
+ case 'j':
+ along = (strend - s) / IVSIZE;
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
+ Copy(s, &aiv, 1, IV);
+ s += IVSIZE;
+ if (checksum > bits_in_uv)
+ cdouble += (NV)aiv;
+ else
+ cuv += aiv;
+ }
+ }
+ else {
+ EXTEND(SP, len);
+ EXTEND_MORTAL(len);
+ while (len-- > 0) {
+ Copy(s, &aiv, 1, IV);
+ s += IVSIZE;
+ sv = NEWSV(40, 0);
+ sv_setiv(sv, aiv);
+ PUSHs(sv_2mortal(sv));
+ }
+ }
+ break;
+ case 'J':
+ along = (strend - s) / UVSIZE;
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
+ Copy(s, &auv, 1, UV);
+ s += UVSIZE;
+ if (checksum > bits_in_uv)
+ cdouble += (NV)auv;
+ else
+ cuv += auv;
+ }
+ }
+ else {
+ EXTEND(SP, len);
+ EXTEND_MORTAL(len);
+ while (len-- > 0) {
+ Copy(s, &auv, 1, UV);
+ s += UVSIZE;
+ sv = NEWSV(41, 0);
+ sv_setuv(sv, auv);
+ PUSHs(sv_2mortal(sv));
+ }
+ }
+ break;
case 'l':
#if LONGSIZE == SIZE32
along = (strend - s) / SIZE32;
if (checksum > bits_in_uv)
cdouble += (NV)along;
else
- culong += along;
+ cuv += along;
}
}
else
if (checksum > bits_in_uv)
cdouble += (NV)along;
else
- culong += along;
+ cuv += along;
}
}
}
if (checksum > bits_in_uv)
cdouble += (NV)aulong;
else
- culong += aulong;
+ cuv += aulong;
}
}
else
if (checksum > bits_in_uv)
cdouble += (NV)aulong;
else
- culong += aulong;
+ cuv += aulong;
}
}
}
if (checksum > bits_in_uv)
cdouble += (NV)aquad;
else
- culong += aquad;
+ cuv += aquad;
}
}
else {
if (s + sizeof(Quad_t) > strend)
aquad = 0;
else {
- Copy(s, &aquad, 1, Quad_t);
- s += sizeof(Quad_t);
+ Copy(s, &aquad, 1, Quad_t);
+ s += sizeof(Quad_t);
}
sv = NEWSV(42, 0);
if (aquad >= IV_MIN && aquad <= IV_MAX)
- sv_setiv(sv, (IV)aquad);
+ sv_setiv(sv, (IV)aquad);
else
sv_setnv(sv, (NV)aquad);
PUSHs(sv_2mortal(sv));
if (checksum > bits_in_uv)
cdouble += (NV)auquad;
else
- culong += auquad;
+ cuv += auquad;
}
}
else {
#endif
/* float and double added gnb@melba.bby.oz.au 22/11/89 */
case 'f':
- case 'F':
along = (strend - s) / sizeof(float);
if (len > along)
len = along;
}
break;
case 'd':
- case 'D':
along = (strend - s) / sizeof(double);
if (len > along)
len = along;
}
}
break;
+ case 'F':
+ along = (strend - s) / NVSIZE;
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
+ Copy(s, &anv, 1, NV);
+ s += NVSIZE;
+ cdouble += anv;
+ }
+ }
+ else {
+ EXTEND(SP, len);
+ EXTEND_MORTAL(len);
+ while (len-- > 0) {
+ Copy(s, &anv, 1, NV);
+ s += NVSIZE;
+ sv = NEWSV(48, 0);
+ sv_setnv(sv, anv);
+ PUSHs(sv_2mortal(sv));
+ }
+ }
+ break;
+#if defined(HAS_LONG_DOUBLE) && defined(USE_LONG_DOUBLE)
+ case 'D':
+ along = (strend - s) / LONG_DOUBLESIZE;
+ if (len > along)
+ len = along;
+ if (checksum) {
+ while (len-- > 0) {
+ Copy(s, &aldouble, 1, long double);
+ s += LONG_DOUBLESIZE;
+ cdouble += aldouble;
+ }
+ }
+ else {
+ EXTEND(SP, len);
+ EXTEND_MORTAL(len);
+ while (len-- > 0) {
+ Copy(s, &aldouble, 1, long double);
+ s += LONG_DOUBLESIZE;
+ sv = NEWSV(48, 0);
+ sv_setnv(sv, (NV)aldouble);
+ PUSHs(sv_2mortal(sv));
+ }
+ }
+ break;
+#endif
case 'u':
/* MKS:
* Initialise the decode mapping. By using a table driven
}
if (*s == '\n')
s++;
- else if (s[1] == '\n') /* possible checksum byte */
- s += 2;
+ else /* possible checksum byte */
+ if (s + 1 < strend && s[1] == '\n')
+ s += 2;
}
XPUSHs(sv_2mortal(sv));
break;
if (checksum) {
sv = NEWSV(42, 0);
if (strchr("fFdD", datumtype) ||
- (checksum > bits_in_uv && strchr("csSiIlLnNUvVqQ", datumtype)) ) {
+ (checksum > bits_in_uv &&
+ strchr("csSiIlLnNUvVqQjJ", datumtype)) ) {
NV trouble;
adouble = (NV) (1 << (checksum & 15));
else {
if (checksum < bits_in_uv) {
UV mask = ((UV)1 << checksum) - 1;
- culong &= mask;
+
+ cuv &= mask;
}
- sv_setuv(sv, (UV)culong);
+ sv_setuv(sv, cuv);
}
XPUSHs(sv_2mortal(sv));
checksum = 0;
unsigned int auint;
I32 along;
U32 aulong;
+ IV aiv;
+ UV auv;
+ NV anv;
+#if defined(HAS_LONG_DOUBLE) && defined(USE_LONG_DOUBLE)
+ long double aldouble;
+#endif
#ifdef HAS_QUAD
Quad_t aquad;
Uquad_t auquad;
Perl_croak(aTHX_ "Invalid type in pack: '%c'", (int)datumtype);
case ',': /* grandfather in commas but with a warning */
if (commas++ == 0 && ckWARN(WARN_PACK))
- Perl_warner(aTHX_ WARN_PACK,
+ Perl_warner(aTHX_ packWARN(WARN_PACK),
"Invalid type in pack: '%c'", (int)datumtype);
break;
case '%':
aint = SvIV(fromstr);
if ((aint < 0 || aint > 255) &&
ckWARN(WARN_PACK))
- Perl_warner(aTHX_ WARN_PACK,
+ Perl_warner(aTHX_ packWARN(WARN_PACK),
"Character in \"C\" format wrapped");
achar = aint & 255;
sv_catpvn(cat, &achar, sizeof(char));
aint = SvIV(fromstr);
if ((aint < -128 || aint > 127) &&
ckWARN(WARN_PACK))
- Perl_warner(aTHX_ WARN_PACK,
+ Perl_warner(aTHX_ packWARN(WARN_PACK),
"Character in \"c\" format wrapped");
achar = aint & 255;
sv_catpvn(cat, &achar, sizeof(char));
fromstr = NEXTFROM;
auint = UNI_TO_NATIVE(SvUV(fromstr));
SvGROW(cat, SvCUR(cat) + UTF8_MAXLEN + 1);
- SvCUR_set(cat, (char*)uvchr_to_utf8((U8*)SvEND(cat),auint)
- - SvPVX(cat));
+ SvCUR_set(cat,
+ (char*)uvchr_to_utf8_flags((U8*)SvEND(cat),
+ auint,
+ ckWARN(WARN_UTF8) ?
+ 0 : UNICODE_ALLOW_ANY)
+ - SvPVX(cat));
}
*SvEND(cat) = '\0';
break;
/* Float and double added by gnb@melba.bby.oz.au 22/11/89 */
case 'f':
- case 'F':
while (len-- > 0) {
fromstr = NEXTFROM;
afloat = (float)SvNV(fromstr);
}
break;
case 'd':
- case 'D':
while (len-- > 0) {
fromstr = NEXTFROM;
adouble = (double)SvNV(fromstr);
sv_catpvn(cat, (char *)&adouble, sizeof (double));
}
break;
+ case 'F':
+ while (len-- > 0) {
+ fromstr = NEXTFROM;
+ anv = SvNV(fromstr);
+ sv_catpvn(cat, (char *)&anv, NVSIZE);
+ }
+ break;
+#if defined(HAS_LONG_DOUBLE) && defined(USE_LONG_DOUBLE)
+ case 'D':
+ while (len-- > 0) {
+ fromstr = NEXTFROM;
+ aldouble = (long double)SvNV(fromstr);
+ sv_catpvn(cat, (char *)&aldouble, LONG_DOUBLESIZE);
+ }
+ break;
+#endif
case 'n':
while (len-- > 0) {
fromstr = NEXTFROM;
sv_catpvn(cat, (char*)&auint, sizeof(unsigned int));
}
break;
+ case 'j':
+ while (len-- > 0) {
+ fromstr = NEXTFROM;
+ aiv = SvIV(fromstr);
+ sv_catpvn(cat, (char*)&aiv, IVSIZE);
+ }
+ break;
+ case 'J':
+ while (len-- > 0) {
+ fromstr = NEXTFROM;
+ auv = SvUV(fromstr);
+ sv_catpvn(cat, (char*)&auv, UVSIZE);
+ }
+ break;
case 'w':
while (len-- > 0) {
fromstr = NEXTFROM;
- adouble = Perl_floor(SvNV(fromstr));
+ adouble = SvNV(fromstr);
if (adouble < 0)
Perl_croak(aTHX_ "Cannot compress negative numbers");
- if (
-#if UVSIZE > 4 && UVSIZE >= NVSIZE
- adouble <= 0xffffffff
-#else
-# ifdef CXUX_BROKEN_CONSTANT_CONVERT
- adouble <= UV_MAX_cxux
-# else
- adouble <= UV_MAX
-# endif
-#endif
- )
+ /* 0xFFFFFFFFFFFFFFFF may cast to 18446744073709551616.0,
+ which is == UV_MAX_P1. IOK is fine (instead of UV_only), as
+ any negative IVs will have already been got by the croak()
+ above. IOK is untrue for fractions, so we test them
+ against UV_MAX_P1. */
+ if (SvIOK(fromstr) || adouble < UV_MAX_P1)
{
- char buf[1 + sizeof(UV)];
+ char buf[(sizeof(UV)*8)/7+1];
char *in = buf + sizeof(buf);
- UV auv = U_V(adouble);
+ UV auv = SvUV(fromstr);
do {
*--in = (auv & 0x7f) | 0x80;
char buf[sizeof(double) * 2]; /* 8/7 <= 2 */
char *in = buf + sizeof(buf);
+ adouble = Perl_floor(adouble);
do {
double next = floor(adouble / 128);
*--in = (unsigned char)(adouble - (next * 128)) | 0x80;
|| (SvPADTMP(fromstr)
&& !SvREADONLY(fromstr))))
{
- Perl_warner(aTHX_ WARN_PACK,
+ Perl_warner(aTHX_ packWARN(WARN_PACK),
"Attempt to pack pointer to temporary value");
}
if (SvPOK(fromstr) || SvNIOK(fromstr))