summaryrefslogtreecommitdiffstats
path: root/1c9bfcb6a766d4062f2dd1e594b30831d59cc36c.patch
blob: cc43800343b7c088df4d3e0f8aafc145b6de0c00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
From 1c9bfcb6a766d4062f2dd1e594b30831d59cc36c Mon Sep 17 00:00:00 2001
From: "Christoph M. Becker" <cmbecker69@gmx.de>
Date: Tue, 22 Oct 2019 11:33:00 +0200
Subject: [PATCH] Fix #78716: Function name mangling is wrong for some
 parameter types

We have to cater to function parameter alignment when calculating the
parameter size.
---
 NEWS                           |   4 ++++
 ext/ffi/ffi.c                  |   2 +-
 ext/ffi/tests/callconv.phpt    |  30 +++++++++++++++---------------
 ext/ffi/tests/callconv_x86.dll | Bin 8704 -> 8704 bytes
 4 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/ext/ffi/ffi.c b/ext/ffi/ffi.c
index 1d6f84b6b223..1edba157a171 100644
--- a/ext/ffi/ffi.c
+++ b/ext/ffi/ffi.c
@@ -775,7 +775,7 @@ static size_t zend_ffi_arg_size(zend_ffi_type *type) /* {{{ */
 	size_t arg_size = 0;
 
 	ZEND_HASH_FOREACH_PTR(type->func.args, arg_type) {
-		arg_size += ZEND_FFI_TYPE(arg_type)->size;
+		arg_size += MAX(ZEND_FFI_TYPE(arg_type)->size, sizeof(size_t));
 	} ZEND_HASH_FOREACH_END();
 	return arg_size;
 }
diff --git a/ext/ffi/tests/callconv.phpt b/ext/ffi/tests/callconv.phpt
index aa481de2249c..233c73f11010 100644
--- a/ext/ffi/tests/callconv.phpt
+++ b/ext/ffi/tests/callconv.phpt
@@ -9,32 +9,32 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only");
 --FILE--
 <?php
 $header = <<<HEADER
-void __cdecl cdecl_func(int arg1, double arg2);
-void __stdcall stdcall_func(int arg1, double arg2);
-void __fastcall fastcall_func(int arg1, double arg2);
+void __cdecl cdecl_func(int arg1, double arg2, char arg3);
+void __stdcall stdcall_func(int arg1, double arg2, char arg3);
+void __fastcall fastcall_func(int arg1, double arg2, char arg3);
 HEADER;
 $headername = __DIR__ . '/callconv.h';
 $dllname = __DIR__ . "/callconv_x86.dll";
 
 $ffi1 = FFI::cdef($header, $dllname);
-$ffi1->cdecl_func(1, 2.3);
-$ffi1->stdcall_func(4, 5.6);
-$ffi1->fastcall_func(7, 8.9);
+$ffi1->cdecl_func(1, 2.3, 'a');
+$ffi1->stdcall_func(4, 5.6, 'b');
+$ffi1->fastcall_func(7, 8.9, 'c');
 
 file_put_contents($headername, "#define FFI_LIB \"$dllname\"\n$header");
 
 $ffi2 = FFI::load($headername);
-$ffi2->cdecl_func(2, 3.4);
-$ffi2->stdcall_func(5, 6.7);
-$ffi2->fastcall_func(8, 9.1);
+$ffi2->cdecl_func(2, 3.4, 'a');
+$ffi2->stdcall_func(5, 6.7, 'b');
+$ffi2->fastcall_func(8, 9.1, 'c');
 ?>
 --EXPECT--
-cdecl: 1, 2.300000
-stdcall: 4, 5.600000
-fastcall: 7, 8.900000
-cdecl: 2, 3.400000
-stdcall: 5, 6.700000
-fastcall: 8, 9.100000
+cdecl: 1, 2.300000, a
+stdcall: 4, 5.600000, b
+fastcall: 7, 8.900000, c
+cdecl: 2, 3.400000, a
+stdcall: 5, 6.700000, b
+fastcall: 8, 9.100000, c
 --CLEAN--
 <?php
 unlink(__DIR__ . '/callconv.h');