@@ -972,6 +972,10 @@ static void zend_ffi_fci_prepare(
972
972
}
973
973
974
974
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
+
975
979
tsrm_mutex_lock (FFI_G (vm_request_lock ));
976
980
if (!zend_atomic_bool_load_ex (& FFI_G (callback_in_progress ))) {
977
981
goto end ;
@@ -1072,7 +1076,14 @@ static void zend_ffi_callback_trampoline(ffi_cif* cif, void* ret, void** args, v
1072
1076
}
1073
1077
1074
1078
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
+
1076
1087
efree (call_data .data -> fiber .fci .params );
1077
1088
}
1078
1089
@@ -5613,6 +5624,10 @@ ZEND_MINIT_FUNCTION(ffi)
5613
5624
zend_ffi_ctype_handlers .get_properties = zend_fake_get_properties ;
5614
5625
zend_ffi_ctype_handlers .get_gc = zend_fake_get_gc ;
5615
5626
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
+
5616
5631
if (FFI_G (preload )) {
5617
5632
return zend_ffi_preload (FFI_G (preload ));
5618
5633
}
@@ -5623,10 +5638,6 @@ ZEND_MINIT_FUNCTION(ffi)
5623
5638
orig_interrupt_function = zend_interrupt_function ;
5624
5639
zend_interrupt_function = zend_ffi_interrupt_function ;
5625
5640
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
-
5630
5641
return SUCCESS ;
5631
5642
}
5632
5643
/* }}} */
@@ -5748,6 +5759,10 @@ static ZEND_GINIT_FUNCTION(ffi)
5748
5759
static ZEND_GSHUTDOWN_FUNCTION (ffi )
5749
5760
{
5750
5761
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
+
5751
5766
if (ffi_globals -> scopes ) {
5752
5767
zend_hash_destroy (ffi_globals -> scopes );
5753
5768
free (ffi_globals -> scopes );
0 commit comments