Skip to content

Check FFI_* ABI with Autoconf AC_CHECK_DECL #13552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 13 additions & 90 deletions ext/ffi/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -13,96 +13,19 @@ if test "$PHP_FFI" != "no"; then

AC_CHECK_TYPES(long double)

AC_CACHE_CHECK([for fastcall calling convention], ac_cv_ffi_fastcall,
[
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <ffi.h>]],
[[return FFI_FASTCALL]])
],
[ac_cv_ffi_fastcall=yes], [ac_cv_ffi_fastcall=no])
])

if test "$ac_cv_ffi_fastcall" = yes; then
AC_DEFINE(HAVE_FFI_FASTCALL,1,[Whether libffi supports fastcall calling convention])
fi

AC_CACHE_CHECK([for thiscall calling convention], ac_cv_ffi_thiscall,
[
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <ffi.h>]],
[[return FFI_THISCALL]])
],
[ac_cv_ffi_thiscall=yes], [ac_cv_ffi_thiscall=no])
])

if test "$ac_cv_ffi_thiscall" = yes; then
AC_DEFINE(HAVE_FFI_THISCALL,1,[Whether libffi supports thiscall calling convention])
fi

AC_CACHE_CHECK([for stdcall calling convention], ac_cv_ffi_stdcall,
[
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <ffi.h>]],
[[return FFI_STDCALL]])
],
[ac_cv_ffi_stdcall=yes], [ac_cv_ffi_stdcall=no])
])

if test "$ac_cv_ffi_stdcall" = yes; then
AC_DEFINE(HAVE_FFI_STDCALL,1,[Whether libffi supports stdcall calling convention])
fi

AC_CACHE_CHECK([for pascal calling convention], ac_cv_ffi_pascal,
[
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <ffi.h>]],
[[return FFI_PASCAL]])
],
[ac_cv_ffi_pascal=yes], [ac_cv_ffi_pascal=no])
])

if test "$ac_cv_ffi_pascal" = yes; then
AC_DEFINE(HAVE_FFI_PASCAL,1,[Whether libffi supports pascal calling convention])
fi

AC_CACHE_CHECK([for register calling convention], ac_cv_ffi_register,
[
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <ffi.h>]],
[[return FFI_REGISTER]])
],
[ac_cv_ffi_register=yes], [ac_cv_ffi_register=no])
])

if test "$ac_cv_ffi_register" = yes; then
AC_DEFINE(HAVE_FFI_REGISTER,1,[Whether libffi supports register calling convention])
fi

AC_CACHE_CHECK([for ms_cdecl calling convention], ac_cv_ffi_ms_cdecl,
[
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <ffi.h>]],
[[return FFI_MS_CDECL]])
],
[ac_cv_ffi_ms_cdecl=yes], [ac_cv_ffi_ms_cdecl=no])
])

if test "$ac_cv_ffi_ms_cdecl" = yes; then
AC_DEFINE(HAVE_FFI_MS_CDECL,1,[Whether libffi supports ms_cdecl calling convention])
fi

AC_CACHE_CHECK([for sysv calling convention], ac_cv_ffi_sysv,
[
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM([[#include <ffi.h>]],
[[return FFI_SYSV]])
],
[ac_cv_ffi_sysv=yes], [ac_cv_ffi_sysv=no])
])

if test "$ac_cv_ffi_sysv" = yes; then
AC_DEFINE(HAVE_FFI_SYSV,1,[Whether libffi supports sysv calling convention])
fi
AC_DEFUN([PHP_FFI_CHECK_DECL],
[AC_CHECK_DECL([$1],
[AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1],
[Whether libffi supports the '$1' calling convention.])],,
[#include <ffi.h>])])

PHP_FFI_CHECK_DECL([FFI_FASTCALL])
PHP_FFI_CHECK_DECL([FFI_THISCALL])
PHP_FFI_CHECK_DECL([FFI_STDCALL])
PHP_FFI_CHECK_DECL([FFI_PASCAL])
PHP_FFI_CHECK_DECL([FFI_REGISTER])
PHP_FFI_CHECK_DECL([FFI_MS_CDECL])
PHP_FFI_CHECK_DECL([FFI_SYSV])

PHP_NEW_EXTENSION(ffi, ffi.c ffi_parser.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
PHP_SUBST(FFI_SHARED_LIBADD)
Expand Down
1 change: 1 addition & 0 deletions ext/ffi/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ if (PHP_FFI != 'no') {
AC_DEFINE('HAVE_FFI_MS_CDECL', 1 ,'libffi supports ms_cdecl calling convention');
AC_DEFINE('HAVE_FFI_SYSV', 1 ,'libffi supports sysv calling convention');
}
// Available in https://github.com/winlibs/libffi.
if (GREP_HEADER("ffitarget.h", "FFI_VECTORCALL_PARTIAL", PHP_PHP_BUILD + "\\include")) {
AC_DEFINE('HAVE_FFI_VECTORCALL_PARTIAL', 1 ,'libffi partially supports vectorcall calling convention');
}
Expand Down