@@ -76,12 +76,16 @@ void *rb_wasm_handle_fiber_unwind(void (**new_fiber_entry)(void *, void *),
76
76
}
77
77
78
78
static VALUE rb_abi_guest_arena_hash ;
79
+ static VALUE rb_abi_guest_refcount_hash ;
80
+
79
81
static VALUE rb_abi_lend_object_internal (VALUE obj ) {
80
- VALUE ref_count = rb_hash_lookup (rb_abi_guest_arena_hash , obj );
82
+ VALUE object_id = rb_obj_id (obj );
83
+ VALUE ref_count = rb_hash_lookup (rb_abi_guest_refcount_hash , object_id );
81
84
if (NIL_P (ref_count )) {
82
- rb_hash_aset (rb_abi_guest_arena_hash , obj , INT2FIX (1 ));
85
+ rb_hash_aset (rb_abi_guest_arena_hash , object_id , obj );
86
+ rb_hash_aset (rb_abi_guest_refcount_hash , object_id , INT2FIX (1 ));
83
87
} else {
84
- rb_hash_aset (rb_abi_guest_arena_hash , obj , INT2FIX (FIX2INT (ref_count ) + 1 ));
88
+ rb_hash_aset (rb_abi_guest_refcount_hash , object_id , INT2FIX (FIX2INT (ref_count ) + 1 ));
85
89
}
86
90
return Qundef ;
87
91
}
@@ -93,17 +97,19 @@ static void rb_abi_lend_object(VALUE obj) {
93
97
}
94
98
95
99
static VALUE rb_abi_guest_rb_abi_value_dtor_internal (VALUE obj ) {
96
- VALUE ref_count = rb_hash_lookup (rb_abi_guest_arena_hash , obj );
100
+ VALUE object_id = rb_obj_id (obj );
101
+ VALUE ref_count = rb_hash_lookup (rb_abi_guest_refcount_hash , object_id );
97
102
if (NIL_P (ref_count )) {
98
103
rb_warning ("rb_abi_guest_rb_abi_value_dtor: double free detected" );
99
104
return Qundef ;
100
105
}
101
106
if (ref_count == INT2FIX (1 )) {
102
- rb_hash_delete (rb_abi_guest_arena_hash , obj );
103
107
RB_WASM_DEBUG_LOG ("rb_abi_guest_rb_abi_value_dtor: ref_count == 1\n" );
108
+ rb_hash_delete (rb_abi_guest_refcount_hash , object_id );
109
+ rb_hash_delete (rb_abi_guest_arena_hash , object_id );
104
110
} else {
105
- rb_hash_aset (rb_abi_guest_arena_hash , obj , INT2FIX (FIX2INT (ref_count ) - 1 ));
106
111
RB_WASM_DEBUG_LOG ("rb_abi_guest_rb_abi_value_dtor: ref_count = %d\n" , FIX2INT (ref_count ));
112
+ rb_hash_aset (rb_abi_guest_refcount_hash , object_id , INT2FIX (FIX2INT (ref_count ) - 1 ));
107
113
}
108
114
return Qundef ;
109
115
}
@@ -125,7 +131,10 @@ void rb_abi_guest_ruby_init(void) {
125
131
RB_WASM_LIB_RT (ruby_init ())
126
132
127
133
rb_abi_guest_arena_hash = rb_hash_new ();
134
+ rb_abi_guest_refcount_hash = rb_hash_new ();
135
+
128
136
rb_gc_register_mark_object (rb_abi_guest_arena_hash );
137
+ rb_gc_register_mark_object (rb_abi_guest_refcount_hash );
129
138
}
130
139
131
140
void rb_abi_guest_ruby_sysinit (rb_abi_guest_list_string_t * args ) {
0 commit comments