XS.xs

filter: Statementstmt 70.5% 194 / 275 Branchbran 53.4% 109 / 204 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 63.2% 303 / 479 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Net/Async/Redis/Cluster/Node/XS.pm ↑ Summary
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5 #include <math.h>
6  
7 /* Back-compatibility */
8 #ifndef G_LIST
9 #define G_LIST G_ARRAY
10 #endif
11  
12 /* Types of data structures that can nest */
13 enum PendingStackType {
14 array, map, set, attribute, push
15 };
16 /* Container representation - basic stack of nested lists */
17 struct pending_stack {
18 AV *data;
19 struct pending_stack *prev;
20 long expected;
21 enum PendingStackType type;
22 };
23  
24 void
25 150 add_value(struct pending_stack *target, SV *v)
26 {
27 150 ▶ if(!target)
Branch: 1 branch
BranchTrueFalseTotal
if(!target) 0 150 150
28 0 return;
29  
30 150 av_push(
31 target->data,
32 v
33 );
34 }
35  
36 MODULE = Net::Async::Redis::XS PACKAGE = Net::Async::Redis::XS
37  
38 PROTOTYPES: DISABLE
39  
40 AV *
41 decode_buffer(SV *this, SV *p)
42 PPCODE:
43 /* Plain bytestring required: no magic, no UTF-8, no nonsense */
44 105 ▶ if(!SvPOK(p))
Branch: 1 branch
BranchTrueFalseTotal
if(!SvPOK(p)) 2 103 105
45 2 croak("expected a string");
46 103 ▶ if(SvUTF8(p))
Branch: 1 branch
BranchTrueFalseTotal
if(SvUTF8(p)) 0 103 103
47 0 sv_utf8_downgrade(p, true);
48  
49 STRLEN len;
50 103 const char *in = SvPVbyte(p, len);
51 103 const char *ptr = in;
52 103 const char *end = in + len;
53 103 struct pending_stack *ps = NULL;
54 103 AV *results = (AV *) sv_2mortal((SV *) newAV());
55 103 bool extracted_item = false;
56 103 SV *extracted = &PL_sv_undef;
57 /* Perl strings _should_ guarantee this, so perhaps better as an assert? */
58 103 ▶ if(*end != '\0') {
Branch: 1 branch
BranchTrueFalseTotal
if(*end != '\0') { 0 103 103
59 0 croak("no trailing null?");
60 }
61  
62 /* The shortest command is a single-character null, which has the
63 * type `_` followed by CRLF terminator, so that's at least 3
64 * characters for a valid command.
65 */
66 103 ▶ if(len >= 3) { // && *(end - 1) == '\x0A' && *(end - 2) == '\x0D') {
Branch: 1 branch
BranchTrueFalseTotal
if(len >= 3) { // && *(end - 1) == '\x0A' && *(end - 2) == '\x0D') { 6 97 103
67 508 ▶ while(*ptr && ptr < end) {
Branch: 2 branches
BranchTrueFalseTotal
while(*ptr && ptr < end) { 31 477 508
while(*ptr && ptr < end) { 477 0 477
68 /* First step is to check the data type and extract it if we can */
69 477 switch(*ptr++) {
70 276 case '~': /* set */
71 case '*': { /* array */
72 276 int n = 0;
73 /* We effectively want grok_atoUV behaviour, but without having a full UV */
74 546 ▶ while(*ptr >= '0' && *ptr <= '9') {
Branch: 2 branches
BranchTrueFalseTotal
while(*ptr >= '0' && *ptr <= '9') { 270 276 546
while(*ptr >= '0' && *ptr <= '9') { 270 0 270
75 270 n = (n * 10) + (*ptr - '0');
76 270 ++ptr;
77 }
78 276 ▶ if(ptr + 2 > end) {
Branch: 1 branch
BranchTrueFalseTotal
if(ptr + 2 > end) { 20 256 276
79 20 goto end_parsing;
80 }
81 256 ▶ if(ptr[0] != '\x0D' || ptr[1] != '\x0A') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 256 0 256
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 256 256
82 0 croak("protocol violation - array length not followed by CRLF");
83 }
84 256 ptr += 2;
85  
86 256 AV *x = (AV *) sv_2mortal((SV *)newAV());
87 256 ▶ if(n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(n > 0) { 253 3 256
88 253 av_extend(x, n);
89 }
90 256 struct pending_stack *pn = Newx(pn, 1, struct pending_stack);
91 256 *pn = (struct pending_stack) {
92 .data = x,
93 .prev = ps,
94 .expected = n,
95 .type = array
96 };
97 256 ps = pn;
98 256 break;
99 }
100 1 case '>': { /* push (pubsub) */
101 1 int n = 0;
102 2 ▶ while(*ptr >= '0' && *ptr <= '9') {
Branch: 2 branches
BranchTrueFalseTotal
while(*ptr >= '0' && *ptr <= '9') { 1 1 2
while(*ptr >= '0' && *ptr <= '9') { 1 0 1
103 1 n = (n * 10) + (*ptr - '0');
104 1 ++ptr;
105 }
106 1 ▶ if(ptr + 2 > end) {
Branch: 1 branch
BranchTrueFalseTotal
if(ptr + 2 > end) { 0 1 1
107 0 goto end_parsing;
108 }
109 1 ▶ if(ptr[0] != '\x0D' || ptr[1] != '\x0A') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 1 0 1
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 1 1
110 0 croak("protocol violation - push length not followed by CRLF");
111 }
112 1 ptr += 2;
113  
114 1 AV *x = (AV *) sv_2mortal((SV *)newAV());
115 1 ▶ if(n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(n > 0) { 1 0 1
116 1 av_extend(x, n);
117 }
118 1 struct pending_stack *pn = Newx(pn, 1, struct pending_stack);
119 1 *pn = (struct pending_stack) {
120 .data = x,
121 .prev = ps,
122 .expected = n,
123 .type = push
124 };
125 1 ps = pn;
126 1 break;
127 }
128 1 case '%': { /* hash */
129 1 int n = 0;
130 2 ▶ while(*ptr >= '0' && *ptr <= '9') {
Branch: 2 branches
BranchTrueFalseTotal
while(*ptr >= '0' && *ptr <= '9') { 1 1 2
while(*ptr >= '0' && *ptr <= '9') { 1 0 1
131 1 n = (n * 10) + (*ptr - '0');
132 1 ++ptr;
133 }
134 1 ▶ if(ptr + 2 > end) {
Branch: 1 branch
BranchTrueFalseTotal
if(ptr + 2 > end) { 0 1 1
135 0 goto end_parsing;
136 }
137  
138 /* Hash of key/value pairs */
139 1 n = n * 2;
140 1 ▶ if(ptr[0] != '\x0D' || ptr[1] != '\x0A') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 1 0 1
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 1 1
141 0 croak("protocol violation - number of hash entries not followed by CRLF");
142 }
143 1 ptr += 2;
144 1 AV *x = (AV *) sv_2mortal((SV *)newAV());
145 1 ▶ if(n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if(n > 0) { 0 1 1
146 0 av_extend(x, n);
147 }
148 1 struct pending_stack *pn = Newx(pn, 1, struct pending_stack);
149 1 *pn = (struct pending_stack) {
150 .data = x,
151 .prev = ps,
152 .expected = n,
153 .type = map
154 };
155 1 ps = pn;
156 1 break;
157 }
158 63 case ':': { /* integer */
159 63 int n = 0;
160 63 int negative = 0;
161 63 ▶ if(*ptr == '-') {
Branch: 1 branch
BranchTrueFalseTotal
if(*ptr == '-') { 1 62 63
162 1 negative = 1;
163 1 ++ptr;
164 }
165 126 ▶ while(*ptr >= '0' && *ptr <= '9' && ptr < end) {
Branch: 3 branches
BranchTrueFalseTotal
while(*ptr >= '0' && *ptr <= '9' && ptr < end) { 63 63 126
while(*ptr >= '0' && *ptr <= '9' && ptr < end) { 63 0 63
while(*ptr >= '0' && *ptr <= '9' && ptr < end) { 63 0 63
166 63 n = (n * 10) + (*ptr - '0');
167 63 ++ptr;
168 }
169 63 ▶ if(negative) {
Branch: 1 branch
BranchTrueFalseTotal
if(negative) { 1 62 63
170 1 n = -n;
171 }
172 63 ▶ if(ptr + 2 > end) {
Branch: 1 branch
BranchTrueFalseTotal
if(ptr + 2 > end) { 6 57 63
173 6 goto end_parsing;
174 }
175 57 ▶ if(ptr[0] != '\x0D' || ptr[1] != '\x0A') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 57 0 57
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 57 57
176 0 croak("protocol violation - integer not followed by CRLF\n");
177 }
178 57 ptr += 2;
179 57 SV *v = newSViv(n);
180 57 ▶ if(ps) {
Branch: 1 branch
BranchTrueFalseTotal
if(ps) { 52 5 57
181 52 add_value(ps, v);
182 } else {
183 5 av_push(results, v);
184 5 extracted_item = true;
185 }
186 57 break;
187 }
188 5 case ',': { /* decimal floating-point */
189 5 char *terminator = strchr(ptr, '\x0D');
190 5 ▶ if(terminator == NULL) {
Branch: 1 branch
BranchTrueFalseTotal
if(terminator == NULL) { 0 5 5
191 0 goto end_parsing;
192 }
193 5 SV *v = newSVnv(my_strtod(ptr, &terminator));
194 5 ptr = terminator;
195 5 ▶ if(ptr + 2 > end) {
Branch: 1 branch
BranchTrueFalseTotal
if(ptr + 2 > end) { 0 5 5
196 0 goto end_parsing;
197 }
198 5 ▶ if(ptr[0] != '\x0D' || ptr[1] != '\x0A') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 5 0 5
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 5 5
199 0 croak("protocol violation - decimal number not followed by CRLF\n");
200 }
201 5 ptr += 2;
202 5 ▶ if(ps) {
Branch: 1 branch
BranchTrueFalseTotal
if(ps) { 0 5 5
203 0 add_value(ps, v);
204 } else {
205 5 av_push(results, v);
206 5 extracted_item = true;
207 }
208 5 break;
209 }
210 0 case '=': /* verbatim string - fall through */
211 case '$': { /* bulk string */
212 0 int n = 0;
213 SV *v;
214 0 ▶ if(ptr[0] == '-' && ptr[1] == '1') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] == '-' && ptr[1] == '1') { 0 0 0
if(ptr[0] == '-' && ptr[1] == '1') { 0 0 0
215 0 ▶ if(ptr + 4 > end) {
Branch: 1 branch
BranchTrueFalseTotal
if(ptr + 4 > end) { 0 0 0
216 0 goto end_parsing;
217 }
218 // null
219 0 ptr += 2;
220 0 v = &PL_sv_undef;
221 } else {
222 0 ▶ while(*ptr >= '0' && *ptr <= '9' && ptr < end) {
Branch: 3 branches
BranchTrueFalseTotal
while(*ptr >= '0' && *ptr <= '9' && ptr < end) { 0 0 0
while(*ptr >= '0' && *ptr <= '9' && ptr < end) { 0 0 0
while(*ptr >= '0' && *ptr <= '9' && ptr < end) { 0 0 0
223 0 n = (n * 10) + (*ptr - '0');
224 0 ++ptr;
225 }
226 0 ▶ if(ptr + n + 4 > end) {
Branch: 1 branch
BranchTrueFalseTotal
if(ptr + n + 4 > end) { 0 0 0
227 0 goto end_parsing;
228 }
229 0 ▶ if(ptr[0] != '\x0D' || ptr[1] != '\x0A') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 0 0
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 0 0
230 0 croak("protocol violation - bulk string length not followed by CRLF");
231 }
232 0 ptr += 2;
233 0 v = newSVpvn(ptr, n);
234 0 ptr += n;
235 }
236 0 ▶ if(ptr[0] != '\x0D' || ptr[1] != '\x0A') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 0 0
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 0 0
237 0 croak("protocol violation - bulk string not terminated by CRLF");
238 }
239 0 ptr += 2;
240 0 ▶ if(ps) {
Branch: 1 branch
BranchTrueFalseTotal
if(ps) { 0 0 0
241 0 add_value(ps, v);
242 } else {
243 0 av_push(results, v);
244 0 extracted_item = true;
245 }
246 0 break;
247 }
248 129 case '(': /* big number - treat as a string for now */
249 case '+': { /* string */
250 129 const char *start = ptr;
251 260 ▶ while(*ptr && (ptr[0] != '\x0D' && ptr[1] != '\x0A' && ptr < end)) {
Branch: 4 branches
BranchTrueFalseTotal
while(*ptr && (ptr[0] != '\x0D' && ptr[1] != '\x0A' && ptr < end)) { 240 20 260
while(*ptr && (ptr[0] != '\x0D' && ptr[1] != '\x0A' && ptr < end)) { 131 109 240
while(*ptr && (ptr[0] != '\x0D' && ptr[1] != '\x0A' && ptr < end)) { 131 0 131
while(*ptr && (ptr[0] != '\x0D' && ptr[1] != '\x0A' && ptr < end)) { 131 0 131
252 131 ++ptr;
253 }
254 129 ▶ if(ptr + 2 > end) {
Branch: 1 branch
BranchTrueFalseTotal
if(ptr + 2 > end) { 30 99 129
255 30 goto end_parsing;
256 }
257 99 ▶ if(ptr[0] != '\x0D' || ptr[1] != '\x0A') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 99 0 99
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 99 99
258 0 croak("protocol violation - string not terminated by CRLF");
259 }
260 99 int n = ptr - start;
261 99 SV *v = newSVpvn(start, n);
262 99 ptr += 2;
263 99 ▶ if(ps) {
Branch: 1 branch
BranchTrueFalseTotal
if(ps) { 98 1 99
264 98 add_value(ps, v);
265 } else {
266 1 av_push(results, v);
267 1 extracted_item = true;
268 }
269 99 break;
270 }
271 2 case '-': { /* error */
272 2 const char *start = ptr;
273 12 ▶ while(*ptr && (ptr[0] != '\x0D' && ptr[1] != '\x0A' && ptr < end)) {
Branch: 4 branches
BranchTrueFalseTotal
while(*ptr && (ptr[0] != '\x0D' && ptr[1] != '\x0A' && ptr < end)) { 12 0 12
while(*ptr && (ptr[0] != '\x0D' && ptr[1] != '\x0A' && ptr < end)) { 10 2 12
while(*ptr && (ptr[0] != '\x0D' && ptr[1] != '\x0A' && ptr < end)) { 10 0 10
while(*ptr && (ptr[0] != '\x0D' && ptr[1] != '\x0A' && ptr < end)) { 10 0 10
274 10 ++ptr;
275 }
276 2 ▶ if(ptr + 2 > end) {
Branch: 1 branch
BranchTrueFalseTotal
if(ptr + 2 > end) { 0 2 2
277 0 goto end_parsing;
278 }
279 2 ▶ if(ptr[0] != '\x0D' || ptr[1] != '\x0A') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 2 0 2
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 2 2
280 0 croak("protocol violation - error not terminated by CRLF");
281 }
282 2 int n = ptr - start;
283 2 SV *v = newSVpvn(start, n);
284 2 ptr += 2;
285 2 SV *rv = SvRV(this);
286  
287 /* Remove anything we processed - we're doing this _before_ the call,
288 * since it may throw an exception */
289 2 sv_chop(p, ptr);
290 2 ptr = SvPVbyte(p, len);
291 2 end = ptr + len - 1;
292 2 ▶ if(hv_exists((HV *) rv, "error", 5)) {
Branch: 1 branch
BranchTrueFalseTotal
if(hv_exists((HV *) rv, "error", 5)) { 2 0 2
293 2 SV **cv_ptr = hv_fetchs((HV *) rv, "error", 0);
294 2 ▶ if(cv_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
if(cv_ptr) { 2 0 2
295 2 CV *cv = (CV *) *cv_ptr;
296 2 dSP;
297 2 ENTER;
298 2 SAVETMPS;
299 2 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 2 2
300 2 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 2 2
301 2 PUSHs(sv_2mortal(v));
302 2 PUTBACK;
303 2 call_sv((SV *) cv, G_VOID | G_DISCARD);
304 2 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 2 0 2
305 2 LEAVE;
306 } else {
307 0 warn("no CV for ->{error}");
308 }
309 } else {
310 0 warn("no ->{error} handler");
311 }
312 /* Note that we are _not_ setting extracted_item here, because there
313 * were no items to put in results, and we've already updated the buffer
314 * to move past the error item. */
315 2 break;
316 }
317 0 case '_': { /* single-character null */
318 0 int n = 0;
319 0 SV *v = &PL_sv_undef;
320 0 ▶ if(ptr + 2 > end) {
Branch: 1 branch
BranchTrueFalseTotal
if(ptr + 2 > end) { 0 0 0
321 0 goto end_parsing;
322 }
323 0 ▶ if(ptr[0] != '\x0D' || ptr[1] != '\x0A') {
Branch: 2 branches
BranchTrueFalseTotal
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 0 0
if(ptr[0] != '\x0D' || ptr[1] != '\x0A') { 0 0 0
324 0 croak("protocol violation - single-character null not followed by CRLF");
325 }
326 0 ptr += 2;
327 0 ▶ if(ps) {
Branch: 1 branch
BranchTrueFalseTotal
if(ps) { 0 0 0
328 0 add_value(ps, v);
329 } else {
330 0 av_push(results, v);
331 0 extracted_item = true;
332 }
333 0 break;
334 }
335 0 default:
336 0 croak("Unknown type %d, bail out", ptr[-1]);
337 }
338  
339 /* Do some housekeeping after parsing: see if we've accumulated enough
340 * data to fill the requirements for one or more levels of our nested container
341 * handling.
342 */
343 439 ▶ while(ps && av_count(ps->data) >= ps->expected) {
Branch: 2 branches
BranchTrueFalseTotal
while(ps && av_count(ps->data) >= ps->expected) { 418 21 439
while(ps && av_count(ps->data) >= ps->expected) { 18 400 418
344 18 AV *data = ps->data;
345 18 struct pending_stack *orig = ps;
346 18 ps = orig->prev;
347 18 ▶ if(ps) {
Branch: 1 branch
BranchTrueFalseTotal
if(ps) { 10 8 18
348 10 SV *value_ref = newRV((SV *) data);
349 10 av_push(
350 ps->data,
351 value_ref
352 );
353 } else {
354 8 switch(orig->type) {
355 1 case push: { /* pub/sub is treated as an out-of-bound message */
356 1 SV *rv = SvRV(this);
357 1 ▶ if(hv_exists((HV *) rv, "pubsub", 6)) {
Branch: 1 branch
BranchTrueFalseTotal
if(hv_exists((HV *) rv, "pubsub", 6)) { 1 0 1
358 1 SV **cv_ptr = hv_fetchs((HV *) rv, "pubsub", 0);
359 1 ▶ if(cv_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
if(cv_ptr) { 1 0 1
360 1 CV *cv = (CV *) *cv_ptr;
361 1 dSP;
362 1 ENTER;
363 1 SAVETMPS;
364 1 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 1 1
365 1 long count = av_count(data);
366 1 ▶ if(count) {
Branch: 1 branch
BranchTrueFalseTotal
if(count) { 1 0 1
367 1 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 1 0 1
EXTEND(SP, count); 0 1 1
368 2 ▶ for(int i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(int i = 0; i < count; ++i) { 1 1 2
369 1 mPUSHs(av_shift(data));
370 }
371 }
372 1 PUTBACK;
373 1 call_sv((SV *) cv, G_VOID | G_DISCARD);
374 1 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 1 0 1
375 1 LEAVE;
376 } else {
377 0 warn("no CV for ->{pubsub}");
378 }
379 } else {
380 0 warn("no ->{pubsub} handler");
381 }
382 1 break;
383 }
384 0 case attribute: {
385 /* attributes aren't used much: for now, we emit as an event,
386 * but eventually would aim to apply this to the response,
387 * by returning a blessed object for example
388 */
389 0 SV *rv = SvRV(this);
390 0 SV *value_ref = newRV((SV *) data);
391 0 ▶ if(hv_exists((HV *) rv, "attribute", 9)) {
Branch: 1 branch
BranchTrueFalseTotal
if(hv_exists((HV *) rv, "attribute", 9)) { 0 0 0
392 0 SV **cv_ptr = hv_fetchs((HV *) rv, "attribute", 0);
393 0 ▶ if(cv_ptr) {
Branch: 1 branch
BranchTrueFalseTotal
if(cv_ptr) { 0 0 0
394 0 CV *cv = (CV *) *cv_ptr;
395 0 dSP;
396 0 ENTER;
397 0 SAVETMPS;
398 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
399 0 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 0 0
400 0 PUSHs(sv_2mortal(value_ref));
401 0 PUTBACK;
402 0 call_sv((SV *) cv, G_VOID | G_DISCARD);
403 0 ▶ FREETMPS;
Branch: 1 branch
BranchTrueFalseTotal
FREETMPS; 0 0 0
404 0 LEAVE;
405 } else {
406 0 warn("no CV for ->{attribute}");
407 }
408 } else {
409 0 warn("no ->{attribute} handler");
410 }
411 0 break;
412 }
413 7 default: {
414 /* Yes, we fall through as a default for map and array: unless the
415 * hashrefs option is set, we want to map all key/value pairs to plain
416 * arrays anyway.
417 */
418 7 SV *value_ref = newRV((SV *) data);
419 7 av_push(
420 results,
421 value_ref
422 );
423 7 break;
424 }
425 }
426 8 extracted_item = true;
427 }
428 18 Safefree(orig);
429 }
430  
431 /* Every time we reach the end of a complete item, we update
432 * our parsed string progress and add to our list of things to
433 * return.
434 */
435 421 ▶ if(extracted_item) {
Branch: 1 branch
BranchTrueFalseTotal
if(extracted_item) { 19 402 421
436 /* Remove anything we processed */
437 19 sv_chop(p, ptr);
438 19 ptr = SvPVbyte(p, len);
439 19 end = ptr + len;
440 19 extracted_item = false;
441 /* ... and our "list" is only ever going to be a single item if we're in scalar context */
442 19 ▶ if (GIMME_V == G_SCALAR && av_count(results) > 0) {
Branch: 2 branches
BranchTrueFalseTotal
if (GIMME_V == G_SCALAR && av_count(results) > 0) { 10 9 19
if (GIMME_V == G_SCALAR && av_count(results) > 0) { 10 0 10
443 10 extracted = av_shift(results);
444 10 break;
445 }
446 }
447 }
448 }
449 37 end_parsing:
450 /* Clean up our temporary parse stack */
451 343 ▶ while(ps) {
Branch: 1 branch
BranchTrueFalseTotal
while(ps) { 240 103 343
452 240 struct pending_stack *orig = ps;
453 240 ps = ps->prev;
454 240 Safefree(orig);
455 }
456  
457 /* Flatten our results back into scalars for return */
458 103 ▶ if (GIMME_V == G_LIST) {
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_LIST) { 51 52 103
459 51 long count = av_count(results);
460 51 ▶ if(count) {
Branch: 1 branch
BranchTrueFalseTotal
if(count) { 8 43 51
461 8 ▶ EXTEND(SP, count);
Branch: 2 branches
BranchTrueFalseTotal
EXTEND(SP, count); 8 0 8
EXTEND(SP, count); 0 8 8
462 16 ▶ for(int i = 0; i < count; ++i) {
Branch: 1 branch
BranchTrueFalseTotal
for(int i = 0; i < count; ++i) { 8 8 16
463 8 mPUSHs(av_shift(results));
464 }
465 }
466 52 ▶ } else if (GIMME_V == G_SCALAR) {
Branch: 1 branch
BranchTrueFalseTotal
} else if (GIMME_V == G_SCALAR) { 52 0 52
467 52 ▶ mXPUSHs(extracted);
Branch: 1 branch
BranchTrueFalseTotal
mXPUSHs(extracted); 0 52 52
468 }
« blib/lib/Net/Async/Redis/Cluster/Node/XS.pm ↑ Summary