From 851e4623f58926ff387c43960ab5c31e09701c51 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 13 Feb 2023 22:42:39 +0300 Subject: [PATCH] Make C functions returning "void" to return PHP "null" In PHP-2.0 and below we by mistake returned "obcect(FFI\CData:void)#2 (0) {}". We decided not to fix this in PHP-2.0 and below to aboid BC breaks. --- ext/ffi/ffi.c | 6 +++++- ext/ffi/tests/gh10568.phpt | 3 +-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index ebb2522f84790..f22c44e80c460 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -2832,7 +2832,11 @@ static ZEND_FUNCTION(ffi_trampoline) /* {{{ */ free_alloca(arg_values, arg_values_use_heap); } - zend_ffi_cdata_to_zval(NULL, ret, ZEND_FFI_TYPE(type->func.ret_type), BP_VAR_R, return_value, 0, 1, 0); + if (ZEND_FFI_TYPE(type->func.ret_type)->kind != ZEND_FFI_TYPE_VOID) { + zend_ffi_cdata_to_zval(NULL, ret, ZEND_FFI_TYPE(type->func.ret_type), BP_VAR_R, return_value, 0, 1, 0); + } else { + ZVAL_NULL(return_value); + } free_alloca(ret, ret_use_heap); exit: diff --git a/ext/ffi/tests/gh10568.phpt b/ext/ffi/tests/gh10568.phpt index bd76671438d1b..9da9334920666 100644 --- a/ext/ffi/tests/gh10568.phpt +++ b/ext/ffi/tests/gh10568.phpt @@ -20,6 +20,5 @@ var_dump($libc->strlen("abc")); ?> DONE --EXPECT-- -object(FFI\CData:void)#2 (0) { -} +NULL DONE