ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/XS.xs
(Generate patch)

Comparing JSON-XS/XS.xs (file contents):
Revision 1.63 by root, Mon Aug 27 01:49:01 2007 UTC vs.
Revision 1.73 by root, Wed Mar 19 13:44:43 2008 UTC

50 50
51#define SB do { 51#define SB do {
52#define SE } while (0) 52#define SE } while (0)
53 53
54#if __GNUC__ >= 3 54#if __GNUC__ >= 3
55# define expect(expr,value) __builtin_expect ((expr),(value)) 55# define expect(expr,value) __builtin_expect ((expr), (value))
56# define inline inline 56# define INLINE static inline
57#else 57#else
58# define expect(expr,value) (expr) 58# define expect(expr,value) (expr)
59# define inline static 59# define INLINE static
60#endif 60#endif
61 61
62#define expect_false(expr) expect ((expr) != 0, 0) 62#define expect_false(expr) expect ((expr) != 0, 0)
63#define expect_true(expr) expect ((expr) != 0, 1) 63#define expect_true(expr) expect ((expr) != 0, 1)
64
65#define IN_RANGE_INC(type,val,beg,end) \
66 ((unsigned type)((unsigned type)(val) - (unsigned type)(beg)) \
67 <= (unsigned type)((unsigned type)(end) - (unsigned type)(beg)))
64 68
65#ifdef USE_ITHREADS 69#ifdef USE_ITHREADS
66# define JSON_SLOW 1 70# define JSON_SLOW 1
67# define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) 71# define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1))
68#else 72#else
80} JSON; 84} JSON;
81 85
82///////////////////////////////////////////////////////////////////////////// 86/////////////////////////////////////////////////////////////////////////////
83// utility functions 87// utility functions
84 88
85inline void 89INLINE void
86shrink (SV *sv) 90shrink (SV *sv)
87{ 91{
88 sv_utf8_downgrade (sv, 1); 92 sv_utf8_downgrade (sv, 1);
89 if (SvLEN (sv) > SvCUR (sv) + 1) 93 if (SvLEN (sv) > SvCUR (sv) + 1)
90 { 94 {
99// decode an utf-8 character and return it, or (UV)-1 in 103// decode an utf-8 character and return it, or (UV)-1 in
100// case of an error. 104// case of an error.
101// we special-case "safe" characters from U+80 .. U+7FF, 105// we special-case "safe" characters from U+80 .. U+7FF,
102// but use the very good perl function to parse anything else. 106// but use the very good perl function to parse anything else.
103// note that we never call this function for a ascii codepoints 107// note that we never call this function for a ascii codepoints
104inline UV 108INLINE UV
105decode_utf8 (unsigned char *s, STRLEN len, STRLEN *clen) 109decode_utf8 (unsigned char *s, STRLEN len, STRLEN *clen)
106{ 110{
107 if (expect_false (s[0] > 0xdf || s[0] < 0xc2)) 111 if (expect_true (len >= 2
108 return utf8n_to_uvuni (s, len, clen, UTF8_CHECK_ONLY); 112 && IN_RANGE_INC (char, s[0], 0xc2, 0xdf)
109 else if (len > 1 && s[1] >= 0x80 && s[1] <= 0xbf) 113 && IN_RANGE_INC (char, s[1], 0x80, 0xbf)))
110 { 114 {
111 *clen = 2; 115 *clen = 2;
112 return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f); 116 return ((s[0] & 0x1f) << 6) | (s[1] & 0x3f);
113 } 117 }
114 else 118 else
115 { 119 return utf8n_to_uvuni (s, len, clen, UTF8_CHECK_ONLY);
116 *clen = (STRLEN)-1; 120}
117 return (UV)-1; 121
122// likewise for encoding, also never called for ascii codepoints
123// this function takes advantage of this fact, although current gccs
124// seem to optimise the check for >= 0x80 away anyways
125INLINE unsigned char *
126encode_utf8 (unsigned char *s, UV ch)
127{
128 if (ch <= 0x7FF)
118 } 129 {
130 *s++ = (ch >> 6) | 0xc0;
131 *s++ = (ch & 0x3f) | 0x80;
132 }
133 else
134 s = uvuni_to_utf8_flags (s, ch, 0);
135
136 return s;
119} 137}
120 138
121///////////////////////////////////////////////////////////////////////////// 139/////////////////////////////////////////////////////////////////////////////
122// encoder 140// encoder
123 141
128 char *end; // SvEND (sv) 146 char *end; // SvEND (sv)
129 SV *sv; // result scalar 147 SV *sv; // result scalar
130 JSON json; 148 JSON json;
131 U32 indent; // indentation level 149 U32 indent; // indentation level
132 U32 maxdepth; // max. indentation/recursion level 150 U32 maxdepth; // max. indentation/recursion level
151 UV limit; // escape character values >= this value when encoding
133} enc_t; 152} enc_t;
134 153
135inline void 154INLINE void
136need (enc_t *enc, STRLEN len) 155need (enc_t *enc, STRLEN len)
137{ 156{
138 if (expect_false (enc->cur + len >= enc->end)) 157 if (expect_false (enc->cur + len >= enc->end))
139 { 158 {
140 STRLEN cur = enc->cur - SvPVX (enc->sv); 159 STRLEN cur = enc->cur - SvPVX (enc->sv);
142 enc->cur = SvPVX (enc->sv) + cur; 161 enc->cur = SvPVX (enc->sv) + cur;
143 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1; 162 enc->end = SvPVX (enc->sv) + SvLEN (enc->sv) - 1;
144 } 163 }
145} 164}
146 165
147inline void 166INLINE void
148encode_ch (enc_t *enc, char ch) 167encode_ch (enc_t *enc, char ch)
149{ 168{
150 need (enc, 1); 169 need (enc, 1);
151 *enc->cur++ = ch; 170 *enc->cur++ = ch;
152} 171}
206 { 225 {
207 uch = ch; 226 uch = ch;
208 clen = 1; 227 clen = 1;
209 } 228 }
210 229
211 if (uch > 0x10FFFFUL) 230 if (uch < 0x80/*0x20*/ || uch >= enc->limit)
212 croak ("out of range codepoint (0x%lx) encountered, unrepresentable in JSON", (unsigned long)uch);
213
214 if (uch < 0x80 || enc->json.flags & F_ASCII || (enc->json.flags & F_LATIN1 && uch > 0xFF))
215 { 231 {
216 if (uch > 0xFFFFUL) 232 if (uch > 0xFFFFUL)
217 { 233 {
234 if (uch > 0x10FFFFUL)
235 croak ("out of range codepoint (0x%lx) encountered, unrepresentable in JSON", (unsigned long)uch);
236
218 need (enc, len += 11); 237 need (enc, len += 11);
219 sprintf (enc->cur, "\\u%04x\\u%04x", 238 sprintf (enc->cur, "\\u%04x\\u%04x",
220 (int)((uch - 0x10000) / 0x400 + 0xD800), 239 (int)((uch - 0x10000) / 0x400 + 0xD800),
221 (int)((uch - 0x10000) % 0x400 + 0xDC00)); 240 (int)((uch - 0x10000) % 0x400 + 0xDC00));
222 enc->cur += 12; 241 enc->cur += 12;
250 while (--clen); 269 while (--clen);
251 } 270 }
252 else 271 else
253 { 272 {
254 need (enc, len += UTF8_MAXBYTES - 1); // never more than 11 bytes needed 273 need (enc, len += UTF8_MAXBYTES - 1); // never more than 11 bytes needed
255 enc->cur = uvuni_to_utf8_flags (enc->cur, uch, 0); 274 enc->cur = encode_utf8 (enc->cur, uch);
256 ++str; 275 ++str;
257 } 276 }
258 } 277 }
259 } 278 }
260 } 279 }
261 280
262 --len; 281 --len;
263 } 282 }
264} 283}
265 284
266inline void 285INLINE void
267encode_indent (enc_t *enc) 286encode_indent (enc_t *enc)
268{ 287{
269 if (enc->json.flags & F_INDENT) 288 if (enc->json.flags & F_INDENT)
270 { 289 {
271 int spaces = enc->indent * INDENT_STEP; 290 int spaces = enc->indent * INDENT_STEP;
274 memset (enc->cur, ' ', spaces); 293 memset (enc->cur, ' ', spaces);
275 enc->cur += spaces; 294 enc->cur += spaces;
276 } 295 }
277} 296}
278 297
279inline void 298INLINE void
280encode_space (enc_t *enc) 299encode_space (enc_t *enc)
281{ 300{
282 need (enc, 1); 301 need (enc, 1);
283 encode_ch (enc, ' '); 302 encode_ch (enc, ' ');
284} 303}
285 304
286inline void 305INLINE void
287encode_nl (enc_t *enc) 306encode_nl (enc_t *enc)
288{ 307{
289 if (enc->json.flags & F_INDENT) 308 if (enc->json.flags & F_INDENT)
290 { 309 {
291 need (enc, 1); 310 need (enc, 1);
292 encode_ch (enc, '\n'); 311 encode_ch (enc, '\n');
293 } 312 }
294} 313}
295 314
296inline void 315INLINE void
297encode_comma (enc_t *enc) 316encode_comma (enc_t *enc)
298{ 317{
299 encode_ch (enc, ','); 318 encode_ch (enc, ',');
300 319
301 if (enc->json.flags & F_INDENT) 320 if (enc->json.flags & F_INDENT)
312 int i, len = av_len (av); 331 int i, len = av_len (av);
313 332
314 if (enc->indent >= enc->maxdepth) 333 if (enc->indent >= enc->maxdepth)
315 croak ("data structure too deep (hit recursion limit)"); 334 croak ("data structure too deep (hit recursion limit)");
316 335
317 encode_ch (enc, '['); encode_nl (enc); 336 encode_ch (enc, '[');
318 ++enc->indent; 337
338 if (len >= 0)
339 {
340 encode_nl (enc); ++enc->indent;
319 341
320 for (i = 0; i <= len; ++i) 342 for (i = 0; i <= len; ++i)
321 { 343 {
322 SV **svp = av_fetch (av, i, 0); 344 SV **svp = av_fetch (av, i, 0);
323 345
324 encode_indent (enc); 346 encode_indent (enc);
325 347
326 if (svp) 348 if (svp)
327 encode_sv (enc, *svp); 349 encode_sv (enc, *svp);
328 else 350 else
329 encode_str (enc, "null", 4, 0); 351 encode_str (enc, "null", 4, 0);
330 352
331 if (i < len) 353 if (i < len)
332 encode_comma (enc); 354 encode_comma (enc);
333 } 355 }
334 356
357 encode_nl (enc); --enc->indent; encode_indent (enc);
358 }
359
335 encode_nl (enc); 360 encode_ch (enc, ']');
336
337 --enc->indent;
338 encode_indent (enc); encode_ch (enc, ']');
339} 361}
340 362
341static void 363static void
342encode_hk (enc_t *enc, HE *he) 364encode_hk (enc_t *enc, HE *he)
343{ 365{
396 int count; 418 int count;
397 419
398 if (enc->indent >= enc->maxdepth) 420 if (enc->indent >= enc->maxdepth)
399 croak ("data structure too deep (hit recursion limit)"); 421 croak ("data structure too deep (hit recursion limit)");
400 422
401 encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; 423 encode_ch (enc, '{');
402 424
403 // for canonical output we have to sort by keys first 425 // for canonical output we have to sort by keys first
404 // actually, this is mostly due to the stupid so-called 426 // actually, this is mostly due to the stupid so-called
405 // security workaround added somewhere in 5.8.x. 427 // security workaround added somewhere in 5.8.x.
406 // that randomises hash orderings 428 // that randomises hash orderings
459 481
460 FREETMPS; 482 FREETMPS;
461 LEAVE; 483 LEAVE;
462 } 484 }
463 485
486 encode_nl (enc); ++enc->indent;
487
464 while (count--) 488 while (count--)
465 { 489 {
466 encode_indent (enc); 490 encode_indent (enc);
467 he = hes [count]; 491 he = hes [count];
468 encode_hk (enc, he); 492 encode_hk (enc, he);
469 encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he)); 493 encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he));
470 494
471 if (count) 495 if (count)
472 encode_comma (enc); 496 encode_comma (enc);
473 } 497 }
498
499 encode_nl (enc); --enc->indent; encode_indent (enc);
474 } 500 }
475 } 501 }
476 else 502 else
477 { 503 {
478 if (hv_iterinit (hv) || SvMAGICAL (hv)) 504 if (hv_iterinit (hv) || SvMAGICAL (hv))
479 if ((he = hv_iternext (hv))) 505 if ((he = hv_iternext (hv)))
506 {
507 encode_nl (enc); ++enc->indent;
508
480 for (;;) 509 for (;;)
481 { 510 {
482 encode_indent (enc); 511 encode_indent (enc);
483 encode_hk (enc, he); 512 encode_hk (enc, he);
484 encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he)); 513 encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he));
485 514
486 if (!(he = hv_iternext (hv))) 515 if (!(he = hv_iternext (hv)))
487 break; 516 break;
488 517
489 encode_comma (enc); 518 encode_comma (enc);
490 } 519 }
491 }
492 520
521 encode_nl (enc); --enc->indent; encode_indent (enc);
522 }
523 }
524
493 encode_nl (enc); 525 encode_ch (enc, '}');
494
495 --enc->indent; encode_indent (enc); encode_ch (enc, '}');
496} 526}
497 527
498// encode objects, arrays and special \0=false and \1=true values. 528// encode objects, arrays and special \0=false and \1=true values.
499static void 529static void
500encode_rv (enc_t *enc, SV *sv) 530encode_rv (enc_t *enc, SV *sv)
669 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); 699 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE));
670 enc.cur = SvPVX (enc.sv); 700 enc.cur = SvPVX (enc.sv);
671 enc.end = SvEND (enc.sv); 701 enc.end = SvEND (enc.sv);
672 enc.indent = 0; 702 enc.indent = 0;
673 enc.maxdepth = DEC_DEPTH (enc.json.flags); 703 enc.maxdepth = DEC_DEPTH (enc.json.flags);
704 enc.limit = enc.json.flags & F_ASCII ? 0x000080UL
705 : enc.json.flags & F_LATIN1 ? 0x000100UL
706 : 0x10FFFFUL;
674 707
675 SvPOK_only (enc.sv); 708 SvPOK_only (enc.sv);
676 encode_sv (&enc, scalar); 709 encode_sv (&enc, scalar);
677 710
678 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); 711 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv));
699 JSON json; 732 JSON json;
700 U32 depth; // recursion depth 733 U32 depth; // recursion depth
701 U32 maxdepth; // recursion depth limit 734 U32 maxdepth; // recursion depth limit
702} dec_t; 735} dec_t;
703 736
704inline void 737INLINE void
738decode_comment (dec_t *dec)
739{
740 // only '#'-style comments allowed a.t.m.
741
742 while (*dec->cur && *dec->cur != 0x0a && *dec->cur != 0x0d)
743 ++dec->cur;
744}
745
746INLINE void
705decode_ws (dec_t *dec) 747decode_ws (dec_t *dec)
706{ 748{
707 for (;;) 749 for (;;)
708 { 750 {
709 char ch = *dec->cur; 751 char ch = *dec->cur;
710 752
711 if (ch > 0x20 753 if (ch > 0x20)
754 {
755 if (expect_false (ch == '#'))
756 {
757 if (dec->json.flags & F_RELAXED)
758 decode_comment (dec);
759 else
760 break;
761 }
762 else
763 break;
764 }
712 || (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09)) 765 else if (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09)
713 break; 766 break; // parse error, but let higher level handle it, gives better error messages
714
715 if (ch == '#' && dec->json.flags & F_RELAXED)
716 ++dec->cur;
717 767
718 ++dec->cur; 768 ++dec->cur;
719 } 769 }
720} 770}
721 771
827 877
828 if (hi >= 0x80) 878 if (hi >= 0x80)
829 { 879 {
830 utf8 = 1; 880 utf8 = 1;
831 881
832 cur = (char *)uvuni_to_utf8_flags (cur, hi, 0); 882 cur = encode_utf8 (cur, hi);
833 } 883 }
834 else 884 else
835 *cur++ = hi; 885 *cur++ = hi;
836 } 886 }
837 break; 887 break;
972 1022
973 if (!is_nv) 1023 if (!is_nv)
974 { 1024 {
975 int len = dec->cur - start; 1025 int len = dec->cur - start;
976 1026
977 // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so 1027 // special case the rather common 1..5-digit-int case
978 if (*start == '-') 1028 if (*start == '-')
979 switch (len) 1029 switch (len)
980 { 1030 {
981 case 2: return newSViv (-( start [1] - '0' * 1)); 1031 case 2: return newSViv (-( start [1] - '0' * 1));
982 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); 1032 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11));
983 case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); 1033 case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111));
984 case 5: return newSViv (-(start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); 1034 case 5: return newSViv (-( start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111));
1035 case 6: return newSViv (-(start [1] * 10000 + start [2] * 1000 + start [3] * 100 + start [4] * 10 + start [5] - '0' * 11111));
985 } 1036 }
986 else 1037 else
987 switch (len) 1038 switch (len)
988 { 1039 {
989 case 1: return newSViv ( start [0] - '0' * 1); 1040 case 1: return newSViv ( start [0] - '0' * 1);
990 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); 1041 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11);
991 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); 1042 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111);
992 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); 1043 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111);
1044 case 5: return newSViv ( start [0] * 10000 + start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 11111);
993 } 1045 }
994 1046
995 { 1047 {
996 UV uv; 1048 UV uv;
997 int numtype = grok_number (start, len, &uv); 1049 int numtype = grok_number (start, len, &uv);
1246 1298
1247static SV * 1299static SV *
1248decode_sv (dec_t *dec) 1300decode_sv (dec_t *dec)
1249{ 1301{
1250 // the beauty of JSON: you need exactly one character lookahead 1302 // the beauty of JSON: you need exactly one character lookahead
1251 // to parse anything. 1303 // to parse everything.
1252 switch (*dec->cur) 1304 switch (*dec->cur)
1253 { 1305 {
1254 case '"': ++dec->cur; return decode_str (dec); 1306 case '"': ++dec->cur; return decode_str (dec);
1255 case '[': ++dec->cur; return decode_av (dec); 1307 case '[': ++dec->cur; return decode_av (dec);
1256 case '{': ++dec->cur; return decode_hv (dec); 1308 case '{': ++dec->cur; return decode_hv (dec);
1257 1309
1258 case '-': 1310 case '-':
1259 case '0': case '1': case '2': case '3': case '4': 1311 case '0': case '1': case '2': case '3': case '4':
1260 case '5': case '6': case '7': case '8': case '9': 1312 case '5': case '6': case '7': case '8': case '9':
1261 return decode_num (dec); 1313 return decode_num (dec);
1429{ 1481{
1430 SV *pv = NEWSV (0, sizeof (JSON)); 1482 SV *pv = NEWSV (0, sizeof (JSON));
1431 SvPOK_only (pv); 1483 SvPOK_only (pv);
1432 Zero (SvPVX (pv), 1, JSON); 1484 Zero (SvPVX (pv), 1, JSON);
1433 ((JSON *)SvPVX (pv))->flags = F_DEFAULT; 1485 ((JSON *)SvPVX (pv))->flags = F_DEFAULT;
1434 XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), JSON_STASH))); 1486 XPUSHs (sv_2mortal (sv_bless (
1487 newRV_noinc (pv),
1488 strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1)
1489 )));
1435} 1490}
1436 1491
1437void ascii (JSON *self, int enable = 1) 1492void ascii (JSON *self, int enable = 1)
1438 ALIAS: 1493 ALIAS:
1439 ascii = F_ASCII 1494 ascii = F_ASCII
1457 self->flags &= ~ix; 1512 self->flags &= ~ix;
1458 1513
1459 XPUSHs (ST (0)); 1514 XPUSHs (ST (0));
1460} 1515}
1461 1516
1517void get_ascii (JSON *self)
1518 ALIAS:
1519 get_ascii = F_ASCII
1520 get_latin1 = F_LATIN1
1521 get_utf8 = F_UTF8
1522 get_indent = F_INDENT
1523 get_canonical = F_CANONICAL
1524 get_space_before = F_SPACE_BEFORE
1525 get_space_after = F_SPACE_AFTER
1526 get_allow_nonref = F_ALLOW_NONREF
1527 get_shrink = F_SHRINK
1528 get_allow_blessed = F_ALLOW_BLESSED
1529 get_convert_blessed = F_CONV_BLESSED
1530 get_relaxed = F_RELAXED
1531 PPCODE:
1532 XPUSHs (boolSV (self->flags & ix));
1533
1462void max_depth (JSON *self, UV max_depth = 0x80000000UL) 1534void max_depth (JSON *self, UV max_depth = 0x80000000UL)
1463 PPCODE: 1535 PPCODE:
1464{ 1536{
1465 UV log2 = 0; 1537 UV log2 = 0;
1466 1538
1472 self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); 1544 self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH);
1473 1545
1474 XPUSHs (ST (0)); 1546 XPUSHs (ST (0));
1475} 1547}
1476 1548
1549U32 get_max_depth (JSON *self)
1550 CODE:
1551 RETVAL = DEC_DEPTH (self->flags);
1552 OUTPUT:
1553 RETVAL
1554
1477void max_size (JSON *self, UV max_size = 0) 1555void max_size (JSON *self, UV max_size = 0)
1478 PPCODE: 1556 PPCODE:
1479{ 1557{
1480 UV log2 = 0; 1558 UV log2 = 0;
1481 1559
1487 1565
1488 self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE); 1566 self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE);
1489 1567
1490 XPUSHs (ST (0)); 1568 XPUSHs (ST (0));
1491} 1569}
1570
1571int get_max_size (JSON *self)
1572 CODE:
1573 RETVAL = DEC_SIZE (self->flags);
1574 OUTPUT:
1575 RETVAL
1492 1576
1493void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) 1577void filter_json_object (JSON *self, SV *cb = &PL_sv_undef)
1494 PPCODE: 1578 PPCODE:
1495{ 1579{
1496 SvREFCNT_dec (self->cb_object); 1580 SvREFCNT_dec (self->cb_object);
1543 SvREFCNT_dec (self->cb_sk_object); 1627 SvREFCNT_dec (self->cb_sk_object);
1544 SvREFCNT_dec (self->cb_object); 1628 SvREFCNT_dec (self->cb_object);
1545 1629
1546PROTOTYPES: ENABLE 1630PROTOTYPES: ENABLE
1547 1631
1548void to_json (SV *scalar) 1632void encode_json (SV *scalar)
1549 PPCODE: 1633 PPCODE:
1550{ 1634{
1551 JSON json = { F_DEFAULT | F_UTF8 }; 1635 JSON json = { F_DEFAULT | F_UTF8 };
1552 XPUSHs (encode_json (scalar, &json)); 1636 XPUSHs (encode_json (scalar, &json));
1553} 1637}
1554 1638
1555void from_json (SV *jsonstr) 1639void decode_json (SV *jsonstr)
1556 PPCODE: 1640 PPCODE:
1557{ 1641{
1558 JSON json = { F_DEFAULT | F_UTF8 }; 1642 JSON json = { F_DEFAULT | F_UTF8 };
1559 XPUSHs (decode_json (jsonstr, &json, 0)); 1643 XPUSHs (decode_json (jsonstr, &json, 0));
1560} 1644}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines