Skip to content

Commit b5e2f3a

Browse files
authored
Check FFI_* ABI with Autoconf AC_CHECK_DECL (#13552)
The FFI_* calling conventions are enum constants and AC_CHECK_DECL(S) can be used to check for their existence in the ffi.h header. This simplifes the checks and adds a simple AC_CHECK_DECL macro wrapper which defines the HAVE_FFI_* belonging symbols.
1 parent 3c98b1d commit b5e2f3a

File tree

2 files changed

+14
-90
lines changed

2 files changed

+14
-90
lines changed

ext/ffi/config.m4

Lines changed: 13 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -13,96 +13,19 @@ if test "$PHP_FFI" != "no"; then
1313

1414
AC_CHECK_TYPES(long double)
1515

16-
AC_CACHE_CHECK([for fastcall calling convention], ac_cv_ffi_fastcall,
17-
[
18-
AC_COMPILE_IFELSE(
19-
[AC_LANG_PROGRAM([[#include <ffi.h>]],
20-
[[return FFI_FASTCALL]])
21-
],
22-
[ac_cv_ffi_fastcall=yes], [ac_cv_ffi_fastcall=no])
23-
])
24-
25-
if test "$ac_cv_ffi_fastcall" = yes; then
26-
AC_DEFINE(HAVE_FFI_FASTCALL,1,[Whether libffi supports fastcall calling convention])
27-
fi
28-
29-
AC_CACHE_CHECK([for thiscall calling convention], ac_cv_ffi_thiscall,
30-
[
31-
AC_COMPILE_IFELSE(
32-
[AC_LANG_PROGRAM([[#include <ffi.h>]],
33-
[[return FFI_THISCALL]])
34-
],
35-
[ac_cv_ffi_thiscall=yes], [ac_cv_ffi_thiscall=no])
36-
])
37-
38-
if test "$ac_cv_ffi_thiscall" = yes; then
39-
AC_DEFINE(HAVE_FFI_THISCALL,1,[Whether libffi supports thiscall calling convention])
40-
fi
41-
42-
AC_CACHE_CHECK([for stdcall calling convention], ac_cv_ffi_stdcall,
43-
[
44-
AC_COMPILE_IFELSE(
45-
[AC_LANG_PROGRAM([[#include <ffi.h>]],
46-
[[return FFI_STDCALL]])
47-
],
48-
[ac_cv_ffi_stdcall=yes], [ac_cv_ffi_stdcall=no])
49-
])
50-
51-
if test "$ac_cv_ffi_stdcall" = yes; then
52-
AC_DEFINE(HAVE_FFI_STDCALL,1,[Whether libffi supports stdcall calling convention])
53-
fi
54-
55-
AC_CACHE_CHECK([for pascal calling convention], ac_cv_ffi_pascal,
56-
[
57-
AC_COMPILE_IFELSE(
58-
[AC_LANG_PROGRAM([[#include <ffi.h>]],
59-
[[return FFI_PASCAL]])
60-
],
61-
[ac_cv_ffi_pascal=yes], [ac_cv_ffi_pascal=no])
62-
])
63-
64-
if test "$ac_cv_ffi_pascal" = yes; then
65-
AC_DEFINE(HAVE_FFI_PASCAL,1,[Whether libffi supports pascal calling convention])
66-
fi
67-
68-
AC_CACHE_CHECK([for register calling convention], ac_cv_ffi_register,
69-
[
70-
AC_COMPILE_IFELSE(
71-
[AC_LANG_PROGRAM([[#include <ffi.h>]],
72-
[[return FFI_REGISTER]])
73-
],
74-
[ac_cv_ffi_register=yes], [ac_cv_ffi_register=no])
75-
])
76-
77-
if test "$ac_cv_ffi_register" = yes; then
78-
AC_DEFINE(HAVE_FFI_REGISTER,1,[Whether libffi supports register calling convention])
79-
fi
80-
81-
AC_CACHE_CHECK([for ms_cdecl calling convention], ac_cv_ffi_ms_cdecl,
82-
[
83-
AC_COMPILE_IFELSE(
84-
[AC_LANG_PROGRAM([[#include <ffi.h>]],
85-
[[return FFI_MS_CDECL]])
86-
],
87-
[ac_cv_ffi_ms_cdecl=yes], [ac_cv_ffi_ms_cdecl=no])
88-
])
89-
90-
if test "$ac_cv_ffi_ms_cdecl" = yes; then
91-
AC_DEFINE(HAVE_FFI_MS_CDECL,1,[Whether libffi supports ms_cdecl calling convention])
92-
fi
93-
94-
AC_CACHE_CHECK([for sysv calling convention], ac_cv_ffi_sysv,
95-
[
96-
AC_COMPILE_IFELSE(
97-
[AC_LANG_PROGRAM([[#include <ffi.h>]],
98-
[[return FFI_SYSV]])
99-
],
100-
[ac_cv_ffi_sysv=yes], [ac_cv_ffi_sysv=no])
101-
])
102-
103-
if test "$ac_cv_ffi_sysv" = yes; then
104-
AC_DEFINE(HAVE_FFI_SYSV,1,[Whether libffi supports sysv calling convention])
105-
fi
16+
AC_DEFUN([PHP_FFI_CHECK_DECL],
17+
[AC_CHECK_DECL([$1],
18+
[AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1],
19+
[Whether libffi supports the '$1' calling convention.])],,
20+
[#include <ffi.h>])])
21+
22+
PHP_FFI_CHECK_DECL([FFI_FASTCALL])
23+
PHP_FFI_CHECK_DECL([FFI_THISCALL])
24+
PHP_FFI_CHECK_DECL([FFI_STDCALL])
25+
PHP_FFI_CHECK_DECL([FFI_PASCAL])
26+
PHP_FFI_CHECK_DECL([FFI_REGISTER])
27+
PHP_FFI_CHECK_DECL([FFI_MS_CDECL])
28+
PHP_FFI_CHECK_DECL([FFI_SYSV])
10629

10730
PHP_NEW_EXTENSION(ffi, ffi.c ffi_parser.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
10831
PHP_SUBST(FFI_SHARED_LIBADD)

ext/ffi/config.w32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ if (PHP_FFI != 'no') {
1212
AC_DEFINE('HAVE_FFI_MS_CDECL', 1 ,'libffi supports ms_cdecl calling convention');
1313
AC_DEFINE('HAVE_FFI_SYSV', 1 ,'libffi supports sysv calling convention');
1414
}
15+
// Available in https://github.com/winlibs/libffi.
1516
if (GREP_HEADER("ffitarget.h", "FFI_VECTORCALL_PARTIAL", PHP_PHP_BUILD + "\\include")) {
1617
AC_DEFINE('HAVE_FFI_VECTORCALL_PARTIAL', 1 ,'libffi partially supports vectorcall calling convention');
1718
}

0 commit comments

Comments
 (0)