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 | |
… | |
… | |
25 | #define F_SPACE_BEFORE 0x00000020UL |
26 | #define F_SPACE_BEFORE 0x00000020UL |
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 // NYI |
31 | #define F_CONV_BLESSED 0x00000800UL |
31 | #define F_MAXDEPTH 0xf8000000UL |
32 | #define F_MAXDEPTH 0xf8000000UL |
32 | #define S_MAXDEPTH 27 |
33 | #define S_MAXDEPTH 27 |
33 | #define F_MAXSIZE 0x01f00000UL |
34 | #define F_MAXSIZE 0x01f00000UL |
34 | #define S_MAXSIZE 20 |
35 | #define S_MAXSIZE 20 |
|
|
36 | #define F_HOOK 0x00080000UL // some hooks exist, so slow-path processing |
35 | |
37 | |
36 | #define DEC_DEPTH(flags) (1UL << ((flags & F_MAXDEPTH) >> S_MAXDEPTH)) |
38 | #define DEC_DEPTH(flags) (1UL << ((flags & F_MAXDEPTH) >> S_MAXDEPTH)) |
37 | #define DEC_SIZE(flags) (1UL << ((flags & F_MAXSIZE ) >> S_MAXSIZE )) |
39 | #define DEC_SIZE(flags) (1UL << ((flags & F_MAXSIZE ) >> S_MAXSIZE )) |
38 | |
40 | |
39 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
41 | #define F_PRETTY F_INDENT | F_SPACE_BEFORE | F_SPACE_AFTER |
… | |
… | |
56 | #endif |
58 | #endif |
57 | |
59 | |
58 | #define expect_false(expr) expect ((expr) != 0, 0) |
60 | #define expect_false(expr) expect ((expr) != 0, 0) |
59 | #define expect_true(expr) expect ((expr) != 0, 1) |
61 | #define expect_true(expr) expect ((expr) != 0, 1) |
60 | |
62 | |
|
|
63 | #ifdef USE_ITHREADS |
|
|
64 | # define JSON_SLOW 1 |
|
|
65 | #else |
|
|
66 | # define JSON_SLOW 0 |
|
|
67 | #endif |
|
|
68 | |
61 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
69 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
62 | static SV *json_true, *json_false; |
70 | static SV *json_true, *json_false; |
63 | |
71 | |
64 | typedef struct { |
72 | typedef struct { |
65 | U32 flags; |
73 | U32 flags; |
|
|
74 | SV *cb_object; |
|
|
75 | HV *cb_sk_object; |
66 | } JSON; |
76 | } JSON; |
67 | |
77 | |
68 | ///////////////////////////////////////////////////////////////////////////// |
78 | ///////////////////////////////////////////////////////////////////////////// |
69 | // utility functions |
79 | // utility functions |
70 | |
80 | |
… | |
… | |
303 | encode_ch (enc, '['); encode_nl (enc); |
313 | encode_ch (enc, '['); encode_nl (enc); |
304 | ++enc->indent; |
314 | ++enc->indent; |
305 | |
315 | |
306 | for (i = 0; i <= len; ++i) |
316 | for (i = 0; i <= len; ++i) |
307 | { |
317 | { |
|
|
318 | SV **svp = av_fetch (av, i, 0); |
|
|
319 | |
308 | encode_indent (enc); |
320 | encode_indent (enc); |
309 | encode_sv (enc, *av_fetch (av, i, 0)); |
321 | |
|
|
322 | if (svp) |
|
|
323 | encode_sv (enc, *svp); |
|
|
324 | else |
|
|
325 | encode_str (enc, "null", 4, 0); |
310 | |
326 | |
311 | if (i < len) |
327 | if (i < len) |
312 | encode_comma (enc); |
328 | encode_comma (enc); |
313 | } |
329 | } |
314 | |
330 | |
… | |
… | |
468 | SvGETMAGIC (sv); |
484 | SvGETMAGIC (sv); |
469 | svt = SvTYPE (sv); |
485 | svt = SvTYPE (sv); |
470 | |
486 | |
471 | if (expect_false (SvOBJECT (sv))) |
487 | if (expect_false (SvOBJECT (sv))) |
472 | { |
488 | { |
|
|
489 | HV *stash = !JSON_SLOW || json_boolean_stash |
|
|
490 | ? json_boolean_stash |
|
|
491 | : gv_stashpv ("JSON::XS::Boolean", 1); |
|
|
492 | |
473 | if (SvSTASH (sv) == json_boolean_stash) |
493 | if (SvSTASH (sv) == stash) |
474 | { |
494 | { |
475 | if (SvIV (sv) == 0) |
495 | if (SvIV (sv)) |
|
|
496 | encode_str (enc, "true", 4, 0); |
|
|
497 | else |
476 | encode_str (enc, "false", 5, 0); |
498 | encode_str (enc, "false", 5, 0); |
477 | else |
|
|
478 | encode_str (enc, "true", 4, 0); |
|
|
479 | } |
499 | } |
480 | else |
500 | else |
481 | { |
501 | { |
482 | #if 0 |
502 | #if 0 |
483 | if (0 && sv_derived_from (rv, "JSON::Literal")) |
503 | if (0 && sv_derived_from (rv, "JSON::Literal")) |
… | |
… | |
486 | } |
506 | } |
487 | #endif |
507 | #endif |
488 | if (enc->json.flags & F_CONV_BLESSED) |
508 | if (enc->json.flags & F_CONV_BLESSED) |
489 | { |
509 | { |
490 | // we re-bless the reference to get overload and other niceties right |
510 | // we re-bless the reference to get overload and other niceties right |
491 | GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 1); |
511 | GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 0); |
492 | |
512 | |
493 | if (to_json) |
513 | if (to_json) |
494 | { |
514 | { |
495 | dSP; |
515 | dSP; |
496 | ENTER; |
516 | |
497 | SAVETMPS; |
|
|
498 | PUSHMARK (SP); |
517 | ENTER; SAVETMPS; PUSHMARK (SP); |
499 | XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); |
518 | XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); |
500 | |
519 | |
501 | // calling with G_SCALAR ensures that we always get a 1 reutrn value |
520 | // calling with G_SCALAR ensures that we always get a 1 return value |
502 | // check anyways. |
|
|
503 | PUTBACK; |
521 | PUTBACK; |
504 | assert (1 == call_sv ((SV *)GvCV (to_json), G_SCALAR)); |
522 | call_sv ((SV *)GvCV (to_json), G_SCALAR); |
505 | SPAGAIN; |
523 | SPAGAIN; |
506 | |
524 | |
|
|
525 | // catch this surprisingly common error |
|
|
526 | if (SvROK (TOPs) && SvRV (TOPs) == sv) |
|
|
527 | croak ("%s::TO_JSON method returned same object as was passed instead of a new one", HvNAME (SvSTASH (sv))); |
|
|
528 | |
|
|
529 | sv = POPs; |
|
|
530 | PUTBACK; |
|
|
531 | |
507 | encode_sv (enc, POPs); |
532 | encode_sv (enc, sv); |
508 | |
533 | |
509 | FREETMPS; |
534 | FREETMPS; LEAVE; |
510 | LEAVE; |
|
|
511 | } |
535 | } |
512 | else if (enc->json.flags & F_ALLOW_BLESSED) |
536 | else if (enc->json.flags & F_ALLOW_BLESSED) |
513 | encode_str (enc, "null", 4, 0); |
537 | encode_str (enc, "null", 4, 0); |
514 | else |
538 | else |
515 | croak ("encountered object '%s', but neither allow_blessed enabled nor TO_JSON method available on it", |
539 | croak ("encountered object '%s', but neither allow_blessed enabled nor TO_JSON method available on it", |
… | |
… | |
526 | encode_hv (enc, (HV *)sv); |
550 | encode_hv (enc, (HV *)sv); |
527 | else if (svt == SVt_PVAV) |
551 | else if (svt == SVt_PVAV) |
528 | encode_av (enc, (AV *)sv); |
552 | encode_av (enc, (AV *)sv); |
529 | else if (svt < SVt_PVAV) |
553 | else if (svt < SVt_PVAV) |
530 | { |
554 | { |
531 | if (SvNIOK (sv) && SvIV (sv) == 0) |
555 | STRLEN len = 0; |
|
|
556 | char *pv = svt ? SvPV (sv, len) : 0; |
|
|
557 | |
|
|
558 | if (len == 1 && *pv == '1') |
|
|
559 | encode_str (enc, "true", 4, 0); |
|
|
560 | else if (len == 1 && *pv == '0') |
532 | encode_str (enc, "false", 5, 0); |
561 | encode_str (enc, "false", 5, 0); |
533 | else if (SvNIOK (sv) && SvIV (sv) == 1) |
|
|
534 | encode_str (enc, "true", 4, 0); |
|
|
535 | else |
562 | else |
536 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
563 | croak ("cannot encode reference to scalar '%s' unless the scalar is 0 or 1", |
537 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
564 | SvPV_nolen (sv_2mortal (newRV_inc (sv)))); |
538 | } |
565 | } |
539 | else |
566 | else |
… | |
… | |
920 | is_nv = 1; |
947 | is_nv = 1; |
921 | } |
948 | } |
922 | |
949 | |
923 | if (!is_nv) |
950 | if (!is_nv) |
924 | { |
951 | { |
|
|
952 | int len = dec->cur - start; |
|
|
953 | |
925 | // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so |
954 | // special case the rather common 1..4-digit-int case, assumes 32 bit ints or so |
926 | if (*start == '-') |
955 | if (*start == '-') |
927 | switch (dec->cur - start) |
956 | switch (len) |
928 | { |
957 | { |
929 | case 2: return newSViv (-( start [1] - '0' * 1)); |
958 | case 2: return newSViv (-( start [1] - '0' * 1)); |
930 | case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); |
959 | case 3: return newSViv (-( start [1] * 10 + start [2] - '0' * 11)); |
931 | case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); |
960 | case 4: return newSViv (-( start [1] * 100 + start [2] * 10 + start [3] - '0' * 111)); |
932 | case 5: return newSViv (-(start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); |
961 | case 5: return newSViv (-(start [1] * 1000 + start [2] * 100 + start [3] * 10 + start [4] - '0' * 1111)); |
933 | } |
962 | } |
934 | else |
963 | else |
935 | switch (dec->cur - start) |
964 | switch (len) |
936 | { |
965 | { |
937 | case 1: return newSViv ( start [0] - '0' * 1); |
966 | case 1: return newSViv ( start [0] - '0' * 1); |
938 | case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); |
967 | case 2: return newSViv ( start [0] * 10 + start [1] - '0' * 11); |
939 | case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); |
968 | case 3: return newSViv ( start [0] * 100 + start [1] * 10 + start [2] - '0' * 111); |
940 | case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); |
969 | case 4: return newSViv ( start [0] * 1000 + start [1] * 100 + start [2] * 10 + start [3] - '0' * 1111); |
941 | } |
970 | } |
942 | |
971 | |
943 | { |
972 | { |
944 | UV uv; |
973 | UV uv; |
945 | int numtype = grok_number (start, dec->cur - start, &uv); |
974 | int numtype = grok_number (start, len, &uv); |
946 | if (numtype & IS_NUMBER_IN_UV) |
975 | if (numtype & IS_NUMBER_IN_UV) |
947 | if (numtype & IS_NUMBER_NEG) |
976 | if (numtype & IS_NUMBER_NEG) |
948 | { |
977 | { |
949 | if (uv < (UV)IV_MIN) |
978 | if (uv < (UV)IV_MIN) |
950 | return newSViv (-(IV)uv); |
979 | return newSViv (-(IV)uv); |
951 | } |
980 | } |
952 | else |
981 | else |
953 | return newSVuv (uv); |
982 | return newSVuv (uv); |
954 | |
|
|
955 | // here would likely be the place for bigint support |
|
|
956 | } |
983 | } |
957 | } |
|
|
958 | |
984 | |
959 | // if we ever support bigint or bigfloat, this is the place for bigfloat |
985 | len -= *start == '-' ? 1 : 0; |
|
|
986 | |
|
|
987 | // does not fit into IV or UV, try NV |
|
|
988 | if ((sizeof (NV) == sizeof (double) && DBL_DIG >= len) |
|
|
989 | #if defined (LDBL_DIG) |
|
|
990 | || (sizeof (NV) == sizeof (long double) && LDBL_DIG >= len) |
|
|
991 | #endif |
|
|
992 | ) |
|
|
993 | // fits into NV without loss of precision |
|
|
994 | return newSVnv (Atof (start)); |
|
|
995 | |
|
|
996 | // everything else fails, convert it to a string |
|
|
997 | return newSVpvn (start, dec->cur - start); |
|
|
998 | } |
|
|
999 | |
|
|
1000 | // loss of precision here |
960 | return newSVnv (Atof (start)); |
1001 | return newSVnv (Atof (start)); |
961 | |
1002 | |
962 | fail: |
1003 | fail: |
963 | return 0; |
1004 | return 0; |
964 | } |
1005 | } |
… | |
… | |
1008 | } |
1049 | } |
1009 | |
1050 | |
1010 | static SV * |
1051 | static SV * |
1011 | decode_hv (dec_t *dec) |
1052 | decode_hv (dec_t *dec) |
1012 | { |
1053 | { |
|
|
1054 | SV *sv; |
1013 | HV *hv = newHV (); |
1055 | HV *hv = newHV (); |
1014 | |
1056 | |
1015 | DEC_INC_DEPTH; |
1057 | DEC_INC_DEPTH; |
1016 | decode_ws (dec); |
1058 | decode_ws (dec); |
1017 | |
1059 | |
… | |
… | |
1091 | |
1133 | |
1092 | ++dec->cur; |
1134 | ++dec->cur; |
1093 | } |
1135 | } |
1094 | |
1136 | |
1095 | DEC_DEC_DEPTH; |
1137 | DEC_DEC_DEPTH; |
1096 | return newRV_noinc ((SV *)hv); |
1138 | sv = newRV_noinc ((SV *)hv); |
|
|
1139 | |
|
|
1140 | // check filter callbacks |
|
|
1141 | if (dec->json.flags & F_HOOK) |
|
|
1142 | { |
|
|
1143 | if (dec->json.cb_sk_object && HvKEYS (hv) == 1) |
|
|
1144 | { |
|
|
1145 | HE *cb, *he; |
|
|
1146 | |
|
|
1147 | hv_iterinit (hv); |
|
|
1148 | he = hv_iternext (hv); |
|
|
1149 | hv_iterinit (hv); |
|
|
1150 | |
|
|
1151 | // the next line creates a mortal sv each time its called. |
|
|
1152 | // might want to optimise this for common cases. |
|
|
1153 | cb = hv_fetch_ent (dec->json.cb_sk_object, hv_iterkeysv (he), 0, 0); |
|
|
1154 | |
|
|
1155 | if (cb) |
|
|
1156 | { |
|
|
1157 | dSP; |
|
|
1158 | int count; |
|
|
1159 | |
|
|
1160 | ENTER; SAVETMPS; PUSHMARK (SP); |
|
|
1161 | XPUSHs (HeVAL (he)); |
|
|
1162 | |
|
|
1163 | PUTBACK; count = call_sv (HeVAL (cb), G_ARRAY); SPAGAIN; |
|
|
1164 | |
|
|
1165 | if (count == 1) |
|
|
1166 | { |
|
|
1167 | sv = newSVsv (POPs); |
|
|
1168 | FREETMPS; LEAVE; |
|
|
1169 | return sv; |
|
|
1170 | } |
|
|
1171 | |
|
|
1172 | FREETMPS; LEAVE; |
|
|
1173 | } |
|
|
1174 | } |
|
|
1175 | |
|
|
1176 | if (dec->json.cb_object) |
|
|
1177 | { |
|
|
1178 | dSP; |
|
|
1179 | int count; |
|
|
1180 | |
|
|
1181 | ENTER; SAVETMPS; PUSHMARK (SP); |
|
|
1182 | XPUSHs (sv_2mortal (sv)); |
|
|
1183 | |
|
|
1184 | PUTBACK; count = call_sv (dec->json.cb_object, G_ARRAY); SPAGAIN; |
|
|
1185 | |
|
|
1186 | if (count == 1) |
|
|
1187 | { |
|
|
1188 | sv = newSVsv (POPs); |
|
|
1189 | FREETMPS; LEAVE; |
|
|
1190 | return sv; |
|
|
1191 | } |
|
|
1192 | |
|
|
1193 | SvREFCNT_inc (sv); |
|
|
1194 | FREETMPS; LEAVE; |
|
|
1195 | } |
|
|
1196 | } |
|
|
1197 | |
|
|
1198 | return sv; |
1097 | |
1199 | |
1098 | fail: |
1200 | fail: |
1099 | SvREFCNT_dec (hv); |
1201 | SvREFCNT_dec (hv); |
1100 | DEC_DEC_DEPTH; |
1202 | DEC_DEC_DEPTH; |
1101 | return 0; |
1203 | return 0; |
… | |
… | |
1187 | dec.end = SvEND (string); |
1289 | dec.end = SvEND (string); |
1188 | dec.err = 0; |
1290 | dec.err = 0; |
1189 | dec.depth = 0; |
1291 | dec.depth = 0; |
1190 | dec.maxdepth = DEC_DEPTH (dec.json.flags); |
1292 | dec.maxdepth = DEC_DEPTH (dec.json.flags); |
1191 | |
1293 | |
|
|
1294 | if (dec.json.cb_object || dec.json.cb_sk_object) |
|
|
1295 | dec.json.flags |= F_HOOK; |
|
|
1296 | |
1192 | *dec.end = 0; // this should basically be a nop, too, but make sure it's there |
1297 | *dec.end = 0; // this should basically be a nop, too, but make sure it's there |
1193 | sv = decode_sv (&dec); |
1298 | sv = decode_sv (&dec); |
1194 | |
1299 | |
1195 | if (!(offset_return || !sv)) |
1300 | if (!(offset_return || !sv)) |
1196 | { |
1301 | { |
… | |
… | |
1265 | json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); |
1370 | json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); |
1266 | } |
1371 | } |
1267 | |
1372 | |
1268 | PROTOTYPES: DISABLE |
1373 | PROTOTYPES: DISABLE |
1269 | |
1374 | |
|
|
1375 | void CLONE (...) |
|
|
1376 | CODE: |
|
|
1377 | json_stash = 0; |
|
|
1378 | json_boolean_stash = 0; |
|
|
1379 | |
1270 | void new (char *klass) |
1380 | void new (char *klass) |
1271 | PPCODE: |
1381 | PPCODE: |
1272 | { |
1382 | { |
|
|
1383 | HV *stash = !JSON_SLOW || json_stash |
|
|
1384 | ? json_stash |
|
|
1385 | : gv_stashpv ("JSON::XS", 1); |
1273 | SV *pv = NEWSV (0, sizeof (JSON)); |
1386 | SV *pv = NEWSV (0, sizeof (JSON)); |
1274 | SvPOK_only (pv); |
1387 | SvPOK_only (pv); |
1275 | Zero (SvPVX (pv), 1, sizeof (JSON)); |
1388 | Zero (SvPVX (pv), 1, JSON); |
1276 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
1389 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
1277 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), json_stash))); |
1390 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), stash))); |
1278 | } |
1391 | } |
1279 | |
1392 | |
1280 | void ascii (JSON *self, int enable = 1) |
1393 | void ascii (JSON *self, int enable = 1) |
1281 | ALIAS: |
1394 | ALIAS: |
1282 | ascii = F_ASCII |
1395 | ascii = F_ASCII |
… | |
… | |
1330 | self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE); |
1443 | self->flags = self->flags & ~F_MAXSIZE | (log2 << S_MAXSIZE); |
1331 | |
1444 | |
1332 | XPUSHs (ST (0)); |
1445 | XPUSHs (ST (0)); |
1333 | } |
1446 | } |
1334 | |
1447 | |
|
|
1448 | void filter_json_object (JSON *self, SV *cb = &PL_sv_undef) |
|
|
1449 | PPCODE: |
|
|
1450 | { |
|
|
1451 | SvREFCNT_dec (self->cb_object); |
|
|
1452 | self->cb_object = SvOK (cb) ? newSVsv (cb) : 0; |
|
|
1453 | |
|
|
1454 | XPUSHs (ST (0)); |
|
|
1455 | } |
|
|
1456 | |
|
|
1457 | void filter_json_single_key_object (JSON *self, SV *key, SV *cb = &PL_sv_undef) |
|
|
1458 | PPCODE: |
|
|
1459 | { |
|
|
1460 | if (!self->cb_sk_object) |
|
|
1461 | self->cb_sk_object = newHV (); |
|
|
1462 | |
|
|
1463 | if (SvOK (cb)) |
|
|
1464 | hv_store_ent (self->cb_sk_object, key, newSVsv (cb), 0); |
|
|
1465 | else |
|
|
1466 | { |
|
|
1467 | hv_delete_ent (self->cb_sk_object, key, G_DISCARD, 0); |
|
|
1468 | |
|
|
1469 | if (!HvKEYS (self->cb_sk_object)) |
|
|
1470 | { |
|
|
1471 | SvREFCNT_dec (self->cb_sk_object); |
|
|
1472 | self->cb_sk_object = 0; |
|
|
1473 | } |
|
|
1474 | } |
|
|
1475 | |
|
|
1476 | XPUSHs (ST (0)); |
|
|
1477 | } |
|
|
1478 | |
1335 | void encode (JSON *self, SV *scalar) |
1479 | void encode (JSON *self, SV *scalar) |
1336 | PPCODE: |
1480 | PPCODE: |
1337 | XPUSHs (encode_json (scalar, self)); |
1481 | XPUSHs (encode_json (scalar, self)); |
1338 | |
1482 | |
1339 | void decode (JSON *self, SV *jsonstr) |
1483 | void decode (JSON *self, SV *jsonstr) |
… | |
… | |
1347 | EXTEND (SP, 2); |
1491 | EXTEND (SP, 2); |
1348 | PUSHs (decode_json (jsonstr, self, &offset)); |
1492 | PUSHs (decode_json (jsonstr, self, &offset)); |
1349 | PUSHs (sv_2mortal (newSVuv (offset))); |
1493 | PUSHs (sv_2mortal (newSVuv (offset))); |
1350 | } |
1494 | } |
1351 | |
1495 | |
|
|
1496 | void DESTROY (JSON *self) |
|
|
1497 | CODE: |
|
|
1498 | SvREFCNT_dec (self->cb_sk_object); |
|
|
1499 | SvREFCNT_dec (self->cb_object); |
|
|
1500 | |
1352 | PROTOTYPES: ENABLE |
1501 | PROTOTYPES: ENABLE |
1353 | |
1502 | |
1354 | void to_json (SV *scalar) |
1503 | void to_json (SV *scalar) |
1355 | PPCODE: |
1504 | PPCODE: |
1356 | { |
1505 | { |