… | |
… | |
7 | #include "stdlib.h" |
7 | #include "stdlib.h" |
8 | #include "stdio.h" |
8 | #include "stdio.h" |
9 | |
9 | |
10 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
10 | #if defined(__BORLANDC__) || defined(_MSC_VER) |
11 | # define snprintf _snprintf // C compilers have this in stdio.h |
11 | # define snprintf _snprintf // C compilers have this in stdio.h |
|
|
12 | #endif |
|
|
13 | |
|
|
14 | // some old perls do not have this, try to make it work, no |
|
|
15 | // guarentees, though. if it breaks, you get to keep the pieces. |
|
|
16 | #ifndef UTF8_MAXBYTES |
|
|
17 | # define UTF8_MAXBYTES 13 |
12 | #endif |
18 | #endif |
13 | |
19 | |
14 | #define F_ASCII 0x00000001UL |
20 | #define F_ASCII 0x00000001UL |
15 | #define F_LATIN1 0x00000002UL |
21 | #define F_LATIN1 0x00000002UL |
16 | #define F_UTF8 0x00000004UL |
22 | #define F_UTF8 0x00000004UL |
… | |
… | |
49 | |
55 | |
50 | #define expect_false(expr) expect ((expr) != 0, 0) |
56 | #define expect_false(expr) expect ((expr) != 0, 0) |
51 | #define expect_true(expr) expect ((expr) != 0, 1) |
57 | #define expect_true(expr) expect ((expr) != 0, 1) |
52 | |
58 | |
53 | static HV *json_stash; // JSON::XS:: |
59 | static HV *json_stash; // JSON::XS:: |
|
|
60 | static SV *json_true, *json_false; |
54 | |
61 | |
55 | ///////////////////////////////////////////////////////////////////////////// |
62 | ///////////////////////////////////////////////////////////////////////////// |
56 | // utility functions |
63 | // utility functions |
57 | |
64 | |
58 | static UV * |
65 | static UV * |
… | |
… | |
1025 | |
1032 | |
1026 | case 't': |
1033 | case 't': |
1027 | if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) |
1034 | if (dec->end - dec->cur >= 4 && !memcmp (dec->cur, "true", 4)) |
1028 | { |
1035 | { |
1029 | dec->cur += 4; |
1036 | dec->cur += 4; |
1030 | return newSViv (1); |
1037 | return SvREFCNT_inc (json_true); |
1031 | } |
1038 | } |
1032 | else |
1039 | else |
1033 | ERR ("'true' expected"); |
1040 | ERR ("'true' expected"); |
1034 | |
1041 | |
1035 | break; |
1042 | break; |
1036 | |
1043 | |
1037 | case 'f': |
1044 | case 'f': |
1038 | if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) |
1045 | if (dec->end - dec->cur >= 5 && !memcmp (dec->cur, "false", 5)) |
1039 | { |
1046 | { |
1040 | dec->cur += 5; |
1047 | dec->cur += 5; |
1041 | return newSViv (0); |
1048 | return SvREFCNT_inc (json_false); |
1042 | } |
1049 | } |
1043 | else |
1050 | else |
1044 | ERR ("'false' expected"); |
1051 | ERR ("'false' expected"); |
1045 | |
1052 | |
1046 | break; |
1053 | break; |
… | |
… | |
1157 | : i >= 'a' && i <= 'f' ? i - 'a' + 10 |
1164 | : i >= 'a' && i <= 'f' ? i - 'a' + 10 |
1158 | : i >= 'A' && i <= 'F' ? i - 'A' + 10 |
1165 | : i >= 'A' && i <= 'F' ? i - 'A' + 10 |
1159 | : -1; |
1166 | : -1; |
1160 | |
1167 | |
1161 | json_stash = gv_stashpv ("JSON::XS", 1); |
1168 | json_stash = gv_stashpv ("JSON::XS", 1); |
|
|
1169 | |
|
|
1170 | json_true = get_sv ("JSON::XS::true" , 1); SvREADONLY_on (json_true ); |
|
|
1171 | json_false = get_sv ("JSON::XS::false", 1); SvREADONLY_on (json_false); |
1162 | } |
1172 | } |
1163 | |
1173 | |
1164 | PROTOTYPES: DISABLE |
1174 | PROTOTYPES: DISABLE |
1165 | |
1175 | |
1166 | SV *new (char *dummy) |
1176 | SV *new (char *dummy) |