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.58 by root, Mon Aug 13 16:06:25 2007 UTC vs.
Revision 1.70 by root, Wed Mar 19 00:44:54 2008 UTC

27#define F_SPACE_AFTER 0x00000040UL 27#define F_SPACE_AFTER 0x00000040UL
28#define F_ALLOW_NONREF 0x00000100UL 28#define F_ALLOW_NONREF 0x00000100UL
29#define F_SHRINK 0x00000200UL 29#define F_SHRINK 0x00000200UL
30#define F_ALLOW_BLESSED 0x00000400UL 30#define F_ALLOW_BLESSED 0x00000400UL
31#define F_CONV_BLESSED 0x00000800UL 31#define F_CONV_BLESSED 0x00000800UL
32#define F_RELAXED 0x00001000UL
33
32#define F_MAXDEPTH 0xf8000000UL 34#define F_MAXDEPTH 0xf8000000UL
33#define S_MAXDEPTH 27 35#define S_MAXDEPTH 27
34#define F_MAXSIZE 0x01f00000UL 36#define F_MAXSIZE 0x01f00000UL
35#define S_MAXSIZE 20 37#define S_MAXSIZE 20
36#define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing 38#define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing
60#define expect_false(expr) expect ((expr) != 0, 0) 62#define expect_false(expr) expect ((expr) != 0, 0)
61#define expect_true(expr) expect ((expr) != 0, 1) 63#define expect_true(expr) expect ((expr) != 0, 1)
62 64
63#ifdef USE_ITHREADS 65#ifdef USE_ITHREADS
64# define JSON_SLOW 1 66# define JSON_SLOW 1
67# define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1))
65#else 68#else
66# define JSON_SLOW 0 69# define JSON_SLOW 0
70# define JSON_STASH json_stash
67#endif 71#endif
68 72
69static HV *json_stash, *json_boolean_stash; // JSON::XS:: 73static HV *json_stash, *json_boolean_stash; // JSON::XS::
70static SV *json_true, *json_false; 74static SV *json_true, *json_false;
71 75
308 int i, len = av_len (av); 312 int i, len = av_len (av);
309 313
310 if (enc->indent >= enc->maxdepth) 314 if (enc->indent >= enc->maxdepth)
311 croak ("data structure too deep (hit recursion limit)"); 315 croak ("data structure too deep (hit recursion limit)");
312 316
313 encode_ch (enc, '['); encode_nl (enc); 317 encode_ch (enc, '[');
314 ++enc->indent; 318
319 if (len >= 0)
320 {
321 encode_nl (enc); ++enc->indent;
315 322
316 for (i = 0; i <= len; ++i) 323 for (i = 0; i <= len; ++i)
317 { 324 {
318 SV **svp = av_fetch (av, i, 0); 325 SV **svp = av_fetch (av, i, 0);
319 326
320 encode_indent (enc); 327 encode_indent (enc);
321 328
322 if (svp) 329 if (svp)
323 encode_sv (enc, *svp); 330 encode_sv (enc, *svp);
324 else 331 else
325 encode_str (enc, "null", 4, 0); 332 encode_str (enc, "null", 4, 0);
326 333
327 if (i < len) 334 if (i < len)
328 encode_comma (enc); 335 encode_comma (enc);
329 } 336 }
330 337
338 encode_nl (enc); --enc->indent; encode_indent (enc);
339 }
340
331 encode_nl (enc); 341 encode_ch (enc, ']');
332
333 --enc->indent;
334 encode_indent (enc); encode_ch (enc, ']');
335} 342}
336 343
337static void 344static void
338encode_he (enc_t *enc, HE *he) 345encode_hk (enc_t *enc, HE *he)
339{ 346{
340 encode_ch (enc, '"'); 347 encode_ch (enc, '"');
341 348
342 if (HeKLEN (he) == HEf_SVKEY) 349 if (HeKLEN (he) == HEf_SVKEY)
343 { 350 {
356 encode_ch (enc, '"'); 363 encode_ch (enc, '"');
357 364
358 if (enc->json.flags & F_SPACE_BEFORE) encode_space (enc); 365 if (enc->json.flags & F_SPACE_BEFORE) encode_space (enc);
359 encode_ch (enc, ':'); 366 encode_ch (enc, ':');
360 if (enc->json.flags & F_SPACE_AFTER ) encode_space (enc); 367 if (enc->json.flags & F_SPACE_AFTER ) encode_space (enc);
361 encode_sv (enc, HeVAL (he));
362} 368}
363 369
364// compare hash entries, used when all keys are bytestrings 370// compare hash entries, used when all keys are bytestrings
365static int 371static int
366he_cmp_fast (const void *a_, const void *b_) 372he_cmp_fast (const void *a_, const void *b_)
371 HE *b = *(HE **)b_; 377 HE *b = *(HE **)b_;
372 378
373 STRLEN la = HeKLEN (a); 379 STRLEN la = HeKLEN (a);
374 STRLEN lb = HeKLEN (b); 380 STRLEN lb = HeKLEN (b);
375 381
376 if (!(cmp = memcmp (HeKEY (a), HeKEY (b), la < lb ? la : lb))) 382 if (!(cmp = memcmp (HeKEY (b), HeKEY (a), lb < la ? lb : la)))
377 cmp = la - lb; 383 cmp = lb - la;
378 384
379 return cmp; 385 return cmp;
380} 386}
381 387
382// compare hash entries, used when some keys are sv's or utf-x 388// compare hash entries, used when some keys are sv's or utf-x
383static int 389static int
384he_cmp_slow (const void *a, const void *b) 390he_cmp_slow (const void *a, const void *b)
385{ 391{
386 return sv_cmp (HeSVKEY_force (*(HE **)a), HeSVKEY_force (*(HE **)b)); 392 return sv_cmp (HeSVKEY_force (*(HE **)b), HeSVKEY_force (*(HE **)a));
387} 393}
388 394
389static void 395static void
390encode_hv (enc_t *enc, HV *hv) 396encode_hv (enc_t *enc, HV *hv)
391{ 397{
398 HE *he;
392 int count, i; 399 int count;
393 400
394 if (enc->indent >= enc->maxdepth) 401 if (enc->indent >= enc->maxdepth)
395 croak ("data structure too deep (hit recursion limit)"); 402 croak ("data structure too deep (hit recursion limit)");
396 403
397 encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; 404 encode_ch (enc, '{');
398 405
399 if ((count = hv_iterinit (hv)))
400 {
401 // for canonical output we have to sort by keys first 406 // for canonical output we have to sort by keys first
402 // actually, this is mostly due to the stupid so-called 407 // actually, this is mostly due to the stupid so-called
403 // security workaround added somewhere in 5.8.x. 408 // security workaround added somewhere in 5.8.x.
404 // that randomises hash orderings 409 // that randomises hash orderings
405 if (enc->json.flags & F_CANONICAL) 410 if (enc->json.flags & F_CANONICAL)
411 {
412 int count = hv_iterinit (hv);
413
414 if (SvMAGICAL (hv))
406 { 415 {
416 // need to count by iterating. could improve by dynamically building the vector below
417 // but I don't care for the speed of this special case.
418 // note also that we will run into undefined behaviour when the two iterations
419 // do not result in the same count, something I might care for in some later release.
420
421 count = 0;
422 while (hv_iternext (hv))
423 ++count;
424
425 hv_iterinit (hv);
426 }
427
428 if (count)
429 {
407 int fast = 1; 430 int i, fast = 1;
408 HE *he;
409#if defined(__BORLANDC__) || defined(_MSC_VER) 431#if defined(__BORLANDC__) || defined(_MSC_VER)
410 HE **hes = _alloca (count * sizeof (HE)); 432 HE **hes = _alloca (count * sizeof (HE));
411#else 433#else
412 HE *hes [count]; // if your compiler dies here, you need to enable C99 mode 434 HE *hes [count]; // if your compiler dies here, you need to enable C99 mode
413#endif 435#endif
440 462
441 FREETMPS; 463 FREETMPS;
442 LEAVE; 464 LEAVE;
443 } 465 }
444 466
445 for (i = 0; i < count; ++i) 467 encode_nl (enc); ++enc->indent;
468
469 while (count--)
446 { 470 {
447 encode_indent (enc); 471 encode_indent (enc);
472 he = hes [count];
448 encode_he (enc, hes [i]); 473 encode_hk (enc, he);
474 encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he));
449 475
450 if (i < count - 1) 476 if (count)
451 encode_comma (enc); 477 encode_comma (enc);
452 } 478 }
453 479
454 encode_nl (enc); 480 encode_nl (enc); --enc->indent; encode_indent (enc);
455 } 481 }
482 }
456 else 483 else
484 {
485 if (hv_iterinit (hv) || SvMAGICAL (hv))
486 if ((he = hv_iternext (hv)))
457 { 487 {
458 HE *he = hv_iternext (hv); 488 encode_nl (enc); ++enc->indent;
459 489
460 for (;;) 490 for (;;)
461 { 491 {
462 encode_indent (enc); 492 encode_indent (enc);
463 encode_he (enc, he); 493 encode_hk (enc, he);
494 encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he));
464 495
465 if (!(he = hv_iternext (hv))) 496 if (!(he = hv_iternext (hv)))
466 break; 497 break;
467 498
468 encode_comma (enc); 499 encode_comma (enc);
469 } 500 }
470 501
471 encode_nl (enc); 502 encode_nl (enc); --enc->indent; encode_indent (enc);
472 } 503 }
473 } 504 }
474 505
475 --enc->indent; encode_indent (enc); encode_ch (enc, '}'); 506 encode_ch (enc, '}');
476} 507}
477 508
478// encode objects, arrays and special \0=false and \1=true values. 509// encode objects, arrays and special \0=false and \1=true values.
479static void 510static void
480encode_rv (enc_t *enc, SV *sv) 511encode_rv (enc_t *enc, SV *sv)
680 U32 depth; // recursion depth 711 U32 depth; // recursion depth
681 U32 maxdepth; // recursion depth limit 712 U32 maxdepth; // recursion depth limit
682} dec_t; 713} dec_t;
683 714
684inline void 715inline void
716decode_comment (dec_t *dec)
717{
718 // only '#'-style comments allowed a.t.m.
719
720 while (*dec->cur && *dec->cur != 0x0a && *dec->cur != 0x0d)
721 ++dec->cur;
722}
723
724inline void
685decode_ws (dec_t *dec) 725decode_ws (dec_t *dec)
686{ 726{
687 for (;;) 727 for (;;)
688 { 728 {
689 char ch = *dec->cur; 729 char ch = *dec->cur;
690 730
691 if (ch > 0x20 731 if (ch > 0x20)
732 {
733 if (expect_false (ch == '#'))
734 {
735 if (dec->json.flags & F_RELAXED)
736 decode_comment (dec);
737 else
738 break;
739 }
740 else
741 break;
742 }
692 || (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09)) 743 else if (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09)
693 break; 744 break; // parse error, but let higher level handle it, gives better error messages
694 745
695 ++dec->cur; 746 ++dec->cur;
696 } 747 }
697} 748}
698 749
949 1000
950 if (!is_nv) 1001 if (!is_nv)
951 { 1002 {
952 int len = dec->cur - start; 1003 int len = dec->cur - start;
953 1004
954 // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so 1005 // special case the rather common 1..5-digit-int case
955 if (*start == '-') 1006 if (*start == '-')
956 switch (len) 1007 switch (len)
957 { 1008 {
958 case 2: return newSViv (-( start [1] - '0' * 1)); 1009 case 2: return newSViv (-( start [1] - '0' * 1));
959 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); 1010 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11));
960 case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); 1011 case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111));
961 case 5: return newSViv (-(start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); 1012 case 5: return newSViv (-( start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111));
1013 case 6: return newSViv (-(start [1] * 10000 + start [2] * 1000 + start [3] * 100 + start [4] * 10 + start [5] - '0' * 11111));
962 } 1014 }
963 else 1015 else
964 switch (len) 1016 switch (len)
965 { 1017 {
966 case 1: return newSViv ( start [0] - '0' * 1); 1018 case 1: return newSViv ( start [0] - '0' * 1);
967 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); 1019 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11);
968 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); 1020 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111);
969 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); 1021 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111);
1022 case 5: return newSViv ( start [0] * 10000 + start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 11111);
970 } 1023 }
971 1024
972 { 1025 {
973 UV uv; 1026 UV uv;
974 int numtype = grok_number (start, len, &uv); 1027 int numtype = grok_number (start, len, &uv);
1035 1088
1036 if (*dec->cur != ',') 1089 if (*dec->cur != ',')
1037 ERR (", or ] expected while parsing array"); 1090 ERR (", or ] expected while parsing array");
1038 1091
1039 ++dec->cur; 1092 ++dec->cur;
1093
1094 decode_ws (dec);
1095
1096 if (*dec->cur == ']' && dec->json.flags & F_RELAXED)
1097 {
1098 ++dec->cur;
1099 break;
1100 }
1040 } 1101 }
1041 1102
1042 DEC_DEC_DEPTH; 1103 DEC_DEC_DEPTH;
1043 return newRV_noinc ((SV *)av); 1104 return newRV_noinc ((SV *)av);
1044 1105
1060 if (*dec->cur == '}') 1121 if (*dec->cur == '}')
1061 ++dec->cur; 1122 ++dec->cur;
1062 else 1123 else
1063 for (;;) 1124 for (;;)
1064 { 1125 {
1065 decode_ws (dec); EXPECT_CH ('"'); 1126 EXPECT_CH ('"');
1066 1127
1067 // heuristic: assume that 1128 // heuristic: assume that
1068 // a) decode_str + hv_store_ent are abysmally slow. 1129 // a) decode_str + hv_store_ent are abysmally slow.
1069 // b) most hash keys are short, simple ascii text. 1130 // b) most hash keys are short, simple ascii text.
1070 // => try to "fast-match" such strings to avoid 1131 // => try to "fast-match" such strings to avoid
1084 if (!key) 1145 if (!key)
1085 goto fail; 1146 goto fail;
1086 1147
1087 decode_ws (dec); EXPECT_CH (':'); 1148 decode_ws (dec); EXPECT_CH (':');
1088 1149
1150 decode_ws (dec);
1089 value = decode_sv (dec); 1151 value = decode_sv (dec);
1090 if (!value) 1152 if (!value)
1091 { 1153 {
1092 SvREFCNT_dec (key); 1154 SvREFCNT_dec (key);
1093 goto fail; 1155 goto fail;
1105 int len = p - key; 1167 int len = p - key;
1106 dec->cur = p + 1; 1168 dec->cur = p + 1;
1107 1169
1108 decode_ws (dec); EXPECT_CH (':'); 1170 decode_ws (dec); EXPECT_CH (':');
1109 1171
1172 decode_ws (dec);
1110 value = decode_sv (dec); 1173 value = decode_sv (dec);
1111 if (!value) 1174 if (!value)
1112 goto fail; 1175 goto fail;
1113 1176
1114 hv_store (hv, key, len, value, 0); 1177 hv_store (hv, key, len, value, 0);
1130 1193
1131 if (*dec->cur != ',') 1194 if (*dec->cur != ',')
1132 ERR (", or } expected while parsing object/hash"); 1195 ERR (", or } expected while parsing object/hash");
1133 1196
1134 ++dec->cur; 1197 ++dec->cur;
1198
1199 decode_ws (dec);
1200
1201 if (*dec->cur == '}' && dec->json.flags & F_RELAXED)
1202 {
1203 ++dec->cur;
1204 break;
1205 }
1135 } 1206 }
1136 1207
1137 DEC_DEC_DEPTH; 1208 DEC_DEC_DEPTH;
1138 sv = newRV_noinc ((SV *)hv); 1209 sv = newRV_noinc ((SV *)hv);
1139 1210
1204} 1275}
1205 1276
1206static SV * 1277static SV *
1207decode_sv (dec_t *dec) 1278decode_sv (dec_t *dec)
1208{ 1279{
1209 decode_ws (dec);
1210
1211 // the beauty of JSON: you need exactly one character lookahead 1280 // the beauty of JSON: you need exactly one character lookahead
1212 // to parse anything. 1281 // to parse anything.
1213 switch (*dec->cur) 1282 switch (*dec->cur)
1214 { 1283 {
1215 case '"': ++dec->cur; return decode_str (dec); 1284 case '"': ++dec->cur; return decode_str (dec);
1223 1292
1224 case 't': 1293 case 't':
1225 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) 1294 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4))
1226 { 1295 {
1227 dec->cur += 4; 1296 dec->cur += 4;
1297#if JSON_SLOW
1298 json_true = get_sv ("JSON::XS::true", 1); SvREADONLY_on (json_true);
1299#endif
1228 return SvREFCNT_inc (json_true); 1300 return SvREFCNT_inc (json_true);
1229 } 1301 }
1230 else 1302 else
1231 ERR ("'true' expected"); 1303 ERR ("'true' expected");
1232 1304
1234 1306
1235 case 'f': 1307 case 'f':
1236 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) 1308 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5))
1237 { 1309 {
1238 dec->cur += 5; 1310 dec->cur += 5;
1311#if JSON_SLOW
1312 json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false);
1313#endif
1239 return SvREFCNT_inc (json_false); 1314 return SvREFCNT_inc (json_false);
1240 } 1315 }
1241 else 1316 else
1242 ERR ("'false' expected"); 1317 ERR ("'false' expected");
1243 1318
1293 1368
1294 if (dec.json.cb_object || dec.json.cb_sk_object) 1369 if (dec.json.cb_object || dec.json.cb_sk_object)
1295 dec.json.flags |= F_HOOK; 1370 dec.json.flags |= F_HOOK;
1296 1371
1297 *dec.end = 0; // this should basically be a nop, too, but make sure it's there 1372 *dec.end = 0; // this should basically be a nop, too, but make sure it's there
1373
1374 decode_ws (&dec);
1298 sv = decode_sv (&dec); 1375 sv = decode_sv (&dec);
1299 1376
1300 if (!(offset_return || !sv)) 1377 if (!(offset_return || !sv))
1301 { 1378 {
1302 // check for trailing garbage 1379 // check for trailing garbage
1378 json_boolean_stash = 0; 1455 json_boolean_stash = 0;
1379 1456
1380void new (char *klass) 1457void new (char *klass)
1381 PPCODE: 1458 PPCODE:
1382{ 1459{
1383 HV *stash = !JSON_SLOW || json_stash
1384 ? json_stash
1385 : gv_stashpv ("JSON::XS", 1);
1386 SV *pv = NEWSV (0, sizeof (JSON)); 1460 SV *pv = NEWSV (0, sizeof (JSON));
1387 SvPOK_only (pv); 1461 SvPOK_only (pv);
1388 Zero (SvPVX (pv), 1, JSON); 1462 Zero (SvPVX (pv), 1, JSON);
1389 ((JSON *)SvPVX (pv))->flags = F_DEFAULT; 1463 ((JSON *)SvPVX (pv))->flags = F_DEFAULT;
1390 XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), stash))); 1464 XPUSHs (sv_2mortal (sv_bless (
1465 newRV_noinc (pv),
1466 strEQ (klass, "JSON::XS") ? JSON_STASH : gv_stashpv (klass, 1)
1467 )));
1391} 1468}
1392 1469
1393void ascii (JSON *self, int enable = 1) 1470void ascii (JSON *self, int enable = 1)
1394 ALIAS: 1471 ALIAS:
1395 ascii = F_ASCII 1472 ascii = F_ASCII
1402 pretty = F_PRETTY 1479 pretty = F_PRETTY
1403 allow_nonref = F_ALLOW_NONREF 1480 allow_nonref = F_ALLOW_NONREF
1404 shrink = F_SHRINK 1481 shrink = F_SHRINK
1405 allow_blessed = F_ALLOW_BLESSED 1482 allow_blessed = F_ALLOW_BLESSED
1406 convert_blessed = F_CONV_BLESSED 1483 convert_blessed = F_CONV_BLESSED
1484 relaxed = F_RELAXED
1407 PPCODE: 1485 PPCODE:
1408{ 1486{
1409 if (enable) 1487 if (enable)
1410 self->flags |= ix; 1488 self->flags |= ix;
1411 else 1489 else
1412 self->flags &= ~ix; 1490 self->flags &= ~ix;
1413 1491
1414 XPUSHs (ST (0)); 1492 XPUSHs (ST (0));
1415} 1493}
1416 1494
1495void get_ascii (JSON *self)
1496 ALIAS:
1497 get_ascii = F_ASCII
1498 get_latin1 = F_LATIN1
1499 get_utf8 = F_UTF8
1500 get_indent = F_INDENT
1501 get_canonical = F_CANONICAL
1502 get_space_before = F_SPACE_BEFORE
1503 get_space_after = F_SPACE_AFTER
1504 get_allow_nonref = F_ALLOW_NONREF
1505 get_shrink = F_SHRINK
1506 get_allow_blessed = F_ALLOW_BLESSED
1507 get_convert_blessed = F_CONV_BLESSED
1508 get_relaxed = F_RELAXED
1509 PPCODE:
1510 XPUSHs (boolSV (self->flags & ix));
1511
1417void max_depth (JSON *self, UV max_depth = 0x80000000UL) 1512void max_depth (JSON *self, UV max_depth = 0x80000000UL)
1418 PPCODE: 1513 PPCODE:
1419{ 1514{
1420 UV log2 = 0; 1515 UV log2 = 0;
1421 1516
1427 self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); 1522 self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH);
1428 1523
1429 XPUSHs (ST (0)); 1524 XPUSHs (ST (0));
1430} 1525}
1431 1526
1527U32 get_max_depth (JSON *self)
1528 CODE:
1529 RETVAL = DEC_DEPTH (self->flags);
1530 OUTPUT:
1531 RETVAL
1532
1432void max_size (JSON *self, UV max_size = 0) 1533void max_size (JSON *self, UV max_size = 0)
1433 PPCODE: 1534 PPCODE:
1434{ 1535{
1435 UV log2 = 0; 1536 UV log2 = 0;
1436 1537
1442 1543
1443 self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE); 1544 self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE);
1444 1545
1445 XPUSHs (ST (0)); 1546 XPUSHs (ST (0));
1446} 1547}
1548
1549int get_max_size (JSON *self)
1550 CODE:
1551 RETVAL = DEC_SIZE (self->flags);
1552 OUTPUT:
1553 RETVAL
1447 1554
1448void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) 1555void filter_json_object (JSON *self, SV *cb = &PL_sv_undef)
1449 PPCODE: 1556 PPCODE:
1450{ 1557{
1451 SvREFCNT_dec (self->cb_object); 1558 SvREFCNT_dec (self->cb_object);
1498 SvREFCNT_dec (self->cb_sk_object); 1605 SvREFCNT_dec (self->cb_sk_object);
1499 SvREFCNT_dec (self->cb_object); 1606 SvREFCNT_dec (self->cb_object);
1500 1607
1501PROTOTYPES: ENABLE 1608PROTOTYPES: ENABLE
1502 1609
1503void to_json (SV *scalar) 1610void encode_json (SV *scalar)
1504 PPCODE: 1611 PPCODE:
1505{ 1612{
1506 JSON json = { F_DEFAULT | F_UTF8 }; 1613 JSON json = { F_DEFAULT | F_UTF8 };
1507 XPUSHs (encode_json (scalar, &json)); 1614 XPUSHs (encode_json (scalar, &json));
1508} 1615}
1509 1616
1510void from_json (SV *jsonstr) 1617void decode_json (SV *jsonstr)
1511 PPCODE: 1618 PPCODE:
1512{ 1619{
1513 JSON json = { F_DEFAULT | F_UTF8 }; 1620 JSON json = { F_DEFAULT | F_UTF8 };
1514 XPUSHs (decode_json (jsonstr, &json, 0)); 1621 XPUSHs (decode_json (jsonstr, &json, 0));
1515} 1622}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines