Skip to content

Commit 1bad12b

Browse files
authored
Merge pull request #335 from msgpack/test-static-insert
Use a runtime assert during init instead of _Static_assert
2 parents 9e74c0b + 92c5ecd commit 1bad12b

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ jobs:
3333
ruby-version: ${{ matrix.ruby }}
3434
bundler-cache: true # 'bundle install' and cache
3535
- run: bundle exec rake
36+
env:
37+
MSGPACK_DEBUG: "true"
3638

3739
valgrind:
3840
runs-on: ubuntu-latest
@@ -59,6 +61,8 @@ jobs:
5961
ruby-version: ${{ matrix.ruby }}
6062
bundler-cache: true # 'bundle install' and cache
6163
- run: bundle exec rake spec
64+
env:
65+
MSGPACK_DEBUG: "true"
6266

6367
head-versions:
6468
continue-on-error: true
@@ -75,3 +79,5 @@ jobs:
7579
ruby-version: ${{ matrix.ruby }}
7680
bundler-cache: true # 'bundle install' and cache
7781
- run: bundle exec rake spec || echo "failed, but ignore it"
82+
env:
83+
MSGPACK_DEBUG: "true"

ext/msgpack/extconf.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
])
1515
append_cflags(RbConfig::CONFIG["debugflags"]) if RbConfig::CONFIG["debugflags"]
1616

17+
append_cflags("-DRUBY_DEBUG=1") if ENV["MSGPACK_DEBUG"]
18+
1719
if RUBY_VERSION.start_with?('3.0.') && RUBY_VERSION <= '3.0.5'
1820
# https://bugs.ruby-lang.org/issues/18772
1921
append_cflags("-DRB_ENC_INTERNED_STR_NULL_CHECK=1")

ext/msgpack/unpacker.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@
1919
#include "unpacker.h"
2020
#include "rmem.h"
2121
#include "extension_value_class.h"
22-
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-
);
22+
#include <assert.h>
2723

2824
static int RAW_TYPE_STRING = 256;
2925
static int RAW_TYPE_BINARY = 257;
@@ -41,6 +37,8 @@ static inline VALUE rb_hash_new_capa(long capa)
4137

4238
void msgpack_unpacker_static_init(void)
4339
{
40+
assert(sizeof(msgpack_unpacker_stack_entry_t) * MSGPACK_UNPACKER_STACK_CAPACITY <= MSGPACK_RMEM_PAGE_SIZE);
41+
4442
msgpack_rmem_init(&s_stack_rmem);
4543

4644
s_call = rb_intern("call");

0 commit comments

Comments
 (0)