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.54 by root, Tue Jul 10 16:22:31 2007 UTC vs.
Revision 1.65 by root, Sat Oct 13 01:55:31 2007 UTC

1#include "EXTERN.h" 1#include "EXTERN.h"
2#include "perl.h" 2#include "perl.h"
3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#include "assert.h" 5#include <assert.h>
6#include "string.h" 6#include <string.h>
7#include "stdlib.h" 7#include <stdlib.h>
8#include "stdio.h" 8#include <stdio.h>
9#include <float.h>
9 10
10#if defined(__BORLANDC__) || defined(_MSC_VER) 11#if defined(__BORLANDC__) || defined(_MSC_VER)
11# define snprintf _snprintf // C compilers have this in stdio.h 12# define snprintf _snprintf // C compilers have this in stdio.h
12#endif 13#endif
13 14
26#define F_SPACE_AFTER 0x00000040UL 27#define F_SPACE_AFTER 0x00000040UL
27#define F_ALLOW_NONREF 0x00000100UL 28#define F_ALLOW_NONREF 0x00000100UL
28#define F_SHRINK 0x00000200UL 29#define F_SHRINK 0x00000200UL
29#define F_ALLOW_BLESSED 0x00000400UL 30#define F_ALLOW_BLESSED 0x00000400UL
30#define F_CONV_BLESSED 0x00000800UL 31#define F_CONV_BLESSED 0x00000800UL
32#define F_RELAXED 0x00001000UL
33
31#define F_MAXDEPTH 0xf8000000UL 34#define F_MAXDEPTH 0xf8000000UL
32#define S_MAXDEPTH 27 35#define S_MAXDEPTH 27
33#define F_MAXSIZE 0x01f00000UL 36#define F_MAXSIZE 0x01f00000UL
34#define S_MAXSIZE 20 37#define S_MAXSIZE 20
35#define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing 38#define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing
56# define inline static 59# define inline static
57#endif 60#endif
58 61
59#define expect_false(expr) expect ((expr) != 0, 0) 62#define expect_false(expr) expect ((expr) != 0, 0)
60#define expect_true(expr) expect ((expr) != 0, 1) 63#define expect_true(expr) expect ((expr) != 0, 1)
64
65#ifdef USE_ITHREADS
66# define JSON_SLOW 1
67# define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1))
68#else
69# define JSON_SLOW 0
70# define JSON_STASH json_stash
71#endif
61 72
62static HV *json_stash, *json_boolean_stash; // JSON::XS:: 73static HV *json_stash, *json_boolean_stash; // JSON::XS::
63static SV *json_true, *json_false; 74static SV *json_true, *json_false;
64 75
65typedef struct { 76typedef struct {
301 int i, len = av_len (av); 312 int i, len = av_len (av);
302 313
303 if (enc->indent >= enc->maxdepth) 314 if (enc->indent >= enc->maxdepth)
304 croak ("data structure too deep (hit recursion limit)"); 315 croak ("data structure too deep (hit recursion limit)");
305 316
306 encode_ch (enc, '['); encode_nl (enc); 317 encode_ch (enc, '[');
307 ++enc->indent; 318
319 if (len >= 0)
320 {
321 encode_nl (enc); ++enc->indent;
308 322
309 for (i = 0; i <= len; ++i) 323 for (i = 0; i <= len; ++i)
310 { 324 {
325 SV **svp = av_fetch (av, i, 0);
326
311 encode_indent (enc); 327 encode_indent (enc);
312 encode_sv (enc, *av_fetch (av, i, 0));
313 328
329 if (svp)
330 encode_sv (enc, *svp);
331 else
332 encode_str (enc, "null", 4, 0);
333
314 if (i < len) 334 if (i < len)
315 encode_comma (enc); 335 encode_comma (enc);
316 } 336 }
317 337
338 encode_nl (enc); --enc->indent; encode_indent (enc);
339 }
340
318 encode_nl (enc); 341 encode_ch (enc, ']');
319
320 --enc->indent;
321 encode_indent (enc); encode_ch (enc, ']');
322} 342}
323 343
324static void 344static void
325encode_he (enc_t *enc, HE *he) 345encode_hk (enc_t *enc, HE *he)
326{ 346{
327 encode_ch (enc, '"'); 347 encode_ch (enc, '"');
328 348
329 if (HeKLEN (he) == HEf_SVKEY) 349 if (HeKLEN (he) == HEf_SVKEY)
330 { 350 {
343 encode_ch (enc, '"'); 363 encode_ch (enc, '"');
344 364
345 if (enc->json.flags & F_SPACE_BEFORE) encode_space (enc); 365 if (enc->json.flags & F_SPACE_BEFORE) encode_space (enc);
346 encode_ch (enc, ':'); 366 encode_ch (enc, ':');
347 if (enc->json.flags & F_SPACE_AFTER ) encode_space (enc); 367 if (enc->json.flags & F_SPACE_AFTER ) encode_space (enc);
348 encode_sv (enc, HeVAL (he));
349} 368}
350 369
351// compare hash entries, used when all keys are bytestrings 370// compare hash entries, used when all keys are bytestrings
352static int 371static int
353he_cmp_fast (const void *a_, const void *b_) 372he_cmp_fast (const void *a_, const void *b_)
358 HE *b = *(HE **)b_; 377 HE *b = *(HE **)b_;
359 378
360 STRLEN la = HeKLEN (a); 379 STRLEN la = HeKLEN (a);
361 STRLEN lb = HeKLEN (b); 380 STRLEN lb = HeKLEN (b);
362 381
363 if (!(cmp = memcmp (HeKEY (a), HeKEY (b), la < lb ? la : lb))) 382 if (!(cmp = memcmp (HeKEY (b), HeKEY (a), lb < la ? lb : la)))
364 cmp = la - lb; 383 cmp = lb - la;
365 384
366 return cmp; 385 return cmp;
367} 386}
368 387
369// 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
370static int 389static int
371he_cmp_slow (const void *a, const void *b) 390he_cmp_slow (const void *a, const void *b)
372{ 391{
373 return sv_cmp (HeSVKEY_force (*(HE **)a), HeSVKEY_force (*(HE **)b)); 392 return sv_cmp (HeSVKEY_force (*(HE **)b), HeSVKEY_force (*(HE **)a));
374} 393}
375 394
376static void 395static void
377encode_hv (enc_t *enc, HV *hv) 396encode_hv (enc_t *enc, HV *hv)
378{ 397{
398 HE *he;
379 int count, i; 399 int count;
380 400
381 if (enc->indent >= enc->maxdepth) 401 if (enc->indent >= enc->maxdepth)
382 croak ("data structure too deep (hit recursion limit)"); 402 croak ("data structure too deep (hit recursion limit)");
383 403
384 encode_ch (enc, '{'); encode_nl (enc); ++enc->indent; 404 encode_ch (enc, '{');
385 405
386 if ((count = hv_iterinit (hv)))
387 {
388 // for canonical output we have to sort by keys first 406 // for canonical output we have to sort by keys first
389 // actually, this is mostly due to the stupid so-called 407 // actually, this is mostly due to the stupid so-called
390 // security workaround added somewhere in 5.8.x. 408 // security workaround added somewhere in 5.8.x.
391 // that randomises hash orderings 409 // that randomises hash orderings
392 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))
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);
393 { 426 }
427
428 if (count)
429 {
394 int fast = 1; 430 int i, fast = 1;
395 HE *he;
396#if defined(__BORLANDC__) || defined(_MSC_VER) 431#if defined(__BORLANDC__) || defined(_MSC_VER)
397 HE **hes = _alloca (count * sizeof (HE)); 432 HE **hes = _alloca (count * sizeof (HE));
398#else 433#else
399 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
400#endif 435#endif
427 462
428 FREETMPS; 463 FREETMPS;
429 LEAVE; 464 LEAVE;
430 } 465 }
431 466
432 for (i = 0; i < count; ++i) 467 encode_nl (enc); ++enc->indent;
468
469 while (count--)
433 { 470 {
434 encode_indent (enc); 471 encode_indent (enc);
472 he = hes [count];
435 encode_he (enc, hes [i]); 473 encode_hk (enc, he);
474 encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he));
436 475
437 if (i < count - 1) 476 if (count)
438 encode_comma (enc); 477 encode_comma (enc);
439 } 478 }
440 479
441 encode_nl (enc); 480 encode_nl (enc); --enc->indent; encode_indent (enc);
442 } 481 }
482 }
443 else 483 else
484 {
485 if (hv_iterinit (hv) || SvMAGICAL (hv))
486 if ((he = hv_iternext (hv)))
444 { 487 {
445 HE *he = hv_iternext (hv); 488 encode_nl (enc); ++enc->indent;
446 489
447 for (;;) 490 for (;;)
448 { 491 {
449 encode_indent (enc); 492 encode_indent (enc);
450 encode_he (enc, he); 493 encode_hk (enc, he);
494 encode_sv (enc, expect_false (SvMAGICAL (hv)) ? hv_iterval (hv, he) : HeVAL (he));
451 495
452 if (!(he = hv_iternext (hv))) 496 if (!(he = hv_iternext (hv)))
453 break; 497 break;
454 498
455 encode_comma (enc); 499 encode_comma (enc);
456 } 500 }
457 501
458 encode_nl (enc); 502 encode_nl (enc); --enc->indent; encode_indent (enc);
459 } 503 }
460 } 504 }
461 505
462 --enc->indent; encode_indent (enc); encode_ch (enc, '}'); 506 encode_ch (enc, '}');
463} 507}
464 508
465// encode objects, arrays and special \0=false and \1=true values. 509// encode objects, arrays and special \0=false and \1=true values.
466static void 510static void
467encode_rv (enc_t *enc, SV *sv) 511encode_rv (enc_t *enc, SV *sv)
471 SvGETMAGIC (sv); 515 SvGETMAGIC (sv);
472 svt = SvTYPE (sv); 516 svt = SvTYPE (sv);
473 517
474 if (expect_false (SvOBJECT (sv))) 518 if (expect_false (SvOBJECT (sv)))
475 { 519 {
520 HV *stash = !JSON_SLOW || json_boolean_stash
521 ? json_boolean_stash
522 : gv_stashpv ("JSON::XS::Boolean", 1);
523
476 if (SvSTASH (sv) == json_boolean_stash) 524 if (SvSTASH (sv) == stash)
477 { 525 {
478 if (SvIV (sv)) 526 if (SvIV (sv))
479 encode_str (enc, "true", 4, 0); 527 encode_str (enc, "true", 4, 0);
480 else 528 else
481 encode_str (enc, "false", 5, 0); 529 encode_str (enc, "false", 5, 0);
493 // we re-bless the reference to get overload and other niceties right 541 // we re-bless the reference to get overload and other niceties right
494 GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 0); 542 GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 0);
495 543
496 if (to_json) 544 if (to_json)
497 { 545 {
498 int count;
499 dSP; 546 dSP;
500 547
501 ENTER; SAVETMPS; PUSHMARK (SP); 548 ENTER; SAVETMPS; PUSHMARK (SP);
502 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); 549 XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv)));
503 550
664 U32 depth; // recursion depth 711 U32 depth; // recursion depth
665 U32 maxdepth; // recursion depth limit 712 U32 maxdepth; // recursion depth limit
666} dec_t; 713} dec_t;
667 714
668inline 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
669decode_ws (dec_t *dec) 725decode_ws (dec_t *dec)
670{ 726{
671 for (;;) 727 for (;;)
672 { 728 {
673 char ch = *dec->cur; 729 char ch = *dec->cur;
674 730
675 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 }
676 || (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09)) 743 else if (ch != 0x20 && ch != 0x0a && ch != 0x0d && ch != 0x09)
677 break; 744 break; // parse error, but let higher level handle it, gives better error messages
678 745
679 ++dec->cur; 746 ++dec->cur;
680 } 747 }
681} 748}
682 749
931 is_nv = 1; 998 is_nv = 1;
932 } 999 }
933 1000
934 if (!is_nv) 1001 if (!is_nv)
935 { 1002 {
1003 int len = dec->cur - start;
1004
936 // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so 1005 // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so
937 if (*start == '-') 1006 if (*start == '-')
938 switch (dec->cur - start) 1007 switch (len)
939 { 1008 {
940 case 2: return newSViv (-( start [1] - '0' * 1)); 1009 case 2: return newSViv (-( start [1] - '0' * 1));
941 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); 1010 case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11));
942 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));
943 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));
944 } 1013 }
945 else 1014 else
946 switch (dec->cur - start) 1015 switch (len)
947 { 1016 {
948 case 1: return newSViv ( start [0] - '0' * 1); 1017 case 1: return newSViv ( start [0] - '0' * 1);
949 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); 1018 case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11);
950 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); 1019 case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111);
951 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); 1020 case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111);
952 } 1021 }
953 1022
954 { 1023 {
955 UV uv; 1024 UV uv;
956 int numtype = grok_number (start, dec->cur - start, &uv); 1025 int numtype = grok_number (start, len, &uv);
957 if (numtype & IS_NUMBER_IN_UV) 1026 if (numtype & IS_NUMBER_IN_UV)
958 if (numtype & IS_NUMBER_NEG) 1027 if (numtype & IS_NUMBER_NEG)
959 { 1028 {
960 if (uv < (UV)IV_MIN) 1029 if (uv < (UV)IV_MIN)
961 return newSViv (-(IV)uv); 1030 return newSViv (-(IV)uv);
962 } 1031 }
963 else 1032 else
964 return newSVuv (uv); 1033 return newSVuv (uv);
965
966 // here would likely be the place for bigint support
967 } 1034 }
968 }
969 1035
970 // if we ever support bigint or bigfloat, this is the place for bigfloat 1036 len -= *start == '-' ? 1 : 0;
1037
1038 // does not fit into IV or UV, try NV
1039 if ((sizeof (NV) == sizeof (double) && DBL_DIG >= len)
1040 #if defined (LDBL_DIG)
1041 || (sizeof (NV) == sizeof (long double) && LDBL_DIG >= len)
1042 #endif
1043 )
1044 // fits into NV without loss of precision
1045 return newSVnv (Atof (start));
1046
1047 // everything else fails, convert it to a string
1048 return newSVpvn (start, dec->cur - start);
1049 }
1050
1051 // loss of precision here
971 return newSVnv (Atof (start)); 1052 return newSVnv (Atof (start));
972 1053
973fail: 1054fail:
974 return 0; 1055 return 0;
975} 1056}
1005 1086
1006 if (*dec->cur != ',') 1087 if (*dec->cur != ',')
1007 ERR (", or ] expected while parsing array"); 1088 ERR (", or ] expected while parsing array");
1008 1089
1009 ++dec->cur; 1090 ++dec->cur;
1091
1092 decode_ws (dec);
1093
1094 if (*dec->cur == ']' && dec->json.flags & F_RELAXED)
1095 {
1096 ++dec->cur;
1097 break;
1098 }
1010 } 1099 }
1011 1100
1012 DEC_DEC_DEPTH; 1101 DEC_DEC_DEPTH;
1013 return newRV_noinc ((SV *)av); 1102 return newRV_noinc ((SV *)av);
1014 1103
1030 if (*dec->cur == '}') 1119 if (*dec->cur == '}')
1031 ++dec->cur; 1120 ++dec->cur;
1032 else 1121 else
1033 for (;;) 1122 for (;;)
1034 { 1123 {
1035 decode_ws (dec); EXPECT_CH ('"'); 1124 EXPECT_CH ('"');
1036 1125
1037 // heuristic: assume that 1126 // heuristic: assume that
1038 // a) decode_str + hv_store_ent are abysmally slow. 1127 // a) decode_str + hv_store_ent are abysmally slow.
1039 // b) most hash keys are short, simple ascii text. 1128 // b) most hash keys are short, simple ascii text.
1040 // => try to "fast-match" such strings to avoid 1129 // => try to "fast-match" such strings to avoid
1054 if (!key) 1143 if (!key)
1055 goto fail; 1144 goto fail;
1056 1145
1057 decode_ws (dec); EXPECT_CH (':'); 1146 decode_ws (dec); EXPECT_CH (':');
1058 1147
1148 decode_ws (dec);
1059 value = decode_sv (dec); 1149 value = decode_sv (dec);
1060 if (!value) 1150 if (!value)
1061 { 1151 {
1062 SvREFCNT_dec (key); 1152 SvREFCNT_dec (key);
1063 goto fail; 1153 goto fail;
1075 int len = p - key; 1165 int len = p - key;
1076 dec->cur = p + 1; 1166 dec->cur = p + 1;
1077 1167
1078 decode_ws (dec); EXPECT_CH (':'); 1168 decode_ws (dec); EXPECT_CH (':');
1079 1169
1170 decode_ws (dec);
1080 value = decode_sv (dec); 1171 value = decode_sv (dec);
1081 if (!value) 1172 if (!value)
1082 goto fail; 1173 goto fail;
1083 1174
1084 hv_store (hv, key, len, value, 0); 1175 hv_store (hv, key, len, value, 0);
1100 1191
1101 if (*dec->cur != ',') 1192 if (*dec->cur != ',')
1102 ERR (", or } expected while parsing object/hash"); 1193 ERR (", or } expected while parsing object/hash");
1103 1194
1104 ++dec->cur; 1195 ++dec->cur;
1196
1197 decode_ws (dec);
1198
1199 if (*dec->cur == '}' && dec->json.flags & F_RELAXED)
1200 {
1201 ++dec->cur;
1202 break;
1203 }
1105 } 1204 }
1106 1205
1107 DEC_DEC_DEPTH; 1206 DEC_DEC_DEPTH;
1108 sv = newRV_noinc ((SV *)hv); 1207 sv = newRV_noinc ((SV *)hv);
1109 1208
1174} 1273}
1175 1274
1176static SV * 1275static SV *
1177decode_sv (dec_t *dec) 1276decode_sv (dec_t *dec)
1178{ 1277{
1179 decode_ws (dec);
1180
1181 // the beauty of JSON: you need exactly one character lookahead 1278 // the beauty of JSON: you need exactly one character lookahead
1182 // to parse anything. 1279 // to parse anything.
1183 switch (*dec->cur) 1280 switch (*dec->cur)
1184 { 1281 {
1185 case '"': ++dec->cur; return decode_str (dec); 1282 case '"': ++dec->cur; return decode_str (dec);
1193 1290
1194 case 't': 1291 case 't':
1195 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) 1292 if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4))
1196 { 1293 {
1197 dec->cur += 4; 1294 dec->cur += 4;
1295#if JSON_SLOW
1296 json_true = get_sv ("JSON::XS::true", 1); SvREADONLY_on (json_true);
1297#endif
1198 return SvREFCNT_inc (json_true); 1298 return SvREFCNT_inc (json_true);
1199 } 1299 }
1200 else 1300 else
1201 ERR ("'true' expected"); 1301 ERR ("'true' expected");
1202 1302
1204 1304
1205 case 'f': 1305 case 'f':
1206 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) 1306 if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5))
1207 { 1307 {
1208 dec->cur += 5; 1308 dec->cur += 5;
1309#if JSON_SLOW
1310 json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false);
1311#endif
1209 return SvREFCNT_inc (json_false); 1312 return SvREFCNT_inc (json_false);
1210 } 1313 }
1211 else 1314 else
1212 ERR ("'false' expected"); 1315 ERR ("'false' expected");
1213 1316
1263 1366
1264 if (dec.json.cb_object || dec.json.cb_sk_object) 1367 if (dec.json.cb_object || dec.json.cb_sk_object)
1265 dec.json.flags |= F_HOOK; 1368 dec.json.flags |= F_HOOK;
1266 1369
1267 *dec.end = 0; // this should basically be a nop, too, but make sure it's there 1370 *dec.end = 0; // this should basically be a nop, too, but make sure it's there
1371
1372 decode_ws (&dec);
1268 sv = decode_sv (&dec); 1373 sv = decode_sv (&dec);
1269 1374
1270 if (!(offset_return || !sv)) 1375 if (!(offset_return || !sv))
1271 { 1376 {
1272 // check for trailing garbage 1377 // check for trailing garbage
1340 json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); 1445 json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false);
1341} 1446}
1342 1447
1343PROTOTYPES: DISABLE 1448PROTOTYPES: DISABLE
1344 1449
1450void CLONE (...)
1451 CODE:
1452 json_stash = 0;
1453 json_boolean_stash = 0;
1454
1345void new (char *klass) 1455void new (char *klass)
1346 PPCODE: 1456 PPCODE:
1347{ 1457{
1348 SV *pv = NEWSV (0, sizeof (JSON)); 1458 SV *pv = NEWSV (0, sizeof (JSON));
1349 SvPOK_only (pv); 1459 SvPOK_only (pv);
1350 Zero (SvPVX (pv), 1, JSON); 1460 Zero (SvPVX (pv), 1, JSON);
1351 ((JSON *)SvPVX (pv))->flags = F_DEFAULT; 1461 ((JSON *)SvPVX (pv))->flags = F_DEFAULT;
1352 XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), json_stash))); 1462 XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), JSON_STASH)));
1353} 1463}
1354 1464
1355void ascii (JSON *self, int enable = 1) 1465void ascii (JSON *self, int enable = 1)
1356 ALIAS: 1466 ALIAS:
1357 ascii = F_ASCII 1467 ascii = F_ASCII
1364 pretty = F_PRETTY 1474 pretty = F_PRETTY
1365 allow_nonref = F_ALLOW_NONREF 1475 allow_nonref = F_ALLOW_NONREF
1366 shrink = F_SHRINK 1476 shrink = F_SHRINK
1367 allow_blessed = F_ALLOW_BLESSED 1477 allow_blessed = F_ALLOW_BLESSED
1368 convert_blessed = F_CONV_BLESSED 1478 convert_blessed = F_CONV_BLESSED
1479 relaxed = F_RELAXED
1369 PPCODE: 1480 PPCODE:
1370{ 1481{
1371 if (enable) 1482 if (enable)
1372 self->flags |= ix; 1483 self->flags |= ix;
1373 else 1484 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines