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