1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is js-ctypes.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * The Mozilla Foundation <http://www.mozilla.org/>.
19 : * Portions created by the Initial Developer are Copyright (C) 2009
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Dan Witte <dwitte@mozilla.com>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : /**
40 : * This header contains the builtin types available for arguments and return
41 : * values, representing their C counterparts. They are listed inside macros
42 : * that the #includer is expected to #define. Format is:
43 : *
44 : * DEFINE_X_TYPE(typename, ctype, ffitype)
45 : *
46 : * where 'typename' is the name of the type constructor (accessible as
47 : * ctypes.typename), 'ctype' is the corresponding C type declaration (from
48 : * which sizeof(ctype) and templated type conversions will be derived), and
49 : * 'ffitype' is the ffi_type to use. (Special types, such as 'void' and the
50 : * pointer, array, and struct types are handled separately.)
51 : */
52 :
53 : // If we're not breaking the types out, combine them together under one
54 : // DEFINE_TYPE macro. Otherwise, turn off whichever ones we're not using.
55 : #if defined(DEFINE_TYPE)
56 : # define DEFINE_CHAR_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
57 : # define DEFINE_JSCHAR_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
58 : # define DEFINE_BOOL_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
59 : # define DEFINE_INT_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
60 : # define DEFINE_WRAPPED_INT_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
61 : # define DEFINE_FLOAT_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
62 : #else
63 : # ifndef DEFINE_BOOL_TYPE
64 : # define DEFINE_BOOL_TYPE(x, y, z)
65 : # endif
66 : # ifndef DEFINE_CHAR_TYPE
67 : # define DEFINE_CHAR_TYPE(x, y, z)
68 : # endif
69 : # ifndef DEFINE_JSCHAR_TYPE
70 : # define DEFINE_JSCHAR_TYPE(x, y, z)
71 : # endif
72 : # ifndef DEFINE_INT_TYPE
73 : # define DEFINE_INT_TYPE(x, y, z)
74 : # endif
75 : # ifndef DEFINE_WRAPPED_INT_TYPE
76 : # define DEFINE_WRAPPED_INT_TYPE(x, y, z)
77 : # endif
78 : # ifndef DEFINE_FLOAT_TYPE
79 : # define DEFINE_FLOAT_TYPE(x, y, z)
80 : # endif
81 : #endif
82 :
83 : // MSVC doesn't have ssize_t. Help it along a little.
84 : #ifdef HAVE_SSIZE_T
85 : #define CTYPES_SSIZE_T ssize_t
86 : #else
87 : #define CTYPES_SSIZE_T intptr_t
88 : #endif
89 :
90 : // Some #defines to make handling of types whose length varies by platform
91 : // easier. These could be implemented as configure tests, but the expressions
92 : // are all statically resolvable so there's no need. (See CTypes.cpp for the
93 : // appropriate PR_STATIC_ASSERTs; they can't go here since this header is
94 : // used in places where such asserts are illegal.)
95 : #define CTYPES_FFI_BOOL (sizeof(bool) == 1 ? ffi_type_uint8 : ffi_type_uint32)
96 : #define CTYPES_FFI_LONG (sizeof(long) == 4 ? ffi_type_sint32 : ffi_type_sint64)
97 : #define CTYPES_FFI_ULONG (sizeof(long) == 4 ? ffi_type_uint32 : ffi_type_uint64)
98 : #define CTYPES_FFI_SIZE_T (sizeof(size_t) == 4 ? ffi_type_uint32 : ffi_type_uint64)
99 : #define CTYPES_FFI_SSIZE_T (sizeof(size_t) == 4 ? ffi_type_sint32 : ffi_type_sint64)
100 : #define CTYPES_FFI_INTPTR_T (sizeof(uintptr_t) == 4 ? ffi_type_sint32 : ffi_type_sint64)
101 : #define CTYPES_FFI_UINTPTR_T (sizeof(uintptr_t) == 4 ? ffi_type_uint32 : ffi_type_uint64)
102 :
103 : // The meat.
104 23149 : DEFINE_BOOL_TYPE (bool, bool, CTYPES_FFI_BOOL)
105 23387 : DEFINE_INT_TYPE (int8_t, int8_t, ffi_type_sint8)
106 23357 : DEFINE_INT_TYPE (int16_t, int16_t, ffi_type_sint16)
107 23614 : DEFINE_INT_TYPE (int32_t, int32_t, ffi_type_sint32)
108 169594 : DEFINE_INT_TYPE (uint8_t, uint8_t, ffi_type_uint8)
109 23351 : DEFINE_INT_TYPE (uint16_t, uint16_t, ffi_type_uint16)
110 23359 : DEFINE_INT_TYPE (uint32_t, uint32_t, ffi_type_uint32)
111 23356 : DEFINE_INT_TYPE (short, short, ffi_type_sint16)
112 23351 : DEFINE_INT_TYPE (unsigned_short, unsigned short, ffi_type_uint16)
113 29125 : DEFINE_INT_TYPE (int, int, ffi_type_sint32)
114 24564 : DEFINE_INT_TYPE (unsigned_int, unsigned int, ffi_type_uint32)
115 23332 : DEFINE_WRAPPED_INT_TYPE(int64_t, int64_t, ffi_type_sint64)
116 23334 : DEFINE_WRAPPED_INT_TYPE(uint64_t, uint64_t, ffi_type_uint64)
117 23330 : DEFINE_WRAPPED_INT_TYPE(long, long, CTYPES_FFI_LONG)
118 25277 : DEFINE_WRAPPED_INT_TYPE(unsigned_long, unsigned long, CTYPES_FFI_ULONG)
119 23330 : DEFINE_WRAPPED_INT_TYPE(long_long, long long, ffi_type_sint64)
120 23326 : DEFINE_WRAPPED_INT_TYPE(unsigned_long_long, unsigned long long, ffi_type_uint64)
121 23654 : DEFINE_WRAPPED_INT_TYPE(size_t, size_t, CTYPES_FFI_SIZE_T)
122 23330 : DEFINE_WRAPPED_INT_TYPE(ssize_t, CTYPES_SSIZE_T, CTYPES_FFI_SSIZE_T)
123 23330 : DEFINE_WRAPPED_INT_TYPE(intptr_t, intptr_t, CTYPES_FFI_INTPTR_T)
124 24654 : DEFINE_WRAPPED_INT_TYPE(uintptr_t, uintptr_t, CTYPES_FFI_UINTPTR_T)
125 23369 : DEFINE_FLOAT_TYPE (float32_t, float, ffi_type_float)
126 23366 : DEFINE_FLOAT_TYPE (float64_t, double, ffi_type_double)
127 24353 : DEFINE_FLOAT_TYPE (float, float, ffi_type_float)
128 23393 : DEFINE_FLOAT_TYPE (double, double, ffi_type_double)
129 24339 : DEFINE_CHAR_TYPE (char, char, ffi_type_uint8)
130 23354 : DEFINE_CHAR_TYPE (signed_char, signed char, ffi_type_sint8)
131 23351 : DEFINE_CHAR_TYPE (unsigned_char, unsigned char, ffi_type_uint8)
132 23300 : DEFINE_JSCHAR_TYPE (jschar, jschar, ffi_type_uint16)
133 :
134 : #undef CTYPES_SSIZE_T
135 : #undef CTYPES_FFI_BOOL
136 : #undef CTYPES_FFI_LONG
137 : #undef CTYPES_FFI_ULONG
138 : #undef CTYPES_FFI_SIZE_T
139 : #undef CTYPES_FFI_SSIZE_T
140 : #undef CTYPES_FFI_INTPTR_T
141 : #undef CTYPES_FFI_UINTPTR_T
142 :
143 : #undef DEFINE_TYPE
144 : #undef DEFINE_CHAR_TYPE
145 : #undef DEFINE_JSCHAR_TYPE
146 : #undef DEFINE_BOOL_TYPE
147 : #undef DEFINE_INT_TYPE
148 : #undef DEFINE_WRAPPED_INT_TYPE
149 : #undef DEFINE_FLOAT_TYPE
150 :
|