Skip to content

Commit e8b2b5f

Browse files
committed
ffi: fix tests
- skip locking in main thread
1 parent 391ca94 commit e8b2b5f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

ext/ffi/ffi.c

+20-5
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,10 @@ static void zend_ffi_fci_prepare(
972972
}
973973

974974
static void zend_ffi_interrupt_function(zend_execute_data *execute_data){ /* {{{ */
975+
if(FFI_G(callback_tid) == FFI_G(main_tid)){
976+
goto end;
977+
}
978+
975979
tsrm_mutex_lock(FFI_G(vm_request_lock));
976980
if (!zend_atomic_bool_load_ex(&FFI_G(callback_in_progress))) {
977981
goto end;
@@ -1072,7 +1076,14 @@ static void zend_ffi_callback_trampoline(ffi_cif* cif, void* ret, void** args, v
10721076
}
10731077

10741078
if (zend_atomic_bool_load_ex(&FFI_G(callback_in_progress))) {
1075-
zend_fiber_resume(&call_data.data->fiber, NULL, false);
1079+
// call PHP function
1080+
zend_fiber_transfer transfer = zend_fiber_resume(&call_data.data->fiber, NULL, false);
1081+
zend_ffi_type *ret_type = ZEND_FFI_TYPE(call_data.data->type->func.ret_type);
1082+
if(ret_type->kind != ZEND_FFI_TYPE_VOID){
1083+
// extract return value from fiber
1084+
zend_ffi_zval_to_cdata(call_data.ret, ret_type, &call_data.data->fiber.result);
1085+
}
1086+
10761087
efree(call_data.data->fiber.fci.params);
10771088
}
10781089

@@ -5613,6 +5624,10 @@ ZEND_MINIT_FUNCTION(ffi)
56135624
zend_ffi_ctype_handlers.get_properties = zend_fake_get_properties;
56145625
zend_ffi_ctype_handlers.get_gc = zend_fake_get_gc;
56155626

5627+
FFI_G(vm_request_lock) = tsrm_mutex_alloc();
5628+
FFI_G(vm_ack) = tsrm_cond_alloc();
5629+
FFI_G(vm_unlock) = tsrm_cond_alloc();
5630+
56165631
if (FFI_G(preload)) {
56175632
return zend_ffi_preload(FFI_G(preload));
56185633
}
@@ -5623,10 +5638,6 @@ ZEND_MINIT_FUNCTION(ffi)
56235638
orig_interrupt_function = zend_interrupt_function;
56245639
zend_interrupt_function = zend_ffi_interrupt_function;
56255640

5626-
FFI_G(vm_request_lock) = tsrm_mutex_alloc();
5627-
FFI_G(vm_ack) = tsrm_cond_alloc();
5628-
FFI_G(vm_unlock) = tsrm_cond_alloc();
5629-
56305641
return SUCCESS;
56315642
}
56325643
/* }}} */
@@ -5748,6 +5759,10 @@ static ZEND_GINIT_FUNCTION(ffi)
57485759
static ZEND_GSHUTDOWN_FUNCTION(ffi)
57495760
{
57505761
zend_ffi_wait_request_barrier(true);
5762+
tsrm_cond_free(ffi_globals->vm_ack);
5763+
tsrm_cond_free(ffi_globals->vm_unlock);
5764+
tsrm_mutex_free(ffi_globals->vm_request_lock);
5765+
57515766
if (ffi_globals->scopes) {
57525767
zend_hash_destroy(ffi_globals->scopes);
57535768
free(ffi_globals->scopes);

0 commit comments

Comments
 (0)