Add a minimal internal WeakMap C-API

This will be used to make the refinement iclasses cache weak, avoiding
a memory leak when creating and using an arbitrary number of
refinements.
This commit is contained in:
Jeremy Evans committed 2026-10-10 01:14:57 -07:00
1 parent 34a2abf607
commit 35c32429e1
2 files changed
+21
Notes: git 2026-10-10 08:16:16 +00:00

No files matched your search

+3
View File
@@ -188,6 +188,9 @@ RUBY_ATTR_MALLOC void *ruby_mimmalloc(size_t size);
RUBY_ATTR_MALLOC void *ruby_mimcalloc(size_t num, size_t size);
void ruby_mimfree(void *ptr);
void rb_gc_prepare_heap(void);
VALUE rb_wmap_new_hidden(void);
VALUE rb_wmap_lookup(VALUE wmap, VALUE key);
void rb_wmap_aset(VALUE wmap, VALUE key, VALUE val);
void rb_objspace_set_event_hook(const rb_event_flag_t event);
VALUE rb_objspace_gc_enable(void *objspace);
VALUE rb_objspace_gc_disable(void *objspace);
+18
View File
@@ -504,6 +504,24 @@ wmap_size(VALUE self)
#endif
}
VALUE
rb_wmap_new_hidden(void)
{
return wmap_allocate(0);
}
VALUE
rb_wmap_lookup(VALUE self, VALUE key)
{
return wmap_lookup(self, key);
}
void
rb_wmap_aset(VALUE self, VALUE key, VALUE val)
{
wmap_aset(self, key, val);
}
/* ===== WeakKeyMap =====
*
* WeakKeyMap contains one ST table which contains a pointer to the object as