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.45 by root, Mon Jun 25 06:57:42 2007 UTC vs.
Revision 1.48 by root, Sun Jul 1 22:20:00 2007 UTC

59#define expect_true(expr) expect ((expr) != 0, 1) 59#define expect_true(expr) expect ((expr) != 0, 1)
60 60
61static HV *json_stash, *json_boolean_stash; // JSON::XS:: 61static HV *json_stash, *json_boolean_stash; // JSON::XS::
62static SV *json_true, *json_false; 62static SV *json_true, *json_false;
63 63
64typedef struct {
65 U32 flags;
66} JSON;
67
64///////////////////////////////////////////////////////////////////////////// 68/////////////////////////////////////////////////////////////////////////////
65// utility functions 69// utility functions
66 70
67static UV * 71inline void
68SvJSON (SV *sv)
69{
70 if (!(SvROK (sv) && SvOBJECT (SvRV (sv)) && SvSTASH (SvRV (sv)) == json_stash))
71 croak ("object is not of type JSON::XS");
72
73 return &SvUVX (SvRV (sv));
74}
75
76static void
77shrink (SV *sv) 72shrink (SV *sv)
78{ 73{
79 sv_utf8_downgrade (sv, 1); 74 sv_utf8_downgrade (sv, 1);
80 if (SvLEN (sv) > SvCUR (sv) + 1) 75 if (SvLEN (sv) > SvCUR (sv) + 1)
81 { 76 {
116typedef struct 111typedef struct
117{ 112{
118 char *cur; // SvPVX (sv) + current output position 113 char *cur; // SvPVX (sv) + current output position
119 char *end; // SvEND (sv) 114 char *end; // SvEND (sv)
120 SV *sv; // result scalar 115 SV *sv; // result scalar
121 U32 flags; // F_* 116 JSON json;
122 U32 indent; // indentation level 117 U32 indent; // indentation level
123 U32 maxdepth; // max. indentation/recursion level 118 U32 maxdepth; // max. indentation/recursion level
124} enc_t; 119} enc_t;
125 120
126inline void 121inline void
200 } 195 }
201 196
202 if (uch > 0x10FFFFUL) 197 if (uch > 0x10FFFFUL)
203 croak ("out of range codepoint (0x%lx) encountered, unrepresentable in JSON", (unsigned long)uch); 198 croak ("out of range codepoint (0x%lx) encountered, unrepresentable in JSON", (unsigned long)uch);
204 199
205 if (uch < 0x80 || enc->flags & F_ASCII || (enc->flags & F_LATIN1 && uch > 0xFF)) 200 if (uch < 0x80 || enc->json.flags & F_ASCII || (enc->json.flags & F_LATIN1 && uch > 0xFF))
206 { 201 {
207 if (uch > 0xFFFFUL) 202 if (uch > 0xFFFFUL)
208 { 203 {
209 need (enc, len += 11); 204 need (enc, len += 11);
210 sprintf (enc->cur, "\\u%04x\\u%04x", 205 sprintf (enc->cur, "\\u%04x\\u%04x",
224 *enc->cur++ = hexdigit [(uch >> 0) & 15]; 219 *enc->cur++ = hexdigit [(uch >> 0) & 15];
225 } 220 }
226 221
227 str += clen; 222 str += clen;
228 } 223 }
229 else if (enc->flags & F_LATIN1) 224 else if (enc->json.flags & F_LATIN1)
230 { 225 {
231 *enc->cur++ = uch; 226 *enc->cur++ = uch;
232 str += clen; 227 str += clen;
233 } 228 }
234 else if (is_utf8) 229 else if (is_utf8)
255} 250}
256 251
257inline void 252inline void
258encode_indent (enc_t *enc) 253encode_indent (enc_t *enc)
259{ 254{
260 if (enc->flags & F_INDENT) 255 if (enc->json.flags & F_INDENT)
261 { 256 {
262 int spaces = enc->indent * INDENT_STEP; 257 int spaces = enc->indent * INDENT_STEP;
263 258
264 need (enc, spaces); 259 need (enc, spaces);
265 memset (enc->cur, ' ', spaces); 260 memset (enc->cur, ' ', spaces);
275} 270}
276 271
277inline void 272inline void
278encode_nl (enc_t *enc) 273encode_nl (enc_t *enc)
279{ 274{
280 if (enc->flags & F_INDENT) 275 if (enc->json.flags & F_INDENT)
281 { 276 {
282 need (enc, 1); 277 need (enc, 1);
283 encode_ch (enc, '\n'); 278 encode_ch (enc, '\n');
284 } 279 }
285} 280}
287inline void 282inline void
288encode_comma (enc_t *enc) 283encode_comma (enc_t *enc)
289{ 284{
290 encode_ch (enc, ','); 285 encode_ch (enc, ',');
291 286
292 if (enc->flags & F_INDENT) 287 if (enc->json.flags & F_INDENT)
293 encode_nl (enc); 288 encode_nl (enc);
294 else if (enc->flags & F_SPACE_AFTER) 289 else if (enc->json.flags & F_SPACE_AFTER)
295 encode_space (enc); 290 encode_space (enc);
296} 291}
297 292
298static void encode_sv (enc_t *enc, SV *sv); 293static void encode_sv (enc_t *enc, SV *sv);
299 294
342 else 337 else
343 encode_str (enc, HeKEY (he), HeKLEN (he), HeKUTF8 (he)); 338 encode_str (enc, HeKEY (he), HeKLEN (he), HeKUTF8 (he));
344 339
345 encode_ch (enc, '"'); 340 encode_ch (enc, '"');
346 341
347 if (enc->flags & F_SPACE_BEFORE) encode_space (enc); 342 if (enc->json.flags & F_SPACE_BEFORE) encode_space (enc);
348 encode_ch (enc, ':'); 343 encode_ch (enc, ':');
349 if (enc->flags & F_SPACE_AFTER ) encode_space (enc); 344 if (enc->json.flags & F_SPACE_AFTER ) encode_space (enc);
350 encode_sv (enc, HeVAL (he)); 345 encode_sv (enc, HeVAL (he));
351} 346}
352 347
353// compare hash entries, used when all keys are bytestrings 348// compare hash entries, used when all keys are bytestrings
354static int 349static int
389 { 384 {
390 // for canonical output we have to sort by keys first 385 // for canonical output we have to sort by keys first
391 // actually, this is mostly due to the stupid so-called 386 // actually, this is mostly due to the stupid so-called
392 // security workaround added somewhere in 5.8.x. 387 // security workaround added somewhere in 5.8.x.
393 // that randomises hash orderings 388 // that randomises hash orderings
394 if (enc->flags & F_CANONICAL) 389 if (enc->json.flags & F_CANONICAL)
395 { 390 {
396 int fast = 1; 391 int fast = 1;
397 HE *he; 392 HE *he;
398#if defined(__BORLANDC__) || defined(_MSC_VER) 393#if defined(__BORLANDC__) || defined(_MSC_VER)
399 HE **hes = _alloca (count * sizeof (HE)); 394 HE **hes = _alloca (count * sizeof (HE));
488 if (0 && sv_derived_from (rv, "JSON::Literal")) 483 if (0 && sv_derived_from (rv, "JSON::Literal"))
489 { 484 {
490 // not yet 485 // not yet
491 } 486 }
492#endif 487#endif
493 if (enc->flags & F_CONV_BLESSED) 488 if (enc->json.flags & F_CONV_BLESSED)
494 { 489 {
495 // we re-bless the reference to get overload and other niceties right 490 // we re-bless the reference to get overload and other niceties right
496 GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 1); 491 GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 1);
497 492
498 if (to_json) 493 if (to_json)
512 encode_sv (enc, POPs); 507 encode_sv (enc, POPs);
513 508
514 FREETMPS; 509 FREETMPS;
515 LEAVE; 510 LEAVE;
516 } 511 }
517 else if (enc->flags & F_ALLOW_BLESSED) 512 else if (enc->json.flags & F_ALLOW_BLESSED)
518 encode_str (enc, "null", 4, 0); 513 encode_str (enc, "null", 4, 0);
519 else 514 else
520 croak ("encountered object '%s', but neither allow_blessed enabled nor TO_JSON method available on it", 515 croak ("encountered object '%s', but neither allow_blessed enabled nor TO_JSON method available on it",
521 SvPV_nolen (sv_2mortal (newRV_inc (sv)))); 516 SvPV_nolen (sv_2mortal (newRV_inc (sv))));
522 } 517 }
523 else if (enc->flags & F_ALLOW_BLESSED) 518 else if (enc->json.flags & F_ALLOW_BLESSED)
524 encode_str (enc, "null", 4, 0); 519 encode_str (enc, "null", 4, 0);
525 else 520 else
526 croak ("encountered object '%s', but neither allow_blessed nor convert_blessed settings are enabled", 521 croak ("encountered object '%s', but neither allow_blessed nor convert_blessed settings are enabled",
527 SvPV_nolen (sv_2mortal (newRV_inc (sv)))); 522 SvPV_nolen (sv_2mortal (newRV_inc (sv))));
528 } 523 }
614 croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this", 609 croak ("encountered perl type (%s,0x%x) that JSON cannot handle, you might want to report this",
615 SvPV_nolen (sv), SvFLAGS (sv)); 610 SvPV_nolen (sv), SvFLAGS (sv));
616} 611}
617 612
618static SV * 613static SV *
619encode_json (SV *scalar, U32 flags) 614encode_json (SV *scalar, JSON *json)
620{ 615{
621 enc_t enc; 616 enc_t enc;
622 617
623 if (!(flags & F_ALLOW_NONREF) && !SvROK (scalar)) 618 if (!(json->flags & F_ALLOW_NONREF) && !SvROK (scalar))
624 croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)"); 619 croak ("hash- or arrayref expected (not a simple scalar, use allow_nonref to allow this)");
625 620
626 enc.flags = flags; 621 enc.json = *json;
627 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE)); 622 enc.sv = sv_2mortal (NEWSV (0, INIT_SIZE));
628 enc.cur = SvPVX (enc.sv); 623 enc.cur = SvPVX (enc.sv);
629 enc.end = SvEND (enc.sv); 624 enc.end = SvEND (enc.sv);
630 enc.indent = 0; 625 enc.indent = 0;
631 enc.maxdepth = DEC_DEPTH (flags); 626 enc.maxdepth = DEC_DEPTH (enc.json.flags);
632 627
633 SvPOK_only (enc.sv); 628 SvPOK_only (enc.sv);
634 encode_sv (&enc, scalar); 629 encode_sv (&enc, scalar);
635 630
636 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv)); 631 SvCUR_set (enc.sv, enc.cur - SvPVX (enc.sv));
637 *SvEND (enc.sv) = 0; // many xs functions expect a trailing 0 for text strings 632 *SvEND (enc.sv) = 0; // many xs functions expect a trailing 0 for text strings
638 633
639 if (!(flags & (F_ASCII | F_LATIN1 | F_UTF8))) 634 if (!(enc.json.flags & (F_ASCII | F_LATIN1 | F_UTF8)))
640 SvUTF8_on (enc.sv); 635 SvUTF8_on (enc.sv);
641 636
642 if (enc.flags & F_SHRINK) 637 if (enc.json.flags & F_SHRINK)
643 shrink (enc.sv); 638 shrink (enc.sv);
644 639
645 return enc.sv; 640 return enc.sv;
646} 641}
647 642
652typedef struct 647typedef struct
653{ 648{
654 char *cur; // current parser pointer 649 char *cur; // current parser pointer
655 char *end; // end of input string 650 char *end; // end of input string
656 const char *err; // parse error, if != 0 651 const char *err; // parse error, if != 0
657 U32 flags; // F_* 652 JSON json;
658 U32 depth; // recursion depth 653 U32 depth; // recursion depth
659 U32 maxdepth; // recursion depth limit 654 U32 maxdepth; // recursion depth limit
660} dec_t; 655} dec_t;
661 656
662inline void 657inline void
1023 if (*dec->cur == '}') 1018 if (*dec->cur == '}')
1024 ++dec->cur; 1019 ++dec->cur;
1025 else 1020 else
1026 for (;;) 1021 for (;;)
1027 { 1022 {
1028 SV *key, *value;
1029
1030 decode_ws (dec); EXPECT_CH ('"'); 1023 decode_ws (dec); EXPECT_CH ('"');
1031 1024
1032 key = decode_str (dec); 1025 // heuristic: assume that
1033 if (!key) 1026 // a) decode_str + hv_store_ent are abysmally slow.
1034 goto fail; 1027 // b) most hash keys are short, simple ascii text.
1028 // => try to "fast-match" such strings to avoid
1029 // the overhead of decode_str + hv_store_ent.
1030 {
1031 SV *value;
1032 char *p = dec->cur;
1033 char *e = p + 24; // only try up to 24 bytes
1035 1034
1036 decode_ws (dec); EXPECT_CH (':'); 1035 for (;;)
1037
1038 value = decode_sv (dec);
1039 if (!value)
1040 { 1036 {
1037 // the >= 0x80 is true on most architectures
1038 if (p == e || *p < 0x20 || *p >= 0x80 || *p == '\\')
1039 {
1040 // slow path, back up and use decode_str
1041 SV *key = decode_str (dec);
1042 if (!key)
1043 goto fail;
1044
1045 decode_ws (dec); EXPECT_CH (':');
1046
1047 value = decode_sv (dec);
1048 if (!value)
1049 {
1050 SvREFCNT_dec (key);
1051 goto fail;
1052 }
1053
1054 hv_store_ent (hv, key, value, 0);
1041 SvREFCNT_dec (key); 1055 SvREFCNT_dec (key);
1056
1057 break;
1058 }
1059 else if (*p == '"')
1060 {
1061 // fast path, got a simple key
1062 char *key = dec->cur;
1063 int len = p - key;
1064 dec->cur = p + 1;
1065
1066 decode_ws (dec); EXPECT_CH (':');
1067
1068 value = decode_sv (dec);
1069 if (!value)
1042 goto fail; 1070 goto fail;
1071
1072 hv_store (hv, key, len, value, 0);
1073
1074 break;
1075 }
1076
1077 ++p;
1043 } 1078 }
1044 1079 }
1045 hv_store_ent (hv, key, value, 0);
1046 SvREFCNT_dec (key);
1047 1080
1048 decode_ws (dec); 1081 decode_ws (dec);
1049 1082
1050 if (*dec->cur == '}') 1083 if (*dec->cur == '}')
1051 { 1084 {
1127fail: 1160fail:
1128 return 0; 1161 return 0;
1129} 1162}
1130 1163
1131static SV * 1164static SV *
1132decode_json (SV *string, U32 flags, UV *offset_return) 1165decode_json (SV *string, JSON *json, UV *offset_return)
1133{ 1166{
1134 dec_t dec; 1167 dec_t dec;
1135 UV offset; 1168 UV offset;
1136 SV *sv; 1169 SV *sv;
1137 1170
1138 SvGETMAGIC (string); 1171 SvGETMAGIC (string);
1139 SvUPGRADE (string, SVt_PV); 1172 SvUPGRADE (string, SVt_PV);
1140 1173
1141 if (flags & F_MAXSIZE && SvCUR (string) > DEC_SIZE (flags)) 1174 if (json->flags & F_MAXSIZE && SvCUR (string) > DEC_SIZE (json->flags))
1142 croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu", 1175 croak ("attempted decode of JSON text of %lu bytes size, but max_size is set to %lu",
1143 (unsigned long)SvCUR (string), (unsigned long)DEC_SIZE (flags)); 1176 (unsigned long)SvCUR (string), (unsigned long)DEC_SIZE (json->flags));
1144 1177
1145 if (flags & F_UTF8) 1178 if (json->flags & F_UTF8)
1146 sv_utf8_downgrade (string, 0); 1179 sv_utf8_downgrade (string, 0);
1147 else 1180 else
1148 sv_utf8_upgrade (string); 1181 sv_utf8_upgrade (string);
1149 1182
1150 SvGROW (string, SvCUR (string) + 1); // should basically be a NOP 1183 SvGROW (string, SvCUR (string) + 1); // should basically be a NOP
1151 1184
1152 dec.flags = flags; 1185 dec.json = *json;
1153 dec.cur = SvPVX (string); 1186 dec.cur = SvPVX (string);
1154 dec.end = SvEND (string); 1187 dec.end = SvEND (string);
1155 dec.err = 0; 1188 dec.err = 0;
1156 dec.depth = 0; 1189 dec.depth = 0;
1157 dec.maxdepth = DEC_DEPTH (dec.flags); 1190 dec.maxdepth = DEC_DEPTH (dec.json.flags);
1158 1191
1159 *dec.end = 0; // this should basically be a nop, too, but make sure it's there 1192 *dec.end = 0; // this should basically be a nop, too, but make sure it's there
1160 sv = decode_sv (&dec); 1193 sv = decode_sv (&dec);
1161 1194
1162 if (!(offset_return || !sv)) 1195 if (!(offset_return || !sv))
1172 } 1205 }
1173 } 1206 }
1174 1207
1175 if (offset_return || !sv) 1208 if (offset_return || !sv)
1176 { 1209 {
1177 offset = dec.flags & F_UTF8 1210 offset = dec.json.flags & F_UTF8
1178 ? dec.cur - SvPVX (string) 1211 ? dec.cur - SvPVX (string)
1179 : utf8_distance (dec.cur, SvPVX (string)); 1212 : utf8_distance (dec.cur, SvPVX (string));
1180 1213
1181 if (offset_return) 1214 if (offset_return)
1182 *offset_return = offset; 1215 *offset_return = offset;
1201 dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)"); 1234 dec.cur != dec.end ? SvPV_nolen (uni) : "(end of string)");
1202 } 1235 }
1203 1236
1204 sv = sv_2mortal (sv); 1237 sv = sv_2mortal (sv);
1205 1238
1206 if (!(dec.flags & F_ALLOW_NONREF) && !SvROK (sv)) 1239 if (!(dec.json.flags & F_ALLOW_NONREF) && !SvROK (sv))
1207 croak ("JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)"); 1240 croak ("JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this)");
1208 1241
1209 return sv; 1242 return sv;
1210} 1243}
1211 1244
1232 json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); 1265 json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false);
1233} 1266}
1234 1267
1235PROTOTYPES: DISABLE 1268PROTOTYPES: DISABLE
1236 1269
1237SV *new (char *dummy) 1270void new (char *klass)
1238 CODE: 1271 PPCODE:
1239 RETVAL = sv_bless (newRV_noinc (newSVuv (F_DEFAULT)), json_stash); 1272{
1240 OUTPUT: 1273 SV *pv = NEWSV (0, sizeof (JSON));
1241 RETVAL 1274 SvPOK_only (pv);
1275 Zero (SvPVX (pv), 1, sizeof (JSON));
1276 ((JSON *)SvPVX (pv))->flags = F_DEFAULT;
1277 XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), json_stash)));
1278}
1242 1279
1243SV *ascii (SV *self, int enable = 1) 1280void ascii (JSON *self, int enable = 1)
1244 ALIAS: 1281 ALIAS:
1245 ascii = F_ASCII 1282 ascii = F_ASCII
1246 latin1 = F_LATIN1 1283 latin1 = F_LATIN1
1247 utf8 = F_UTF8 1284 utf8 = F_UTF8
1248 indent = F_INDENT 1285 indent = F_INDENT
1252 pretty = F_PRETTY 1289 pretty = F_PRETTY
1253 allow_nonref = F_ALLOW_NONREF 1290 allow_nonref = F_ALLOW_NONREF
1254 shrink = F_SHRINK 1291 shrink = F_SHRINK
1255 allow_blessed = F_ALLOW_BLESSED 1292 allow_blessed = F_ALLOW_BLESSED
1256 convert_blessed = F_CONV_BLESSED 1293 convert_blessed = F_CONV_BLESSED
1257 CODE: 1294 PPCODE:
1258{ 1295{
1259 UV *uv = SvJSON (self);
1260 if (enable) 1296 if (enable)
1261 *uv |= ix; 1297 self->flags |= ix;
1262 else 1298 else
1263 *uv &= ~ix; 1299 self->flags &= ~ix;
1264 1300
1265 RETVAL = newSVsv (self); 1301 XPUSHs (ST (0));
1266} 1302}
1267 OUTPUT:
1268 RETVAL
1269 1303
1270SV *max_depth (SV *self, UV max_depth = 0x80000000UL) 1304void max_depth (JSON *self, UV max_depth = 0x80000000UL)
1271 CODE: 1305 PPCODE:
1272{ 1306{
1273 UV *uv = SvJSON (self);
1274 UV log2 = 0; 1307 UV log2 = 0;
1275 1308
1276 if (max_depth > 0x80000000UL) max_depth = 0x80000000UL; 1309 if (max_depth > 0x80000000UL) max_depth = 0x80000000UL;
1277 1310
1278 while ((1UL << log2) < max_depth) 1311 while ((1UL << log2) < max_depth)
1279 ++log2; 1312 ++log2;
1280 1313
1281 *uv = *uv & ~F_MAXDEPTH | (log2 << S_MAXDEPTH); 1314 self->flags = self->flags & ~F_MAXDEPTH | (log2 << S_MAXDEPTH);
1282 1315
1283 RETVAL = newSVsv (self); 1316 XPUSHs (ST (0));
1284} 1317}
1285 OUTPUT:
1286 RETVAL
1287 1318
1288SV *max_size (SV *self, UV max_size = 0) 1319void max_size (JSON *self, UV max_size = 0)
1289 CODE: 1320 PPCODE:
1290{ 1321{
1291 UV *uv = SvJSON (self);
1292 UV log2 = 0; 1322 UV log2 = 0;
1293 1323
1294 if (max_size > 0x80000000UL) max_size = 0x80000000UL; 1324 if (max_size > 0x80000000UL) max_size = 0x80000000UL;
1295 if (max_size == 1) max_size = 2; 1325 if (max_size == 1) max_size = 2;
1296 1326
1297 while ((1UL << log2) < max_size) 1327 while ((1UL << log2) < max_size)
1298 ++log2; 1328 ++log2;
1299 1329
1300 *uv = *uv & ~F_MAXSIZE | (log2 << S_MAXSIZE); 1330 self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE);
1301 1331
1302 RETVAL = newSVsv (self); 1332 XPUSHs (ST (0));
1303} 1333}
1304 OUTPUT:
1305 RETVAL
1306 1334
1307void encode (SV *self, SV *scalar) 1335void encode (JSON *self, SV *scalar)
1308 PPCODE: 1336 PPCODE:
1309 XPUSHs (encode_json (scalar, *SvJSON (self))); 1337 XPUSHs (encode_json (scalar, self));
1310 1338
1311void decode (SV *self, SV *jsonstr) 1339void decode (JSON *self, SV *jsonstr)
1312 PPCODE: 1340 PPCODE:
1313 XPUSHs (decode_json (jsonstr, *SvJSON (self), 0)); 1341 XPUSHs (decode_json (jsonstr, self, 0));
1314 1342
1315void decode_prefix (SV *self, SV *jsonstr) 1343void decode_prefix (JSON *self, SV *jsonstr)
1316 PPCODE: 1344 PPCODE:
1317{ 1345{
1318 UV offset; 1346 UV offset;
1319 EXTEND (SP, 2); 1347 EXTEND (SP, 2);
1320 PUSHs (decode_json (jsonstr, *SvJSON (self), &offset)); 1348 PUSHs (decode_json (jsonstr, self, &offset));
1321 PUSHs (sv_2mortal (newSVuv (offset))); 1349 PUSHs (sv_2mortal (newSVuv (offset)));
1322} 1350}
1323 1351
1324PROTOTYPES: ENABLE 1352PROTOTYPES: ENABLE
1325 1353
1326void to_json (SV *scalar) 1354void to_json (SV *scalar)
1327 ALIAS:
1328 objToJson = 0
1329 PPCODE: 1355 PPCODE:
1356{
1357 JSON json = { F_DEFAULT | F_UTF8 };
1330 XPUSHs (encode_json (scalar, F_DEFAULT | F_UTF8)); 1358 XPUSHs (encode_json (scalar, &json));
1359}
1331 1360
1332void from_json (SV *jsonstr) 1361void from_json (SV *jsonstr)
1333 ALIAS:
1334 jsonToObj = 0
1335 PPCODE: 1362 PPCODE:
1363{
1364 JSON json = { F_DEFAULT | F_UTF8 };
1336 XPUSHs (decode_json (jsonstr, F_DEFAULT | F_UTF8, 0)); 1365 XPUSHs (decode_json (jsonstr, &json, 0));
1366}
1337 1367

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines