This is the mail archive of the libffi-discuss@sourceware.org mailing list for the libffi project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix FFI_LAST_ABI definition


Anthony,

On Windows, using FFI_STDCALL triggers a bogus assert in prep_cif.c. This fixes the definition of FFI_LAST_ABI to be consistent with FFI_FIRST_ABI, and tweaks the assertions.

Look OK?

Cheers,
Dan.
diff --git a/ChangeLog b/ChangeLog
index d3df310..2547ad3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,14 @@
+2010-07-22  Dan Witte  <dwitte@mozilla.com>
+
+	* src/*/ffitarget.h: Make FFI_LAST_ABI one past the last valid ABI.
+	* src/prep_cif.c: Fix ABI assertion.
+        * src/cris/ffi.c: Ditto.
+
 2010-07-10  Evan Phoenix  <evan@fallingsnow.net>
 
 	* src/closures.c (selinux_enabled_check): Fix strncmp usage bug.
 
 2010-05-05  Michael Kohler <michaelkohler@live.com>
 
 	* src/dlmalloc.c (dlfree): Fix spelling.
 	* src/ia64/ffi.c (ffi_prep_cif_machdep): Ditto.
diff --git a/src/arm/ffitarget.h b/src/arm/ffitarget.h
index a957426..eede79f 100644
--- a/src/arm/ffitarget.h
+++ b/src/arm/ffitarget.h
@@ -29,18 +29,18 @@
 
 #ifndef LIBFFI_ASM
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_SYSV,
-  FFI_DEFAULT_ABI = FFI_SYSV,
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_SYSV
 } ffi_abi;
 #endif
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
 #define FFI_TRAMPOLINE_SIZE 20
 #define FFI_NATIVE_RAW_API 0
diff --git a/src/avr32/ffitarget.h b/src/avr32/ffitarget.h
index 1c799b1..b85d062 100644
--- a/src/avr32/ffitarget.h
+++ b/src/avr32/ffitarget.h
@@ -29,18 +29,18 @@
 
 #ifndef LIBFFI_ASM
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_SYSV,
-  FFI_DEFAULT_ABI = FFI_SYSV,
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_SYSV
 } ffi_abi;
 #endif
 
 #define FFI_EXTRA_CIF_FIELDS unsigned int rstruct_flag
 
 /* Definitions for closures */
 
 #define FFI_CLOSURES 1
diff --git a/src/cris/ffi.c b/src/cris/ffi.c
index e9c3953..f25d7b4 100644
--- a/src/cris/ffi.c
+++ b/src/cris/ffi.c
@@ -158,17 +158,17 @@ ffi_prep_cif (ffi_cif * cif,
 	      ffi_abi abi, unsigned int nargs,
 	      ffi_type * rtype, ffi_type ** atypes)
 {
   unsigned bytes = 0;
   unsigned int i;
   ffi_type **ptr;
 
   FFI_ASSERT (cif != NULL);
-  FFI_ASSERT ((abi > FFI_FIRST_ABI) && (abi <= FFI_DEFAULT_ABI));
+  FFI_ASSERT (abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI);
 
   cif->abi = abi;
   cif->arg_types = atypes;
   cif->nargs = nargs;
   cif->rtype = rtype;
 
   cif->flags = 0;
 
diff --git a/src/cris/ffitarget.h b/src/cris/ffitarget.h
index 4257f10..0e3705d 100644
--- a/src/cris/ffitarget.h
+++ b/src/cris/ffitarget.h
@@ -29,18 +29,18 @@
 
 #ifndef LIBFFI_ASM
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_SYSV,
-  FFI_DEFAULT_ABI = FFI_SYSV,
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_SYSV
 } ffi_abi;
 #endif
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
 #define FFI_CRIS_TRAMPOLINE_CODE_PART_SIZE 36
 #define FFI_CRIS_TRAMPOLINE_DATA_PART_SIZE (7*4)
diff --git a/src/frv/ffitarget.h b/src/frv/ffitarget.h
index 1c319ea..4839069 100644
--- a/src/frv/ffitarget.h
+++ b/src/frv/ffitarget.h
@@ -30,23 +30,19 @@
 /* ---- System specific configurations ----------------------------------- */
 
 #ifndef LIBFFI_ASM
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
-
-#ifdef FRV
   FFI_EABI,
-  FFI_DEFAULT_ABI = FFI_EABI,
-#endif
-
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_EABI
 } ffi_abi;
 #endif
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
 #define FFI_NATIVE_RAW_API 0
 
diff --git a/src/ia64/ffitarget.h b/src/ia64/ffitarget.h
index d85c049..0d2001d 100644
--- a/src/ia64/ffitarget.h
+++ b/src/ia64/ffitarget.h
@@ -29,18 +29,18 @@
 
 #ifndef LIBFFI_ASM
 typedef unsigned long long          ffi_arg;
 typedef signed long long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_UNIX,   	/* Linux and all Unix variants use the same conventions	*/
-  FFI_DEFAULT_ABI = FFI_UNIX,
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_UNIX
 } ffi_abi;
 #endif
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
 #define FFI_TRAMPOLINE_SIZE 24  /* Really the following struct, which 	*/
 				/* can be interpreted as a C function	*/
diff --git a/src/m32r/ffitarget.h b/src/m32r/ffitarget.h
index 6a761f6..2e2ea48 100644
--- a/src/m32r/ffitarget.h
+++ b/src/m32r/ffitarget.h
@@ -31,18 +31,18 @@
 #ifndef LIBFFI_ASM
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi
   {
     FFI_FIRST_ABI = 0,
     FFI_SYSV,
-    FFI_DEFAULT_ABI = FFI_SYSV,
-    FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+    FFI_LAST_ABI,
+    FFI_DEFAULT_ABI = FFI_SYSV
   } ffi_abi;
 #endif
 
 #define FFI_CLOSURES 		0
 #define FFI_TRAMPOLINE_SIZE	24
 #define FFI_NATIVE_RAW_API 	0
 
 #endif
diff --git a/src/m68k/ffitarget.h b/src/m68k/ffitarget.h
index 633717b..3b777ed 100644
--- a/src/m68k/ffitarget.h
+++ b/src/m68k/ffitarget.h
@@ -29,18 +29,18 @@
 
 #ifndef LIBFFI_ASM
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_SYSV,
-  FFI_DEFAULT_ABI = FFI_SYSV,
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_SYSV
 } ffi_abi;
 #endif
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
 #define FFI_TRAMPOLINE_SIZE 16
 #define FFI_NATIVE_RAW_API 0
diff --git a/src/mips/ffitarget.h b/src/mips/ffitarget.h
index c5f4e05..d70197c 100644
--- a/src/mips/ffitarget.h
+++ b/src/mips/ffitarget.h
@@ -181,40 +181,39 @@ typedef __int64_t ffi_sarg;
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_O32,
   FFI_N32,
   FFI_N64,
   FFI_O32_SOFT_FLOAT,
   FFI_N32_SOFT_FLOAT,
   FFI_N64_SOFT_FLOAT,
+  FFI_LAST_ABI,
 
 #ifdef FFI_MIPS_O32
 #ifdef __mips_soft_float
-  FFI_DEFAULT_ABI = FFI_O32_SOFT_FLOAT,
+  FFI_DEFAULT_ABI = FFI_O32_SOFT_FLOAT
 #else
-  FFI_DEFAULT_ABI = FFI_O32,
+  FFI_DEFAULT_ABI = FFI_O32
 #endif
 #else
 # if _MIPS_SIM==_ABI64
 #  ifdef __mips_soft_float
-  FFI_DEFAULT_ABI = FFI_N64_SOFT_FLOAT,
+  FFI_DEFAULT_ABI = FFI_N64_SOFT_FLOAT
 #  else
-  FFI_DEFAULT_ABI = FFI_N64,
+  FFI_DEFAULT_ABI = FFI_N64
 #  endif
 # else
 #  ifdef __mips_soft_float
-  FFI_DEFAULT_ABI = FFI_N32_SOFT_FLOAT,
+  FFI_DEFAULT_ABI = FFI_N32_SOFT_FLOAT
 #  else
-  FFI_DEFAULT_ABI = FFI_N32,
+  FFI_DEFAULT_ABI = FFI_N32
 #  endif
 # endif
 #endif
-
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
 } ffi_abi;
 
 #define FFI_EXTRA_CIF_FIELDS unsigned rstruct_flag
 #endif /* !LIBFFI_ASM */
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #if defined(FFI_MIPS_O32)
diff --git a/src/moxie/ffitarget.h b/src/moxie/ffitarget.h
index f5305d1..2a9d954 100644
--- a/src/moxie/ffitarget.h
+++ b/src/moxie/ffitarget.h
@@ -30,23 +30,19 @@
 /* ---- System specific configurations ----------------------------------- */
 
 #ifndef LIBFFI_ASM
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
-
-#ifdef MOXIE
   FFI_EABI,
-  FFI_DEFAULT_ABI = FFI_EABI,
-#endif
-
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_EABI
 } ffi_abi;
 #endif
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 0
 #define FFI_NATIVE_RAW_API 0
 
diff --git a/src/pa/ffitarget.h b/src/pa/ffitarget.h
index 001f891..efa2f4e 100644
--- a/src/pa/ffitarget.h
+++ b/src/pa/ffitarget.h
@@ -33,31 +33,32 @@
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
 
 #ifdef PA_LINUX
   FFI_PA32,
-  FFI_DEFAULT_ABI = FFI_PA32,
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_PA32
 #endif
 
 #ifdef PA_HPUX
   FFI_PA32,
-  FFI_DEFAULT_ABI = FFI_PA32,
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_PA32
 #endif
 
 #ifdef PA64_HPUX
 #error "PA64_HPUX FFI is not yet implemented"
   FFI_PA64,
-  FFI_DEFAULT_ABI = FFI_PA64,
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_PA64
 #endif
-
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
 } ffi_abi;
 #endif
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
 #define FFI_NATIVE_RAW_API 0
 
diff --git a/src/prep_cif.c b/src/prep_cif.c
index c1c3b9a..5d749ef 100644
--- a/src/prep_cif.c
+++ b/src/prep_cif.c
@@ -88,17 +88,17 @@ static ffi_status initialize_aggregate(ffi_type *arg)
 ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs,
 			ffi_type *rtype, ffi_type **atypes)
 {
   unsigned bytes = 0;
   unsigned int i;
   ffi_type **ptr;
 
   FFI_ASSERT(cif != NULL);
-  FFI_ASSERT((abi > FFI_FIRST_ABI) && (abi <= FFI_DEFAULT_ABI));
+  FFI_ASSERT(abi > FFI_FIRST_ABI && abi < FFI_LAST_ABI);
 
   cif->abi = abi;
   cif->arg_types = atypes;
   cif->nargs = nargs;
   cif->rtype = rtype;
 
   cif->flags = 0;
 
diff --git a/src/s390/ffitarget.h b/src/s390/ffitarget.h
index 78f3c65..41d7a7d 100644
--- a/src/s390/ffitarget.h
+++ b/src/s390/ffitarget.h
@@ -35,18 +35,18 @@
 
 #ifndef LIBFFI_ASM
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_SYSV,
-  FFI_DEFAULT_ABI = FFI_SYSV,
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_SYSV
 } ffi_abi;
 #endif
 
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
 #ifdef S390X
