Skip to content

Commit 965f425

Browse files
committed
Move check for GC to xmalloc and xcalloc
Moves the check earlier to before we actually perform the allocation.
1 parent 9da5a7e commit 965f425

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

gc.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12217,13 +12217,6 @@ malloc_during_gc_p(rb_objspace_t *objspace)
1221712217
static inline void *
1221812218
objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size)
1221912219
{
12220-
if (UNLIKELY(malloc_during_gc_p(objspace))) {
12221-
rb_warn("malloc during GC detected, this could cause crashes if it triggers another GC");
12222-
#if RGENGC_CHECK_MODE
12223-
rb_bug("Cannot malloc during GC");
12224-
#endif
12225-
}
12226-
1222712220
size = objspace_malloc_size(objspace, mem, size);
1222812221
objspace_malloc_increase(objspace, mem, size, 0, MEMOP_TYPE_MALLOC);
1222912222

@@ -12285,6 +12278,13 @@ objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size)
1228512278
static void *
1228612279
objspace_xmalloc0(rb_objspace_t *objspace, size_t size)
1228712280
{
12281+
if (UNLIKELY(malloc_during_gc_p(objspace))) {
12282+
rb_warn("malloc during GC detected, this could cause crashes if it triggers another GC");
12283+
#if RGENGC_CHECK_MODE
12284+
rb_bug("Cannot malloc during GC");
12285+
#endif
12286+
}
12287+
1228812288
void *mem;
1228912289

1229012290
size = objspace_malloc_prepare(objspace, size);
@@ -12546,6 +12546,13 @@ ruby_xmalloc2_body(size_t n, size_t size)
1254612546
static void *
1254712547
objspace_xcalloc(rb_objspace_t *objspace, size_t size)
1254812548
{
12549+
if (UNLIKELY(malloc_during_gc_p(objspace))) {
12550+
rb_warn("calloc during GC detected, this could cause crashes if it triggers another GC");
12551+
#if RGENGC_CHECK_MODE
12552+
rb_bug("Cannot calloc during GC");
12553+
#endif
12554+
}
12555+
1254912556
void *mem;
1255012557

1255112558
size = objspace_malloc_prepare(objspace, size);

0 commit comments

Comments
 (0)