… | |
… | |
260 | } |
260 | } |
261 | |
261 | |
262 | // this relies greatly on the quality of the pow () |
262 | // this relies greatly on the quality of the pow () |
263 | // implementation of the platform, but a good |
263 | // implementation of the platform, but a good |
264 | // implementation is hard to beat. |
264 | // implementation is hard to beat. |
|
|
265 | // (IEEE 754 conformant ones are required to be exact) |
265 | if (postdp) *expo -= eaccum; |
266 | if (postdp) *expo -= eaccum; |
266 | *accum += uaccum * Perl_pow (10., *expo); |
267 | *accum += uaccum * Perl_pow (10., *expo); |
267 | *expo += eaccum; |
268 | *expo += eaccum; |
268 | } |
269 | } |
269 | |
270 | |
… | |
… | |
836 | encode_rv (enc, SvRV (sv)); |
837 | encode_rv (enc, SvRV (sv)); |
837 | else if (!SvOK (sv) || enc->json.flags & F_ALLOW_UNKNOWN) |
838 | else if (!SvOK (sv) || enc->json.flags & F_ALLOW_UNKNOWN) |
838 | encode_str (enc, "null", 4, 0); |
839 | encode_str (enc, "null", 4, 0); |
839 | else |
840 | else |
840 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
841 | croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", |
841 | SvPV_nolen (sv), SvFLAGS (sv)); |
842 | SvPV_nolen (sv), (unsigned int)SvFLAGS (sv)); |
842 | } |
843 | } |
843 | |
844 | |
844 | static SV * |
845 | static SV * |
845 | encode_json (SV *scalar, JSON *json) |
846 | encode_json (SV *scalar, JSON *json) |
846 | { |
847 | { |
… | |
… | |
1520 | { |
1521 | { |
1521 | dec_t dec; |
1522 | dec_t dec; |
1522 | SV *sv; |
1523 | SV *sv; |
1523 | |
1524 | |
1524 | /* work around bugs in 5.10 where manipulating magic values |
1525 | /* work around bugs in 5.10 where manipulating magic values |
1525 | * will perl ignore the magic in subsequent accesses |
1526 | * will perl ignore the magic in subsequent accesses. |
|
|
1527 | * also make a copy of non-PV values, to get them into a clean |
|
|
1528 | * state (SvPV should do that, but it's buggy, see below). |
1526 | */ |
1529 | */ |
1527 | /*SvGETMAGIC (string);*/ |
1530 | /*SvGETMAGIC (string);*/ |
1528 | if (SvMAGICAL (string)) |
1531 | if (SvMAGICAL (string) || !SvPOK (string)) |
1529 | string = sv_2mortal (newSVsv (string)); |
1532 | string = sv_2mortal (newSVsv (string)); |
1530 | |
1533 | |
1531 | SvUPGRADE (string, SVt_PV); |
1534 | SvUPGRADE (string, SVt_PV); |
1532 | |
1535 | |
1533 | /* work around a bug in perl 5.10, which causes SvCUR to fail an |
1536 | /* work around a bug in perl 5.10, which causes SvCUR to fail an |
… | |
… | |
1602 | pv_uni_display (uni, dec.cur, dec.end - dec.cur, 20, UNI_DISPLAY_QQ); |
1605 | pv_uni_display (uni, dec.cur, dec.end - dec.cur, 20, UNI_DISPLAY_QQ); |
1603 | LEAVE; |
1606 | LEAVE; |
1604 | |
1607 | |
1605 | croak ("%s, at character offset %d (before \"%s\")", |
1608 | croak ("%s, at character offset %d (before \"%s\")", |
1606 | dec.err, |
1609 | dec.err, |
1607 | ptr_to_index (string, dec.cur), |
1610 | (int)ptr_to_index (string, dec.cur), |
1608 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
1611 | dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); |
1609 | } |
1612 | } |
1610 | |
1613 | |
1611 | sv = sv_2mortal (sv); |
1614 | sv = sv_2mortal (sv); |
1612 | |
1615 | |
… | |
… | |
1989 | if (self->incr_pos > self->max_size && self->max_size) |
1992 | if (self->incr_pos > self->max_size && self->max_size) |
1990 | croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", |
1993 | croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", |
1991 | (unsigned long)self->incr_pos, (unsigned long)self->max_size); |
1994 | (unsigned long)self->incr_pos, (unsigned long)self->max_size); |
1992 | |
1995 | |
1993 | if (!INCR_DONE (self)) |
1996 | if (!INCR_DONE (self)) |
|
|
1997 | { |
|
|
1998 | // as an optimisation, do not accumulate white space in the incr buffer |
|
|
1999 | if (self->incr_mode == INCR_M_WS && self->incr_pos) |
|
|
2000 | { |
|
|
2001 | self->incr_pos = 0; |
|
|
2002 | SvCUR_set (self->incr_text, 0); |
|
|
2003 | } |
|
|
2004 | |
1994 | break; |
2005 | break; |
|
|
2006 | } |
1995 | } |
2007 | } |
1996 | |
2008 | |
1997 | XPUSHs (decode_json (self->incr_text, self, &offset)); |
2009 | XPUSHs (decode_json (self->incr_text, self, &offset)); |
1998 | |
2010 | |
1999 | self->incr_pos -= offset - SvPVX (self->incr_text); |
2011 | self->incr_pos -= offset - SvPVX (self->incr_text); |