Merge pull request #245 from rth7680/tromey-ffi-prep-cif-core-is-private A rebase of #219
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
diff --git a/include/ffi.h.in b/include/ffi.h.in
index 9e65277..5833525 100644
--- a/include/ffi.h.in
+++ b/include/ffi.h.in
@@ -25,23 +25,14 @@
----------------------------------------------------------------------- */
/* -------------------------------------------------------------------
- The basic API is described in the README file.
+ Most of the API is documented in doc/libffi.texi.
- The raw API is designed to bypass some of the argument packing
- and unpacking on architectures for which it can be avoided.
+ The raw API is designed to bypass some of the argument packing and
+ unpacking on architectures for which it can be avoided. Routines
+ are provided to emulate the raw API if the underlying platform
+ doesn't allow faster implementation.
- The closure API allows interpreted functions to be packaged up
- inside a C function pointer, so that they can be called as C functions,
- with no understanding on the client side that they are interpreted.
- It can also be used in other cases in which it is necessary to package
- up a user specified parameter and a function pointer as a single
- function pointer.
-
- The closure API must be implemented in order to get its functionality,
- e.g. for use by gij. Routines are provided to emulate the raw API
- if the underlying platform doesn't allow faster implementation.
-
- More details on the raw and cloure API can be found in:
+ More details on the raw API can be found in:
http://gcc.gnu.org/ml/java/1999-q3/msg00138.html
@@ -106,8 +97,8 @@ extern "C" {
# endif
#endif
-/* The closure code assumes that this works on pointers, i.e. a size_t */
-/* can hold a pointer. */
+/* The closure code assumes that this works on pointers, i.e. a size_t
+ can hold a pointer. */
typedef struct _ffi_type
{
@@ -166,21 +157,20 @@ typedef struct _ffi_type
#error "long size not supported"
#endif
-/* Need minimal decorations for DLLs to works on Windows. */
-/* GCC has autoimport and autoexport. Rely on Libtool to */
-/* help MSVC export from a DLL, but always declare data */
-/* to be imported for MSVC clients. This costs an extra */
-/* indirection for MSVC clients using the static version */
-/* of the library, but don't worry about that. Besides, */
-/* as a workaround, they can define FFI_BUILDING if they */
-/* *know* they are going to link with the static library. */
+/* Need minimal decorations for DLLs to works on Windows. GCC has
+ autoimport and autoexport. Rely on Libtool to help MSVC export
+ from a DLL, but always declare data to be imported for MSVC
+ clients. This costs an extra indirection for MSVC clients using
+ the static version of the library, but don't worry about that.
+ Besides, as a workaround, they can define FFI_BUILDING if they
+ *know* they are going to link with the static library. */
#if defined _MSC_VER && !defined FFI_BUILDING
#define FFI_EXTERN extern __declspec(dllimport)
#else
#define FFI_EXTERN extern
#endif
-/* These are defined in types.c */
+/* These are defined in types.c. */
FFI_EXTERN ffi_type ffi_type_void;
FFI_EXTERN ffi_type ffi_type_uint8;
FFI_EXTERN ffi_type ffi_type_sint8;
@@ -229,15 +219,6 @@ typedef struct {
#endif
} ffi_cif;
-/* Used internally, but overridden by some architectures */
-ffi_status ffi_prep_cif_core(ffi_cif *cif,
- ffi_abi abi,
- unsigned int isvariadic,
- unsigned int nfixedargs,
- unsigned int ntotalargs,
- ffi_type *rtype,
- ffi_type **atypes);
-
/* ---- Definitions for the raw API -------------------------------------- */
#ifndef FFI_SIZEOF_ARG
@@ -284,9 +265,9 @@ void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
size_t ffi_raw_size (ffi_cif *cif);
-/* This is analogous to the raw API, except it uses Java parameter */
-/* packing, even on 64-bit machines. I.e. on 64-bit machines */
-/* longs and doubles are followed by an empty 64-bit word. */
+/* This is analogous to the raw API, except it uses Java parameter
+ packing, even on 64-bit machines. I.e. on 64-bit machines longs
+ and doubles are followed by an empty 64-bit word. */
void ffi_java_raw_call (ffi_cif *cif,
void (*fn)(void),
@@ -314,10 +295,13 @@ typedef struct {
ffi_cif *cif;
void (*fun)(ffi_cif*,void*,void**,void*);
void *user_data;
+} ffi_closure
#ifdef __GNUC__
-} ffi_closure __attribute__((aligned (8)));
-#else
-} ffi_closure;
+ __attribute__((aligned (8)))
+#endif
+ ;
+
+#ifndef __GNUC__
# ifdef __sgi
# pragma pack 0
# endif
@@ -354,9 +338,9 @@ typedef struct {
#if !FFI_NATIVE_RAW_API
- /* if this is enabled, then a raw closure has the same layout
+ /* If this is enabled, then a raw closure has the same layout
as a regular closure. We use this to install an intermediate
- handler to do the transaltion, void** -> ffi_raw*. */
+ handler to do the transaltion, void** -> ffi_raw*. */
void (*translate_args)(ffi_cif*,void*,void**,void*);
void *this_closure;
@@ -380,9 +364,9 @@ typedef struct {
#if !FFI_NATIVE_RAW_API
- /* if this is enabled, then a raw closure has the same layout
+ /* If this is enabled, then a raw closure has the same layout
as a regular closure. We use this to install an intermediate
- handler to do the transaltion, void** -> ffi_raw*. */
+ handler to do the translation, void** -> ffi_raw*. */
void (*translate_args)(ffi_cif*,void*,void**,void*);
void *this_closure;
@@ -461,7 +445,7 @@ void ffi_call(ffi_cif *cif,
ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type,
size_t *offsets);
-/* Useful for eliminating compiler warnings */
+/* Useful for eliminating compiler warnings. */
#define FFI_FN(f) ((void (*)(void))f)
/* ---- Definitions shared with assembly code ---------------------------- */
@@ -490,7 +474,7 @@ ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type,
#define FFI_TYPE_POINTER 14
#define FFI_TYPE_COMPLEX 15
-/* This should always refer to the last type code (for sanity checks) */
+/* This should always refer to the last type code (for sanity checks). */
#define FFI_TYPE_LAST FFI_TYPE_COMPLEX
#ifdef __cplusplus
diff --git a/include/ffi_common.h b/include/ffi_common.h
index b312297..00eae1b 100644
--- a/include/ffi_common.h
+++ b/include/ffi_common.h
@@ -82,11 +82,21 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif);
ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
unsigned int nfixedargs, unsigned int ntotalargs);
+
#if HAVE_LONG_DOUBLE_VARIANT
/* Used to adjust size/alignment of ffi types. */
void ffi_prep_types (ffi_abi abi);
#endif
+/* Used internally, but overridden by some architectures */
+ffi_status ffi_prep_cif_core(ffi_cif *cif,
+ ffi_abi abi,
+ unsigned int isvariadic,
+ unsigned int nfixedargs,
+ unsigned int ntotalargs,
+ ffi_type *rtype,
+ ffi_type **atypes);
+
/* Extended cif, used in callback from assembly routine */
typedef struct
{