… | |
… | |
60 | #define expect_false(expr) expect ((expr) != 0, 0) |
60 | #define expect_false(expr) expect ((expr) != 0, 0) |
61 | #define expect_true(expr) expect ((expr) != 0, 1) |
61 | #define expect_true(expr) expect ((expr) != 0, 1) |
62 | |
62 | |
63 | #ifdef USE_ITHREADS |
63 | #ifdef USE_ITHREADS |
64 | # define JSON_SLOW 1 |
64 | # define JSON_SLOW 1 |
|
|
65 | # define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) |
65 | #else |
66 | #else |
66 | # define JSON_SLOW 1 |
67 | # define JSON_SLOW 0 |
|
|
68 | # define JSON_STASH json_stash |
67 | #endif |
69 | #endif |
68 | |
70 | |
69 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
71 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
70 | static SV *json_true, *json_false; |
72 | static SV *json_true, *json_false; |
71 | |
73 | |
… | |
… | |
510 | // we re-bless the reference to get overload and other niceties right |
512 | // we re-bless the reference to get overload and other niceties right |
511 | GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 0); |
513 | GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 0); |
512 | |
514 | |
513 | if (to_json) |
515 | if (to_json) |
514 | { |
516 | { |
515 | int count; |
|
|
516 | dSP; |
517 | dSP; |
517 | |
518 | |
518 | ENTER; SAVETMPS; PUSHMARK (SP); |
519 | ENTER; SAVETMPS; PUSHMARK (SP); |
519 | XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); |
520 | XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); |
520 | |
521 | |
… | |
… | |
1224 | |
1225 | |
1225 | case 't': |
1226 | case 't': |
1226 | if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) |
1227 | if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) |
1227 | { |
1228 | { |
1228 | dec->cur += 4; |
1229 | dec->cur += 4; |
|
|
1230 | #if JSON_SLOW |
|
|
1231 | json_true = get_sv ("JSON::XS::true", 1); SvREADONLY_on (json_true); |
|
|
1232 | #endif |
1229 | return SvREFCNT_inc (json_true); |
1233 | return SvREFCNT_inc (json_true); |
1230 | } |
1234 | } |
1231 | else |
1235 | else |
1232 | ERR ("'true' expected"); |
1236 | ERR ("'true' expected"); |
1233 | |
1237 | |
… | |
… | |
1235 | |
1239 | |
1236 | case 'f': |
1240 | case 'f': |
1237 | if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) |
1241 | if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) |
1238 | { |
1242 | { |
1239 | dec->cur += 5; |
1243 | dec->cur += 5; |
|
|
1244 | #if JSON_SLOW |
|
|
1245 | json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); |
|
|
1246 | #endif |
1240 | return SvREFCNT_inc (json_false); |
1247 | return SvREFCNT_inc (json_false); |
1241 | } |
1248 | } |
1242 | else |
1249 | else |
1243 | ERR ("'false' expected"); |
1250 | ERR ("'false' expected"); |
1244 | |
1251 | |
… | |
… | |
1379 | json_boolean_stash = 0; |
1386 | json_boolean_stash = 0; |
1380 | |
1387 | |
1381 | void new (char *klass) |
1388 | void new (char *klass) |
1382 | PPCODE: |
1389 | PPCODE: |
1383 | { |
1390 | { |
1384 | HV *stash = !JSON_SLOW || json_stash |
|
|
1385 | ? json_stash |
|
|
1386 | : gv_stashpv ("JSON::XS", 1); |
|
|
1387 | SV *pv = NEWSV (0, sizeof (JSON)); |
1391 | SV *pv = NEWSV (0, sizeof (JSON)); |
1388 | SvPOK_only (pv); |
1392 | SvPOK_only (pv); |
1389 | Zero (SvPVX (pv), 1, JSON); |
1393 | Zero (SvPVX (pv), 1, JSON); |
1390 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
1394 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
1391 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), stash))); |
1395 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), JSON_STASH))); |
1392 | } |
1396 | } |
1393 | |
1397 | |
1394 | void ascii (JSON *self, int enable = 1) |
1398 | void ascii (JSON *self, int enable = 1) |
1395 | ALIAS: |
1399 | ALIAS: |
1396 | ascii = F_ASCII |
1400 | ascii = F_ASCII |