File tree Expand file tree Collapse file tree 11 files changed +67
-55
lines changed Expand file tree Collapse file tree 11 files changed +67
-55
lines changed Original file line number Diff line number Diff line change 2
2
FFI 100: PHP symbols
3
3
--SKIPIF--
4
4
<?php require_once ('skipif.inc ' ); ?>
5
+ <?php require_once ('utils.inc ' ); ?>
5
6
<?php
6
7
try {
7
- FFI :: cdef ("extern void *zend_printf; " );
8
+ ffi_cdef ("extern void *zend_printf; " , ffi_get_php_dll_name () );
8
9
} catch (Throwable $ e ) {
9
10
die ('skip PHP symbols not available ' );
10
11
}
13
14
ffi.enable=1
14
15
--FILE--
15
16
<?php
16
- // Check if target supports "fastcall" calling convention
17
- try {
18
- FFI ::cdef ("extern size_t __attribute__((fastcall)) (*zend_printf)(const char *format); " );
19
- $ fastcall = "__attribute__((fastcall)) " ;
20
- } catch (Throwable $ e ) {
21
- $ fastcall = "" ;
22
- }
23
- $ zend = FFI ::cdef ("
17
+ require_once ('utils.inc ' );
18
+ $ fastcall = ffi_get_fastcall_specifier ();
19
+ $ zend = ffi_cdef ("
24
20
const char *get_zend_version(void);
25
21
//char *get_zend_version(void);
26
22
extern size_t (*zend_printf)(const char *format, ...);
@@ -29,7 +25,7 @@ $zend = FFI::cdef("
29
25
30
26
void $ fastcall zend_str_tolower(char *str, size_t length);
31
27
32
- " );
28
+ ", ffi_get_php_dll_name () );
33
29
var_dump (trim (explode ("\n" ,$ zend ->get_zend_version ())[0 ]));
34
30
//var_dump(trim(FFI::string($zend->get_zend_version())));
35
31
var_dump ($ zend ->zend_printf );
Original file line number Diff line number Diff line change 2
2
FFI 101: PHP symbols (function address)
3
3
--SKIPIF--
4
4
<?php require_once ('skipif.inc ' ); ?>
5
+ <?php require_once ('utils.inc ' ); ?>
5
6
<?php
6
7
try {
7
- FFI :: cdef ("extern void *zend_printf; " );
8
+ ffi_cdef ("extern void *zend_printf; " , ffi_get_php_dll_name () );
8
9
} catch (Throwable $ e ) {
9
10
die ('skip PHP symbols not available ' );
10
11
}
13
14
ffi.enable=1
14
15
--FILE--
15
16
<?php
16
- // Check if target supports "fastcall" calling convention
17
- try {
18
- FFI ::cdef ("extern size_t __attribute__((fastcall)) (*zend_printf)(const char *format); " );
19
- $ fastcall = "__attribute__((fastcall)) " ;
20
- } catch (Throwable $ e ) {
21
- $ fastcall = "" ;
22
- }
23
- $ zend = FFI ::cdef ("
17
+ require_once ('utils.inc ' );
18
+ $ fastcall = ffi_get_fastcall_specifier ();
19
+ $ zend = ffi_cdef ("
24
20
const char *get_zend_version(void);
25
21
//char *get_zend_version(void);
26
22
extern size_t (*zend_printf)(const char *format, ...);
@@ -29,7 +25,7 @@ $zend = FFI::cdef("
29
25
30
26
void $ fastcall zend_str_tolower(char *str, size_t length);
31
27
32
- " );
28
+ ", ffi_get_php_dll_name () );
33
29
$ f = $ zend ->get_zend_version ;
34
30
var_dump (trim (explode ("\n" ,$ f ())[0 ]));
35
31
//var_dump(trim(FFI::string($zend->get_zend_version())));
Original file line number Diff line number Diff line change 2
2
FFI 200: PHP callbacks
3
3
--SKIPIF--
4
4
<?php require_once ('skipif.inc ' ); ?>
5
+ <?php require_once ('utils.inc ' ); ?>
5
6
<?php
6
7
try {
7
- FFI ::cdef ("void* zend_write; " );
8
+ FFI ::cdef ("void* zend_write; " , ffi_get_php_dll_name () );
8
9
} catch (Throwable $ e ) {
9
10
die ('skip PHP symbols not available ' );
10
11
}
@@ -14,10 +15,11 @@ ffi.enable=1
14
15
opcache.jit=0
15
16
--FILE--
16
17
<?php
18
+ require_once ('utils.inc ' );
17
19
$ zend = FFI ::cdef ("
18
20
typedef int (*zend_write_func_t)(const char *str, size_t str_length);
19
21
extern zend_write_func_t zend_write;
20
- " );
22
+ ", ffi_get_php_dll_name () );
21
23
22
24
echo "Hello World! \n" ;
23
25
Original file line number Diff line number Diff line change @@ -7,12 +7,13 @@ FFI 301: FFI loading on Windows
7
7
ffi.enable=1
8
8
--FILE--
9
9
<?php
10
+ require_once ('utils.inc ' );
10
11
$ fn = __DIR__ . "/300-win32.h " ;
11
12
$ cont = str_replace (
12
- "PHP_DLL_NAME " ,
13
- " php " . PHP_MAJOR_VERSION . ( PHP_ZTS ? " ts " : "" ) . ( PHP_DEBUG ? " _debug " : "" ) . " .dll " ,
14
- file_get_contents ("$ fn.in " )
15
- );
13
+ "PHP_DLL_NAME " ,
14
+ ffi_get_php_dll_name () ,
15
+ file_get_contents ("$ fn.in " )
16
+ );
16
17
file_put_contents ($ fn , $ cont );
17
18
18
19
$ ffi = FFI ::load ($ fn );
Original file line number Diff line number Diff line change @@ -3,8 +3,9 @@ Bug #77632 (FFI function pointers with variadics)
3
3
--SKIPIF--
4
4
<?php
5
5
require_once ('skipif.inc ' );
6
+ require_once ('utils.inc ' );
6
7
try {
7
- FFI ::cdef ("extern void *zend_printf; " );
8
+ FFI ::cdef ("extern void *zend_printf; " , ffi_get_php_dll_name () );
8
9
} catch (Throwable $ _ ) {
9
10
die ('skip PHP symbols not available ' );
10
11
}
13
14
ffi.enable=1
14
15
--FILE--
15
16
<?php
16
- $ libc = FFI ::cdef ("extern size_t (*zend_printf)(const char *format, ...); " );
17
+ require_once ('utils.inc ' );
18
+ $ libc = FFI ::cdef ("extern size_t (*zend_printf)(const char *format, ...); " , ffi_get_php_dll_name ());
17
19
$ args = ["test from zend_printf \n" ];
18
20
($ libc ->zend_printf )(...$ args );
19
21
$ args2 = ["Hello, %s from zend_printf \n" , "world " ];
Original file line number Diff line number Diff line change @@ -5,26 +5,26 @@ FR #78270 (Usage of __vectorcall convention with FFI)
5
5
require_once ('skipif.inc ' );
6
6
if (substr (PHP_OS , 0 , 3 ) != 'WIN ' ) die ("skip this test is for Windows platforms only " );
7
7
8
+ require_once ('utils.inc ' );
8
9
ob_start ();
9
10
phpinfo (INFO_GENERAL );
10
11
$ info = ob_get_clean ();
11
12
if (preg_match ('/Compiler => .*clang.*/ ' , $ info )) die ("skip not for clang " );
12
13
13
- $ dll = 'php8 ' . (PHP_ZTS ? 'ts ' : '' ) . (PHP_DEBUG ? '_debug ' : '' ) . '.dll ' ;
14
14
try {
15
15
FFI ::cdef (<<<EOC
16
16
__vectorcall int zend_atoi(const char *str, size_t str_len);
17
- EOC , $ dll );
17
+ EOC , ffi_get_php_dll_name () );
18
18
} catch (FFI \ParserException $ ex ) {
19
19
die ('skip __vectorcall not supported ' );
20
20
}
21
21
?>
22
22
--FILE--
23
23
<?php
24
- $ dll = ' php8 ' . ( PHP_ZTS ? ' ts ' : '' ) . ( PHP_DEBUG ? ' _debug ' : '' ) . ' .dll ' ;
24
+ require_once ( ' utils.inc ' ) ;
25
25
$ ffi = FFI ::cdef (<<<EOC
26
26
__vectorcall int zend_atoi(const char *str, size_t str_len);
27
- EOC , $ dll );
27
+ EOC , ffi_get_php_dll_name () );
28
28
var_dump ($ ffi ->zend_atoi ("17.4 " , 4 ));
29
29
?>
30
30
--EXPECT--
Original file line number Diff line number Diff line change @@ -5,11 +5,11 @@ FR #78270 (Usage of __vectorcall convention with FFI)
5
5
require_once ('skipif.inc ' );
6
6
if (substr (PHP_OS , 0 , 3 ) != 'WIN ' ) die ("skip this test is for Windows platforms only " );
7
7
8
- $ dll = ' php8 ' . ( PHP_ZTS ? ' ts ' : '' ) . ( PHP_DEBUG ? ' _debug ' : '' ) . ' .dll ' ;
8
+ require_once ( ' utils.inc ' ) ;
9
9
try {
10
10
FFI ::cdef (<<<EOC
11
11
__vectorcall int zend_atoi(const char *str, size_t str_len);
12
- EOC , $ dll );
12
+ EOC , ffi_get_php_dll_name () );
13
13
} catch (FFI \ParserException $ ex ) {
14
14
die ('skip __vectorcall not supported ' );
15
15
}
Original file line number Diff line number Diff line change @@ -6,13 +6,9 @@ Bug #78714 (funcs returning pointer can't use call convention spec)
6
6
ffi.enable=1
7
7
--FILE--
8
8
<?php
9
+ require_once ('utils.inc ' );
9
10
$ def = 'char * __cdecl get_zend_version(void); ' ;
10
- if (substr (PHP_OS , 0 , 3 ) != 'WIN ' ) {
11
- $ ffi = FFI ::cdef ($ def );
12
- } else {
13
- $ dll = 'php8 ' . (PHP_ZTS ? 'ts ' : '' ) . (PHP_DEBUG ? '_debug ' : '' ) . '.dll ' ;
14
- $ ffi = FFI ::cdef ($ def , $ dll );
15
- }
11
+ $ ffi = ffi_cdef ($ def , ffi_get_php_dll_name ());
16
12
echo substr (FFI ::string ($ ffi ->get_zend_version ()), 0 , 4 ) . "\n" ;
17
13
?>
18
14
--EXPECT--
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ if (!extension_loaded('zend-test')) die('skip zend-test extension not available'
7
7
?>
8
8
--FILE--
9
9
<?php
10
+ require_once ('utils.inc ' );
10
11
$ header = <<<HEADER
11
12
struct bug79096 {
12
13
uint64_t a;
@@ -22,8 +23,7 @@ if (PHP_OS_FAMILY !== 'Windows') {
22
23
try {
23
24
$ ffi = FFI ::cdef ($ header , 'php_zend_test.dll ' );
24
25
} catch (FFI \Exception $ ex ) {
25
- $ dll = $ dll = 'php7 ' . (PHP_ZTS ? 'ts ' : '' ) . (PHP_DEBUG ? '_debug ' : '' ) . '.dll ' ;
26
- $ ffi = FFI ::cdef ($ header , $ dll );
26
+ $ ffi = FFI ::cdef ($ header , ffi_get_php_dll_name ());
27
27
}
28
28
}
29
29
Original file line number Diff line number Diff line change 1
1
<?php
2
- if (substr (PHP_OS , 0 , 3 ) == 'WIN ' ) {
3
- $ fn = __DIR__ . "/300-win32.h " ;
4
- $ cont = str_replace (
5
- "PHP_DLL_NAME " ,
6
- "php " . PHP_MAJOR_VERSION . (PHP_ZTS ? "ts " : "" ) . (PHP_DEBUG ? "_debug " : "" ) . ".dll " ,
7
- file_get_contents ("$ fn.in " )
8
- );
9
- file_put_contents ($ fn , $ cont );
10
- $ ffi = FFI ::load ($ fn );
11
- /* Test should cleanup this. */
12
- } else {
13
- FFI ::load (__DIR__ . "/300.h " );
14
- }
2
+
3
+ FFI ::load (__DIR__ . "/300.h " );
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ function ffi_cdef ($ code , $ lib )
4
+ {
5
+ if (isset ($ lib )) {
6
+ return FFI ::cdef ($ code , $ lib );
7
+ } else {
8
+ return FFI ::cdef ($ code );
9
+ }
10
+ }
11
+
12
+ function ffi_get_php_dll_name ()
13
+ {
14
+ if (PHP_OS_FAMILY === 'Windows ' ) {
15
+ return "php " . PHP_MAJOR_VERSION . (PHP_ZTS ? "ts " : "" ) . (PHP_DEBUG ? "_debug " : "" ) . ".dll " ;
16
+ } else {
17
+ return null ;
18
+ }
19
+ }
20
+
21
+ function ffi_get_fastcall_specifier ()
22
+ {
23
+ foreach (['__attribute__((fastcall)) ' , '__fastcall ' , '__vectorcall ' ] as $ spec ) {
24
+ try {
25
+ ffi_cdef ("extern size_t $ spec zend_list_insert(void *ptr, int type); " , ffi_get_php_dll_name ());
26
+ return "$ spec " ;
27
+ } catch (Throwable $ e ) {}
28
+ }
29
+ return "" ;
30
+ }
You can’t perform that action at this time.
0 commit comments