ext/ffi: Refactor methods to use ZPP parsing#13461
Open
Girgias wants to merge 2 commits intophp:masterfrom
Open
ext/ffi: Refactor methods to use ZPP parsing#13461Girgias wants to merge 2 commits intophp:masterfrom
Girgias wants to merge 2 commits intophp:masterfrom
Conversation
kocsismate
reviewed
Feb 23, 2024
| 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"); |
Member
There was a problem hiding this comment.
missing RETURN_THROWS(); here and below
Member
There was a problem hiding this comment.
Ah, I guess it's not missing, I just didn't notice the one at line 4532 (the diff is a bit clunky)
dstogov
reviewed
Feb 26, 2024
Member
dstogov
left a comment
There was a problem hiding this comment.
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.
Comment on lines
-1764
to
+1765
| #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); \ |
Member
There was a problem hiding this comment.
The change of prototype may affect other users.
Comment on lines
+4385
to
+4423
| 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; | ||
| } | ||
|
|
Member
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.