Skip to content
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

FFI:Add support multiple instance struct pointer compatible and callback error contain args offset #5070

Closed
wants to merge 22 commits into from

Conversation

chopins
Copy link
Contributor

@chopins chopins commented Jan 9, 2020

change:
1. zend_ffi_is_compatible_type()
support check same name struct pointer of multiple FFI instance

Pseudo code:

<?php
$ffi1 = FFI::cdef("
typedef struct _a {
int a;
}
");
$ffi2 = FFI::cdef("
typedef struct _a {
int a;
}
extern void test (a* instance);
"
);
$av = $ffi1->new('a*');
$ffi2->test($av); //exec success, do not trigger segfaults or type incompatible error
?>

2. zend_ffi_create_callback()
report error message that contain offset of parameter
when has argc, will report below message:
Variadic function closures are not supported, parameter 1 occur
Attempt to assign parameter 1 to be invalid callback, %s
Attempt to assign parameter 1 to be invalid callback, insufficient number of arguments
Cannot allocate callback, parameter 1 occur

@chopins chopins changed the title ffi compatible struct pointers type and report callback args offset Add FFI support check same name struct pointer and report callback args offset Jan 11, 2020
@chopins chopins changed the title Add FFI support check same name struct pointer and report callback args offset Add FFI support check same name struct pointer of multiple instance and report callback error contain args offset Jan 11, 2020
@chopins chopins changed the title Add FFI support check same name struct pointer of multiple instance and report callback error contain args offset FFI:Add support multiple instance struct pointer compatible and callback error contain args offset, variadic callback Jan 17, 2020
@dstogov
Copy link
Member

dstogov commented Jan 27, 2020

hi @chopins,

  1. The first part of the patch (zend_ffi_is_compatible_type()) is incorrect. If you mix two different FFI objects with different C declarations, they may declare different structures with the same name. In general, you shouldn't mix different FFI objects or perform C casts.

  2. variadic callbacks. I've tested the patch, and it seems doesn't work as expected:

<?php
$ffi = FFI::cdef("
size_t (*zend_printf)(const char *format, ...);
");
$ffi->zend_printf = function ($format, ...$args) {
	var_dump($format, $args);
};
$f = $ffi->zend_printf;
$f("%s:%d:%d\n", "str", 5, 3);
?>

Please, use separate patches//PRs for different features.

@chopins
Copy link
Contributor Author

chopins commented Feb 6, 2020

@dstogov
for incorrect, I will test again and fix it
for mix object type, this is convenient features, and not conflict different structures with the same name, the developer to decide how to use.
multiple dll load convenience will enhance the usefulness of FFI

@chopins chopins changed the title FFI:Add support multiple instance struct pointer compatible and callback error contain args offset, variadic callback FFI:Add support multiple instance struct pointer compatible and callback error contain args offset Feb 11, 2020
@chopins
Copy link
Contributor Author

chopins commented Feb 11, 2020

i remove variadic callbacks feature

@chopins
Copy link
Contributor Author

chopins commented Mar 12, 2020

use pure php implement

@chopins chopins closed this Mar 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants