From f4d413725030b35ec2f01733b154489d0b4c6e1d Mon Sep 17 00:00:00 2001
From: matoro <matoro@users.noreply.github.com>
Date: Sun, 26 Jun 2022 23:19:00 -0400
Subject: [PATCH] Move FFI_TYPE definitions above <ffitarget.h> include

For powerpc at least, these definitions are referenced in the
target-specific ffitarget.h.  Discovered in the jffi project.  Should
close https://github.com/libffi/libffi/issues/637.  Downstream jffi bug
https://github.com/jnr/jffi/issues/107.  Downstream distro bug
https://bugs.gentoo.org/827215.

Testing - both libffi and jffi test suites pass with this patch applied,
at least on ppc64le linux.  I did not see any warnings about
redefinitions.

Tested versions - libffi 3.4.2, jffi 1.3.6 and 1.3.9.
---
 include/ffi.h.in | 50 ++++++++++++++++++++++++------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/include/ffi.h.in b/include/ffi.h.in
index d16f307e..6cd19baa 100644
--- a/include/ffi.h.in
+++ b/include/ffi.h.in
@@ -56,6 +56,31 @@ extern "C" {
 
 /* ---- System configuration information --------------------------------- */
 
+/* If these change, update src/mips/ffitarget.h. */
+#define FFI_TYPE_VOID       0
+#define FFI_TYPE_INT        1
+#define FFI_TYPE_FLOAT      2
+#define FFI_TYPE_DOUBLE     3
+#if @HAVE_LONG_DOUBLE@
+#define FFI_TYPE_LONGDOUBLE 4
+#else
+#define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
+#endif
+#define FFI_TYPE_UINT8      5
+#define FFI_TYPE_SINT8      6
+#define FFI_TYPE_UINT16     7
+#define FFI_TYPE_SINT16     8
+#define FFI_TYPE_UINT32     9
+#define FFI_TYPE_SINT32     10
+#define FFI_TYPE_UINT64     11
+#define FFI_TYPE_SINT64     12
+#define FFI_TYPE_STRUCT     13
+#define FFI_TYPE_POINTER    14
+#define FFI_TYPE_COMPLEX    15
+
+/* This should always refer to the last type code (for sanity checks).  */
+#define FFI_TYPE_LAST       FFI_TYPE_COMPLEX
+
 #include <ffitarget.h>
 
 #ifndef LIBFFI_ASM
@@ -496,31 +521,6 @@ ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type,
 
 #endif
 
-/* If these change, update src/mips/ffitarget.h. */
-#define FFI_TYPE_VOID       0
-#define FFI_TYPE_INT        1
-#define FFI_TYPE_FLOAT      2
-#define FFI_TYPE_DOUBLE     3
-#if @HAVE_LONG_DOUBLE@
-#define FFI_TYPE_LONGDOUBLE 4
-#else
-#define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
-#endif
-#define FFI_TYPE_UINT8      5
-#define FFI_TYPE_SINT8      6
-#define FFI_TYPE_UINT16     7
-#define FFI_TYPE_SINT16     8
-#define FFI_TYPE_UINT32     9
-#define FFI_TYPE_SINT32     10
-#define FFI_TYPE_UINT64     11
-#define FFI_TYPE_SINT64     12
-#define FFI_TYPE_STRUCT     13
-#define FFI_TYPE_POINTER    14
-#define FFI_TYPE_COMPLEX    15
-
-/* This should always refer to the last type code (for sanity checks).  */
-#define FFI_TYPE_LAST       FFI_TYPE_COMPLEX
-
 #ifdef __cplusplus
 }
 #endif
