xref: /PHP-7.4/ext/ffi/tests/callconv.phpt (revision 1c9bfcb6)
1--TEST--
2Different calling conventions
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6if (substr(PHP_OS, 0, 3) != 'WIN') die('skip for Windows only');
7if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only");
8?>
9--FILE--
10<?php
11$header = <<<HEADER
12void __cdecl cdecl_func(int arg1, double arg2, char arg3);
13void __stdcall stdcall_func(int arg1, double arg2, char arg3);
14void __fastcall fastcall_func(int arg1, double arg2, char arg3);
15HEADER;
16$headername = __DIR__ . '/callconv.h';
17$dllname = __DIR__ . "/callconv_x86.dll";
18
19$ffi1 = FFI::cdef($header, $dllname);
20$ffi1->cdecl_func(1, 2.3, 'a');
21$ffi1->stdcall_func(4, 5.6, 'b');
22$ffi1->fastcall_func(7, 8.9, 'c');
23
24file_put_contents($headername, "#define FFI_LIB \"$dllname\"\n$header");
25
26$ffi2 = FFI::load($headername);
27$ffi2->cdecl_func(2, 3.4, 'a');
28$ffi2->stdcall_func(5, 6.7, 'b');
29$ffi2->fastcall_func(8, 9.1, 'c');
30?>
31--EXPECT--
32cdecl: 1, 2.300000, a
33stdcall: 4, 5.600000, b
34fastcall: 7, 8.900000, c
35cdecl: 2, 3.400000, a
36stdcall: 5, 6.700000, b
37fastcall: 8, 9.100000, c
38--CLEAN--
39<?php
40unlink(__DIR__ . '/callconv.h');
41?>
42