1817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose/* -----------------------------------------------------------------------
2817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   types.c - Copyright (c) 1996, 1998  Red Hat, Inc.
3817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
4817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   Predefined ffi_types needed by libffi.
5817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
6817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   Permission is hereby granted, free of charge, to any person obtaining
7817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   a copy of this software and associated documentation files (the
8817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   ``Software''), to deal in the Software without restriction, including
9817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   without limitation the rights to use, copy, modify, merge, publish,
10817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   distribute, sublicense, and/or sell copies of the Software, and to
11817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   permit persons to whom the Software is furnished to do so, subject to
12817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   the following conditions:
13817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
14817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   The above copyright notice and this permission notice shall be included
15817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   in all copies or substantial portions of the Software.
16817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
17817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
18817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   DEALINGS IN THE SOFTWARE.
25817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   ----------------------------------------------------------------------- */
26817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
27817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose/* Hide the basic type definitions from the header file, so that we
28817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   can redefine them here as "const".  */
29817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose#define LIBFFI_HIDE_BASIC_TYPES
30817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
31817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose#include <ffi.h>
32817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose#include <ffi_common.h>
33817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
34817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose/* Type definitions */
35817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
36817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose#define FFI_TYPEDEF(name, type, id)		\
37817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klosestruct struct_align_##name {			\
38817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose  char c;					\
39817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose  type x;					\
40817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose};						\
41817acef0e6c6b33ade68132b090ea745badbbeceMatthias Kloseconst ffi_type ffi_type_##name = {		\
42817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose  sizeof(type),					\
43817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose  offsetof(struct struct_align_##name, x),	\
44817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose  id, NULL					\
45817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose}
46817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
47baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com#define FFI_NONCONST_TYPEDEF(name, type, id)	\
48baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.comstruct struct_align_##name {			\
49baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com  char c;					\
50baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com  type x;					\
51baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com};						\
52baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.comffi_type ffi_type_##name = {			\
53baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com  sizeof(type),					\
54baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com  offsetof(struct struct_align_##name, x),	\
55baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com  id, NULL					\
56baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com}
57baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com
58817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose/* Size and alignment are fake here. They must not be 0. */
59817acef0e6c6b33ade68132b090ea745badbbeceMatthias Kloseconst ffi_type ffi_type_void = {
60817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose  1, 1, FFI_TYPE_VOID, NULL
61817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose};
62817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
63817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(uint8, UINT8, FFI_TYPE_UINT8);
64817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(sint8, SINT8, FFI_TYPE_SINT8);
65817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(uint16, UINT16, FFI_TYPE_UINT16);
66817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(sint16, SINT16, FFI_TYPE_SINT16);
67817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(uint32, UINT32, FFI_TYPE_UINT32);
68817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(sint32, SINT32, FFI_TYPE_SINT32);
69817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(uint64, UINT64, FFI_TYPE_UINT64);
70817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(sint64, SINT64, FFI_TYPE_SINT64);
71817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
72817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(pointer, void*, FFI_TYPE_POINTER);
73817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
74817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(float, float, FFI_TYPE_FLOAT);
75817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(double, double, FFI_TYPE_DOUBLE);
76817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose
77817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose#ifdef __alpha__
78817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose/* Even if we're not configured to default to 128-bit long double,
79817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   maintain binary compatibility, as -mlong-double-128 can be used
80817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose   at any time.  */
81817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose/* Validate the hard-coded number below.  */
82817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose# if defined(__LONG_DOUBLE_128__) && FFI_TYPE_LONGDOUBLE != 4
83817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose#  error FFI_TYPE_LONGDOUBLE out of date
84817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose# endif
85817acef0e6c6b33ade68132b090ea745badbbeceMatthias Kloseconst ffi_type ffi_type_longdouble = { 16, 16, 4, NULL };
86817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose#elif FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
87baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com# if HAVE_LONG_DOUBLE_VARIANT
88baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.comFFI_NONCONST_TYPEDEF(longdouble, long double, FFI_TYPE_LONGDOUBLE);
89baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com# else
90817acef0e6c6b33ade68132b090ea745badbbeceMatthias KloseFFI_TYPEDEF(longdouble, long double, FFI_TYPE_LONGDOUBLE);
91baa84b827b80380ff181757e2997e5648e69b1e4doko@ubuntu.com# endif
92817acef0e6c6b33ade68132b090ea745badbbeceMatthias Klose#endif
93