| 1 |
|
| /* |
| 2 |
|
| Copyright (c) 2007-2010 Don Owens <don@regexguy.com>. All rights reserved. |
| 3 |
|
| |
| 4 |
|
| This is free software; you can redistribute it and/or modify it |
| 5 |
|
| under the same terms as Perl itself. See perlartistic. |
| 6 |
|
| |
| 7 |
|
| This program is distributed in the hope that it will be |
| 8 |
|
| useful, but WITHOUT ANY WARRANTY; without even the implied |
| 9 |
|
| warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 10 |
|
| PURPOSE. |
| 11 |
|
| */ |
| 12 |
|
| |
| 13 |
|
| /* $Revision: 1737 $ */ |
| 14 |
|
| |
| 15 |
|
| /* TODO: |
| 16 |
|
| |
| 17 |
|
| - "strict" option to follow Crockford's tests |
| 18 |
|
| */ |
| 19 |
|
| |
| 20 |
|
| /* #define PERL_NO_GET_CONTEXT */ |
| 21 |
|
| |
| 22 |
|
| #ifdef __cplusplus |
| 23 |
|
| extern "C" { |
| 24 |
|
| #endif |
| 25 |
|
| #include "EXTERN.h" |
| 26 |
|
| #include "perl.h" |
| 27 |
|
| #include "XSUB.h" |
| 28 |
|
| #ifdef __cplusplus |
| 29 |
|
| } |
| 30 |
|
| #endif |
| 31 |
|
| |
| 32 |
|
| #if PERL_VERSION >= 8 |
| 33 |
|
| #define IS_PERL_5_8 |
| 34 |
|
| #else |
| 35 |
|
| #if PERL_VERSION <= 5 |
| 36 |
|
| #error "This module requires at least Perl 5.6" |
| 37 |
|
| #else |
| 38 |
|
| #define IS_PERL_5_6 |
| 39 |
|
| #endif |
| 40 |
|
| #endif |
| 41 |
|
| |
| 42 |
|
| #include <stdlib.h> |
| 43 |
|
| |
| 44 |
|
| #include "jsonevt.h" |
| 45 |
|
| #include "evt.h" |
| 46 |
|
| |
| 47 |
|
| #ifndef DO_DEBUG |
| 48 |
|
| #define DO_DEBUG 0 |
| 49 |
|
| #endif |
| 50 |
|
| |
| 51 |
|
| #if DO_DEBUG && defined(JSONEVT_HAVE_FULL_VARIADIC_MACROS) |
| 52 |
|
| #define LOG_DEBUG(...) printf("%s (%d) - ", __FILE__, __LINE__); printf(__VA_ARGS__); \ |
| 53 |
|
| printf("\n"); fflush(stdout) |
| 54 |
|
| #define DUMP_STACK(ctx) dump_stack(ctx) |
| 55 |
|
| #else |
| 56 |
|
| #define LOG_DEBUG(...) |
| 57 |
|
| #define DUMP_STACK |
| 58 |
|
| #endif |
| 59 |
|
| |
| 60 |
|
| #if 0 && defined(JSONEVT_HAVE_FULL_VARIADIC_MACROS) |
| 61 |
|
| #define PDB(...) fprintf(stderr, "in %s, line %d of %s: ", __func__, __LINE__, __FILE__); \ |
| 62 |
|
| fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr) |
| 63 |
|
| #else |
| 64 |
|
| #define PDB(...) |
| 65 |
|
| #endif |
| 66 |
|
| |
| 67 |
|
| #if 0 |
| 68 |
|
| #define SETUP_TRACE fprintf(stderr, "in %s() at line %d of %s\n", __func__, __LINE__, __FILE__); \ |
| 69 |
|
| fflush(stderr); |
| 70 |
|
| #else |
| 71 |
|
| #define SETUP_TRACE |
| 72 |
|
| #endif |
| 73 |
|
| |
| 74 |
|
| #define MOD_NAME "JSON::DWIW" |
| 75 |
|
| |
| 76 |
|
| #define UNLESS(stuff) if (! (stuff)) |
| 77 |
|
| |
| 78 |
|
| /* get rid of "value computed is not used" warnings */ |
| 79 |
|
| #define IGNORE_RV(x) (void)(x) |
| 80 |
|
| |
| 81 |
|
| typedef struct { |
| 82 |
|
| SV * data; |
| 83 |
|
| } parse_cb_stack_entry; |
| 84 |
|
| |
| 85 |
|
| #define EVT_OPTION_CONVERT_BOOL 1 |
| 86 |
|
| #define EVT_OPTION_USE_EXCEPTIONS (1 << 1) |
| 87 |
|
| |
| 88 |
|
| typedef struct { |
| 89 |
|
| parse_cb_stack_entry * stack; |
| 90 |
|
| int stack_level; |
| 91 |
|
| int stack_size; |
| 92 |
|
| uint options; |
| 93 |
|
| SV *parse_number_cb; |
| 94 |
|
| SV *parse_const_cb; |
| 95 |
|
| IV start_depth; |
| 96 |
|
| SV *start_depth_handler; |
| 97 |
|
| } parse_callback_ctx; |
| 98 |
|
| |
| 99 |
|
| typedef struct { |
| 100 |
|
| parse_callback_ctx cbd; |
| 101 |
|
| } perl_wrapper_ctx; |
| 102 |
|
| |
| 103 |
|
| #define GROW_STACK(ctx) ( ((ctx)->stack_size <<= 1), JSONEVT_RENEW_RV((ctx)->stack, (ctx)->stack_size, parse_cb_stack_entry)) |
| 104 |
|
| |
| 105 |
|
| |
| 106 |
|
| /* #define GROW_STACK(ctx) ( ((ctx)->stack_size <<= 1), Renew((ctx)->stack, (ctx)->stack_size, parse_cb_stack_entry)) |
| 107 |
|
| */ |
| 108 |
|
| |
| 109 |
|
| #define PARENT_STACK_ENTRY(ctx) ( (ctx)->stack_level > 0 ? \ |
| 110 |
|
| (parse_cb_stack_entry *)((ctx)->stack + (ctx)->stack_level - 1) : NULL ) |
| 111 |
|
| #define ENSURE_STACK(ctx) ( (ctx)->stack_level >= (ctx)->stack_size - 1 ? GROW_STACK(ctx) : 0 ) |
| 112 |
|
| #define CUR_STACK_LEVEL(ctx) ((ctx)->stack_level) |
| 113 |
|
| #define CUR_STACK_ENTRY(ctx) ( (parse_cb_stack_entry *)((ctx)->stack + (ctx)->stack_level) ) |
| 114 |
|
| #define POP_STACK(ctx) memzero((void *)((ctx)->stack + (ctx)->stack_level), sizeof((ctx)->stack));\ |
| 115 |
|
| (ctx)->stack_level--; |
| 116 |
|
| #define PUSH_STACK_ENTRY(ctx) ( ENSURE_STACK(ctx), (ctx)->stack_level++, ( (parse_cb_stack_entry *)((ctx)->stack + (ctx)->stack_level) ) ) |
| 117 |
|
| |
| 118 |
|
| static void |
| 119 |
4 |
| _json_call_method_no_arg_one_return(SV * obj_or_class, char * method, SV ** rv_ptr) { |
| 120 |
4 |
| dSP; |
| 121 |
|
| |
| 122 |
4 |
| ENTER; |
| 123 |
4 |
| SAVETMPS; |
| 124 |
4 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
4 |
4 |
|
| 125 |
4 |
▶ | XPUSHs(obj_or_class); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(obj_or_class); |
0 |
4 |
4 |
|
| 126 |
4 |
| PUTBACK; |
| 127 |
|
| |
| 128 |
4 |
| call_method(method, G_SCALAR); |
| 129 |
|
| |
| 130 |
4 |
| SPAGAIN; |
| 131 |
|
| |
| 132 |
4 |
| *rv_ptr = POPs; |
| 133 |
4 |
▶ | if (SvOK(*rv_ptr)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(*rv_ptr)) { |
4 |
0 |
4 |
|
| 134 |
4 |
| SvREFCNT_inc(*rv_ptr); |
| 135 |
|
| } |
| 136 |
|
| |
| 137 |
4 |
| PUTBACK; |
| 138 |
4 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
4 |
0 |
4 |
|
| 139 |
4 |
| LEAVE; |
| 140 |
4 |
| } |
| 141 |
|
| |
| 142 |
|
| static SV * |
| 143 |
4 |
| json_call_method_no_arg_one_return(SV * obj_or_class, char * method) { |
| 144 |
4 |
| SV * rv = NULL; |
| 145 |
4 |
| _json_call_method_no_arg_one_return(obj_or_class, method, &rv); |
| 146 |
|
| |
| 147 |
4 |
| return rv; |
| 148 |
|
| } |
| 149 |
|
| |
| 150 |
|
| static void |
| 151 |
7 |
| _json_call_method_one_arg_one_return(SV * obj_or_class, char * method, SV * arg, SV ** rv_ptr) { |
| 152 |
7 |
| dSP; |
| 153 |
|
| |
| 154 |
7 |
| ENTER; |
| 155 |
7 |
| SAVETMPS; |
| 156 |
7 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
7 |
7 |
|
| 157 |
7 |
▶ | XPUSHs(obj_or_class); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(obj_or_class); |
0 |
7 |
7 |
|
| 158 |
7 |
▶ | XPUSHs(arg); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(arg); |
0 |
7 |
7 |
|
| 159 |
7 |
| PUTBACK; |
| 160 |
|
| |
| 161 |
7 |
| call_method(method, G_SCALAR); |
| 162 |
|
| |
| 163 |
7 |
| SPAGAIN; |
| 164 |
|
| |
| 165 |
7 |
| *rv_ptr = POPs; |
| 166 |
7 |
▶ | if (SvOK(*rv_ptr)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(*rv_ptr)) { |
7 |
0 |
7 |
|
| 167 |
7 |
| SvREFCNT_inc(*rv_ptr); |
| 168 |
|
| } |
| 169 |
|
| |
| 170 |
7 |
| PUTBACK; |
| 171 |
7 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
7 |
0 |
7 |
|
| 172 |
7 |
| LEAVE; |
| 173 |
7 |
| } |
| 174 |
|
| |
| 175 |
|
| static SV * |
| 176 |
7 |
| json_call_method_one_arg_one_return(SV * obj_or_class, char * method, SV * arg) { |
| 177 |
7 |
| SV * rv = NULL; |
| 178 |
7 |
| _json_call_method_one_arg_one_return(obj_or_class, method, arg, &rv); |
| 179 |
|
| |
| 180 |
7 |
| return rv; |
| 181 |
|
| } |
| 182 |
|
| |
| 183 |
|
| /* the function passed to this should be a copy of the one passed in (see perlcall), |
| 184 |
|
| e.g., SV *keep = newSVsv(func); |
| 185 |
|
| */ |
| 186 |
|
| static void |
| 187 |
7 |
| _json_call_function_one_arg_one_return(SV *func, SV *arg, SV **rv_ptr) { |
| 188 |
7 |
| dSP; |
| 189 |
|
| |
| 190 |
7 |
| ENTER; |
| 191 |
7 |
| SAVETMPS; |
| 192 |
7 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
7 |
7 |
|
| 193 |
7 |
▶ | XPUSHs(arg); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(arg); |
0 |
7 |
7 |
|
| 194 |
7 |
| PUTBACK; |
| 195 |
|
| |
| 196 |
7 |
| call_sv(func, G_SCALAR); |
| 197 |
|
| |
| 198 |
7 |
| SPAGAIN; |
| 199 |
|
| |
| 200 |
7 |
| *rv_ptr = POPs; |
| 201 |
7 |
▶ | if (SvOK(*rv_ptr)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(*rv_ptr)) { |
7 |
0 |
7 |
|
| 202 |
7 |
| SvREFCNT_inc(*rv_ptr); |
| 203 |
|
| } |
| 204 |
|
| |
| 205 |
7 |
| PUTBACK; |
| 206 |
7 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
7 |
0 |
7 |
|
| 207 |
7 |
| LEAVE; |
| 208 |
|
| |
| 209 |
7 |
| } |
| 210 |
|
| |
| 211 |
|
| static SV * |
| 212 |
7 |
| json_call_function_one_arg_one_return(SV *func, SV *arg) { |
| 213 |
7 |
| SV * rv = NULL; |
| 214 |
7 |
| _json_call_function_one_arg_one_return(func, arg, &rv); |
| 215 |
|
| |
| 216 |
7 |
| return rv; |
| 217 |
|
| } |
| 218 |
|
| |
| 219 |
|
| static SV * |
| 220 |
4 |
| get_new_bool_obj(int bool_val) { |
| 221 |
4 |
| SV * class_name = newSVpv("JSON::DWIW::Boolean", 19); |
| 222 |
|
| SV * obj; |
| 223 |
|
| |
| 224 |
4 |
▶ | if (bool_val) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (bool_val) { |
2 |
2 |
4 |
|
| 225 |
2 |
| obj = json_call_method_no_arg_one_return(class_name, "true"); |
| 226 |
|
| } |
| 227 |
|
| else { |
| 228 |
2 |
| obj = json_call_method_no_arg_one_return(class_name, "false"); |
| 229 |
|
| } |
| 230 |
|
| |
| 231 |
4 |
| SvREFCNT_dec(class_name); |
| 232 |
|
| |
| 233 |
4 |
| return obj; |
| 234 |
|
| } |
| 235 |
|
| |
| 236 |
|
| #define kHaveModuleNotChecked 0 |
| 237 |
|
| #define kHaveModule 1 |
| 238 |
|
| #define kHaveModuleDontHave 2 |
| 239 |
|
| |
| 240 |
|
| static int |
| 241 |
3 |
| have_bigint() { |
| 242 |
|
| static unsigned char have_big_int = kHaveModuleNotChecked; |
| 243 |
|
| SV *rv; |
| 244 |
|
| |
| 245 |
3 |
▶ | if (have_big_int != kHaveModuleNotChecked) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (have_big_int != kHaveModuleNotChecked) { |
1 |
2 |
3 |
|
| 246 |
1 |
▶ | if (have_big_int == kHaveModule) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (have_big_int == kHaveModule) { |
1 |
0 |
1 |
|
| 247 |
1 |
| return 1; |
| 248 |
|
| } |
| 249 |
|
| else { |
| 250 |
0 |
| return 0; |
| 251 |
|
| } |
| 252 |
|
| } |
| 253 |
|
| |
| 254 |
2 |
| rv = eval_pv("require Math::BigInt", 0); |
| 255 |
2 |
▶ | if (rv && SvTRUE(rv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (rv && SvTRUE(rv)) { |
2 |
0 |
2 |
| if (rv && SvTRUE(rv)) { |
2 |
0 |
2 |
|
| 256 |
|
| /* module loaded successfully */ |
| 257 |
2 |
| have_big_int = kHaveModule; |
| 258 |
2 |
| return 1; |
| 259 |
|
| } |
| 260 |
|
| else { |
| 261 |
|
| /* we don't have it */ |
| 262 |
0 |
| have_big_int = kHaveModuleDontHave; |
| 263 |
0 |
| return 0; |
| 264 |
|
| } |
| 265 |
|
| |
| 266 |
|
| return 0; |
| 267 |
|
| |
| 268 |
|
| } |
| 269 |
|
| |
| 270 |
|
| static int |
| 271 |
4 |
| have_bigfloat() { |
| 272 |
|
| static unsigned char have_big_float = kHaveModuleNotChecked; |
| 273 |
|
| SV *rv; |
| 274 |
|
| |
| 275 |
4 |
▶ | if (have_big_float != kHaveModuleNotChecked) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (have_big_float != kHaveModuleNotChecked) { |
2 |
2 |
4 |
|
| 276 |
2 |
▶ | if (have_big_float == kHaveModule) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (have_big_float == kHaveModule) { |
2 |
0 |
2 |
|
| 277 |
2 |
| return 1; |
| 278 |
|
| } |
| 279 |
|
| else { |
| 280 |
0 |
| return 0; |
| 281 |
|
| } |
| 282 |
|
| } |
| 283 |
|
| |
| 284 |
2 |
| rv = eval_pv("require Math::BigFloat", 0); |
| 285 |
2 |
▶ | if (rv && SvTRUE(rv)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (rv && SvTRUE(rv)) { |
2 |
0 |
2 |
| if (rv && SvTRUE(rv)) { |
2 |
0 |
2 |
|
| 286 |
|
| /* module loaded successfully */ |
| 287 |
2 |
| have_big_float = kHaveModule; |
| 288 |
2 |
| return 1; |
| 289 |
|
| } |
| 290 |
|
| else { |
| 291 |
|
| /* we don't have it */ |
| 292 |
0 |
| have_big_float = kHaveModuleDontHave; |
| 293 |
0 |
| return 0; |
| 294 |
|
| } |
| 295 |
|
| |
| 296 |
|
| return 0; |
| 297 |
|
| |
| 298 |
|
| } |
| 299 |
|
| |
| 300 |
|
| static SV * |
| 301 |
3 |
| get_new_big_int(SV * num_string) { |
| 302 |
3 |
| SV * class_name = newSVpv("Math::BigInt", 12); |
| 303 |
3 |
| SV * rv = NULL; |
| 304 |
|
| |
| 305 |
3 |
| rv = json_call_method_one_arg_one_return(class_name, "new", num_string); |
| 306 |
3 |
| SvREFCNT_dec(class_name); |
| 307 |
3 |
| return rv; |
| 308 |
|
| } |
| 309 |
|
| |
| 310 |
|
| static SV * |
| 311 |
4 |
| get_new_big_float(SV * num_string) { |
| 312 |
4 |
| SV * class_name = newSVpv("Math::BigFloat", 14); |
| 313 |
4 |
| SV * rv = NULL; |
| 314 |
|
| |
| 315 |
4 |
| rv = json_call_method_one_arg_one_return(class_name, "new", num_string); |
| 316 |
4 |
| SvREFCNT_dec(class_name); |
| 317 |
4 |
| return rv; |
| 318 |
|
| } |
| 319 |
|
| |
| 320 |
|
| static int |
| 321 |
1041 |
| insert_entry(parse_callback_ctx * ctx, SV * val) { |
| 322 |
1041 |
| parse_cb_stack_entry * cur_entry = CUR_STACK_ENTRY(ctx); |
| 323 |
|
| parse_cb_stack_entry * new_entry; |
| 324 |
1041 |
| int type = 0; |
| 325 |
1041 |
| int level = CUR_STACK_LEVEL(ctx); |
| 326 |
|
| SV * s; |
| 327 |
|
| |
| 328 |
|
| |
| 329 |
1041 |
▶ | if (SvROK(cur_entry->data)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(cur_entry->data)) { |
665 |
376 |
1041 |
|
| 330 |
665 |
| s = SvRV(cur_entry->data); |
| 331 |
665 |
| type = SvTYPE(s); |
| 332 |
|
| |
| 333 |
665 |
▶ | if (type == SVt_PVAV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (type == SVt_PVAV) { |
264 |
401 |
665 |
|
| 334 |
264 |
| av_push((AV *)SvRV(cur_entry->data), val); |
| 335 |
|
| } |
| 336 |
|
| else { |
| 337 |
|
| /* must be a hash (SVt_PVHV) */ |
| 338 |
|
| /* val must be a hash key, so push it onto the stack */ |
| 339 |
401 |
▶ | new_entry = PUSH_STACK_ENTRY(ctx); |
Branch: 1 branch
| Branch | True | False | Total |
| new_entry = PUSH_STACK_ENTRY(ctx); |
2 |
399 |
401 |
|
| 340 |
401 |
| new_entry->data = val; |
| 341 |
|
| } |
| 342 |
|
| } |
| 343 |
|
| else { |
| 344 |
|
| /* scalar -- must be a hash key, so insert the val */ |
| 345 |
376 |
| s = cur_entry->data; |
| 346 |
376 |
| cur_entry = (parse_cb_stack_entry *)(ctx->stack + level - 1); |
| 347 |
|
| |
| 348 |
|
| /* note that, if we didn't create the has ourselves, we would |
| 349 |
|
| have to check the return value and decrement the ref count |
| 350 |
|
| of val if NULL is returned */ |
| 351 |
376 |
| IGNORE_RV(hv_store_ent((HV *)SvRV(cur_entry->data), s, val, 0)); |
| 352 |
376 |
| SvREFCNT_dec(s); |
| 353 |
376 |
| POP_STACK(ctx); |
| 354 |
|
| } |
| 355 |
|
| |
| 356 |
1041 |
| return 1; |
| 357 |
|
| } |
| 358 |
|
| |
| 359 |
|
| static int |
| 360 |
1223 |
| push_stack_val(parse_callback_ctx * ctx, SV * val) { |
| 361 |
1223 |
| int cur_level = CUR_STACK_LEVEL(ctx); |
| 362 |
|
| |
| 363 |
|
| |
| 364 |
|
| /* parse_cb_stack_entry * cur_entry = CUR_STACK_ENTRY(ctx); */ |
| 365 |
|
| parse_cb_stack_entry * new_entry; |
| 366 |
1223 |
| int is_hash_or_array = 0; |
| 367 |
1223 |
| int type = 0; |
| 368 |
|
| |
| 369 |
|
| /* |
| 370 |
|
| int type = cur_entry->type; |
| 371 |
|
| int sv_type = SvTYPE(val); |
| 372 |
|
| */ |
| 373 |
|
| |
| 374 |
1223 |
▶ | if (SvROK(val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(val)) { |
427 |
796 |
1223 |
|
| 375 |
427 |
| type = SvTYPE(SvRV(val)); |
| 376 |
427 |
▶ | if ( (type == SVt_PVHV || type == SVt_PVAV) && !sv_isobject(val) ) { |
Branch: 3 branches
| Branch | True | False | Total |
| if ( (type == SVt_PVHV || type == SVt_PVAV) && !sv_isobject(val) ) { |
171 |
256 |
427 |
| if ( (type == SVt_PVHV || type == SVt_PVAV) && !sv_isobject(val) ) { |
167 |
4 |
171 |
| if ( (type == SVt_PVHV || type == SVt_PVAV) && !sv_isobject(val) ) { |
416 |
7 |
423 |
|
| 377 |
416 |
| is_hash_or_array = 1; |
| 378 |
|
| } |
| 379 |
|
| } |
| 380 |
|
| |
| 381 |
1223 |
▶ | if (is_hash_or_array) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (is_hash_or_array) { |
416 |
807 |
1223 |
|
| 382 |
416 |
▶ | if (cur_level >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cur_level >= 0) { |
251 |
165 |
416 |
|
| 383 |
|
| SETUP_TRACE; |
| 384 |
251 |
| insert_entry(ctx, val); |
| 385 |
|
| } |
| 386 |
|
| |
| 387 |
416 |
▶ | new_entry = PUSH_STACK_ENTRY(ctx); |
Branch: 1 branch
| Branch | True | False | Total |
| new_entry = PUSH_STACK_ENTRY(ctx); |
0 |
416 |
416 |
|
| 388 |
416 |
| new_entry->data = val; |
| 389 |
|
| } |
| 390 |
|
| else { |
| 391 |
|
| SETUP_TRACE; |
| 392 |
807 |
▶ | if (cur_level >= 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cur_level >= 0) { |
790 |
17 |
807 |
|
| 393 |
|
| SETUP_TRACE; |
| 394 |
790 |
| insert_entry(ctx, val); |
| 395 |
|
| } |
| 396 |
|
| else { |
| 397 |
|
| SETUP_TRACE; |
| 398 |
17 |
▶ | new_entry = PUSH_STACK_ENTRY(ctx); |
Branch: 1 branch
| Branch | True | False | Total |
| new_entry = PUSH_STACK_ENTRY(ctx); |
0 |
17 |
17 |
|
| 399 |
17 |
| new_entry->data = val; |
| 400 |
|
| } |
| 401 |
|
| } |
| 402 |
|
| |
| 403 |
1223 |
| return 1; |
| 404 |
|
| } |
| 405 |
|
| |
| 406 |
|
| static int |
| 407 |
559 |
| string_callback(void * cb_data, const char * data, uint data_len, uint flags, uint level) { |
| 408 |
559 |
| parse_callback_ctx * ctx = (parse_callback_ctx *)cb_data; |
| 409 |
|
| SV * val; |
| 410 |
|
| |
| 411 |
559 |
| val = newSVpvn(data, data_len); |
| 412 |
|
| |
| 413 |
|
| /* flag as utf-8 */ |
| 414 |
559 |
| SvUTF8_on(val); |
| 415 |
|
| |
| 416 |
|
| SETUP_TRACE; |
| 417 |
559 |
| push_stack_val(ctx, val); |
| 418 |
|
| SETUP_TRACE; |
| 419 |
|
| |
| 420 |
559 |
| return 0; |
| 421 |
|
| } |
| 422 |
|
| |
| 423 |
|
| static int |
| 424 |
163 |
| number_callback(void * cb_data, const char * data, uint data_len, uint flags, uint level) { |
| 425 |
163 |
| parse_callback_ctx * ctx = (parse_callback_ctx *)cb_data; |
| 426 |
|
| NV nv_val; |
| 427 |
|
| IV iv_val; |
| 428 |
|
| UV uv_val; |
| 429 |
|
| |
| 430 |
163 |
| SV * sv_val = Nullsv; |
| 431 |
163 |
| SV * tmp_sv = Nullsv; |
| 432 |
163 |
| int try_big_num = 0; |
| 433 |
163 |
| char * uv_str = Nullch; |
| 434 |
163 |
| unsigned char number_done = 0; |
| 435 |
|
| |
| 436 |
|
| SETUP_TRACE; |
| 437 |
|
| |
| 438 |
163 |
▶ | if (ctx->parse_number_cb) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->parse_number_cb) { |
2 |
161 |
163 |
|
| 439 |
2 |
| tmp_sv = newSVpv(data, data_len); |
| 440 |
2 |
| sv_val = json_call_function_one_arg_one_return(ctx->parse_number_cb, tmp_sv); |
| 441 |
2 |
| SvREFCNT_dec(tmp_sv); |
| 442 |
2 |
| push_stack_val(ctx, sv_val); |
| 443 |
2 |
| return 0; |
| 444 |
|
| } |
| 445 |
|
| |
| 446 |
|
| |
| 447 |
|
| /* figure out if we need to create a BigNum object or not */ |
| 448 |
161 |
▶ | if (flags & (JSON_EVT_PARSE_NUMBER_HAVE_DECIMAL | JSON_EVT_PARSE_NUMBER_HAVE_EXPONENT)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & (JSON_EVT_PARSE_NUMBER_HAVE_DECIMAL | JSON_EVT_PARSE_NUMBER_HAVE_EXPONENT)) { |
46 |
115 |
161 |
|
| 449 |
46 |
▶ | if (flags & JSON_EVT_PARSE_NUMBER_HAVE_SIGN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & JSON_EVT_PARSE_NUMBER_HAVE_SIGN) { |
3 |
43 |
46 |
|
| 450 |
3 |
▶ | if (data_len - 1 >= DBL_DIG) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (data_len - 1 >= DBL_DIG) { |
0 |
3 |
3 |
|
| 451 |
0 |
| try_big_num = 1; |
| 452 |
|
| } |
| 453 |
|
| } |
| 454 |
43 |
▶ | else if (data_len >= DBL_DIG) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (data_len >= DBL_DIG) { |
4 |
39 |
43 |
|
| 455 |
4 |
| try_big_num = 1; |
| 456 |
|
| } |
| 457 |
|
| } |
| 458 |
|
| else { |
| 459 |
115 |
▶ | if (flags & JSON_EVT_PARSE_NUMBER_HAVE_SIGN) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & JSON_EVT_PARSE_NUMBER_HAVE_SIGN) { |
2 |
113 |
115 |
|
| 460 |
2 |
▶ | if (data_len - 1 >= IV_DIG) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (data_len - 1 >= IV_DIG) { |
0 |
2 |
2 |
|
| 461 |
0 |
▶ | if (data_len - 1 == IV_DIG) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (data_len - 1 == IV_DIG) { |
0 |
0 |
0 |
|
| 462 |
0 |
| uv_str = form("%"IVdf"", (IV)IV_MIN); |
| 463 |
0 |
▶ | if (strncmp(data, uv_str, data_len) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strncmp(data, uv_str, data_len) > 0) { |
0 |
0 |
0 |
|
| 464 |
0 |
| try_big_num = 1; |
| 465 |
|
| } |
| 466 |
|
| } |
| 467 |
|
| else { |
| 468 |
0 |
| try_big_num = 1; |
| 469 |
|
| } |
| 470 |
|
| } |
| 471 |
|
| } |
| 472 |
|
| else { |
| 473 |
113 |
▶ | if (data_len >= UV_DIG) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (data_len >= UV_DIG) { |
3 |
110 |
113 |
|
| 474 |
3 |
▶ | if (data_len == UV_DIG) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (data_len == UV_DIG) { |
2 |
1 |
3 |
|
| 475 |
2 |
| uv_str = form("%"UVuf"", (UV)UV_MAX); |
| 476 |
2 |
▶ | if (strncmp(data, uv_str, data_len) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (strncmp(data, uv_str, data_len) > 0) { |
2 |
0 |
2 |
|
| 477 |
2 |
| try_big_num = 1; |
| 478 |
|
| } |
| 479 |
|
| } |
| 480 |
|
| else { |
| 481 |
1 |
| try_big_num = 1; |
| 482 |
|
| } |
| 483 |
|
| } |
| 484 |
|
| } |
| 485 |
|
| } |
| 486 |
|
| |
| 487 |
161 |
▶ | if (try_big_num) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (try_big_num) { |
7 |
154 |
161 |
|
| 488 |
7 |
▶ | if (flags & (JSON_EVT_PARSE_NUMBER_HAVE_EXPONENT | JSON_EVT_PARSE_NUMBER_HAVE_DECIMAL)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & (JSON_EVT_PARSE_NUMBER_HAVE_EXPONENT | JSON_EVT_PARSE_NUMBER_HAVE_DECIMAL)) { |
4 |
3 |
7 |
|
| 489 |
4 |
▶ | if (have_bigfloat()) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (have_bigfloat()) { |
4 |
0 |
4 |
|
| 490 |
4 |
| tmp_sv = newSVpvn(data, data_len); |
| 491 |
4 |
| sv_val = get_new_big_float(tmp_sv); |
| 492 |
4 |
| SvREFCNT_dec(tmp_sv); |
| 493 |
|
| } |
| 494 |
|
| } |
| 495 |
|
| else { |
| 496 |
3 |
▶ | if (have_bigint()) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (have_bigint()) { |
3 |
0 |
3 |
|
| 497 |
3 |
| tmp_sv = newSVpvn(data, data_len); |
| 498 |
3 |
| sv_val = get_new_big_int(tmp_sv); |
| 499 |
3 |
| SvREFCNT_dec(tmp_sv); |
| 500 |
|
| } |
| 501 |
|
| } |
| 502 |
|
| |
| 503 |
7 |
▶ | if (sv_val) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_val) { |
7 |
0 |
7 |
|
| 504 |
7 |
▶ | if (SvOK(sv_val)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvOK(sv_val)) { |
7 |
0 |
7 |
|
| 505 |
7 |
| number_done = 1; |
| 506 |
|
| } |
| 507 |
|
| else { |
| 508 |
0 |
| SvREFCNT_dec(sv_val); |
| 509 |
0 |
| sv_val = Nullsv; |
| 510 |
|
| } |
| 511 |
|
| } |
| 512 |
|
| } |
| 513 |
|
| |
| 514 |
161 |
▶ | UNLESS (number_done) { |
Branch: 1 branch
| Branch | True | False | Total |
| UNLESS (number_done) { |
154 |
7 |
161 |
|
| 515 |
154 |
| sv_val = newSVpvn(data, data_len); |
| 516 |
|
| |
| 517 |
154 |
▶ | if (try_big_num) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (try_big_num) { |
0 |
154 |
154 |
|
| 518 |
|
| /* we're in danger of overflow, so leave it as a string */ |
| 519 |
0 |
| SvUTF8_on(sv_val); |
| 520 |
|
| } |
| 521 |
|
| else { |
| 522 |
154 |
▶ | if (flags & (JSON_EVT_PARSE_NUMBER_HAVE_DECIMAL | JSON_EVT_PARSE_NUMBER_HAVE_EXPONENT)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (flags & (JSON_EVT_PARSE_NUMBER_HAVE_DECIMAL | JSON_EVT_PARSE_NUMBER_HAVE_EXPONENT)) { |
42 |
112 |
154 |
|
| 523 |
|
| |
| 524 |
|
| /* float */ |
| 525 |
42 |
| nv_val = SvNV(sv_val); |
| 526 |
42 |
| sv_setnv(sv_val, nv_val); |
| 527 |
|
| } |
| 528 |
112 |
▶ | else if (flags & JSON_EVT_PARSE_NUMBER_HAVE_SIGN) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (flags & JSON_EVT_PARSE_NUMBER_HAVE_SIGN) { |
2 |
110 |
112 |
|
| 529 |
|
| /* signed int */ |
| 530 |
2 |
| iv_val = SvIV(sv_val); |
| 531 |
2 |
| sv_setiv(sv_val, iv_val); |
| 532 |
|
| } |
| 533 |
|
| else { |
| 534 |
|
| /* unsigned int */ |
| 535 |
110 |
| uv_val = SvUV(sv_val); |
| 536 |
110 |
| sv_setuv(sv_val, uv_val); |
| 537 |
|
| } |
| 538 |
|
| } |
| 539 |
|
| |
| 540 |
|
| } |
| 541 |
|
| |
| 542 |
161 |
| push_stack_val(ctx, sv_val); |
| 543 |
|
| |
| 544 |
161 |
| return 0; |
| 545 |
|
| } |
| 546 |
|
| |
| 547 |
|
| static int |
| 548 |
167 |
| array_begin_callback(void * cb_data, uint flags, uint level) { |
| 549 |
167 |
| parse_callback_ctx * ctx = (parse_callback_ctx *)cb_data; |
| 550 |
|
| |
| 551 |
167 |
| push_stack_val(ctx, newRV_noinc((SV *)newAV())); |
| 552 |
|
| |
| 553 |
|
| LOG_DEBUG("\nin array_begin callback at level %u\n", level); |
| 554 |
|
| |
| 555 |
167 |
| return 0; |
| 556 |
|
| } |
| 557 |
|
| |
| 558 |
|
| static int |
| 559 |
153 |
| array_end_callback(void * cb_data, uint flags, uint level) { |
| 560 |
153 |
| parse_callback_ctx * ctx = (parse_callback_ctx *)cb_data; |
| 561 |
|
| |
| 562 |
153 |
▶ | if (CUR_STACK_LEVEL(ctx) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (CUR_STACK_LEVEL(ctx) > 0) { |
140 |
13 |
153 |
|
| 563 |
140 |
| POP_STACK(ctx); |
| 564 |
|
| } |
| 565 |
|
| |
| 566 |
|
| LOG_DEBUG("\nin array_end callback at level %u\n", level); |
| 567 |
|
| |
| 568 |
153 |
| return 0; |
| 569 |
|
| } |
| 570 |
|
| |
| 571 |
|
| |
| 572 |
|
| static int |
| 573 |
264 |
| array_element_end_callback(void * cb_data, uint flags, uint level) { |
| 574 |
264 |
| parse_callback_ctx * ctx = (parse_callback_ctx *)cb_data; |
| 575 |
|
| |
| 576 |
|
| LOG_DEBUG("\nin array element end callback at level %u\n", level); |
| 577 |
|
| |
| 578 |
|
| /* |
| 579 |
|
| fprintf(stderr, "=====> HERE 4 -- start_depth=%d, level=%u\n", (int)ctx->start_depth, |
| 580 |
|
| level); |
| 581 |
|
| */ |
| 582 |
|
| |
| 583 |
264 |
▶ | if (level == ctx->start_depth && ctx->start_depth > 0 |
Branch: 2 branches
| Branch | True | False | Total |
| if (level == ctx->start_depth && ctx->start_depth > 0 |
2 |
262 |
264 |
| if (level == ctx->start_depth && ctx->start_depth > 0 |
2 |
0 |
2 |
|
| 584 |
2 |
▶ | && ctx->start_depth_handler) { |
Branch: 1 branch
| Branch | True | False | Total |
| && ctx->start_depth_handler) { |
2 |
0 |
2 |
|
| 585 |
|
| SV *rv; |
| 586 |
2 |
| parse_cb_stack_entry *entry = CUR_STACK_ENTRY(ctx); |
| 587 |
|
| SV *val; |
| 588 |
|
| |
| 589 |
2 |
| val = av_pop((AV *)SvRV(entry->data)); |
| 590 |
|
| |
| 591 |
2 |
| rv = json_call_function_one_arg_one_return(ctx->start_depth_handler, val); |
| 592 |
|
| |
| 593 |
|
| /* |
| 594 |
|
| parse_cb_stack_entry *entry = CUR_STACK_ENTRY(ctx); |
| 595 |
|
| SV *data = entry->data; |
| 596 |
|
| SV *rv; |
| 597 |
|
| |
| 598 |
|
| data = av_pop((AV *)entry->data); |
| 599 |
|
| */ |
| 600 |
|
| |
| 601 |
|
| /* rv will be a mortal, so don't decrement it's ref count */ |
| 602 |
|
| /* rv = json_call_function_one_arg_one_return(ctx->start_depth_handler, data); */ |
| 603 |
|
| |
| 604 |
|
| /* POP_STACK(ctx); */ |
| 605 |
|
| /* entry = CUR_STACK_ENTRY(ctx); */ |
| 606 |
|
| |
| 607 |
|
| /* |
| 608 |
|
| data = av_pop((AV *)entry->data); |
| 609 |
|
| SvREFCNT_dec(data); |
| 610 |
|
| */ |
| 611 |
|
| |
| 612 |
|
| /* FIXME: check whether ref count gets decremented when popped off the array */ |
| 613 |
|
| |
| 614 |
2 |
▶ | UNLESS (SvOK(rv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| UNLESS (SvOK(rv)) { |
0 |
2 |
2 |
|
| 615 |
0 |
| return 1; |
| 616 |
|
| } |
| 617 |
|
| } |
| 618 |
|
| |
| 619 |
|
| |
| 620 |
264 |
| return 0; |
| 621 |
|
| } |
| 622 |
|
| |
| 623 |
|
| #if 0 |
| 624 |
|
| static int |
| 625 |
|
| array_element_begin_callback(void * cb_data, uint flags, uint level) { |
| 626 |
|
| LOG_DEBUG("\nin array element begin callback at level %u\n", level); |
| 627 |
|
| |
| 628 |
|
| return 0; |
| 629 |
|
| } |
| 630 |
|
| |
| 631 |
|
| #endif |
| 632 |
|
| |
| 633 |
|
| static int |
| 634 |
249 |
| hash_begin_callback(void * cb_data, uint flags, uint level) { |
| 635 |
249 |
| parse_callback_ctx * ctx = (parse_callback_ctx *)cb_data; |
| 636 |
|
| |
| 637 |
249 |
| push_stack_val(ctx, newRV_noinc((SV *)newHV())); |
| 638 |
|
| |
| 639 |
|
| LOG_DEBUG("in hash_begin callback at level %u, cb_data is %"UVxf, level, PTR2UV(ctx)); |
| 640 |
|
| |
| 641 |
249 |
| return 0; |
| 642 |
|
| } |
| 643 |
|
| |
| 644 |
|
| static int |
| 645 |
217 |
| hash_end_callback(void * cb_data, uint flags, uint level) { |
| 646 |
217 |
| parse_callback_ctx * ctx = (parse_callback_ctx *)cb_data; |
| 647 |
|
| |
| 648 |
|
| |
| 649 |
217 |
▶ | if (CUR_STACK_LEVEL(ctx) > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (CUR_STACK_LEVEL(ctx) > 0) { |
111 |
106 |
217 |
|
| 650 |
111 |
| POP_STACK(ctx); |
| 651 |
|
| } |
| 652 |
|
| |
| 653 |
|
| LOG_DEBUG("in hash_end callback at level %u, cb_data is %"UVxf, level, PTR2UV(ctx)); |
| 654 |
|
| |
| 655 |
217 |
| return 0; |
| 656 |
|
| } |
| 657 |
|
| |
| 658 |
|
| #if 0 |
| 659 |
|
| static int |
| 660 |
|
| hash_entry_begin_callback(void * cb_data, uint flags, uint level) { |
| 661 |
|
| |
| 662 |
|
| /* parse_callback_ctx * ctx = (parse_callback_ctx *)cb_data; */ |
| 663 |
|
| LOG_DEBUG("in hash_entry_begin callback at level %u", level); |
| 664 |
|
| |
| 665 |
|
| return 0; |
| 666 |
|
| } |
| 667 |
|
| |
| 668 |
|
| static int |
| 669 |
|
| hash_entry_end_callback(void * cb_data, uint flags, uint level) { |
| 670 |
|
| LOG_DEBUG("\nin hash_entry_end callback at level %u, stack_level %d\n", level, ctx->stack_level); |
| 671 |
|
| return 0; |
| 672 |
|
| } |
| 673 |
|
| #endif |
| 674 |
|
| |
| 675 |
|
| static int |
| 676 |
59 |
| bool_callback(void * cb_data, uint bool_val, uint flags, uint level) { |
| 677 |
59 |
| parse_callback_ctx * ctx = (parse_callback_ctx *)cb_data; |
| 678 |
59 |
| SV * s = Nullsv; |
| 679 |
59 |
| SV *arg = Nullsv; |
| 680 |
|
| |
| 681 |
59 |
▶ | if (ctx->parse_const_cb) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->parse_const_cb) { |
2 |
57 |
59 |
|
| 682 |
2 |
▶ | if (bool_val) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (bool_val) { |
1 |
1 |
2 |
|
| 683 |
1 |
| arg = newSVpv("true", 4); |
| 684 |
|
| } |
| 685 |
|
| else { |
| 686 |
1 |
| arg = newSVpv("false", 5); |
| 687 |
|
| } |
| 688 |
|
| |
| 689 |
2 |
| s = json_call_function_one_arg_one_return(ctx->parse_const_cb, arg); |
| 690 |
2 |
| SvREFCNT_dec(arg); |
| 691 |
|
| } |
| 692 |
57 |
▶ | else if (ctx->options & EVT_OPTION_CONVERT_BOOL) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (ctx->options & EVT_OPTION_CONVERT_BOOL) { |
4 |
53 |
57 |
|
| 693 |
4 |
| s = get_new_bool_obj(bool_val); |
| 694 |
|
| } |
| 695 |
|
| else { |
| 696 |
53 |
▶ | s = bool_val ? newSVuv(1) : newSVpvn("", 0); |
Branch: 1 branch
| Branch | True | False | Total |
| s = bool_val ? newSVuv(1) : newSVpvn("", 0); |
30 |
23 |
53 |
|
| 697 |
|
| } |
| 698 |
|
| |
| 699 |
59 |
| push_stack_val(ctx, s); |
| 700 |
|
| |
| 701 |
|
| LOG_DEBUG("\nin bool_callback with val %u at level %u\n", bool_val, level); |
| 702 |
|
| |
| 703 |
59 |
| return 0; |
| 704 |
|
| } |
| 705 |
|
| |
| 706 |
|
| static int |
| 707 |
26 |
| null_callback(void * cb_data, uint flags, uint level) { |
| 708 |
26 |
| parse_callback_ctx * ctx = (parse_callback_ctx *)cb_data; |
| 709 |
26 |
| SV * s = Nullsv; |
| 710 |
26 |
| SV * arg = Nullsv; |
| 711 |
|
| |
| 712 |
26 |
▶ | if (ctx->parse_const_cb) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx->parse_const_cb) { |
1 |
25 |
26 |
|
| 713 |
1 |
| arg = newSVpv("null", 4); |
| 714 |
1 |
| s = json_call_function_one_arg_one_return(ctx->parse_const_cb, arg); |
| 715 |
1 |
| SvREFCNT_dec(arg); |
| 716 |
|
| } |
| 717 |
|
| else { |
| 718 |
25 |
| s = newSV(0); |
| 719 |
|
| } |
| 720 |
|
| |
| 721 |
26 |
| push_stack_val(ctx, s); |
| 722 |
|
| |
| 723 |
26 |
| return 0; |
| 724 |
|
| } |
| 725 |
|
| |
| 726 |
|
| static int |
| 727 |
2 |
| sv_str_eq(SV * sv_val, const char * c_buf, STRLEN c_buf_len) { |
| 728 |
2 |
| STRLEN sv_len = 0; |
| 729 |
|
| char * sv_buf; |
| 730 |
|
| |
| 731 |
2 |
| sv_buf = SvPV(sv_val, sv_len); |
| 732 |
|
| |
| 733 |
2 |
▶ | UNLESS (sv_len == c_buf_len) { |
Branch: 1 branch
| Branch | True | False | Total |
| UNLESS (sv_len == c_buf_len) { |
0 |
2 |
2 |
|
| 734 |
0 |
| return 0; |
| 735 |
|
| } |
| 736 |
|
| |
| 737 |
2 |
▶ | UNLESS (memcmp((void *)sv_buf, (void *)c_buf, (size_t)c_buf_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| UNLESS (memcmp((void *)sv_buf, (void *)c_buf, (size_t)c_buf_len)) { |
2 |
0 |
2 |
|
| 738 |
2 |
| return 1; |
| 739 |
|
| } |
| 740 |
|
| |
| 741 |
0 |
| return 0; |
| 742 |
|
| } |
| 743 |
|
| |
| 744 |
|
| static int |
| 745 |
26 |
| setup_options(jsonevt_ctx * json_ctx, parse_callback_ctx * ctx, SV * self_sv) { |
| 746 |
|
| SV ** ptr; |
| 747 |
|
| HV * self_hash; |
| 748 |
26 |
| IV num_keys = 0; |
| 749 |
|
| |
| 750 |
26 |
▶ | UNLESS (self_sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| UNLESS (self_sv) { |
0 |
26 |
26 |
|
| 751 |
0 |
| return 0; |
| 752 |
|
| } |
| 753 |
|
| |
| 754 |
26 |
▶ | if (SvROK(self_sv)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(self_sv)) { |
26 |
0 |
26 |
|
| 755 |
26 |
| self_hash = (HV *)SvRV(self_sv); |
| 756 |
|
| } |
| 757 |
|
| else { |
| 758 |
0 |
| self_hash = (HV *)self_sv; |
| 759 |
|
| } |
| 760 |
|
| |
| 761 |
26 |
▶ | if (SvTYPE(self_hash) != SVt_PVHV) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTYPE(self_hash) != SVt_PVHV) { |
0 |
26 |
26 |
|
| 762 |
0 |
| return 0; |
| 763 |
|
| } |
| 764 |
|
| |
| 765 |
26 |
▶ | num_keys = HvKEYS(self_hash); |
Branch: 1 branch
| Branch | True | False | Total |
| num_keys = HvKEYS(self_hash); |
0 |
26 |
26 |
|
| 766 |
|
| |
| 767 |
26 |
▶ | if (num_keys == 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (num_keys == 0) { |
0 |
26 |
26 |
|
| 768 |
0 |
| return 0; |
| 769 |
|
| } |
| 770 |
|
| |
| 771 |
26 |
| ptr = hv_fetch((HV *)self_hash, "convert_bool", 12, 0); |
| 772 |
26 |
▶ | if (ptr && SvTRUE(*ptr)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ptr && SvTRUE(*ptr)) { |
4 |
22 |
26 |
| if (ptr && SvTRUE(*ptr)) { |
4 |
0 |
4 |
|
| 773 |
4 |
| ctx->options |= EVT_OPTION_CONVERT_BOOL; |
| 774 |
|
| } |
| 775 |
|
| |
| 776 |
26 |
| ptr = hv_fetch((HV *)self_hash, "use_exceptions", 14, 0); |
| 777 |
26 |
▶ | if (ptr && SvTRUE(*ptr)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ptr && SvTRUE(*ptr)) { |
6 |
20 |
26 |
| if (ptr && SvTRUE(*ptr)) { |
6 |
0 |
6 |
|
| 778 |
6 |
| ctx->options |= EVT_OPTION_USE_EXCEPTIONS; |
| 779 |
|
| } |
| 780 |
|
| |
| 781 |
26 |
| ptr = hv_fetch((HV *)self_hash, "bad_char_policy", 15, 0); |
| 782 |
26 |
▶ | if (ptr && SvTRUE(*ptr)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ptr && SvTRUE(*ptr)) { |
2 |
24 |
26 |
| if (ptr && SvTRUE(*ptr)) { |
2 |
0 |
2 |
|
| 783 |
2 |
▶ | if (sv_str_eq(*ptr, "convert", 7)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (sv_str_eq(*ptr, "convert", 7)) { |
2 |
0 |
2 |
|
| 784 |
2 |
| jsonevt_set_bad_char_policy(json_ctx, JSON_EVT_OPTION_BAD_CHAR_POLICY_CONVERT); |
| 785 |
|
| } |
| 786 |
0 |
▶ | else if (sv_str_eq(*ptr, "pass_through", 12)) { |
Branch: 1 branch
| Branch | True | False | Total |
| else if (sv_str_eq(*ptr, "pass_through", 12)) { |
0 |
0 |
0 |
|
| 787 |
0 |
| jsonevt_set_bad_char_policy(json_ctx, JSON_EVT_OPTION_BAD_CHAR_POLICY_PASS); |
| 788 |
|
| } |
| 789 |
|
| } |
| 790 |
|
| |
| 791 |
26 |
| ptr = hv_fetch((HV *)self_hash, "parse_number", 12, 0); |
| 792 |
26 |
▶ | if (ptr && SvTRUE(*ptr)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ptr && SvTRUE(*ptr)) { |
1 |
25 |
26 |
| if (ptr && SvTRUE(*ptr)) { |
1 |
0 |
1 |
|
| 793 |
1 |
| ctx->parse_number_cb = newSVsv(*ptr); |
| 794 |
|
| } |
| 795 |
|
| |
| 796 |
26 |
| ptr = hv_fetch((HV *)self_hash, "parse_constant", 14, 0); |
| 797 |
26 |
▶ | if (ptr && SvTRUE(*ptr)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ptr && SvTRUE(*ptr)) { |
1 |
25 |
26 |
| if (ptr && SvTRUE(*ptr)) { |
1 |
0 |
1 |
|
| 798 |
1 |
| ctx->parse_const_cb = newSVsv(*ptr); |
| 799 |
|
| } |
| 800 |
|
| |
| 801 |
26 |
| ptr = hv_fetch((HV *)self_hash, "start_depth", 11, 0); |
| 802 |
26 |
▶ | if (ptr && SvOK(*ptr)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ptr && SvOK(*ptr)) { |
1 |
25 |
26 |
| if (ptr && SvOK(*ptr)) { |
1 |
0 |
1 |
|
| 803 |
1 |
| ctx->start_depth = SvIV(*ptr); |
| 804 |
1 |
| ptr = hv_fetch((HV *)self_hash, "start_depth_handler", 19, 0); |
| 805 |
|
| |
| 806 |
1 |
▶ | if (ptr && SvOK(*ptr)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (ptr && SvOK(*ptr)) { |
1 |
0 |
1 |
| if (ptr && SvOK(*ptr)) { |
1 |
0 |
1 |
|
| 807 |
1 |
| ctx->start_depth_handler = *ptr; |
| 808 |
1 |
| SvREFCNT_inc(ctx->start_depth_handler); |
| 809 |
|
| } |
| 810 |
|
| } |
| 811 |
|
| else { |
| 812 |
25 |
| ctx->start_depth = -1; |
| 813 |
|
| } |
| 814 |
|
| |
| 815 |
26 |
| return 1; |
| 816 |
|
| } |
| 817 |
|
| |
| 818 |
|
| SV * |
| 819 |
0 |
| do_json_dummy_parse(SV * self_sv, SV * json_str_sv) { |
| 820 |
0 |
| SV *rv = Nullsv; |
| 821 |
0 |
| jsonevt_ctx *ctx = jsonevt_new_ctx(); |
| 822 |
|
| char *buf; |
| 823 |
|
| STRLEN buf_len; |
| 824 |
|
| |
| 825 |
0 |
| buf = SvPV(json_str_sv, buf_len); |
| 826 |
0 |
▶ | if (jsonevt_parse(ctx, buf, buf_len)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (jsonevt_parse(ctx, buf, buf_len)) { |
0 |
0 |
0 |
|
| 827 |
|
| /* success */ |
| 828 |
0 |
| rv = &PL_sv_yes; |
| 829 |
|
| } |
| 830 |
|
| else { |
| 831 |
0 |
| rv = &PL_sv_undef; |
| 832 |
|
| } |
| 833 |
|
| |
| 834 |
0 |
| jsonevt_free_ctx(ctx); |
| 835 |
|
| |
| 836 |
0 |
| return rv; |
| 837 |
|
| } |
| 838 |
|
| |
| 839 |
|
| static jsonevt_ctx * |
| 840 |
192 |
| init_cbs(perl_wrapper_ctx * pwctx, SV * self_sv) { |
| 841 |
|
| /* static jsonevt_ctx * ctx = (jsonevt_ctx *)0; */ |
| 842 |
|
| |
| 843 |
|
| /* FIXME: need to find a way to reuse this without making it a static var */ |
| 844 |
192 |
| jsonevt_ctx * ctx = (jsonevt_ctx *)0; |
| 845 |
|
| |
| 846 |
|
| /* jsonevt_ctx * ctx = jsonevt_new_ctx(); */ |
| 847 |
|
| parse_callback_ctx * cb_data; |
| 848 |
|
| /* |
| 849 |
|
| char * error = Nullch; |
| 850 |
|
| SV * rv = Nullsv; |
| 851 |
|
| HV * error_hash = Nullhv; |
| 852 |
|
| HV * stats = Nullhv; |
| 853 |
|
| int throw_exception = 0; |
| 854 |
|
| SV * tmp_sv = Nullsv; |
| 855 |
|
| SV * error_msg = Nullsv; |
| 856 |
|
| SV * error_data_ref = Nullsv; |
| 857 |
|
| SV * stats_ref = Nullsv; |
| 858 |
|
| */ |
| 859 |
|
| |
| 860 |
|
| SETUP_TRACE; |
| 861 |
|
| |
| 862 |
192 |
▶ | UNLESS (ctx) { |
Branch: 1 branch
| Branch | True | False | Total |
| UNLESS (ctx) { |
192 |
0 |
192 |
|
| 863 |
192 |
| ctx = jsonevt_new_ctx(); |
| 864 |
|
| |
| 865 |
|
| LOG_DEBUG("creating ctx %#08"UVxf, PTR2UV(ctx)); |
| 866 |
|
| |
| 867 |
192 |
| jsonevt_set_string_cb(ctx, string_callback); |
| 868 |
192 |
| jsonevt_set_number_cb(ctx, number_callback); |
| 869 |
192 |
| jsonevt_set_begin_array_cb(ctx, array_begin_callback); |
| 870 |
192 |
| jsonevt_set_end_array_cb(ctx, array_end_callback); |
| 871 |
|
| /* |
| 872 |
|
| jsonevt_set_begin_array_element_cb(ctx, array_element_begin_callback); |
| 873 |
|
| */ |
| 874 |
192 |
| jsonevt_set_end_array_element_cb(ctx, array_element_end_callback); |
| 875 |
|
| |
| 876 |
192 |
| jsonevt_set_begin_hash_cb(ctx, hash_begin_callback); |
| 877 |
192 |
| jsonevt_set_end_hash_cb(ctx, hash_end_callback); |
| 878 |
|
| /* |
| 879 |
|
| jsonevt_set_begin_hash_entry_cb(ctx, hash_entry_begin_callback); |
| 880 |
|
| jsonevt_set_end_hash_entry_cb(ctx, hash_entry_end_callback); |
| 881 |
|
| */ |
| 882 |
|
| |
| 883 |
192 |
| jsonevt_set_bool_cb(ctx, bool_callback); |
| 884 |
192 |
| jsonevt_set_null_cb(ctx, null_callback); |
| 885 |
|
| } |
| 886 |
|
| |
| 887 |
192 |
| memzero(pwctx, sizeof(*pwctx)); |
| 888 |
192 |
| cb_data = &pwctx->cbd; |
| 889 |
|
| |
| 890 |
|
| /* memzero(&cb_data, sizeof(parse_callback_ctx)); */ |
| 891 |
|
| |
| 892 |
192 |
| cb_data->stack_size = 64; |
| 893 |
|
| |
| 894 |
192 |
| JSONEVT_NEW(cb_data->stack, cb_data->stack_size, parse_cb_stack_entry); |
| 895 |
|
| |
| 896 |
192 |
| cb_data->stack_level = -1; |
| 897 |
192 |
| memzero(cb_data->stack, cb_data->stack_size * sizeof(parse_cb_stack_entry)); |
| 898 |
|
| |
| 899 |
192 |
| jsonevt_set_cb_data(ctx, cb_data); |
| 900 |
|
| |
| 901 |
192 |
▶ | if (self_sv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (self_sv) { |
26 |
166 |
192 |
|
| 902 |
26 |
| setup_options(ctx, cb_data, self_sv); |
| 903 |
|
| } |
| 904 |
|
| |
| 905 |
192 |
| return ctx; |
| 906 |
|
| } |
| 907 |
|
| |
| 908 |
|
| static SV * |
| 909 |
192 |
| handle_parse_result(int result, jsonevt_ctx * ctx, perl_wrapper_ctx * wctx) { |
| 910 |
192 |
| char * error = Nullch; |
| 911 |
192 |
| SV * rv = Nullsv; |
| 912 |
192 |
| HV * error_hash = Nullhv; |
| 913 |
192 |
| int throw_exception = 0; |
| 914 |
192 |
| SV * tmp_sv = Nullsv; |
| 915 |
192 |
| SV * error_msg = Nullsv; |
| 916 |
192 |
| SV * error_data_ref = Nullsv; |
| 917 |
192 |
| SV * stats_ref = Nullsv; |
| 918 |
192 |
| HV * stats = Nullhv; |
| 919 |
|
| |
| 920 |
192 |
▶ | UNLESS (result) { |
Branch: 1 branch
| Branch | True | False | Total |
| UNLESS (result) { |
61 |
131 |
192 |
|
| 921 |
|
| SETUP_TRACE; |
| 922 |
|
| |
| 923 |
61 |
| error = jsonevt_get_error(ctx); |
| 924 |
|
| |
| 925 |
61 |
▶ | if (wctx->cbd.options & EVT_OPTION_USE_EXCEPTIONS) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (wctx->cbd.options & EVT_OPTION_USE_EXCEPTIONS) { |
6 |
55 |
61 |
|
| 926 |
6 |
| throw_exception = 1; |
| 927 |
|
| } |
| 928 |
|
| |
| 929 |
|
| SETUP_TRACE; |
| 930 |
|
| |
| 931 |
|
| LOG_DEBUG("\nError: %s\n\n", error); |
| 932 |
61 |
▶ | if (error) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (error) { |
61 |
0 |
61 |
|
| 933 |
61 |
| error_msg = newSVpvf("%s v%s %s", MOD_NAME, XS_VERSION, error); |
| 934 |
|
| } |
| 935 |
|
| else { |
| 936 |
0 |
| error_msg = newSVpvf("%s v%s - error", MOD_NAME, XS_VERSION); |
| 937 |
|
| } |
| 938 |
|
| |
| 939 |
61 |
| error_hash = newHV(); |
| 940 |
|
| |
| 941 |
61 |
| error_data_ref = newRV_noinc((SV *)error_hash); |
| 942 |
|
| |
| 943 |
61 |
| IGNORE_RV(hv_store(error_hash, "version", 7, newSVpvf("%s", XS_VERSION), 0)); |
| 944 |
61 |
| IGNORE_RV(hv_store(error_hash, "char", 4, newSVuv(jsonevt_get_error_char_pos(ctx)), 0)); |
| 945 |
61 |
| IGNORE_RV(hv_store(error_hash, "byte", 4, newSVuv(jsonevt_get_error_byte_pos(ctx)), 0)); |
| 946 |
61 |
| IGNORE_RV(hv_store(error_hash, "line", 4, newSVuv(jsonevt_get_error_line(ctx)), 0)); |
| 947 |
61 |
| IGNORE_RV(hv_store(error_hash, "col", 3, newSVuv(jsonevt_get_error_char_col(ctx)), 0)); |
| 948 |
61 |
| IGNORE_RV(hv_store(error_hash, "byte_col", 8, newSVuv(jsonevt_get_error_byte_col(ctx)), 0)); |
| 949 |
|
| |
| 950 |
61 |
| tmp_sv = get_sv("JSON::DWIW::LastErrorData", 1); |
| 951 |
61 |
| sv_setsv(tmp_sv, error_data_ref); |
| 952 |
61 |
| SvREFCNT_dec(error_data_ref); |
| 953 |
|
| |
| 954 |
61 |
| tmp_sv = get_sv("JSON::DWIW::LastError", 1); |
| 955 |
61 |
| sv_setsv(tmp_sv, error_msg); /* ref count decremented below after exceptions check */ |
| 956 |
|
| |
| 957 |
61 |
| tmp_sv = get_sv("JSON::DWIW::Last_Stats", 1); |
| 958 |
61 |
| sv_setsv(tmp_sv, &PL_sv_undef); |
| 959 |
|
| |
| 960 |
61 |
▶ | if (wctx->cbd.stack[0].data) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (wctx->cbd.stack[0].data) { |
51 |
10 |
61 |
|
| 961 |
51 |
| SvREFCNT_dec(wctx->cbd.stack[0].data); |
| 962 |
|
| } |
| 963 |
|
| |
| 964 |
|
| SETUP_TRACE; |
| 965 |
|
| } |
| 966 |
|
| else { |
| 967 |
|
| SETUP_TRACE; |
| 968 |
131 |
| rv = wctx->cbd.stack[0].data; |
| 969 |
131 |
| stats = newHV(); |
| 970 |
|
| |
| 971 |
131 |
| IGNORE_RV(hv_store(stats, "strings", 7, |
| 972 |
|
| newSVuv(jsonevt_get_stats_string_count(ctx)), 0)); |
| 973 |
131 |
| IGNORE_RV(hv_store(stats, "max_string_bytes", 16, |
| 974 |
|
| newSVuv(jsonevt_get_stats_longest_string_bytes(ctx)), 0)); |
| 975 |
131 |
| IGNORE_RV(hv_store(stats, "max_string_chars", 16, |
| 976 |
|
| newSVuv(jsonevt_get_stats_longest_string_chars(ctx)), 0)); |
| 977 |
131 |
| IGNORE_RV(hv_store(stats, "numbers", 7, |
| 978 |
|
| newSVuv(jsonevt_get_stats_number_count(ctx)), 0)); |
| 979 |
131 |
| IGNORE_RV(hv_store(stats, "bools", 5, newSVuv(jsonevt_get_stats_bool_count(ctx)), 0)); |
| 980 |
131 |
| IGNORE_RV(hv_store(stats, "nulls", 5, newSVuv(jsonevt_get_stats_null_count(ctx)), 0)); |
| 981 |
131 |
| IGNORE_RV(hv_store(stats, "hashes", 6, newSVuv(jsonevt_get_stats_hash_count(ctx)), 0)); |
| 982 |
131 |
| IGNORE_RV(hv_store(stats, "arrays", 6, newSVuv(jsonevt_get_stats_array_count(ctx)), 0)); |
| 983 |
131 |
| IGNORE_RV(hv_store(stats, "max_depth", 9, |
| 984 |
|
| newSVuv(jsonevt_get_stats_deepest_level(ctx)), 0)); |
| 985 |
|
| |
| 986 |
131 |
| IGNORE_RV(hv_store(stats, "lines", 5, newSVuv(jsonevt_get_stats_line_count(ctx)), 0)); |
| 987 |
131 |
| IGNORE_RV(hv_store(stats, "bytes", 5, newSVuv(jsonevt_get_stats_byte_count(ctx)), 0)); |
| 988 |
131 |
| IGNORE_RV(hv_store(stats, "chars", 5, newSVuv(jsonevt_get_stats_char_count(ctx)), 0)); |
| 989 |
|
| |
| 990 |
131 |
| tmp_sv = get_sv("JSON::DWIW::Last_Stats", 1); |
| 991 |
131 |
| stats_ref = newRV_noinc((SV *)stats); |
| 992 |
131 |
| sv_setsv(tmp_sv, stats_ref); |
| 993 |
131 |
| SvREFCNT_dec(stats_ref); |
| 994 |
|
| |
| 995 |
131 |
| tmp_sv = get_sv("JSON::DWIW::LastErrorData", 1); |
| 996 |
131 |
| sv_setsv(tmp_sv, &PL_sv_undef); |
| 997 |
|
| |
| 998 |
131 |
| tmp_sv = get_sv("JSON::DWIW::LastError", 1); |
| 999 |
131 |
| sv_setsv(tmp_sv, &PL_sv_undef); |
| 1000 |
|
| } |
| 1001 |
|
| |
| 1002 |
|
| /* fix memory leak -- the stack was allocated in init_cbs() */ |
| 1003 |
192 |
| JSONEVT_FREE_MEM(wctx->cbd.stack); wctx->cbd.stack = NULL; |
| 1004 |
192 |
▶ | if (wctx->cbd.parse_number_cb) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (wctx->cbd.parse_number_cb) { |
1 |
191 |
192 |
|
| 1005 |
1 |
| SvREFCNT_dec(wctx->cbd.parse_number_cb); |
| 1006 |
|
| } |
| 1007 |
|
| |
| 1008 |
192 |
▶ | if (wctx->cbd.parse_const_cb) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (wctx->cbd.parse_const_cb) { |
1 |
191 |
192 |
|
| 1009 |
1 |
| SvREFCNT_dec(wctx->cbd.parse_const_cb); |
| 1010 |
|
| } |
| 1011 |
|
| |
| 1012 |
192 |
▶ | if (wctx->cbd.start_depth_handler) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (wctx->cbd.start_depth_handler) { |
1 |
191 |
192 |
|
| 1013 |
1 |
| SvREFCNT_dec(wctx->cbd.start_depth_handler); |
| 1014 |
|
| } |
| 1015 |
|
| |
| 1016 |
|
| /* change to json_reset_ctx(ctx) once we start reusing the ctx from libjsonevt */ |
| 1017 |
|
| /* jsonevt_reset_ctx(ctx); */ |
| 1018 |
|
| LOG_DEBUG("freeing ctx %#08"UVxf, PTR2UV(ctx)); |
| 1019 |
192 |
| jsonevt_free_ctx(ctx); |
| 1020 |
|
| |
| 1021 |
192 |
▶ | if (throw_exception) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (throw_exception) { |
6 |
186 |
192 |
|
| 1022 |
6 |
| tmp_sv = get_sv("@", TRUE); |
| 1023 |
6 |
| sv_setsv(tmp_sv, error_msg); |
| 1024 |
6 |
| SvREFCNT_dec(error_msg); |
| 1025 |
|
| |
| 1026 |
6 |
▶ | if (error) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (error) { |
6 |
0 |
6 |
|
| 1027 |
6 |
| croak("%s v%s %s", MOD_NAME, XS_VERSION, error); |
| 1028 |
|
| } |
| 1029 |
|
| else { |
| 1030 |
0 |
| croak("%s v%s - error", MOD_NAME, XS_VERSION); |
| 1031 |
|
| } |
| 1032 |
|
| |
| 1033 |
|
| } |
| 1034 |
|
| |
| 1035 |
186 |
| SvREFCNT_dec(error_msg); |
| 1036 |
|
| |
| 1037 |
|
| /* LOG_DEBUG("\n\noriginal buf: %s\n\n", buf); */ |
| 1038 |
|
| |
| 1039 |
186 |
▶ | if (rv) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (rv) { |
131 |
55 |
186 |
|
| 1040 |
|
| LOG_DEBUG("returning rv"); |
| 1041 |
|
| /* return &PL_sv_yes; */ |
| 1042 |
131 |
| return rv; |
| 1043 |
|
| } |
| 1044 |
|
| else { |
| 1045 |
|
| LOG_DEBUG("returning undef"); |
| 1046 |
55 |
| return &PL_sv_undef; |
| 1047 |
|
| } |
| 1048 |
|
| |
| 1049 |
|
| return &PL_sv_undef; |
| 1050 |
|
| } |
| 1051 |
|
| |
| 1052 |
|
| SV * |
| 1053 |
148 |
| do_json_parse_buf(SV * self_sv, char * buf, STRLEN buf_len) { |
| 1054 |
|
| jsonevt_ctx * ctx; |
| 1055 |
|
| perl_wrapper_ctx wctx; |
| 1056 |
|
| |
| 1057 |
|
| SETUP_TRACE; |
| 1058 |
|
| |
| 1059 |
148 |
| memzero(&wctx, sizeof(perl_wrapper_ctx)); |
| 1060 |
148 |
| ctx = init_cbs(&wctx, self_sv); |
| 1061 |
|
| |
| 1062 |
148 |
| return handle_parse_result(jsonevt_parse(ctx, buf, buf_len), ctx, &wctx); |
| 1063 |
|
| } |
| 1064 |
|
| |
| 1065 |
|
| SV * |
| 1066 |
0 |
| do_json_parse(SV * self_sv, SV * json_str_sv) { |
| 1067 |
|
| char * buf; |
| 1068 |
|
| STRLEN buf_len; |
| 1069 |
|
| |
| 1070 |
|
| SETUP_TRACE; |
| 1071 |
|
| |
| 1072 |
0 |
| buf = SvPV(json_str_sv, buf_len); |
| 1073 |
|
| |
| 1074 |
0 |
| return do_json_parse_buf(self_sv, buf, buf_len); |
| 1075 |
|
| } |
| 1076 |
|
| |
| 1077 |
|
| SV * |
| 1078 |
44 |
| do_json_parse_file(SV * self_sv, SV * file_sv) { |
| 1079 |
|
| char * filename; |
| 1080 |
|
| STRLEN filename_len; |
| 1081 |
|
| jsonevt_ctx * ctx; |
| 1082 |
|
| perl_wrapper_ctx wctx; |
| 1083 |
|
| |
| 1084 |
|
| SETUP_TRACE; |
| 1085 |
|
| |
| 1086 |
44 |
| filename = SvPV(file_sv, filename_len); |
| 1087 |
|
| |
| 1088 |
44 |
| memzero(&wctx, sizeof(perl_wrapper_ctx)); |
| 1089 |
44 |
| ctx = init_cbs(&wctx, self_sv); |
| 1090 |
|
| |
| 1091 |
44 |
| return handle_parse_result(jsonevt_parse_file(ctx, filename), ctx, &wctx); |
| 1092 |
|
| } |
| 1093 |
|
| |
| 1094 |
|
| |