|
2 | 2 |
|
3 | 3 | #include "ruby.h"
|
4 | 4 |
|
| 5 | +#define TAG_NONE 0 |
| 6 | + |
5 | 7 | #include "bindgen/rb-abi-guest.h"
|
6 | 8 |
|
7 | 9 | __attribute__((import_module("asyncify"), import_name("start_unwind"))) void
|
@@ -67,30 +69,39 @@ void *rb_wasm_handle_fiber_unwind(void (**new_fiber_entry)(void *, void *),
|
67 | 69 | }
|
68 | 70 |
|
69 | 71 | static VALUE rb_abi_guest_arena_hash;
|
70 |
| -static void rb_abi_lend_object_internal(VALUE obj) { |
| 72 | +static VALUE rb_abi_lend_object_internal(VALUE obj) { |
71 | 73 | VALUE ref_count = rb_hash_lookup(rb_abi_guest_arena_hash, obj);
|
72 | 74 | if (NIL_P(ref_count)) {
|
73 | 75 | rb_hash_aset(rb_abi_guest_arena_hash, obj, INT2FIX(1));
|
74 | 76 | } else {
|
75 | 77 | rb_hash_aset(rb_abi_guest_arena_hash, obj, INT2FIX(FIX2INT(ref_count) + 1));
|
76 | 78 | }
|
| 79 | + return Qundef; |
77 | 80 | }
|
78 | 81 | static void rb_abi_lend_object(VALUE obj) {
|
79 |
| - RB_WASM_LIB_RT(rb_abi_lend_object_internal(obj)); |
| 82 | + int state; |
| 83 | + RB_WASM_LIB_RT(rb_protect(rb_abi_lend_object_internal, obj, &state)); |
| 84 | + assert(state == TAG_NONE && "rb_abi_lend_object_internal failed"); |
80 | 85 | }
|
81 | 86 |
|
82 |
| -void rb_abi_guest_rb_abi_value_dtor(void *data) { |
83 |
| - VALUE obj = (VALUE)data; |
| 87 | +static VALUE rb_abi_guest_rb_abi_value_dtor_internal(VALUE obj) { |
84 | 88 | VALUE ref_count = rb_hash_lookup(rb_abi_guest_arena_hash, obj);
|
85 | 89 | if (NIL_P(ref_count)) {
|
86 | 90 | rb_warning("rb_abi_guest_rb_abi_value_dtor: double free detected");
|
87 |
| - return; |
| 91 | + return Qundef; |
88 | 92 | }
|
89 | 93 | if (ref_count == INT2FIX(1)) {
|
90 | 94 | rb_hash_delete(rb_abi_guest_arena_hash, obj);
|
91 | 95 | } else {
|
92 | 96 | rb_hash_aset(rb_abi_guest_arena_hash, obj, INT2FIX(FIX2INT(ref_count) - 1));
|
93 | 97 | }
|
| 98 | + return Qundef; |
| 99 | +} |
| 100 | + |
| 101 | +void rb_abi_guest_rb_abi_value_dtor(void *data) { |
| 102 | + int state; |
| 103 | + RB_WASM_LIB_RT(rb_protect(rb_abi_guest_rb_abi_value_dtor_internal, (VALUE)data, &state)); |
| 104 | + assert(state == TAG_NONE && "rb_abi_guest_rb_abi_value_dtor_internal failed"); |
94 | 105 | }
|
95 | 106 |
|
96 | 107 | // MARK: - Exported functions
|
|
0 commit comments