-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ext/ffi: Refactor methods to use ZPP parsing #13461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
ptr2 = php_ffi_parse_cdata_or_string_to_ptr(size, op2_obj, op2_zstr, &is_error); | ||
if (is_error) { | ||
if (op2_zstr) { | ||
zend_throw_error(zend_ffi_exception_ce, "attempt to read over string boundary"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing RETURN_THROWS();
here and below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I guess it's not missing, I just didn't notice the one at line 4532 (the diff is a bit clunky)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR name looks weird. ZPP
is abbreviation to Zend Parameter Parsing.
The patch only adds information about types of FFI::memcpy()
and FFI::memset()
arguments.
I'm indifferent to this change.
#define Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, allow_null) \ | ||
Z_PARAM_PROLOGUE(0, 0); \ | ||
#define Z_PARAM_OBJ_OF_CLASS_OR_STR_EX(destination_object, base_ce, destination_string, allow_null, deref) \ | ||
Z_PARAM_PROLOGUE(deref, 0); \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change of prototype may affect other users.
static void *php_ffi_parse_cdata_to_ptr(zend_long size, zend_object *zobj, bool *is_error) | ||
{ | ||
void *result_ptr = NULL; | ||
*is_error = false; | ||
|
||
zend_ffi_cdata *cdata = (zend_ffi_cdata*)zobj; | ||
zend_ffi_type *type = ZEND_FFI_TYPE(cdata->type); | ||
|
||
if (type->kind == ZEND_FFI_TYPE_POINTER) { | ||
result_ptr = *(void**)cdata->ptr; | ||
} else { | ||
if (type->kind != ZEND_FFI_TYPE_POINTER && size > type->size) { | ||
*is_error = true; | ||
return NULL; | ||
} | ||
result_ptr = cdata->ptr; | ||
} | ||
|
||
return result_ptr; | ||
} | ||
|
||
static void *php_ffi_parse_cdata_or_string_to_ptr(zend_long size, zend_object *zobj, zend_string *zstr, bool *is_error) | ||
{ | ||
void *result_ptr = NULL; | ||
*is_error = false; | ||
|
||
if (zstr) { | ||
if (size > ZSTR_LEN(zstr)) { | ||
*is_error = true; | ||
return NULL; | ||
} | ||
result_ptr = ZSTR_VAL(zstr); | ||
} else { | ||
result_ptr = php_ffi_parse_cdata_to_ptr(size, zobj, is_error); | ||
} | ||
|
||
return result_ptr; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separation of this functions doesn't make things more clear, because you delegated them to check for data/string size and this became unclear.
No description provided.