Skip to content

Commit b3e1a42

Browse files
committed
Stop allowing to customize MSGPACK_UNPACKER_STACK_CAPACITY
Allowing to define it forces us to maintain a fallback codepath in case it wouldn't fit in a 4kB page. That codepath is unstested, and passing compilation flags to gems in so wonky I really don't think we should allow this. Superseeds: #321
1 parent 59c44fa commit b3e1a42

2 files changed

Lines changed: 7 additions & 26 deletions

File tree

ext/msgpack/unpacker.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@
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

2828
static int RAW_TYPE_STRING = 256;
2929
static int RAW_TYPE_BINARY = 257;
3030

3131
static ID s_call;
3232

33-
#ifdef UNPACKER_STACK_RMEM
3433
static msgpack_rmem_t s_stack_rmem;
35-
#endif
3634

3735
#if !defined(HAVE_RB_HASH_NEW_CAPA)
3836
static inline VALUE rb_hash_new_capa(long capa)
@@ -43,32 +41,23 @@ static inline VALUE rb_hash_new_capa(long capa)
4341

4442
void 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

5349
void 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

6256
static 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

8776
static 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

ext/msgpack/unpacker.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
#include "buffer.h"
2222
#include "unpacker_ext_registry.h"
2323

24-
#ifndef MSGPACK_UNPACKER_STACK_CAPACITY
2524
#define MSGPACK_UNPACKER_STACK_CAPACITY 128
26-
#endif
2725

2826
struct msgpack_unpacker_t;
2927
typedef struct msgpack_unpacker_t msgpack_unpacker_t;
@@ -49,8 +47,6 @@ struct msgpack_unpacker_stack_t {
4947
msgpack_unpacker_stack_t *parent;
5048
};
5149

52-
#define MSGPACK_UNPACKER_STACK_SIZE (8+4+8+8) /* assumes size_t <= 64bit, enum <= 32bit, VALUE <= 64bit */
53-
5450
struct msgpack_unpacker_t {
5551
msgpack_buffer_t buffer;
5652
msgpack_unpacker_stack_t *stack;

0 commit comments

Comments
 (0)