… | |
… | |
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 | |
… | |
… | |
1379 | json_boolean_stash = 0; |
1380 | json_boolean_stash = 0; |
1380 | |
1381 | |
1381 | void new (char *klass) |
1382 | void new (char *klass) |
1382 | PPCODE: |
1383 | PPCODE: |
1383 | { |
1384 | { |
1384 | HV *stash = !JSON_SLOW || json_stash |
|
|
1385 | ? json_stash |
|
|
1386 | : gv_stashpv ("JSON::XS", 1); |
|
|
1387 | SV *pv = NEWSV (0, sizeof (JSON)); |
1385 | SV *pv = NEWSV (0, sizeof (JSON)); |
1388 | SvPOK_only (pv); |
1386 | SvPOK_only (pv); |
1389 | Zero (SvPVX (pv), 1, JSON); |
1387 | Zero (SvPVX (pv), 1, JSON); |
1390 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
1388 | ((JSON *)SvPVX (pv))->flags = F_DEFAULT; |
1391 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), stash))); |
1389 | XPUSHs (sv_2mortal (sv_bless (newRV_noinc (pv), JSON_STASH))); |
1392 | } |
1390 | } |
1393 | |
1391 | |
1394 | void ascii (JSON *self, int enable = 1) |
1392 | void ascii (JSON *self, int enable = 1) |
1395 | ALIAS: |
1393 | ALIAS: |
1396 | ascii = F_ASCII |
1394 | ascii = F_ASCII |