ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/CBOR-XS/XS.xs
(Generate patch)

Comparing CBOR-XS/XS.xs (file contents):
Revision 1.40 by root, Tue Dec 10 13:54:40 2013 UTC vs.
Revision 1.47 by root, Mon Apr 27 20:21:53 2015 UTC

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))
323 324
324 ++enc->depth; 325 ++enc->depth;
325 326
326 encode_uint (enc, MAJOR_ARRAY, len + 1); 327 encode_uint (enc, MAJOR_ARRAY, len + 1);
327 328
329 if (SvMAGICAL (av))
328 for (i = 0; i <= len; ++i) 330 for (i = 0; i <= len; ++i)
329 { 331 {
330 SV **svp = av_fetch (av, i, 0); 332 SV **svp = av_fetch (av, i, 0);
331 encode_sv (enc, svp ? *svp : &PL_sv_undef); 333 encode_sv (enc, svp ? *svp : &PL_sv_undef);
332 } 334 }
335 else
336 for (i = 0; i <= len; ++i)
337 {
338 SV *sv = AvARRAY (av)[i];
339 encode_sv (enc, sv ? sv : &PL_sv_undef);
340 }
333 341
334 --enc->depth; 342 --enc->depth;
335} 343}
336 344
337static void 345static void
736{ 744{
737 // for speed reasons, we specialcase single-string 745 // for speed reasons, we specialcase single-string
738 // byte or utf-8 strings as keys, but only when !stringref 746 // byte or utf-8 strings as keys, but only when !stringref
739 747
740 if (ecb_expect_true (!dec->stringref)) 748 if (ecb_expect_true (!dec->stringref))
741 if (ecb_expect_true ((*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8)) 749 if (ecb_expect_true ((U8)(*dec->cur - MAJOR_BYTES) <= LENGTH_EXT8))
742 { 750 {
743 I32 len = decode_uint (dec); 751 I32 len = decode_uint (dec);
744 char *key = (char *)dec->cur; 752 char *key = (char *)dec->cur;
745 753
746 dec->cur += len; 754 dec->cur += len;
747 755
748 hv_store (hv, key, len, decode_sv (dec), 0); 756 hv_store (hv, key, len, decode_sv (dec), 0);
749 757
750 return; 758 return;
751 } 759 }
752 else if (ecb_expect_true ((*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8)) 760 else if (ecb_expect_true ((U8)(*dec->cur - MAJOR_TEXT) <= LENGTH_EXT8))
753 { 761 {
754 I32 len = decode_uint (dec); 762 I32 len = decode_uint (dec);
755 char *key = (char *)dec->cur; 763 char *key = (char *)dec->cur;
756 764
757 dec->cur += len; 765 dec->cur += len;
1256 1264
1257 int major = *p >> MAJOR_SHIFT; 1265 int major = *p >> MAJOR_SHIFT;
1258 1266
1259 switch (major) 1267 switch (major)
1260 { 1268 {
1269 case MAJOR_TAG >> MAJOR_SHIFT:
1270 ++count; // tags merely prefix another value
1271 break;
1272
1261 case MAJOR_BYTES >> MAJOR_SHIFT: 1273 case MAJOR_BYTES >> MAJOR_SHIFT:
1262 case MAJOR_TEXT >> MAJOR_SHIFT: 1274 case MAJOR_TEXT >> MAJOR_SHIFT:
1263 case MAJOR_ARRAY >> MAJOR_SHIFT: 1275 case MAJOR_ARRAY >> MAJOR_SHIFT:
1264 case MAJOR_MAP >> MAJOR_SHIFT: 1276 case MAJOR_MAP >> MAJOR_SHIFT:
1265 { 1277 {
1447 EXTEND (SP, 2); 1459 EXTEND (SP, 2);
1448 PUSHs (sv); 1460 PUSHs (sv);
1449 PUSHs (sv_2mortal (newSVuv (offset - SvPVX (cborstr)))); 1461 PUSHs (sv_2mortal (newSVuv (offset - SvPVX (cborstr))));
1450} 1462}
1451 1463
1452void incr_parse (CBOR *self, SV *cborstr, int chop = 0) 1464void incr_parse (CBOR *self, SV *cborstr)
1465 ALIAS:
1466 incr_parse_multiple = 1
1453 PPCODE: 1467 PPCODE:
1454{ 1468{
1455 if (SvUTF8 (cborstr)) 1469 if (SvUTF8 (cborstr))
1456 sv_utf8_downgrade (cborstr, 0); 1470 sv_utf8_downgrade (cborstr, 0);
1457 1471
1462 self->incr_need = 1; 1476 self->incr_need = 1;
1463 1477
1464 av_push (self->incr_count, newSViv (1)); 1478 av_push (self->incr_count, newSViv (1));
1465 } 1479 }
1466 1480
1467 for (;;) 1481 do
1468 { 1482 {
1469 if (!incr_parse (self, cborstr)) 1483 if (!incr_parse (self, cborstr))
1470 { 1484 {
1471 if (self->incr_need > self->max_size && self->max_size) 1485 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", 1486 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); 1487 (unsigned long)self->incr_need, (unsigned long)self->max_size);
1474 1488
1475 break; 1489 break;
1476 } 1490 }
1477 1491
1478 SV *sv; 1492 SV *sv;
1479 char *offset; 1493 char *offset;
1480 1494
1481 PUTBACK; sv = decode_cbor (cborstr, self, &offset); SPAGAIN; 1495 PUTBACK; sv = decode_cbor (cborstr, self, &offset); SPAGAIN;
1482 XPUSHs (sv); 1496 XPUSHs (sv);
1483 1497
1498 sv_chop (cborstr, offset);
1499
1484 av_clear (self->incr_count); 1500 av_clear (self->incr_count);
1485 av_push (self->incr_count, newSViv (1)); 1501 av_push (self->incr_count, newSViv (1));
1486 1502
1487 if (chop)
1488 {
1489 self->incr_pos = 0; 1503 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; 1504 self->incr_need = self->incr_pos + 1;
1496 } 1505 }
1506 while (ix);
1497} 1507}
1498 1508
1499void incr_reset (CBOR *self) 1509void incr_reset (CBOR *self)
1500 CODE: 1510 CODE:
1501{ 1511{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines