… | |
… | |
7 | #include <stdlib.h> |
7 | #include <stdlib.h> |
8 | #include <stdio.h> |
8 | #include <stdio.h> |
9 | #include <limits.h> |
9 | #include <limits.h> |
10 | #include <float.h> |
10 | #include <float.h> |
11 | |
11 | |
|
|
12 | #define ECB_NO_THREADS 1 |
12 | #include "ecb.h" |
13 | #include "ecb.h" |
13 | |
14 | |
14 | // compatibility with perl <5.18 |
15 | // compatibility with perl <5.18 |
15 | #ifndef HvNAMELEN_get |
16 | #ifndef HvNAMELEN_get |
16 | # define HvNAMELEN_get(hv) strlen (HvNAME (hv)) |
17 | # define HvNAMELEN_get(hv) strlen (HvNAME (hv)) |
… | |
… | |
736 | { |
737 | { |
737 | // for speed reasons, we specialcase single-string |
738 | // for speed reasons, we specialcase single-string |
738 | // byte or utf-8 strings as keys, but only when !stringref |
739 | // byte or utf-8 strings as keys, but only when !stringref |
739 | |
740 | |
740 | if (ecb_expect_true (!dec->stringref)) |
741 | if (ecb_expect_true (!dec->stringref)) |
741 | if (ecb_expect_true ((*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8)) |
742 | if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8)) |
742 | { |
743 | { |
743 | I32 len = decode_uint (dec); |
744 | I32 len = decode_uint (dec); |
744 | char *key = (char *)dec->cur; |
745 | char *key = (char *)dec->cur; |
745 | |
746 | |
746 | dec->cur += len; |
747 | dec->cur += len; |
747 | |
748 | |
748 | hv_store (hv, key, len, decode_sv (dec), 0); |
749 | hv_store (hv, key, len, decode_sv (dec), 0); |
749 | |
750 | |
750 | return; |
751 | return; |
751 | } |
752 | } |
752 | else if (ecb_expect_true ((*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) |
753 | else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) |
753 | { |
754 | { |
754 | I32 len = decode_uint (dec); |
755 | I32 len = decode_uint (dec); |
755 | char *key = (char *)dec->cur; |
756 | char *key = (char *)dec->cur; |
756 | |
757 | |
757 | dec->cur += len; |
758 | dec->cur += len; |
… | |
… | |
1447 | EXTEND (SP, 2); |
1448 | EXTEND (SP, 2); |
1448 | PUSHs (sv); |
1449 | PUSHs (sv); |
1449 | PUSHs (sv_2mortal (newSVuv (offset - SvPVX (cborstr)))); |
1450 | PUSHs (sv_2mortal (newSVuv (offset - SvPVX (cborstr)))); |
1450 | } |
1451 | } |
1451 | |
1452 | |
1452 | void incr_parse (CBOR *self, SV *cborstr, int chop = 0) |
1453 | void incr_parse (CBOR *self, SV *cborstr) |
|
|
1454 | ALIAS: |
|
|
1455 | incr_parse_multiple = 1 |
1453 | PPCODE: |
1456 | PPCODE: |
1454 | { |
1457 | { |
1455 | if (SvUTF8 (cborstr)) |
1458 | if (SvUTF8 (cborstr)) |
1456 | sv_utf8_downgrade (cborstr, 0); |
1459 | sv_utf8_downgrade (cborstr, 0); |
1457 | |
1460 | |
… | |
… | |
1462 | self->incr_need = 1; |
1465 | self->incr_need = 1; |
1463 | |
1466 | |
1464 | av_push (self->incr_count, newSViv (1)); |
1467 | av_push (self->incr_count, newSViv (1)); |
1465 | } |
1468 | } |
1466 | |
1469 | |
1467 | for (;;) |
1470 | do |
1468 | { |
1471 | { |
1469 | if (!incr_parse (self, cborstr)) |
1472 | if (!incr_parse (self, cborstr)) |
1470 | { |
1473 | { |
1471 | if (self->incr_need > self->max_size && self->max_size) |
1474 | if (self->incr_need > self->max_size && self->max_size) |
1472 | croak ("attempted decode of CBOR text of %lu bytes size, but max_size is set to %lu", |
1475 | croak ("attempted decode of CBOR text of %lu bytes size, but max_size is set to %lu", |
1473 | (unsigned long)self->incr_need, (unsigned long)self->max_size); |
1476 | (unsigned long)self->incr_need, (unsigned long)self->max_size); |
1474 | |
1477 | |
1475 | break; |
1478 | break; |
1476 | } |
1479 | } |
1477 | |
1480 | |
1478 | SV *sv; |
1481 | SV *sv; |
1479 | char *offset; |
1482 | char *offset; |
1480 | |
1483 | |
1481 | PUTBACK; sv = decode_cbor (cborstr, self, &offset); SPAGAIN; |
1484 | PUTBACK; sv = decode_cbor (cborstr, self, &offset); SPAGAIN; |
1482 | XPUSHs (sv); |
1485 | XPUSHs (sv); |
1483 | |
1486 | |
|
|
1487 | sv_chop (cborstr, offset); |
|
|
1488 | |
1484 | av_clear (self->incr_count); |
1489 | av_clear (self->incr_count); |
1485 | av_push (self->incr_count, newSViv (1)); |
1490 | av_push (self->incr_count, newSViv (1)); |
1486 | |
1491 | |
1487 | if (chop) |
|
|
1488 | { |
|
|
1489 | self->incr_pos = 0; |
1492 | self->incr_pos = 0; |
1490 | sv_chop (cborstr, offset); |
|
|
1491 | } |
|
|
1492 | else |
|
|
1493 | self->incr_pos = offset - SvPVX (cborstr); |
|
|
1494 | |
|
|
1495 | self->incr_need = self->incr_pos + 1; |
1493 | self->incr_need = self->incr_pos + 1; |
1496 | } |
1494 | } |
|
|
1495 | while (ix); |
1497 | } |
1496 | } |
1498 | |
1497 | |
1499 | void incr_reset (CBOR *self) |
1498 | void incr_reset (CBOR *self) |
1500 | CODE: |
1499 | CODE: |
1501 | { |
1500 | { |