Skip to content

Commit b1a0891

Browse files
committed
Fix memsize function for embedded types
We shouldn't report the size of the embedded struct.
1 parent 500f0ea commit b1a0891

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

ext/json/ext/generator/generator.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,11 @@ static void State_compact(void *ptr)
724724

725725
static size_t State_memsize(const void *ptr)
726726
{
727+
#ifdef HAVE_RUBY_TYPED_EMBEDDABLE
728+
return 0;
729+
#else
727730
return sizeof(JSON_Generator_State);
731+
#endif
728732
}
729733

730734
static const rb_data_type_t JSON_Generator_State_type = {

ext/json/ext/parser/parser.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,11 @@ static void rvalue_stack_free(void *ptr)
268268
static size_t rvalue_stack_memsize(const void *ptr)
269269
{
270270
const rvalue_stack *stack = (const rvalue_stack *)ptr;
271-
return sizeof(rvalue_stack) + sizeof(VALUE) * stack->capa;
271+
size_t memsize = sizeof(VALUE) * stack->capa;
272+
#ifndef HAVE_RUBY_TYPED_EMBEDDABLE
273+
memsize += sizeof(rvalue_stack);
274+
#endif
275+
return memsize;
272276
}
273277

274278
static const rb_data_type_t JSON_Parser_rvalue_stack_type = {
@@ -452,7 +456,12 @@ static void json_frame_stack_free(void *ptr)
452456
static size_t json_frame_stack_memsize(const void *ptr)
453457
{
454458
const json_frame_stack *stack = (const json_frame_stack *)ptr;
455-
return sizeof(json_frame_stack) + sizeof(json_frame) * stack->capa;
459+
460+
size_t memsize = sizeof(json_frame) * stack->capa;
461+
#ifndef HAVE_RUBY_TYPED_EMBEDDABLE
462+
memsize += sizeof(json_frame_stack);
463+
#endif
464+
return memsize;
456465
}
457466

458467
static const rb_data_type_t JSON_Parser_frame_stack_type = {
@@ -1961,7 +1970,11 @@ static void JSON_ParserConfig_mark(void *ptr)
19611970

19621971
static size_t JSON_ParserConfig_memsize(const void *ptr)
19631972
{
1973+
#ifdef HAVE_RUBY_TYPED_EMBEDDABLE
1974+
return 0;
1975+
#else
19641976
return sizeof(JSON_ParserConfig);
1977+
#endif
19651978
}
19661979

19671980
static const rb_data_type_t JSON_ParserConfig_type = {

0 commit comments

Comments
 (0)