Introduce free function to rb_concurrent_set_funcs

If we create a key but don't insert it (due to other Ractor winning the
race), then it would leak memory if we don't free it. This introduces a
new function to free that memory for this case.
This commit is contained in:
Peter Zhu 2025-07-18 10:58:41 -04:00
parent 061224f3cb
commit 66349692f0
4 changed files with 22 additions and 7 deletions

View file

@ -4,14 +4,11 @@
#include "ruby/atomic.h"
#include "ruby/ruby.h"
typedef VALUE (*rb_concurrent_set_hash_func)(VALUE key);
typedef bool (*rb_concurrent_set_cmp_func)(VALUE a, VALUE b);
typedef VALUE (*rb_concurrent_set_create_func)(VALUE key, void *data);
struct rb_concurrent_set_funcs {
rb_concurrent_set_hash_func hash;
rb_concurrent_set_cmp_func cmp;
rb_concurrent_set_create_func create;
VALUE (*hash)(VALUE key);
bool (*cmp)(VALUE a, VALUE b);
VALUE (*create)(VALUE key, void *data);
void (*free)(VALUE key);
};
VALUE rb_concurrent_set_new(const struct rb_concurrent_set_funcs *funcs, int capacity);