| 1 |
|
| #include "xh_config.h" |
| 2 |
|
| #include "xh_core.h" |
| 3 |
|
| |
| 4 |
|
| MODULE = XML::Hash::XS PACKAGE = XML::Hash::XS |
| 5 |
|
| |
| 6 |
|
| PROTOTYPES: DISABLE |
| 7 |
|
| |
| 8 |
|
| xh_opts_t * |
| 9 |
|
| new(CLASS,...) |
| 10 |
|
| PREINIT: |
| 11 |
|
| xh_opts_t *opts; |
| 12 |
|
| CODE: |
| 13 |
9 |
| dXCPT; |
| 14 |
|
| |
| 15 |
9 |
▶ | if ((opts = xh_create_opts()) == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((opts = xh_create_opts()) == NULL) |
0 |
9 |
9 |
|
| 16 |
0 |
| croak("Malloc error in new()"); |
| 17 |
|
| |
| 18 |
9 |
▶ | XCPT_TRY_START |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_TRY_START |
9 |
2 |
11 |
|
| 19 |
|
| { |
| 20 |
9 |
| xh_parse_param(opts, 1, ax, items); |
| 21 |
9 |
| } XCPT_TRY_END |
| 22 |
|
| |
| 23 |
9 |
▶ | XCPT_CATCH |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_CATCH |
2 |
7 |
9 |
|
| 24 |
|
| { |
| 25 |
2 |
| xh_destroy_opts(opts); |
| 26 |
2 |
▶ | XCPT_RETHROW; |
Branch: 2 branches
| Branch | True | False | Total |
| XCPT_RETHROW; |
2 |
0 |
2 |
| XCPT_RETHROW; |
0 |
0 |
0 |
|
| 27 |
|
| } |
| 28 |
|
| |
| 29 |
7 |
| RETVAL = opts; |
| 30 |
|
| OUTPUT: |
| 31 |
|
| RETVAL |
| 32 |
|
| |
| 33 |
|
| SV * |
| 34 |
|
| hash2xml(...) |
| 35 |
|
| PREINIT: |
| 36 |
|
| xh_h2x_ctx_t ctx; |
| 37 |
|
| SV *result; |
| 38 |
|
| CODE: |
| 39 |
58 |
| dXCPT; |
| 40 |
58 |
▶ | XCPT_TRY_START |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_TRY_START |
58 |
4 |
62 |
|
| 41 |
|
| { |
| 42 |
58 |
| xh_h2x_init_ctx(&ctx, ax, items); |
| 43 |
|
| |
| 44 |
|
| /* hack */ |
| 45 |
|
| #ifdef XH_HAVE_DOM |
| 46 |
|
| if (ctx.opts.doc) { |
| 47 |
|
| result = xh_h2d(&ctx); |
| 48 |
|
| } |
| 49 |
|
| else { |
| 50 |
|
| result = xh_h2x(&ctx); |
| 51 |
|
| } |
| 52 |
|
| #else |
| 53 |
56 |
| result = xh_h2x(&ctx); |
| 54 |
|
| #endif |
| 55 |
58 |
| } XCPT_TRY_END |
| 56 |
|
| |
| 57 |
58 |
▶ | XCPT_CATCH |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_CATCH |
4 |
54 |
58 |
|
| 58 |
|
| { |
| 59 |
4 |
| xh_h2x_destroy_ctx(&ctx); |
| 60 |
4 |
▶ | XCPT_RETHROW; |
Branch: 2 branches
| Branch | True | False | Total |
| XCPT_RETHROW; |
4 |
0 |
4 |
| XCPT_RETHROW; |
0 |
0 |
0 |
|
| 61 |
|
| } |
| 62 |
|
| |
| 63 |
54 |
▶ | if (ctx.opts.output != NULL || ctx.opts.output_cb != NULL) result = NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| if (ctx.opts.output != NULL || ctx.opts.output_cb != NULL) result = NULL; |
50 |
4 |
54 |
| if (ctx.opts.output != NULL || ctx.opts.output_cb != NULL) result = NULL; |
8 |
42 |
50 |
|
| 64 |
|
| |
| 65 |
54 |
| xh_h2x_destroy_ctx(&ctx); |
| 66 |
|
| |
| 67 |
54 |
▶ | if (result == NULL) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (result == NULL) XSRETURN_UNDEF; |
12 |
42 |
54 |
|
| 68 |
|
| |
| 69 |
42 |
| RETVAL = result; |
| 70 |
|
| |
| 71 |
|
| OUTPUT: |
| 72 |
|
| RETVAL |
| 73 |
|
| |
| 74 |
|
| SV * |
| 75 |
|
| xml2hash(...) |
| 76 |
|
| PREINIT: |
| 77 |
|
| xh_x2h_ctx_t ctx; |
| 78 |
|
| SV *result; |
| 79 |
|
| CODE: |
| 80 |
90 |
| dXCPT; |
| 81 |
90 |
▶ | XCPT_TRY_START |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_TRY_START |
90 |
13 |
103 |
|
| 82 |
|
| { |
| 83 |
90 |
| xh_x2h_init_ctx(&ctx, ax, items); |
| 84 |
|
| |
| 85 |
90 |
| result = xh_x2h(&ctx); |
| 86 |
90 |
| } XCPT_TRY_END |
| 87 |
|
| |
| 88 |
90 |
▶ | XCPT_CATCH |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_CATCH |
13 |
77 |
90 |
|
| 89 |
|
| { |
| 90 |
13 |
| xh_x2h_destroy_ctx(&ctx); |
| 91 |
13 |
▶ | XCPT_RETHROW; |
Branch: 2 branches
| Branch | True | False | Total |
| XCPT_RETHROW; |
13 |
0 |
13 |
| XCPT_RETHROW; |
0 |
0 |
0 |
|
| 92 |
|
| } |
| 93 |
|
| |
| 94 |
77 |
▶ | if (ctx.opts.cb != NULL) result = NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (ctx.opts.cb != NULL) result = NULL; |
12 |
65 |
77 |
|
| 95 |
|
| |
| 96 |
77 |
| xh_x2h_destroy_ctx(&ctx); |
| 97 |
|
| |
| 98 |
77 |
▶ | if (result == NULL) XSRETURN_UNDEF; |
Branch: 1 branch
| Branch | True | False | Total |
| if (result == NULL) XSRETURN_UNDEF; |
12 |
65 |
77 |
|
| 99 |
|
| |
| 100 |
65 |
| RETVAL = result; |
| 101 |
|
| |
| 102 |
|
| OUTPUT: |
| 103 |
|
| RETVAL |
| 104 |
|
| |
| 105 |
|
| void |
| 106 |
|
| DESTROY(opts) |
| 107 |
|
| xh_opts_t *opts; |
| 108 |
|
| CODE: |
| 109 |
7 |
| xh_destroy_opts(opts); |
| 110 |
7 |
| free(opts); |
| 111 |
|
| |
| 112 |
|
| MODULE = XML::Hash::XS PACKAGE = XML::Hash::XS::Parser |
| 113 |
|
| |
| 114 |
|
| SV * |
| 115 |
|
| new(CLASS,...) |
| 116 |
|
| SV *CLASS; |
| 117 |
|
| PREINIT: |
| 118 |
|
| xh_x2h_stream_t *stream; |
| 119 |
|
| CODE: |
| 120 |
2927 |
| dXCPT; |
| 121 |
|
| |
| 122 |
2927 |
▶ | if ((stream = malloc(sizeof(*stream))) == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((stream = malloc(sizeof(*stream))) == NULL) |
0 |
2927 |
2927 |
|
| 123 |
0 |
| croak("Malloc error in XML::Hash::XS::Parser->new()"); |
| 124 |
2927 |
| memset(stream, 0, sizeof(*stream)); |
| 125 |
|
| |
| 126 |
2927 |
▶ | XCPT_TRY_START |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_TRY_START |
2927 |
1 |
2928 |
|
| 127 |
|
| { |
| 128 |
2927 |
| xh_x2h_stream_init(stream, NULL, ax, items); |
| 129 |
2927 |
| } XCPT_TRY_END |
| 130 |
|
| |
| 131 |
2927 |
▶ | XCPT_CATCH |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_CATCH |
1 |
2926 |
2927 |
|
| 132 |
|
| { |
| 133 |
1 |
| xh_x2h_stream_destroy(stream); |
| 134 |
1 |
| free(stream); |
| 135 |
1 |
▶ | XCPT_RETHROW; |
Branch: 2 branches
| Branch | True | False | Total |
| XCPT_RETHROW; |
1 |
0 |
1 |
| XCPT_RETHROW; |
0 |
0 |
0 |
|
| 136 |
|
| } |
| 137 |
|
| |
| 138 |
2926 |
| RETVAL = newRV_noinc(newSViv(PTR2IV(stream))); |
| 139 |
2926 |
| sv_bless(RETVAL, gv_stashsv(CLASS, GV_ADD)); |
| 140 |
|
| OUTPUT: |
| 141 |
|
| RETVAL |
| 142 |
|
| |
| 143 |
|
| void |
| 144 |
|
| feed(parser, input) |
| 145 |
|
| SV *parser; |
| 146 |
|
| SV *input; |
| 147 |
|
| PREINIT: |
| 148 |
|
| xh_x2h_stream_t *stream; |
| 149 |
|
| xh_char_t *data; |
| 150 |
|
| STRLEN len; |
| 151 |
|
| CODE: |
| 152 |
3760 |
| dXCPT; |
| 153 |
3760 |
▶ | if (!sv_isa(parser, "XML::Hash::XS::Parser")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_isa(parser, "XML::Hash::XS::Parser")) |
0 |
3760 |
3760 |
|
| 154 |
0 |
| croak("feed: parser is not of type XML::Hash::XS::Parser"); |
| 155 |
3760 |
| stream = INT2PTR(xh_x2h_stream_t *, SvIV(SvRV(parser))); |
| 156 |
3760 |
▶ | if (stream == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (stream == NULL) |
0 |
3760 |
3760 |
|
| 157 |
0 |
| croak("feed: parser is already destroyed"); |
| 158 |
3760 |
▶ | if (SvROK(input)) input = SvRV(input); |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(input)) input = SvRV(input); |
1 |
3759 |
3760 |
|
| 159 |
3760 |
| data = XH_CHAR_CAST SvPV(input, len); |
| 160 |
3760 |
| SvREFCNT_inc(parser); |
| 161 |
3760 |
▶ | XCPT_TRY_START |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_TRY_START |
3760 |
6 |
3766 |
|
| 162 |
|
| { |
| 163 |
3760 |
| xh_x2h_stream_feed(stream, data, (size_t) len, FALSE); |
| 164 |
3760 |
| } XCPT_TRY_END |
| 165 |
3760 |
▶ | XCPT_CATCH |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_CATCH |
6 |
3754 |
3760 |
|
| 166 |
|
| { |
| 167 |
6 |
| stream->busy = FALSE; |
| 168 |
6 |
| stream->failed = TRUE; |
| 169 |
6 |
| SvREFCNT_dec(parser); |
| 170 |
6 |
▶ | XCPT_RETHROW; |
Branch: 2 branches
| Branch | True | False | Total |
| XCPT_RETHROW; |
6 |
0 |
6 |
| XCPT_RETHROW; |
0 |
0 |
0 |
|
| 171 |
|
| } |
| 172 |
3754 |
| SvREFCNT_dec(parser); |
| 173 |
|
| |
| 174 |
|
| SV * |
| 175 |
|
| finish(parser) |
| 176 |
|
| SV *parser; |
| 177 |
|
| PREINIT: |
| 178 |
|
| xh_x2h_stream_t *stream; |
| 179 |
|
| CODE: |
| 180 |
925 |
| dXCPT; |
| 181 |
925 |
▶ | if (!sv_isa(parser, "XML::Hash::XS::Parser")) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sv_isa(parser, "XML::Hash::XS::Parser")) |
0 |
925 |
925 |
|
| 182 |
0 |
| croak("finish: parser is not of type XML::Hash::XS::Parser"); |
| 183 |
925 |
| stream = INT2PTR(xh_x2h_stream_t *, SvIV(SvRV(parser))); |
| 184 |
925 |
▶ | if (stream == NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| if (stream == NULL) |
0 |
925 |
925 |
|
| 185 |
0 |
| croak("finish: parser is already destroyed"); |
| 186 |
925 |
| SvREFCNT_inc(parser); |
| 187 |
925 |
▶ | XCPT_TRY_START |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_TRY_START |
925 |
503 |
1428 |
|
| 188 |
|
| { |
| 189 |
925 |
| RETVAL = xh_x2h_stream_finish(stream); |
| 190 |
925 |
| } XCPT_TRY_END |
| 191 |
925 |
▶ | XCPT_CATCH |
Branch: 1 branch
| Branch | True | False | Total |
| XCPT_CATCH |
503 |
422 |
925 |
|
| 192 |
|
| { |
| 193 |
503 |
| stream->busy = FALSE; |
| 194 |
503 |
| stream->failed = TRUE; |
| 195 |
503 |
| SvREFCNT_dec(parser); |
| 196 |
503 |
▶ | XCPT_RETHROW; |
Branch: 2 branches
| Branch | True | False | Total |
| XCPT_RETHROW; |
503 |
0 |
503 |
| XCPT_RETHROW; |
0 |
0 |
0 |
|
| 197 |
|
| } |
| 198 |
422 |
| SvREFCNT_dec(parser); |
| 199 |
|
| OUTPUT: |
| 200 |
|
| RETVAL |
| 201 |
|
| |
| 202 |
|
| void |
| 203 |
|
| DESTROY(parser) |
| 204 |
|
| SV *parser; |
| 205 |
|
| PREINIT: |
| 206 |
|
| xh_x2h_stream_t *stream; |
| 207 |
|
| CODE: |
| 208 |
2926 |
| stream = INT2PTR(xh_x2h_stream_t *, SvIV(SvRV(parser))); |
| 209 |
2926 |
▶ | if (stream != NULL) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (stream != NULL) { |
2926 |
0 |
2926 |
|
| 210 |
2926 |
| xh_x2h_stream_destroy(stream); |
| 211 |
2926 |
| free(stream); |
| 212 |
2926 |
| sv_setiv(SvRV(parser), 0); |
| 213 |
|
| } |