From a3113ba2e7b03eb49f9849f46cc993e1a4dba2af Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Tue, 13 Jul 2021 10:11:36 -0400 Subject: [PATCH 1/3] Proposal: Rename FFI `getFuncArg*` to `getFuncParameter*` PHP is already already using "Parameter" instead of "Argument" for reflection on types elsewhere. Parameter is used to refer to the function declarations (AST_PARAM internally in the AST, ReflectionFunctionAbstract->getParameters(), etc.) Argument is used to refer to expressions passed to the functions by the caller (ArgumentCountError, etc.). (Error messages were also changed in php 8.x to refer to passing too many arguments to a function) Other languages use similar definitions, e.g. https://developer.mozilla.org/en-US/docs/Glossary/Parameter --- ext/ffi/ffi.c | 4 ++-- ext/ffi/ffi.stub.php | 4 ++-- ext/ffi/ffi_arginfo.h | 14 +++++++------- ext/ffi/tests/046.phpt | 6 +++--- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 50c898ad4de75..348d1fb80a48b 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -4730,7 +4730,7 @@ ZEND_METHOD(FFI_CType, getFuncReturnType) /* {{{ */ } /* }}} */ -ZEND_METHOD(FFI_CType, getFuncArgCount) /* {{{ */ +ZEND_METHOD(FFI_CType, getFuncParameterCount) /* {{{ */ { zend_ffi_ctype *ctype = (zend_ffi_ctype*)(Z_OBJ_P(ZEND_THIS)); zend_ffi_type *type; @@ -4748,7 +4748,7 @@ ZEND_METHOD(FFI_CType, getFuncArgCount) /* {{{ */ } /* }}} */ -ZEND_METHOD(FFI_CType, getFuncArgType) /* {{{ */ +ZEND_METHOD(FFI_CType, getFuncParameterType) /* {{{ */ { zend_ffi_ctype *ctype = (zend_ffi_ctype*)(Z_OBJ_P(ZEND_THIS)); zend_ffi_type *type, *ptr; diff --git a/ext/ffi/ffi.stub.php b/ext/ffi/ffi.stub.php index 8f20a3daa8f86..3a77550f46b1d 100644 --- a/ext/ffi/ffi.stub.php +++ b/ext/ffi/ffi.stub.php @@ -92,8 +92,8 @@ public function getStructFieldType(string $field_name): CType {} public function getFuncABI(): int {} public function getFuncReturnType(): CType {} - public function getFuncArgCount(): int {} - public function getFuncArgType(int $arg_index): CType {} + public function getFuncParameterCount(): int {} + public function getFuncParameterType(int $arg_index): CType {} } class Exception extends \Error { diff --git a/ext/ffi/ffi_arginfo.h b/ext/ffi/ffi_arginfo.h index 4e2c6dad06980..e300e9a9a4310 100644 --- a/ext/ffi/ffi_arginfo.h +++ b/ext/ffi/ffi_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: bdfc4211d30630290aaf5046dd4ae72936982703 */ + * Stub hash: e1141661e96f6fcf67b7dc79b345cfb50c246ac2 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_cdef, 0, 0, FFI, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 0, "\"\"") @@ -115,9 +115,9 @@ ZEND_END_ARG_INFO() #define arginfo_class_FFI_CType_getFuncReturnType arginfo_class_FFI_CType_getArrayElementType -#define arginfo_class_FFI_CType_getFuncArgCount arginfo_class_FFI_CType_getKind +#define arginfo_class_FFI_CType_getFuncParameterCount arginfo_class_FFI_CType_getKind -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_CType_getFuncArgType, 0, 1, FFI\\CType, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_CType_getFuncParameterType, 0, 1, FFI\\CType, 0) ZEND_ARG_TYPE_INFO(0, arg_index, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -153,8 +153,8 @@ ZEND_METHOD(FFI_CType, getStructFieldOffset); ZEND_METHOD(FFI_CType, getStructFieldType); ZEND_METHOD(FFI_CType, getFuncABI); ZEND_METHOD(FFI_CType, getFuncReturnType); -ZEND_METHOD(FFI_CType, getFuncArgCount); -ZEND_METHOD(FFI_CType, getFuncArgType); +ZEND_METHOD(FFI_CType, getFuncParameterCount); +ZEND_METHOD(FFI_CType, getFuncParameterType); static const zend_function_entry class_FFI_methods[] = { @@ -199,8 +199,8 @@ static const zend_function_entry class_FFI_CType_methods[] = { ZEND_ME(FFI_CType, getStructFieldType, arginfo_class_FFI_CType_getStructFieldType, ZEND_ACC_PUBLIC) ZEND_ME(FFI_CType, getFuncABI, arginfo_class_FFI_CType_getFuncABI, ZEND_ACC_PUBLIC) ZEND_ME(FFI_CType, getFuncReturnType, arginfo_class_FFI_CType_getFuncReturnType, ZEND_ACC_PUBLIC) - ZEND_ME(FFI_CType, getFuncArgCount, arginfo_class_FFI_CType_getFuncArgCount, ZEND_ACC_PUBLIC) - ZEND_ME(FFI_CType, getFuncArgType, arginfo_class_FFI_CType_getFuncArgType, ZEND_ACC_PUBLIC) + ZEND_ME(FFI_CType, getFuncParameterCount, arginfo_class_FFI_CType_getFuncParameterCount, ZEND_ACC_PUBLIC) + ZEND_ME(FFI_CType, getFuncParameterType, arginfo_class_FFI_CType_getFuncParameterType, ZEND_ACC_PUBLIC) ZEND_FE_END }; diff --git a/ext/ffi/tests/046.phpt b/ext/ffi/tests/046.phpt index 345cc84727bd2..ebce17728b42f 100644 --- a/ext/ffi/tests/046.phpt +++ b/ext/ffi/tests/046.phpt @@ -47,9 +47,9 @@ $x = FFI::type("void (*)(double,int32_t)"); var_dump($x->getKind() === $x::TYPE_POINTER); var_dump($x->getPointerType()->getKind() === $x::TYPE_FUNC); var_dump($x->getPointerType()->getFuncReturnType()->getKind() === $x::TYPE_VOID); -var_dump($x->getPointerType()->getFuncArgCount()); -var_dump($x->getPointerType()->getFuncArgType(0)->getKind() === $x::TYPE_DOUBLE); -var_dump($x->getPointerType()->getFuncArgType(1)->getKind() === $x::TYPE_SINT32); +var_dump($x->getPointerType()->getFuncParameterCount()); +var_dump($x->getPointerType()->getFuncParameterType(0)->getKind() === $x::TYPE_DOUBLE); +var_dump($x->getPointerType()->getFuncParameterType(1)->getKind() === $x::TYPE_SINT32); ?> --EXPECT-- bool(true) From 0a2a22f2940c15af2ba25106bc9710307bca8313 Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Tue, 13 Jul 2021 11:55:23 -0400 Subject: [PATCH 2/3] Fix typos --- ext/ffi/ffi.c | 4 ++-- ext/ffi/tests/bug80847.phpt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c index 348d1fb80a48b..1aabd9e030cc6 100644 --- a/ext/ffi/ffi.c +++ b/ext/ffi/ffi.c @@ -4653,7 +4653,7 @@ ZEND_METHOD(FFI_CType, getStructFieldOffset) /* {{{ */ ptr = zend_hash_find_ptr(&type->record.fields, name); if (!ptr) { - zend_throw_error(zend_ffi_exception_ce, "Wrong fileld name"); + zend_throw_error(zend_ffi_exception_ce, "Wrong field name"); RETURN_THROWS(); } RETURN_LONG(ptr->offset); @@ -4680,7 +4680,7 @@ ZEND_METHOD(FFI_CType, getStructFieldType) /* {{{ */ ptr = zend_hash_find_ptr(&type->record.fields, name); if (!ptr) { - zend_throw_error(zend_ffi_exception_ce, "Wrong fileld name"); + zend_throw_error(zend_ffi_exception_ce, "Wrong field name"); RETURN_THROWS(); } diff --git a/ext/ffi/tests/bug80847.phpt b/ext/ffi/tests/bug80847.phpt index 1fc47b4bc560e..efa8bfae946ec 100644 --- a/ext/ffi/tests/bug80847.phpt +++ b/ext/ffi/tests/bug80847.phpt @@ -4,7 +4,7 @@ Bug #80847 (Nested structs) ffi --SKIPIF-- 0)) die('xfail libffi doesn\'t properly support passing big strctures by value on Windows/64'); +if (PHP_OS_FAMILY == 'Windows' && ((1 << 31) > 0)) die('xfail libffi doesn\'t properly support passing big structures by value on Windows/64'); ?> --FILE-- Date: Tue, 13 Jul 2021 11:57:14 -0400 Subject: [PATCH 3/3] Rename $arg_index to $index Elsewhere, just $index is used in stubs such as for ext/zip --- ext/ffi/ffi.stub.php | 2 +- ext/ffi/ffi_arginfo.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/ffi/ffi.stub.php b/ext/ffi/ffi.stub.php index 3a77550f46b1d..cc46a8d15754f 100644 --- a/ext/ffi/ffi.stub.php +++ b/ext/ffi/ffi.stub.php @@ -93,7 +93,7 @@ public function getStructFieldType(string $field_name): CType {} public function getFuncABI(): int {} public function getFuncReturnType(): CType {} public function getFuncParameterCount(): int {} - public function getFuncParameterType(int $arg_index): CType {} + public function getFuncParameterType(int $index): CType {} } class Exception extends \Error { diff --git a/ext/ffi/ffi_arginfo.h b/ext/ffi/ffi_arginfo.h index e300e9a9a4310..4b0ad4e24b63f 100644 --- a/ext/ffi/ffi_arginfo.h +++ b/ext/ffi/ffi_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: e1141661e96f6fcf67b7dc79b345cfb50c246ac2 */ + * Stub hash: 2675462a253edd2a0ea6106b9640f0d1a5a09489 */ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_cdef, 0, 0, FFI, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, code, IS_STRING, 0, "\"\"") @@ -118,7 +118,7 @@ ZEND_END_ARG_INFO() #define arginfo_class_FFI_CType_getFuncParameterCount arginfo_class_FFI_CType_getKind ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_FFI_CType_getFuncParameterType, 0, 1, FFI\\CType, 0) - ZEND_ARG_TYPE_INFO(0, arg_index, IS_LONG, 0) + ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0) ZEND_END_ARG_INFO()