Skip to content

Commit

Permalink
Allow malloc during gc when GC has been disabled
Browse files Browse the repository at this point in the history
We should allow malloc during GC when GC has been explicitly disabled
since garbage_collect_with_gvl won't do anything if GC has been disabled.
  • Loading branch information
peterzhu2118 committed Jan 4, 2023
1 parent 799d805 commit 3bcf92d
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -9913,10 +9913,8 @@ gc_is_moveable_obj(rb_objspace_t *objspace, VALUE obj)
#define COULD_MALLOC_REGION_START() \
GC_ASSERT(during_gc); \
VALUE _already_disabled = rb_gc_disable_no_rest(); \
during_gc = false;

#define COULD_MALLOC_REGION_END() \
during_gc = true; \
if (_already_disabled == Qfalse) rb_objspace_gc_enable(objspace);

static VALUE
Expand Down Expand Up @@ -12216,7 +12214,7 @@ malloc_during_gc_p(rb_objspace_t *objspace)
* (since ractors can run while another thread is sweeping) and when we
* have the GVL (since if we don't have the GVL, we'll try to acquire the
* GVL which will block and ensure the other thread finishes GC). */
return during_gc && !rb_multi_ractor_p() && ruby_thread_has_gvl_p();
return during_gc && !dont_gc_val() && !rb_multi_ractor_p() && ruby_thread_has_gvl_p();
}

static inline void *
Expand Down

0 comments on commit 3bcf92d

Please sign in to comment.