… | |
… | |
57 | # define inline static |
57 | # define inline static |
58 | #endif |
58 | #endif |
59 | |
59 | |
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 | |
|
|
63 | #ifdef USE_ITHREADS |
|
|
64 | # define JSON_SLOW 1 |
|
|
65 | # define JSON_STASH (json_stash ? json_stash : gv_stashpv ("JSON::XS", 1)) |
|
|
66 | #else |
|
|
67 | # define JSON_SLOW 0 |
|
|
68 | # define JSON_STASH json_stash |
|
|
69 | #endif |
62 | |
70 | |
63 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
71 | static HV *json_stash, *json_boolean_stash; // JSON::XS:: |
64 | static SV *json_true, *json_false; |
72 | static SV *json_true, *json_false; |
65 | |
73 | |
66 | typedef struct { |
74 | typedef struct { |
… | |
… | |
478 | SvGETMAGIC (sv); |
486 | SvGETMAGIC (sv); |
479 | svt = SvTYPE (sv); |
487 | svt = SvTYPE (sv); |
480 | |
488 | |
481 | if (expect_false (SvOBJECT (sv))) |
489 | if (expect_false (SvOBJECT (sv))) |
482 | { |
490 | { |
|
|
491 | HV *stash = !JSON_SLOW || json_boolean_stash |
|
|
492 | ? json_boolean_stash |
|
|
493 | : gv_stashpv ("JSON::XS::Boolean", 1); |
|
|
494 | |
483 | if (SvSTASH (sv) == json_boolean_stash) |
495 | if (SvSTASH (sv) == stash) |
484 | { |
496 | { |
485 | if (SvIV (sv)) |
497 | if (SvIV (sv)) |
486 | encode_str (enc, "true", 4, 0); |
498 | encode_str (enc, "true", 4, 0); |
487 | else |
499 | else |
488 | encode_str (enc, "false", 5, 0); |
500 | encode_str (enc, "false", 5, 0); |
… | |
… | |
500 | // 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 |
501 | GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 0); |
513 | GV *to_json = gv_fetchmethod_autoload (SvSTASH (sv), "TO_JSON", 0); |
502 | |
514 | |
503 | if (to_json) |
515 | if (to_json) |
504 | { |
516 | { |
505 | int count; |
|
|
506 | dSP; |
517 | dSP; |
507 | |
518 | |
508 | ENTER; SAVETMPS; PUSHMARK (SP); |
519 | ENTER; SAVETMPS; PUSHMARK (SP); |
509 | XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); |
520 | XPUSHs (sv_bless (sv_2mortal (newRV_inc (sv)), SvSTASH (sv))); |
510 | |
521 | |
… | |
… | |
1361 | json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); |
1372 | json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); |
1362 | } |
1373 | } |
1363 | |
1374 | |
1364 | PROTOTYPES: DISABLE |
1375 | PROTOTYPES: DISABLE |
1365 | |
1376 | |
|
|
1377 | void CLONE (...) |
|
|
1378 | CODE: |
|
|
1379 | json_stash = 0; |
|
|
1380 | json_boolean_stash = 0; |
|
|
1381 | |
1366 | void new (char *klass) |
1382 | void new (char *klass) |
1367 | PPCODE: |
1383 | PPCODE: |
1368 | { |
1384 | { |
1369 | SV *pv = NEWSV (0, sizeof (JSON)); |
1385 | SV *pv = NEWSV (0, sizeof (JSON)); |
1370 | SvPOK_only (pv); |
1386 | SvPOK_only (pv); |
1371 | Zero (SvPVX (pv), 1, JSON); |
1387 | Zero (SvPVX (pv), 1, JSON); |
1372 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
1388 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
1373 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), json_stash))); |
1389 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), JSON_STASH))); |
1374 | } |
1390 | } |
1375 | |
1391 | |
1376 | void ascii (JSON *self, int enable = 1) |
1392 | void ascii (JSON *self, int enable = 1) |
1377 | ALIAS: |
1393 | ALIAS: |
1378 | ascii = F_ASCII |
1394 | ascii = F_ASCII |