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.64 by root, Mon Aug 27 02:03:23 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
705decode_comment (dec_t *dec) 738decode_comment (dec_t *dec)
706{ 739{
707 // only '#'-style comments allowed a.t.m. 740 // only '#'-style comments allowed a.t.m.
708 741
709 while (*dec->cur && *dec->cur != 0x0a && *dec->cur != 0x0d) 742 while (*dec->cur && *dec->cur != 0x0a && *dec->cur != 0x0d)
710 ++dec->cur; 743 ++dec->cur;
711} 744}
712 745
713inline void 746INLINE void
714decode_ws (dec_t *dec) 747decode_ws (dec_t *dec)
715{ 748{
716 for (;;) 749 for (;;)
717 { 750 {
718 char ch = *dec->cur; 751 char ch = *dec->cur;
844 877
845 if (hi >= 0x80) 878 if (hi >= 0x80)
846 { 879 {
847 utf8 = 1; 880 utf8 = 1;
848 881
849 cur = (char *)uvuni_to_utf8_flags (cur, hi, 0); 882 cur = encode_utf8 (cur, hi);
850 } 883 }
851 else 884 else
852 *cur++ = hi; 885 *cur++ = hi;
853 } 886 }
854 break; 887 break;
989 1022
990 if (!is_nv) 1023 if (!is_nv)
991 { 1024 {
992 int len = dec->cur - start; 1025 int len = dec->cur - start;
993 1026
994 // 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
995 if (*start == '-') 1028 if (*start == '-')
996 switch (len) 1029 switch (len)
997 { 1030 {
998 case 2: return newSViv (-( start [1] - '0' * 1)); 1031 case 2: return newSViv (-( start [1] - '0' * 1));
999 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); 1032 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11));
1000 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));
1001 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));
1002 } 1036 }
1003 else 1037 else
1004 switch (len) 1038 switch (len)
1005 { 1039 {
1006 case 1: return newSViv ( start [0] - '0' * 1); 1040 case 1: return newSViv ( start [0] - '0' * 1);
1007 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); 1041 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11);
1008 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);
1009 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);
1010 } 1045 }
1011 1046
1012 { 1047 {
1013 UV uv; 1048 UV uv;
1014 int numtype = grok_number (start, len, &uv); 1049 int numtype = grok_number (start, len, &uv);
1263 1298
1264static SV * 1299static SV *
1265decode_sv (dec_t *dec) 1300decode_sv (dec_t *dec)
1266{ 1301{
1267 // the beauty of JSON: you need exactly one character lookahead 1302 // the beauty of JSON: you need exactly one character lookahead
1268 // to parse anything. 1303 // to parse everything.
1269 switch (*dec->cur) 1304 switch (*dec->cur)
1270 { 1305 {
1271 case '"': ++dec->cur; return decode_str (dec); 1306 case '"': ++dec->cur; return decode_str (dec);
1272 case '[': ++dec->cur; return decode_av (dec); 1307 case '[': ++dec->cur; return decode_av (dec);
1273 case '{': ++dec->cur; return decode_hv (dec); 1308 case '{': ++dec->cur; return decode_hv (dec);
1274 1309
1275 case '-': 1310 case '-':
1276 case '0': case '1': case '2': case '3': case '4': 1311 case '0': case '1': case '2': case '3': case '4':
1277 case '5': case '6': case '7': case '8': case '9': 1312 case '5': case '6': case '7': case '8': case '9':
1278 return decode_num (dec); 1313 return decode_num (dec);
1446{ 1481{
1447 SV *pv = NEWSV (0, sizeof (JSON)); 1482 SV *pv = NEWSV (0, sizeof (JSON));
1448 SvPOK_only (pv); 1483 SvPOK_only (pv);
1449 Zero (SvPVX (pv), 1, JSON); 1484 Zero (SvPVX (pv), 1, JSON);
1450 ((JSON *)SvPVX (pv))->flags = F_DEFAULT; 1485 ((JSON *)SvPVX (pv))->flags = F_DEFAULT;
1451 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 )));
1452} 1490}
1453 1491
1454void ascii (JSON *self, int enable = 1) 1492void ascii (JSON *self, int enable = 1)
1455 ALIAS: 1493 ALIAS:
1456 ascii = F_ASCII 1494 ascii = F_ASCII
1474 self->flags &= ~ix; 1512 self->flags &= ~ix;
1475 1513
1476 XPUSHs (ST (0)); 1514 XPUSHs (ST (0));
1477} 1515}
1478 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
1479void max_depth (JSON *self, UV max_depth = 0x80000000UL) 1534void max_depth (JSON *self, UV max_depth = 0x80000000UL)
1480 PPCODE: 1535 PPCODE:
1481{ 1536{
1482 UV log2 = 0; 1537 UV log2 = 0;
1483 1538
1489 self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); 1544 self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH);
1490 1545
1491 XPUSHs (ST (0)); 1546 XPUSHs (ST (0));
1492} 1547}
1493 1548
1549U32 get_max_depth (JSON *self)
1550 CODE:
1551 RETVAL = DEC_DEPTH (self->flags);
1552 OUTPUT:
1553 RETVAL
1554
1494void max_size (JSON *self, UV max_size = 0) 1555void max_size (JSON *self, UV max_size = 0)
1495 PPCODE: 1556 PPCODE:
1496{ 1557{
1497 UV log2 = 0; 1558 UV log2 = 0;
1498 1559
1504 1565
1505 self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE); 1566 self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE);
1506 1567
1507 XPUSHs (ST (0)); 1568 XPUSHs (ST (0));
1508} 1569}
1570
1571int get_max_size (JSON *self)
1572 CODE:
1573 RETVAL = DEC_SIZE (self->flags);
1574 OUTPUT:
1575 RETVAL
1509 1576
1510void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) 1577void filter_json_object (JSON *self, SV *cb = &PL_sv_undef)
1511 PPCODE: 1578 PPCODE:
1512{ 1579{
1513 SvREFCNT_dec (self->cb_object); 1580 SvREFCNT_dec (self->cb_object);
1560 SvREFCNT_dec (self->cb_sk_object); 1627 SvREFCNT_dec (self->cb_sk_object);
1561 SvREFCNT_dec (self->cb_object); 1628 SvREFCNT_dec (self->cb_object);
1562 1629
1563PROTOTYPES: ENABLE 1630PROTOTYPES: ENABLE
1564 1631
1565void to_json (SV *scalar) 1632void encode_json (SV *scalar)
1566 PPCODE: 1633 PPCODE:
1567{ 1634{
1568 JSON json = { F_DEFAULT | F_UTF8 }; 1635 JSON json = { F_DEFAULT | F_UTF8 };
1569 XPUSHs (encode_json (scalar, &json)); 1636 XPUSHs (encode_json (scalar, &json));
1570} 1637}
1571 1638
1572void from_json (SV *jsonstr) 1639void decode_json (SV *jsonstr)
1573 PPCODE: 1640 PPCODE:
1574{ 1641{
1575 JSON json = { F_DEFAULT | F_UTF8 }; 1642 JSON json = { F_DEFAULT | F_UTF8 };
1576 XPUSHs (decode_json (jsonstr, &json, 0)); 1643 XPUSHs (decode_json (jsonstr, &json, 0));
1577} 1644}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines