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