1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/ctypes/typedefs.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,122 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/** 1.10 + * This header contains the builtin types available for arguments and return 1.11 + * values, representing their C counterparts. They are listed inside macros 1.12 + * that the #includer is expected to #define. Format is: 1.13 + * 1.14 + * DEFINE_X_TYPE(typename, ctype, ffitype) 1.15 + * 1.16 + * where 'typename' is the name of the type constructor (accessible as 1.17 + * ctypes.typename), 'ctype' is the corresponding C type declaration (from 1.18 + * which sizeof(ctype) and templated type conversions will be derived), and 1.19 + * 'ffitype' is the ffi_type to use. (Special types, such as 'void' and the 1.20 + * pointer, array, and struct types are handled separately.) 1.21 + * 1.22 + * This header lacks a #ifndef wrapper because it is deliberately #included 1.23 + * multiple times in ctypes/CTypes.h. 1.24 + */ 1.25 + 1.26 +// If we're not breaking the types out, combine them together under one 1.27 +// DEFINE_TYPE macro. Otherwise, turn off whichever ones we're not using. 1.28 +#if defined(DEFINE_TYPE) 1.29 +# define DEFINE_CHAR_TYPE(x, y, z) DEFINE_TYPE(x, y, z) 1.30 +# define DEFINE_JSCHAR_TYPE(x, y, z) DEFINE_TYPE(x, y, z) 1.31 +# define DEFINE_BOOL_TYPE(x, y, z) DEFINE_TYPE(x, y, z) 1.32 +# define DEFINE_INT_TYPE(x, y, z) DEFINE_TYPE(x, y, z) 1.33 +# define DEFINE_WRAPPED_INT_TYPE(x, y, z) DEFINE_TYPE(x, y, z) 1.34 +# define DEFINE_FLOAT_TYPE(x, y, z) DEFINE_TYPE(x, y, z) 1.35 +#else 1.36 +# ifndef DEFINE_BOOL_TYPE 1.37 +# define DEFINE_BOOL_TYPE(x, y, z) 1.38 +# endif 1.39 +# ifndef DEFINE_CHAR_TYPE 1.40 +# define DEFINE_CHAR_TYPE(x, y, z) 1.41 +# endif 1.42 +# ifndef DEFINE_JSCHAR_TYPE 1.43 +# define DEFINE_JSCHAR_TYPE(x, y, z) 1.44 +# endif 1.45 +# ifndef DEFINE_INT_TYPE 1.46 +# define DEFINE_INT_TYPE(x, y, z) 1.47 +# endif 1.48 +# ifndef DEFINE_WRAPPED_INT_TYPE 1.49 +# define DEFINE_WRAPPED_INT_TYPE(x, y, z) 1.50 +# endif 1.51 +# ifndef DEFINE_FLOAT_TYPE 1.52 +# define DEFINE_FLOAT_TYPE(x, y, z) 1.53 +# endif 1.54 +#endif 1.55 + 1.56 +// MSVC doesn't have ssize_t. Help it along a little. 1.57 +#ifdef HAVE_SSIZE_T 1.58 +#define CTYPES_SSIZE_T ssize_t 1.59 +#else 1.60 +#define CTYPES_SSIZE_T intptr_t 1.61 +#endif 1.62 + 1.63 +// Some #defines to make handling of types whose length varies by platform 1.64 +// easier. These could be implemented as configure tests, but the expressions 1.65 +// are all statically resolvable so there's no need. (See CTypes.cpp for the 1.66 +// appropriate PR_STATIC_ASSERTs; they can't go here since this header is 1.67 +// used in places where such asserts are illegal.) 1.68 +#define CTYPES_FFI_BOOL (sizeof(bool) == 1 ? ffi_type_uint8 : ffi_type_uint32) 1.69 +#define CTYPES_FFI_LONG (sizeof(long) == 4 ? ffi_type_sint32 : ffi_type_sint64) 1.70 +#define CTYPES_FFI_ULONG (sizeof(long) == 4 ? ffi_type_uint32 : ffi_type_uint64) 1.71 +#define CTYPES_FFI_SIZE_T (sizeof(size_t) == 4 ? ffi_type_uint32 : ffi_type_uint64) 1.72 +#define CTYPES_FFI_SSIZE_T (sizeof(size_t) == 4 ? ffi_type_sint32 : ffi_type_sint64) 1.73 +#define CTYPES_FFI_OFF_T (sizeof(off_t) == 4 ? ffi_type_sint32 : ffi_type_sint64) 1.74 +#define CTYPES_FFI_INTPTR_T (sizeof(uintptr_t) == 4 ? ffi_type_sint32 : ffi_type_sint64) 1.75 +#define CTYPES_FFI_UINTPTR_T (sizeof(uintptr_t) == 4 ? ffi_type_uint32 : ffi_type_uint64) 1.76 + 1.77 +// The meat. 1.78 +DEFINE_BOOL_TYPE (bool, bool, CTYPES_FFI_BOOL) 1.79 +DEFINE_INT_TYPE (int8_t, int8_t, ffi_type_sint8) 1.80 +DEFINE_INT_TYPE (int16_t, int16_t, ffi_type_sint16) 1.81 +DEFINE_INT_TYPE (int32_t, int32_t, ffi_type_sint32) 1.82 +DEFINE_INT_TYPE (uint8_t, uint8_t, ffi_type_uint8) 1.83 +DEFINE_INT_TYPE (uint16_t, uint16_t, ffi_type_uint16) 1.84 +DEFINE_INT_TYPE (uint32_t, uint32_t, ffi_type_uint32) 1.85 +DEFINE_INT_TYPE (short, short, ffi_type_sint16) 1.86 +DEFINE_INT_TYPE (unsigned_short, unsigned short, ffi_type_uint16) 1.87 +DEFINE_INT_TYPE (int, int, ffi_type_sint32) 1.88 +DEFINE_INT_TYPE (unsigned_int, unsigned int, ffi_type_uint32) 1.89 +DEFINE_WRAPPED_INT_TYPE(int64_t, int64_t, ffi_type_sint64) 1.90 +DEFINE_WRAPPED_INT_TYPE(uint64_t, uint64_t, ffi_type_uint64) 1.91 +DEFINE_WRAPPED_INT_TYPE(long, long, CTYPES_FFI_LONG) 1.92 +DEFINE_WRAPPED_INT_TYPE(unsigned_long, unsigned long, CTYPES_FFI_ULONG) 1.93 +DEFINE_WRAPPED_INT_TYPE(long_long, long long, ffi_type_sint64) 1.94 +DEFINE_WRAPPED_INT_TYPE(unsigned_long_long, unsigned long long, ffi_type_uint64) 1.95 +DEFINE_WRAPPED_INT_TYPE(size_t, size_t, CTYPES_FFI_SIZE_T) 1.96 +DEFINE_WRAPPED_INT_TYPE(ssize_t, CTYPES_SSIZE_T, CTYPES_FFI_SSIZE_T) 1.97 +DEFINE_WRAPPED_INT_TYPE(off_t, off_t, CTYPES_FFI_OFF_T) 1.98 +DEFINE_WRAPPED_INT_TYPE(intptr_t, intptr_t, CTYPES_FFI_INTPTR_T) 1.99 +DEFINE_WRAPPED_INT_TYPE(uintptr_t, uintptr_t, CTYPES_FFI_UINTPTR_T) 1.100 +DEFINE_FLOAT_TYPE (float32_t, float, ffi_type_float) 1.101 +DEFINE_FLOAT_TYPE (float64_t, double, ffi_type_double) 1.102 +DEFINE_FLOAT_TYPE (float, float, ffi_type_float) 1.103 +DEFINE_FLOAT_TYPE (double, double, ffi_type_double) 1.104 +DEFINE_CHAR_TYPE (char, char, ffi_type_uint8) 1.105 +DEFINE_CHAR_TYPE (signed_char, signed char, ffi_type_sint8) 1.106 +DEFINE_CHAR_TYPE (unsigned_char, unsigned char, ffi_type_uint8) 1.107 +DEFINE_JSCHAR_TYPE (jschar, jschar, ffi_type_uint16) 1.108 + 1.109 +#undef CTYPES_SSIZE_T 1.110 +#undef CTYPES_FFI_BOOL 1.111 +#undef CTYPES_FFI_LONG 1.112 +#undef CTYPES_FFI_ULONG 1.113 +#undef CTYPES_FFI_SIZE_T 1.114 +#undef CTYPES_FFI_SSIZE_T 1.115 +#undef CTYPES_FFI_INTPTR_T 1.116 +#undef CTYPES_FFI_UINTPTR_T 1.117 + 1.118 +#undef DEFINE_TYPE 1.119 +#undef DEFINE_CHAR_TYPE 1.120 +#undef DEFINE_JSCHAR_TYPE 1.121 +#undef DEFINE_BOOL_TYPE 1.122 +#undef DEFINE_INT_TYPE 1.123 +#undef DEFINE_WRAPPED_INT_TYPE 1.124 +#undef DEFINE_FLOAT_TYPE 1.125 +