diff options
author | Peter Zhu <peter@peterzhu.ca> | 2023-09-06 14:20:23 -0400 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2023-09-06 14:20:23 -0400 |
commit | 12102d101af258d7a3e9695b736a189cd3658df1 (patch) | |
tree | 3182fb5048cb979df6b0d84c41e2469fe9fb6a57 /internal | |
parent | 746eede412f083dc93923e39e3299c69fce46c15 (diff) | |
download | ruby-12102d101af258d7a3e9695b736a189cd3658df1.tar.gz |
Fix crash in WeakMap during compaction
WeakMap can crash during compaction because the st_insert could allocate
memory.
Diffstat (limited to 'internal')
-rw-r--r-- | internal/gc.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/internal/gc.h b/internal/gc.h index 28b82f4196..f8f88a41cb 100644 --- a/internal/gc.h +++ b/internal/gc.h @@ -189,6 +189,17 @@ struct rb_objspace; /* in vm_core.h */ # define SIZE_POOL_COUNT 5 #endif +/* Used in places that could malloc during, which can cause the GC to run. We + * need to temporarily disable the GC to allow the malloc to happen. + * Allocating memory during GC is a bad idea, so use this only when absolutely + * necessary. */ +#define DURING_GC_COULD_MALLOC_REGION_START() \ + assert(rb_during_gc()); \ + VALUE _already_disabled = rb_gc_disable_no_rest() + +#define DURING_GC_COULD_MALLOC_REGION_END() \ + if (_already_disabled == Qfalse) rb_gc_enable() + typedef struct ractor_newobj_size_pool_cache { struct RVALUE *freelist; struct heap_page *using_page; |