2020#include "rmem.h"
2121#include "extension_value_class.h"
2222
23- #if !defined( DISABLE_UNPACKER_STACK_RMEM ) && \
24- MSGPACK_UNPACKER_STACK_CAPACITY * MSGPACK_UNPACKER_STACK_SIZE <= MSGPACK_RMEM_PAGE_SIZE
25- #define UNPACKER_STACK_RMEM
26- #endif
23+ _Static_assert (
24+ sizeof ( msgpack_unpacker_stack_entry_t ) * MSGPACK_UNPACKER_STACK_CAPACITY <= MSGPACK_RMEM_PAGE_SIZE ,
25+ "msgpack_unpacker_stack_entry_t is too big to fit MSGPACK_UNPACKER_STACK_CAPACITY in MSGPACK_RMEM_PAGE_SIZE"
26+ );
2727
2828static int RAW_TYPE_STRING = 256 ;
2929static int RAW_TYPE_BINARY = 257 ;
3030
3131static ID s_call ;
3232
33- #ifdef UNPACKER_STACK_RMEM
3433static msgpack_rmem_t s_stack_rmem ;
35- #endif
3634
3735#if !defined(HAVE_RB_HASH_NEW_CAPA )
3836static inline VALUE rb_hash_new_capa (long capa )
@@ -43,32 +41,23 @@ static inline VALUE rb_hash_new_capa(long capa)
4341
4442void msgpack_unpacker_static_init (void )
4543{
46- #ifdef UNPACKER_STACK_RMEM
4744 msgpack_rmem_init (& s_stack_rmem );
48- #endif
4945
5046 s_call = rb_intern ("call" );
5147}
5248
5349void msgpack_unpacker_static_destroy (void )
5450{
55- #ifdef UNPACKER_STACK_RMEM
5651 msgpack_rmem_destroy (& s_stack_rmem );
57- #endif
5852}
5953
6054#define HEAD_BYTE_REQUIRED 0xc1
6155
6256static inline msgpack_unpacker_stack_t * _msgpack_unpacker_new_stack (void ) {
6357 msgpack_unpacker_stack_t * stack = ZALLOC (msgpack_unpacker_stack_t );
6458 stack -> capacity = MSGPACK_UNPACKER_STACK_CAPACITY ;
65- #ifdef UNPACKER_STACK_RMEM
6659 stack -> data = msgpack_rmem_alloc (& s_stack_rmem );
6760 /*memset(uk->stack, 0, MSGPACK_UNPACKER_STACK_CAPACITY);*/
68- #else
69- /*uk->stack = calloc(MSGPACK_UNPACKER_STACK_CAPACITY, sizeof(msgpack_unpacker_stack_entry_t));*/
70- stack -> data = xmalloc (MSGPACK_UNPACKER_STACK_CAPACITY * sizeof (msgpack_unpacker_stack_entry_t ));
71- #endif
7261 return stack ;
7362}
7463
@@ -85,13 +74,9 @@ void _msgpack_unpacker_init(msgpack_unpacker_t* uk)
8574}
8675
8776static inline void _msgpack_unpacker_free_stack (msgpack_unpacker_stack_t * stack ) {
88- #ifdef UNPACKER_STACK_RMEM
89- if (!msgpack_rmem_free (& s_stack_rmem , stack -> data )) {
90- rb_bug ("Failed to free an rmem pointer, memory leak?" );
91- }
92- #else
93- xfree (stack -> data );
94- #endif
77+ if (!msgpack_rmem_free (& s_stack_rmem , stack -> data )) {
78+ rb_bug ("Failed to free an rmem pointer, memory leak?" );
79+ }
9580 xfree (stack );
9681}
9782
0 commit comments