@@ -75,8 +75,7 @@ static inline void unpack_clear(unpack_context *ctx)
75
75
Py_CLEAR (ctx -> stack [0 ].obj );
76
76
}
77
77
78
- template <bool construct>
79
- static inline int unpack_execute (unpack_context* ctx, const char * data, Py_ssize_t len, Py_ssize_t* off)
78
+ static inline int unpack_execute (bool construct , unpack_context * ctx , const char * data , Py_ssize_t len , Py_ssize_t * off )
80
79
{
81
80
assert (len >= * off );
82
81
@@ -386,6 +385,7 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize
386
385
#undef construct_cb
387
386
}
388
387
388
+ #undef NEXT_CS
389
389
#undef SWITCH_RANGE_BEGIN
390
390
#undef SWITCH_RANGE
391
391
#undef SWITCH_RANGE_DEFAULT
@@ -397,68 +397,27 @@ static inline int unpack_execute(unpack_context* ctx, const char* data, Py_ssize
397
397
#undef again_fixed_trail_if_zero
398
398
#undef start_container
399
399
400
- template <unsigned int fixed_offset, unsigned int var_offset>
401
- static inline int unpack_container_header (unpack_context* ctx, const char * data, Py_ssize_t len, Py_ssize_t* off)
402
- {
403
- assert (len >= *off);
404
- uint32_t size;
405
- const unsigned char *const p = (unsigned char *)data + *off;
406
-
407
- #define inc_offset (inc ) \
408
- if (len - *off < inc) \
409
- return 0 ; \
410
- *off += inc;
411
-
412
- switch (*p) {
413
- case var_offset:
414
- inc_offset (3 );
415
- size = _msgpack_load16 (uint16_t , p + 1 );
416
- break ;
417
- case var_offset + 1 :
418
- inc_offset (5 );
419
- size = _msgpack_load32 (uint32_t , p + 1 );
420
- break ;
421
- #ifdef USE_CASE_RANGE
422
- case fixed_offset + 0x0 ... fixed_offset + 0xf :
423
- #else
424
- case fixed_offset + 0x0 :
425
- case fixed_offset + 0x1 :
426
- case fixed_offset + 0x2 :
427
- case fixed_offset + 0x3 :
428
- case fixed_offset + 0x4 :
429
- case fixed_offset + 0x5 :
430
- case fixed_offset + 0x6 :
431
- case fixed_offset + 0x7 :
432
- case fixed_offset + 0x8 :
433
- case fixed_offset + 0x9 :
434
- case fixed_offset + 0xa :
435
- case fixed_offset + 0xb :
436
- case fixed_offset + 0xc :
437
- case fixed_offset + 0xd :
438
- case fixed_offset + 0xe :
439
- case fixed_offset + 0xf :
440
- #endif
441
- ++*off;
442
- size = ((unsigned int )*p) & 0x0f ;
443
- break ;
444
- default :
445
- PyErr_SetString (PyExc_ValueError, " Unexpected type header on stream" );
446
- return -1 ;
447
- }
448
- unpack_callback_uint32 (&ctx->user , size, &ctx->stack [0 ].obj );
449
- return 1 ;
400
+ static int unpack_construct (unpack_context * ctx , const char * data , Py_ssize_t len , Py_ssize_t * off ) {
401
+ return unpack_execute (true, ctx , data , len , off );
402
+ }
403
+ static int unpack_skip (unpack_context * ctx , const char * data , Py_ssize_t len , Py_ssize_t * off ) {
404
+ return unpack_execute (false, ctx , data , len , off );
450
405
}
451
406
452
- #undef SWITCH_RANGE_BEGIN
453
- #undef SWITCH_RANGE
454
- #undef SWITCH_RANGE_DEFAULT
455
- #undef SWITCH_RANGE_END
456
-
457
- static const execute_fn unpack_construct = &unpack_execute<true >;
458
- static const execute_fn unpack_skip = &unpack_execute<false >;
459
- static const execute_fn read_array_header = &unpack_container_header<0x90 , 0xdc >;
460
- static const execute_fn read_map_header = &unpack_container_header<0x80 , 0xde >;
461
-
462
- #undef NEXT_CS
407
+ #define unpack_container_header read_array_header
408
+ #define fixed_offset 0x90
409
+ #define var_offset 0xdc
410
+ #include "unpack_container_header.h"
411
+ #undef unpack_container_header
412
+ #undef fixed_offset
413
+ #undef var_offset
414
+
415
+ #define unpack_container_header read_map_header
416
+ #define fixed_offset 0x80
417
+ #define var_offset 0xde
418
+ #include "unpack_container_header.h"
419
+ #undef unpack_container_header
420
+ #undef fixed_offset
421
+ #undef var_offset
463
422
464
423
/* vim: set ts=4 sw=4 sts=4 expandtab */
0 commit comments