Merge pull request #245 from rth7680/tromey-ffi-prep-cif-core-is-private
A rebase of #219
This commit is contained 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
|
The raw API is designed to bypass some of the argument packing and
|
||||||
and unpacking on architectures for which it can be avoided.
|
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
|
More details on the raw API can be found in:
|
||||||
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:
|
|
||||||
|
|
||||||
http://gcc.gnu.org/ml/java/1999-q3/msg00138.html
|
http://gcc.gnu.org/ml/java/1999-q3/msg00138.html
|
||||||
|
|
||||||
@@ -106,8 +97,8 @@ extern "C" {
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* The closure code assumes that this works on pointers, i.e. a size_t */
|
/* The closure code assumes that this works on pointers, i.e. a size_t
|
||||||
/* can hold a pointer. */
|
can hold a pointer. */
|
||||||
|
|
||||||
typedef struct _ffi_type
|
typedef struct _ffi_type
|
||||||
{
|
{
|
||||||
@@ -166,21 +157,20 @@ typedef struct _ffi_type
|
|||||||
#error "long size not supported"
|
#error "long size not supported"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Need minimal decorations for DLLs to works on Windows. */
|
/* Need minimal decorations for DLLs to works on Windows. GCC has
|
||||||
/* GCC has autoimport and autoexport. Rely on Libtool to */
|
autoimport and autoexport. Rely on Libtool to help MSVC export
|
||||||
/* help MSVC export from a DLL, but always declare data */
|
from a DLL, but always declare data to be imported for MSVC
|
||||||
/* to be imported for MSVC clients. This costs an extra */
|
clients. This costs an extra indirection for MSVC clients using
|
||||||
/* indirection for MSVC clients using the static version */
|
the static version of the library, but don't worry about that.
|
||||||
/* of the library, but don't worry about that. Besides, */
|
Besides, as a workaround, they can define FFI_BUILDING if they
|
||||||
/* as a workaround, they can define FFI_BUILDING if they */
|
*know* they are going to link with the static library. */
|
||||||
/* *know* they are going to link with the static library. */
|
|
||||||
#if defined _MSC_VER && !defined FFI_BUILDING
|
#if defined _MSC_VER && !defined FFI_BUILDING
|
||||||
#define FFI_EXTERN extern __declspec(dllimport)
|
#define FFI_EXTERN extern __declspec(dllimport)
|
||||||
#else
|
#else
|
||||||
#define FFI_EXTERN extern
|
#define FFI_EXTERN extern
|
||||||
#endif
|
#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_void;
|
||||||
FFI_EXTERN ffi_type ffi_type_uint8;
|
FFI_EXTERN ffi_type ffi_type_uint8;
|
||||||
FFI_EXTERN ffi_type ffi_type_sint8;
|
FFI_EXTERN ffi_type ffi_type_sint8;
|
||||||
@@ -229,15 +219,6 @@ typedef struct {
|
|||||||
#endif
|
#endif
|
||||||
} ffi_cif;
|
} 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 -------------------------------------- */
|
/* ---- Definitions for the raw API -------------------------------------- */
|
||||||
|
|
||||||
#ifndef FFI_SIZEOF_ARG
|
#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);
|
void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
|
||||||
size_t ffi_raw_size (ffi_cif *cif);
|
size_t ffi_raw_size (ffi_cif *cif);
|
||||||
|
|
||||||
/* This is analogous to the raw API, except it uses Java parameter */
|
/* This is analogous to the raw API, except it uses Java parameter
|
||||||
/* packing, even on 64-bit machines. I.e. on 64-bit machines */
|
packing, even on 64-bit machines. I.e. on 64-bit machines longs
|
||||||
/* longs and doubles are followed by an empty 64-bit word. */
|
and doubles are followed by an empty 64-bit word. */
|
||||||
|
|
||||||
void ffi_java_raw_call (ffi_cif *cif,
|
void ffi_java_raw_call (ffi_cif *cif,
|
||||||
void (*fn)(void),
|
void (*fn)(void),
|
||||||
@@ -314,10 +295,13 @@ typedef struct {
|
|||||||
ffi_cif *cif;
|
ffi_cif *cif;
|
||||||
void (*fun)(ffi_cif*,void*,void**,void*);
|
void (*fun)(ffi_cif*,void*,void**,void*);
|
||||||
void *user_data;
|
void *user_data;
|
||||||
|
} ffi_closure
|
||||||
#ifdef __GNUC__
|
#ifdef __GNUC__
|
||||||
} ffi_closure __attribute__((aligned (8)));
|
__attribute__((aligned (8)))
|
||||||
#else
|
#endif
|
||||||
} ffi_closure;
|
;
|
||||||
|
|
||||||
|
#ifndef __GNUC__
|
||||||
# ifdef __sgi
|
# ifdef __sgi
|
||||||
# pragma pack 0
|
# pragma pack 0
|
||||||
# endif
|
# endif
|
||||||
@@ -354,9 +338,9 @@ typedef struct {
|
|||||||
|
|
||||||
#if !FFI_NATIVE_RAW_API
|
#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
|
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 (*translate_args)(ffi_cif*,void*,void**,void*);
|
||||||
void *this_closure;
|
void *this_closure;
|
||||||
@@ -380,9 +364,9 @@ typedef struct {
|
|||||||
|
|
||||||
#if !FFI_NATIVE_RAW_API
|
#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
|
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 (*translate_args)(ffi_cif*,void*,void**,void*);
|
||||||
void *this_closure;
|
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,
|
ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type,
|
||||||
size_t *offsets);
|
size_t *offsets);
|
||||||
|
|
||||||
/* Useful for eliminating compiler warnings */
|
/* Useful for eliminating compiler warnings. */
|
||||||
#define FFI_FN(f) ((void (*)(void))f)
|
#define FFI_FN(f) ((void (*)(void))f)
|
||||||
|
|
||||||
/* ---- Definitions shared with assembly code ---------------------------- */
|
/* ---- 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_POINTER 14
|
||||||
#define FFI_TYPE_COMPLEX 15
|
#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
|
#define FFI_TYPE_LAST FFI_TYPE_COMPLEX
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -82,11 +82,21 @@ ffi_status ffi_prep_cif_machdep(ffi_cif *cif);
|
|||||||
ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
|
ffi_status ffi_prep_cif_machdep_var(ffi_cif *cif,
|
||||||
unsigned int nfixedargs, unsigned int ntotalargs);
|
unsigned int nfixedargs, unsigned int ntotalargs);
|
||||||
|
|
||||||
|
|
||||||
#if HAVE_LONG_DOUBLE_VARIANT
|
#if HAVE_LONG_DOUBLE_VARIANT
|
||||||
/* Used to adjust size/alignment of ffi types. */
|
/* Used to adjust size/alignment of ffi types. */
|
||||||
void ffi_prep_types (ffi_abi abi);
|
void ffi_prep_types (ffi_abi abi);
|
||||||
#endif
|
#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 */
|
/* Extended cif, used in callback from assembly routine */
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user