@@ -20,6 +20,13 @@ void *rb_wasm_handle_scan_unwind(void);
20
20
void * rb_wasm_handle_fiber_unwind (void (* * new_fiber_entry )(void * , void * ),
21
21
void * * arg0 , void * * arg1 ,
22
22
bool * is_new_fiber_started );
23
+ #define RB_WASM_ENABLE_DEBUG_LOG 0
24
+
25
+ #if RB_WASM_ENABLE_DEBUG_LOG
26
+ # define RB_WASM_DEBUG_LOG (...) fprintf(stderr, __VA_ARGS__)
27
+ #else
28
+ # define RB_WASM_DEBUG_LOG (...) (void)0
29
+ #endif
23
30
24
31
#define RB_WASM_LIB_RT (MAIN_ENTRY ) \
25
32
{ \
@@ -79,6 +86,7 @@ static VALUE rb_abi_lend_object_internal(VALUE obj) {
79
86
return Qundef ;
80
87
}
81
88
static void rb_abi_lend_object (VALUE obj ) {
89
+ RB_WASM_DEBUG_LOG ("rb_abi_lend_object: obj = %p\n" , (void * )obj );
82
90
int state ;
83
91
RB_WASM_LIB_RT (rb_protect (rb_abi_lend_object_internal , obj , & state ));
84
92
assert (state == TAG_NONE && "rb_abi_lend_object_internal failed" );
@@ -92,13 +100,16 @@ static VALUE rb_abi_guest_rb_abi_value_dtor_internal(VALUE obj) {
92
100
}
93
101
if (ref_count == INT2FIX (1 )) {
94
102
rb_hash_delete (rb_abi_guest_arena_hash , obj );
103
+ RB_WASM_DEBUG_LOG ("rb_abi_guest_rb_abi_value_dtor: ref_count == 1\n" );
95
104
} else {
96
105
rb_hash_aset (rb_abi_guest_arena_hash , obj , INT2FIX (FIX2INT (ref_count ) - 1 ));
106
+ RB_WASM_DEBUG_LOG ("rb_abi_guest_rb_abi_value_dtor: ref_count = %d\n" , FIX2INT (ref_count ));
97
107
}
98
108
return Qundef ;
99
109
}
100
110
101
111
void rb_abi_guest_rb_abi_value_dtor (void * data ) {
112
+ RB_WASM_DEBUG_LOG ("rb_abi_guest_rb_abi_value_dtor: data = %p\n" , data );
102
113
int state ;
103
114
RB_WASM_LIB_RT (rb_protect (rb_abi_guest_rb_abi_value_dtor_internal , (VALUE )data , & state ));
104
115
assert (state == TAG_NONE && "rb_abi_guest_rb_abi_value_dtor_internal failed" );
@@ -153,8 +164,10 @@ void rb_abi_guest_rb_eval_string_protect(rb_abi_guest_string_t *str,
153
164
rb_abi_guest_rb_abi_value_t * result ,
154
165
int32_t * state ) {
155
166
VALUE retval ;
167
+ RB_WASM_DEBUG_LOG ("rb_eval_string_protect: str = %s\n" , str -> ptr );
156
168
RB_WASM_LIB_RT (retval = rb_eval_string_protect (str -> ptr , state ));
157
169
rb_abi_lend_object (retval );
170
+ RB_WASM_DEBUG_LOG ("rb_eval_string_protect: retval = %p, state = %d\n" , (void * )retval , * state );
158
171
159
172
* result = rb_abi_guest_rb_abi_value_new ((void * )retval );
160
173
}
@@ -185,6 +198,8 @@ void rb_abi_guest_rb_funcallv_protect(rb_abi_guest_rb_abi_value_t recv,
185
198
.recv = r_recv , .mid = mid , .args = args };
186
199
RB_WASM_LIB_RT (retval = rb_protect (rb_funcallv_thunk , (VALUE )& ctx , ret1 ));
187
200
rb_abi_lend_object (retval );
201
+ RB_WASM_DEBUG_LOG ("rb_abi_guest_rb_funcallv_protect: retval = %p, state = %d\n" , (void * )retval , * ret1 );
202
+
188
203
* ret0 = rb_abi_guest_rb_abi_value_new ((void * )retval );
189
204
}
190
205
0 commit comments