This is the mail archive of the
libffi-discuss@sourceware.org
mailing list for the libffi project.
[PATCH] Use FFI_DECLARE macros
- From: Mladen Turk <mturk at redhat dot com>
- To: libffi-discuss at sourceware dot org
- Date: Tue, 23 Feb 2010 20:06:38 +0100
- Subject: [PATCH] Use FFI_DECLARE macros
Hi
The patch adds FFI_DECLARE similar to FFI_HIDDEN
so that msvc compilers can create real .dll files
There is no functional change to the code except
when using msvc in which case API is dllexport
Regards
--
^TM
diff --git a/include/ffi.h.in b/include/ffi.h.in
index df7d2cd..2b9ebe0 100644
--- a/include/ffi.h.in
+++ b/include/ffi.h.in
@@ -67,6 +67,16 @@ extern "C" {
#ifdef _MSC_VER
#define __attribute__(X)
+#if defined(DLL_EXPORT)
+#define FFI_DECLARE(type) __declspec(dllexport) type __stdcall
+#define FFI_DECLARE_DATA __declspec(dllexport)
+#else
+#define FFI_DECLARE(type) __declspec(dllimport) type __stdcall
+#define FFI_DECLARE_DATA __declspec(dllimport)
+#endif
+#else
+#define FFI_DECLARE(type) type
+#define FFI_DECLARE_DATA extern
#endif
#include <stddef.h>
@@ -148,21 +158,21 @@ typedef struct _ffi_type
#endif
/* These are defined in types.c */
-extern ffi_type ffi_type_void;
-extern ffi_type ffi_type_uint8;
-extern ffi_type ffi_type_sint8;
-extern ffi_type ffi_type_uint16;
-extern ffi_type ffi_type_sint16;
-extern ffi_type ffi_type_uint32;
-extern ffi_type ffi_type_sint32;
-extern ffi_type ffi_type_uint64;
-extern ffi_type ffi_type_sint64;
-extern ffi_type ffi_type_float;
-extern ffi_type ffi_type_double;
-extern ffi_type ffi_type_pointer;
+FFI_DECLARE_DATA ffi_type ffi_type_void;
+FFI_DECLARE_DATA ffi_type ffi_type_uint8;
+FFI_DECLARE_DATA ffi_type ffi_type_sint8;
+FFI_DECLARE_DATA ffi_type ffi_type_uint16;
+FFI_DECLARE_DATA ffi_type ffi_type_sint16;
+FFI_DECLARE_DATA ffi_type ffi_type_uint32;
+FFI_DECLARE_DATA ffi_type ffi_type_sint32;
+FFI_DECLARE_DATA ffi_type ffi_type_uint64;
+FFI_DECLARE_DATA ffi_type ffi_type_sint64;
+FFI_DECLARE_DATA ffi_type ffi_type_float;
+FFI_DECLARE_DATA ffi_type ffi_type_double;
+FFI_DECLARE_DATA ffi_type ffi_type_pointer;
#if @HAVE_LONG_DOUBLE@
-extern ffi_type ffi_type_longdouble;
+FFI_DECLARE_DATA ffi_type ffi_type_longdouble;
#else
#define ffi_type_longdouble ffi_type_double
#endif
@@ -225,27 +235,35 @@ typedef ffi_raw ffi_java_raw;
#endif
-void ffi_raw_call (ffi_cif *cif,
+FFI_DECLARE(void)
+ ffi_raw_call (ffi_cif *cif,
void (*fn)(void),
void *rvalue,
ffi_raw *avalue);
-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);
+FFI_DECLARE(void)
+ ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
+FFI_DECLARE(void)
+ ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
+FFI_DECLARE(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. */
-void ffi_java_raw_call (ffi_cif *cif,
+FFI_DECLARE(void)
+ ffi_java_raw_call (ffi_cif *cif,
void (*fn)(void),
void *rvalue,
ffi_java_raw *avalue);
-void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw);
-void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args);
-size_t ffi_java_raw_size (ffi_cif *cif);
+FFI_DECLARE(void)
+ ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw);
+FFI_DECLARE(void)
+ ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args);
+FFI_DECLARE(size_t)
+ ffi_java_raw_size (ffi_cif *cif);
/* ---- Definitions for closures ----------------------------------------- */
@@ -265,16 +283,18 @@ typedef struct {
} ffi_closure;
#endif
-void *ffi_closure_alloc (size_t size, void **code);
-void ffi_closure_free (void *);
+FFI_DECLARE(void *)
+ ffi_closure_alloc (size_t size, void **code);
+FFI_DECLARE(void)
+ ffi_closure_free (void *);
-ffi_status
-ffi_prep_closure (ffi_closure*,
+FFI_DECLARE(ffi_status)
+ ffi_prep_closure (ffi_closure*,
ffi_cif *,
void (*fun)(ffi_cif*,void*,void**,void*),
void *user_data);
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_closure_loc (ffi_closure*,
ffi_cif *,
void (*fun)(ffi_cif*,void*,void**,void*),
@@ -323,26 +343,26 @@ typedef struct {
} ffi_java_raw_closure;
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_raw_closure (ffi_raw_closure*,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
void *user_data);
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_raw_closure_loc (ffi_raw_closure*,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
void *user_data,
void *codeloc);
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_java_raw_closure (ffi_java_raw_closure*,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
void *user_data);
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
@@ -353,13 +373,15 @@ ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*,
/* ---- Public interface definition -------------------------------------- */
-ffi_status ffi_prep_cif(ffi_cif *cif,
+FFI_DECLARE(ffi_status)
+ffi_prep_cif(ffi_cif *cif,
ffi_abi abi,
unsigned int nargs,
ffi_type *rtype,
ffi_type **atypes);
-void ffi_call(ffi_cif *cif,
+FFI_DECLARE(void)
+ffi_call(ffi_cif *cif,
void (*fn)(void),
void *rvalue,
void **avalue);
diff --git a/msvcc.sh b/msvcc.sh
index 8301839..d841a3e 100755
--- a/msvcc.sh
+++ b/msvcc.sh
@@ -176,6 +176,7 @@ if [ -n "$assembly" ]; then
#mv *.obj $outdir
else
args="$md $args"
+ args="$(echo $args | sed 's%\\%\\\\\\\\%g')"
echo "$cl $args"
eval "\"$cl\" $args"
result=$?
diff --git a/src/closures.c b/src/closures.c
index 0b156e0..2186482 100644
--- a/src/closures.c
+++ b/src/closures.c
@@ -527,7 +527,7 @@ segment_holding_code (mstate m, char* addr)
/* Allocate a chunk of memory with the given size. Returns a pointer
to the writable address, and sets *CODE to the executable
corresponding virtual address. */
-void *
+FFI_DECLARE(void *)
ffi_closure_alloc (size_t size, void **code)
{
void *ptr;
@@ -551,7 +551,7 @@ ffi_closure_alloc (size_t size, void **code)
FFI_CLOSURE_FREE_CODE is nonzero, the given address can be the
writable or the executable address given. Otherwise, only the
writable address can be provided here. */
-void
+FFI_DECLARE(void)
ffi_closure_free (void *ptr)
{
#if FFI_CLOSURE_FREE_CODE
@@ -591,7 +591,7 @@ int main ()
#include <stdlib.h>
-void *
+FFI_DECLARE(void *)
ffi_closure_alloc (size_t size, void **code)
{
if (!code)
@@ -600,7 +600,7 @@ ffi_closure_alloc (size_t size, void **code)
return *code = malloc (size);
}
-void
+FFI_DECLARE(void)
ffi_closure_free (void *ptr)
{
free (ptr);
diff --git a/src/java_raw_api.c b/src/java_raw_api.c
index 9c5383e..fd3240d 100644
--- a/src/java_raw_api.c
+++ b/src/java_raw_api.c
@@ -41,7 +41,7 @@
#if !defined(NO_JAVA_RAW_API) && !defined(FFI_NO_RAW_API)
-size_t
+FFI_DECLARE(size_t)
ffi_java_raw_size (ffi_cif *cif)
{
size_t result = 0;
@@ -69,7 +69,7 @@ ffi_java_raw_size (ffi_cif *cif)
}
-void
+FFI_DECLARE(void)
ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args)
{
unsigned i;
@@ -143,7 +143,7 @@ ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args)
#endif /* WORDS_BIGENDIAN */
}
-void
+FFI_DECLARE(void)
ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw)
{
unsigned i;
@@ -292,7 +292,8 @@ ffi_java_raw_to_rvalue (ffi_cif *cif, void *rvalue)
* these following couple of functions will handle the translation forth
* and back automatically. */
-void ffi_java_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue,
+FFI_DECLARE(void)
+ffi_java_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue,
ffi_java_raw *raw)
{
void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
@@ -315,7 +316,7 @@ ffi_java_translate_args (ffi_cif *cif, void *rvalue,
ffi_java_raw_to_rvalue (cif, rvalue);
}
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_java_raw_closure_loc (ffi_java_raw_closure* cl,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
@@ -342,7 +343,7 @@ ffi_prep_java_raw_closure_loc (ffi_java_raw_closure* cl,
* will install an intermediate "hub" for translation of arguments from
* the pointer-array format, to the raw format */
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_java_raw_closure (ffi_java_raw_closure* cl,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*),
diff --git a/src/prep_cif.c b/src/prep_cif.c
index c1c3b9a..90bec79 100644
--- a/src/prep_cif.c
+++ b/src/prep_cif.c
@@ -85,7 +85,8 @@ static ffi_status initialize_aggregate(ffi_type *arg)
/* Perform machine independent ffi_cif preparation, then call
machine dependent routine. */
-ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs,
+FFI_DECLARE(ffi_status)
+ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs,
ffi_type *rtype, ffi_type **atypes)
{
unsigned bytes = 0;
@@ -159,7 +160,7 @@ ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs,
#if FFI_CLOSURES
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_closure (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*,void*,void**,void*),
diff --git a/src/raw_api.c b/src/raw_api.c
index ce21372..176819b 100644
--- a/src/raw_api.c
+++ b/src/raw_api.c
@@ -31,7 +31,7 @@
#if !FFI_NO_RAW_API
-size_t
+FFI_DECLARE(size_t)
ffi_raw_size (ffi_cif *cif)
{
size_t result = 0;
@@ -53,7 +53,7 @@ ffi_raw_size (ffi_cif *cif)
}
-void
+FFI_DECLARE(void)
ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args)
{
unsigned i;
@@ -125,7 +125,7 @@ ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args)
#endif /* WORDS_BIGENDIAN */
}
-void
+FFI_DECLARE(void)
ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
{
unsigned i;
@@ -188,7 +188,8 @@ ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw)
* these following couple of functions will handle the translation forth
* and back automatically. */
-void ffi_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *raw)
+FFI_DECLARE(void)
+ffi_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *raw)
{
void **avalue = (void**) alloca (cif->nargs * sizeof (void*));
ffi_raw_to_ptrarray (cif, raw, avalue);
@@ -208,7 +209,7 @@ ffi_translate_args (ffi_cif *cif, void *rvalue,
(*cl->fun) (cif, rvalue, raw, cl->user_data);
}
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_raw_closure_loc (ffi_raw_closure* cl,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
@@ -240,7 +241,7 @@ ffi_prep_raw_closure_loc (ffi_raw_closure* cl,
* will install an intermediate "hub" for translation of arguments from
* the pointer-array format, to the raw format */
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_raw_closure (ffi_raw_closure* cl,
ffi_cif *cif,
void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
diff --git a/src/x86/ffi.c b/src/x86/ffi.c
index d99528b..eb0e992 100644
--- a/src/x86/ffi.c
+++ b/src/x86/ffi.c
@@ -42,7 +42,8 @@
/* ffi_prep_args is called by the assembly routine once stack space
has been allocated for the function's arguments */
-void ffi_prep_args(char *stack, extended_cif *ecif)
+void
+ffi_prep_args(char *stack, extended_cif *ecif)
{
register unsigned int i;
register void **p_argv;
@@ -146,7 +147,8 @@ void ffi_prep_args(char *stack, extended_cif *ecif)
}
/* Perform machine dependent cif processing */
-ffi_status ffi_prep_cif_machdep(ffi_cif *cif)
+FFI_DECLARE(ffi_status)
+ffi_prep_cif_machdep(ffi_cif *cif)
{
unsigned int i;
ffi_type **ptr;
@@ -258,7 +260,8 @@ extern void ffi_call_SYSV(void (*)(char *, extended_cif *), extended_cif *,
unsigned, unsigned, unsigned *, void (*fn)(void));
#endif
-void ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
+FFI_DECLARE(void)
+ffi_call(ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
{
extended_cif ecif;
@@ -522,7 +525,7 @@ ffi_prep_incoming_args_SYSV(char *stack, void **rvalue, void **avalue,
/* the cif must already be prep'ed */
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_closure_loc (ffi_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*,void*,void**,void*),
@@ -572,7 +575,7 @@ ffi_prep_closure_loc (ffi_closure* closure,
#if !FFI_NO_RAW_API
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_raw_closure_loc (ffi_raw_closure* closure,
ffi_cif* cif,
void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
@@ -618,7 +621,7 @@ ffi_prep_args_raw(char *stack, extended_cif *ecif)
* libffi-1.20, this is not the case.)
*/
-void
+FFI_DECLARE(void)
ffi_raw_call(ffi_cif *cif, void (*fn)(void), void *rvalue, ffi_raw *fake_avalue)
{
extended_cif ecif;
diff --git a/src/x86/ffi64.c b/src/x86/ffi64.c
index 51ada0e..0cfcdfd 100644
--- a/src/x86/ffi64.c
+++ b/src/x86/ffi64.c
@@ -326,7 +326,7 @@ examine_argument (ffi_type *type, enum x86_64_reg_class classes[MAX_CLASSES],
/* Perform machine dependent cif processing. */
-ffi_status
+FFI_DECLARE(ffi_status)
ffi_prep_cif_machdep (ffi_cif *cif)
{
int gprcount, ssecount, i, avn, n, ngpr, nsse, flags;
@@ -394,7 +394,7 @@ ffi_prep_cif_machdep (ffi_cif *cif)
return FFI_OK;
}
-void
+FFI_DECLARE(void)
ffi_call (ffi_cif *cif, void (*fn)(void), void *rvalue, void **avalue)
{
enum x86_64_reg_class classes[MAX_CLASSES];