1--TEST-- 2GH-9090 (Support assigning function pointers via FFI) 3--EXTENSIONS-- 4ffi 5zend_test 6--FILE-- 7<?php 8 9$h = <<<'EOD' 10void (*bug_gh9090_void_none_ptr)(); 11void (*bug_gh9090_void_int_char_ptr)(int, char *); 12void (*bug_gh9090_void_int_char_var_ptr)(int, char *, ...); 13void (*bug_gh9090_void_char_int_ptr)(char *, int); 14int (*bug_gh9090_int_int_char_ptr)(int, char *); 15 16void bug_gh9090_void_none(); 17void bug_gh9090_void_int_char(int i, char *s); 18void bug_gh9090_void_int_char_var(int i, char *fmt, ...); 19EOD; 20 21$ffi = FFI::cdef($h); 22 23$func_ptrs = [ 24 'bug_gh9090_void_none_ptr', 25 'bug_gh9090_void_int_char_ptr', 26 'bug_gh9090_void_int_char_var_ptr', 27 'bug_gh9090_void_char_int_ptr', 28 'bug_gh9090_int_int_char_ptr', 29]; 30 31$func_argvs = [ 32 [ 'bug_gh9090_void_none', [ ] ], 33 [ 'bug_gh9090_void_int_char', [ 42, "hello" ] ], 34 [ 'bug_gh9090_void_int_char_var', [ 42, "d=%d s=%s", -1, "ok" ] ], 35]; 36 37foreach ($func_ptrs as $func_ptr) { 38 foreach ($func_argvs as $func_argv) { 39 [ $func, $argv ] = $func_argv; 40 41 $ok = true; 42 try { 43 $ffi->$func_ptr = $ffi->$func; 44 call_user_func_array($ffi->$func_ptr, $argv); 45 } catch (FFI\Exception $e) { 46 $ok = false; 47 } 48 49 printf("%-36s = %-36s ? %s\n", $func_ptr, $func, $ok ? 'yes' : 'no'); 50 } 51} 52?> 53--EXPECT-- 54bug_gh9090_none 55bug_gh9090_void_none_ptr = bug_gh9090_void_none ? yes 56bug_gh9090_void_none_ptr = bug_gh9090_void_int_char ? no 57bug_gh9090_void_none_ptr = bug_gh9090_void_int_char_var ? no 58bug_gh9090_void_int_char_ptr = bug_gh9090_void_none ? no 59bug_gh9090_int_char 42 hello 60bug_gh9090_void_int_char_ptr = bug_gh9090_void_int_char ? yes 61bug_gh9090_void_int_char_ptr = bug_gh9090_void_int_char_var ? no 62bug_gh9090_void_int_char_var_ptr = bug_gh9090_void_none ? no 63bug_gh9090_void_int_char_var_ptr = bug_gh9090_void_int_char ? no 64bug_gh9090_void_int_char_var d=-1 s=ok 65bug_gh9090_void_int_char_var_ptr = bug_gh9090_void_int_char_var ? yes 66bug_gh9090_void_char_int_ptr = bug_gh9090_void_none ? no 67bug_gh9090_void_char_int_ptr = bug_gh9090_void_int_char ? no 68bug_gh9090_void_char_int_ptr = bug_gh9090_void_int_char_var ? no 69bug_gh9090_int_int_char_ptr = bug_gh9090_void_none ? no 70bug_gh9090_int_int_char_ptr = bug_gh9090_void_int_char ? no 71bug_gh9090_int_int_char_ptr = bug_gh9090_void_int_char_var ? no 72