diff --git a/src/sh/ffitarget.h b/src/sh/ffitarget.h
index 218ae3d..4f1f639 100644
--- a/src/sh/ffitarget.h
+++ b/src/sh/ffitarget.h
@@ -31,18 +31,18 @@
 
 #ifndef LIBFFI_ASM
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_SYSV,
-  FFI_DEFAULT_ABI = FFI_SYSV,
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_SYSV
 } ffi_abi;
 #endif
 
 #define FFI_CLOSURES 1
 #define FFI_TRAMPOLINE_SIZE 16
 #define FFI_NATIVE_RAW_API 0
 
 #endif
diff --git a/src/sh64/ffitarget.h b/src/sh64/ffitarget.h
index 4e922fc..d935b89 100644
--- a/src/sh64/ffitarget.h
+++ b/src/sh64/ffitarget.h
@@ -31,18 +31,18 @@
 
 #ifndef LIBFFI_ASM
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_SYSV,
-  FFI_DEFAULT_ABI = FFI_SYSV,
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_SYSV
 } ffi_abi;
 
 #define FFI_EXTRA_CIF_FIELDS long long flags2
 #endif
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
diff --git a/src/sparc/ffitarget.h b/src/sparc/ffitarget.h
index 1a1a1ac..f3ad606 100644
--- a/src/sparc/ffitarget.h
+++ b/src/sparc/ffitarget.h
@@ -37,22 +37,22 @@
 typedef unsigned long          ffi_arg;
 typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
   FFI_V8,
   FFI_V8PLUS,
   FFI_V9,
+  FFI_LAST_ABI,
 #ifdef SPARC64
-  FFI_DEFAULT_ABI = FFI_V9,
+  FFI_DEFAULT_ABI = FFI_V9
 #else
-  FFI_DEFAULT_ABI = FFI_V8,
+  FFI_DEFAULT_ABI = FFI_V8
 #endif
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
 } ffi_abi;
 #endif
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
 #define FFI_NATIVE_RAW_API 0
 
diff --git a/src/x86/ffitarget.h b/src/x86/ffitarget.h
index b85016c..2738875 100644
--- a/src/x86/ffitarget.h
+++ b/src/x86/ffitarget.h
@@ -59,38 +59,39 @@ typedef signed long            ffi_sarg;
 
 typedef enum ffi_abi {
   FFI_FIRST_ABI = 0,
 
   /* ---- Intel x86 Win32 ---------- */
 #ifdef X86_WIN32
   FFI_SYSV,
   FFI_STDCALL,
+  FFI_LAST_ABI,
   /* TODO: Add fastcall support for the sake of completeness */
-  FFI_DEFAULT_ABI = FFI_SYSV,
+  FFI_DEFAULT_ABI = FFI_SYSV
 #endif
 
 #ifdef X86_WIN64
   FFI_WIN64,
-  FFI_DEFAULT_ABI = FFI_WIN64,
+  FFI_LAST_ABI,
+  FFI_DEFAULT_ABI = FFI_WIN64
 #else
 
   /* ---- Intel x86 and AMD x86-64 - */
 #if !defined(X86_WIN32) && (defined(__i386__) || defined(__x86_64__) || defined(__i386) || defined(__amd64))
   FFI_SYSV,
   FFI_UNIX64,   /* Unix variants all use the same ABI for x86-64  */
+  FFI_LAST_ABI,
 #if defined(__i386__) || defined(__i386)
-  FFI_DEFAULT_ABI = FFI_SYSV,
+  FFI_DEFAULT_ABI = FFI_SYSV
 #else
-  FFI_DEFAULT_ABI = FFI_UNIX64,
+  FFI_DEFAULT_ABI = FFI_UNIX64
 #endif
 #endif
 #endif /* X86_WIN64 */
-
-  FFI_LAST_ABI = FFI_DEFAULT_ABI + 1
 } ffi_abi;
 #endif
 
 /* ---- Definitions for closures ----------------------------------------- */
 
 #define FFI_CLOSURES 1
 #define FFI_TYPE_SMALL_STRUCT_1B (FFI_TYPE_LAST + 1)
 #define FFI_TYPE_SMALL_STRUCT_2B (FFI_TYPE_LAST + 2)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]