summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2022-12-17 09:13:46 -0500
committerPeter Zhu <peter@peterzhu.ca>2022-12-17 09:16:26 -0500
commit965f4259db5ad59045f778d4129f65e381aab004 (patch)
tree41394c80c3e2fdc367b29e4fa7d93ab849e2aecf /gc.c
parent9da5a7e79dcaed9bf233f6a9a5df54c727f60c77 (diff)
Move check for GC to xmalloc and xcalloc
Moves the check earlier to before we actually perform the allocation.
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/gc.c b/gc.c
index f5888cf153..c9d336eed3 100644
--- a/gc.c
+++ b/gc.c
@@ -12217,13 +12217,6 @@ malloc_during_gc_p(rb_objspace_t *objspace)
static inline void *
objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size)
{
- if (UNLIKELY(malloc_during_gc_p(objspace))) {
- rb_warn("malloc during GC detected, this could cause crashes if it triggers another GC");
-#if RGENGC_CHECK_MODE
- rb_bug("Cannot malloc during GC");
-#endif
- }
-
size = objspace_malloc_size(objspace, mem, size);
objspace_malloc_increase(objspace, mem, size, 0, MEMOP_TYPE_MALLOC);
@@ -12285,6 +12278,13 @@ objspace_malloc_fixup(rb_objspace_t *objspace, void *mem, size_t size)
static void *
objspace_xmalloc0(rb_objspace_t *objspace, size_t size)
{
+ if (UNLIKELY(malloc_during_gc_p(objspace))) {
+ rb_warn("malloc during GC detected, this could cause crashes if it triggers another GC");
+#if RGENGC_CHECK_MODE
+ rb_bug("Cannot malloc during GC");
+#endif
+ }
+
void *mem;
size = objspace_malloc_prepare(objspace, size);
@@ -12546,6 +12546,13 @@ ruby_xmalloc2_body(size_t n, size_t size)
static void *
objspace_xcalloc(rb_objspace_t *objspace, size_t size)
{
+ if (UNLIKELY(malloc_during_gc_p(objspace))) {
+ rb_warn("calloc during GC detected, this could cause crashes if it triggers another GC");
+#if RGENGC_CHECK_MODE
+ rb_bug("Cannot calloc during GC");
+#endif
+ }
+
void *mem;
size = objspace_malloc_prepare(objspace, size);