js/src/ctypes/typedefs.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /**
michael@0 7 * This header contains the builtin types available for arguments and return
michael@0 8 * values, representing their C counterparts. They are listed inside macros
michael@0 9 * that the #includer is expected to #define. Format is:
michael@0 10 *
michael@0 11 * DEFINE_X_TYPE(typename, ctype, ffitype)
michael@0 12 *
michael@0 13 * where 'typename' is the name of the type constructor (accessible as
michael@0 14 * ctypes.typename), 'ctype' is the corresponding C type declaration (from
michael@0 15 * which sizeof(ctype) and templated type conversions will be derived), and
michael@0 16 * 'ffitype' is the ffi_type to use. (Special types, such as 'void' and the
michael@0 17 * pointer, array, and struct types are handled separately.)
michael@0 18 *
michael@0 19 * This header lacks a #ifndef wrapper because it is deliberately #included
michael@0 20 * multiple times in ctypes/CTypes.h.
michael@0 21 */
michael@0 22
michael@0 23 // If we're not breaking the types out, combine them together under one
michael@0 24 // DEFINE_TYPE macro. Otherwise, turn off whichever ones we're not using.
michael@0 25 #if defined(DEFINE_TYPE)
michael@0 26 # define DEFINE_CHAR_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
michael@0 27 # define DEFINE_JSCHAR_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
michael@0 28 # define DEFINE_BOOL_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
michael@0 29 # define DEFINE_INT_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
michael@0 30 # define DEFINE_WRAPPED_INT_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
michael@0 31 # define DEFINE_FLOAT_TYPE(x, y, z) DEFINE_TYPE(x, y, z)
michael@0 32 #else
michael@0 33 # ifndef DEFINE_BOOL_TYPE
michael@0 34 # define DEFINE_BOOL_TYPE(x, y, z)
michael@0 35 # endif
michael@0 36 # ifndef DEFINE_CHAR_TYPE
michael@0 37 # define DEFINE_CHAR_TYPE(x, y, z)
michael@0 38 # endif
michael@0 39 # ifndef DEFINE_JSCHAR_TYPE
michael@0 40 # define DEFINE_JSCHAR_TYPE(x, y, z)
michael@0 41 # endif
michael@0 42 # ifndef DEFINE_INT_TYPE
michael@0 43 # define DEFINE_INT_TYPE(x, y, z)
michael@0 44 # endif
michael@0 45 # ifndef DEFINE_WRAPPED_INT_TYPE
michael@0 46 # define DEFINE_WRAPPED_INT_TYPE(x, y, z)
michael@0 47 # endif
michael@0 48 # ifndef DEFINE_FLOAT_TYPE
michael@0 49 # define DEFINE_FLOAT_TYPE(x, y, z)
michael@0 50 # endif
michael@0 51 #endif
michael@0 52
michael@0 53 // MSVC doesn't have ssize_t. Help it along a little.
michael@0 54 #ifdef HAVE_SSIZE_T
michael@0 55 #define CTYPES_SSIZE_T ssize_t
michael@0 56 #else
michael@0 57 #define CTYPES_SSIZE_T intptr_t
michael@0 58 #endif
michael@0 59
michael@0 60 // Some #defines to make handling of types whose length varies by platform
michael@0 61 // easier. These could be implemented as configure tests, but the expressions
michael@0 62 // are all statically resolvable so there's no need. (See CTypes.cpp for the
michael@0 63 // appropriate PR_STATIC_ASSERTs; they can't go here since this header is
michael@0 64 // used in places where such asserts are illegal.)
michael@0 65 #define CTYPES_FFI_BOOL (sizeof(bool) == 1 ? ffi_type_uint8 : ffi_type_uint32)
michael@0 66 #define CTYPES_FFI_LONG (sizeof(long) == 4 ? ffi_type_sint32 : ffi_type_sint64)
michael@0 67 #define CTYPES_FFI_ULONG (sizeof(long) == 4 ? ffi_type_uint32 : ffi_type_uint64)
michael@0 68 #define CTYPES_FFI_SIZE_T (sizeof(size_t) == 4 ? ffi_type_uint32 : ffi_type_uint64)
michael@0 69 #define CTYPES_FFI_SSIZE_T (sizeof(size_t) == 4 ? ffi_type_sint32 : ffi_type_sint64)
michael@0 70 #define CTYPES_FFI_OFF_T (sizeof(off_t) == 4 ? ffi_type_sint32 : ffi_type_sint64)
michael@0 71 #define CTYPES_FFI_INTPTR_T (sizeof(uintptr_t) == 4 ? ffi_type_sint32 : ffi_type_sint64)
michael@0 72 #define CTYPES_FFI_UINTPTR_T (sizeof(uintptr_t) == 4 ? ffi_type_uint32 : ffi_type_uint64)
michael@0 73
michael@0 74 // The meat.
michael@0 75 DEFINE_BOOL_TYPE (bool, bool, CTYPES_FFI_BOOL)
michael@0 76 DEFINE_INT_TYPE (int8_t, int8_t, ffi_type_sint8)
michael@0 77 DEFINE_INT_TYPE (int16_t, int16_t, ffi_type_sint16)
michael@0 78 DEFINE_INT_TYPE (int32_t, int32_t, ffi_type_sint32)
michael@0 79 DEFINE_INT_TYPE (uint8_t, uint8_t, ffi_type_uint8)
michael@0 80 DEFINE_INT_TYPE (uint16_t, uint16_t, ffi_type_uint16)
michael@0 81 DEFINE_INT_TYPE (uint32_t, uint32_t, ffi_type_uint32)
michael@0 82 DEFINE_INT_TYPE (short, short, ffi_type_sint16)
michael@0 83 DEFINE_INT_TYPE (unsigned_short, unsigned short, ffi_type_uint16)
michael@0 84 DEFINE_INT_TYPE (int, int, ffi_type_sint32)
michael@0 85 DEFINE_INT_TYPE (unsigned_int, unsigned int, ffi_type_uint32)
michael@0 86 DEFINE_WRAPPED_INT_TYPE(int64_t, int64_t, ffi_type_sint64)
michael@0 87 DEFINE_WRAPPED_INT_TYPE(uint64_t, uint64_t, ffi_type_uint64)
michael@0 88 DEFINE_WRAPPED_INT_TYPE(long, long, CTYPES_FFI_LONG)
michael@0 89 DEFINE_WRAPPED_INT_TYPE(unsigned_long, unsigned long, CTYPES_FFI_ULONG)
michael@0 90 DEFINE_WRAPPED_INT_TYPE(long_long, long long, ffi_type_sint64)
michael@0 91 DEFINE_WRAPPED_INT_TYPE(unsigned_long_long, unsigned long long, ffi_type_uint64)
michael@0 92 DEFINE_WRAPPED_INT_TYPE(size_t, size_t, CTYPES_FFI_SIZE_T)
michael@0 93 DEFINE_WRAPPED_INT_TYPE(ssize_t, CTYPES_SSIZE_T, CTYPES_FFI_SSIZE_T)
michael@0 94 DEFINE_WRAPPED_INT_TYPE(off_t, off_t, CTYPES_FFI_OFF_T)
michael@0 95 DEFINE_WRAPPED_INT_TYPE(intptr_t, intptr_t, CTYPES_FFI_INTPTR_T)
michael@0 96 DEFINE_WRAPPED_INT_TYPE(uintptr_t, uintptr_t, CTYPES_FFI_UINTPTR_T)
michael@0 97 DEFINE_FLOAT_TYPE (float32_t, float, ffi_type_float)
michael@0 98 DEFINE_FLOAT_TYPE (float64_t, double, ffi_type_double)
michael@0 99 DEFINE_FLOAT_TYPE (float, float, ffi_type_float)
michael@0 100 DEFINE_FLOAT_TYPE (double, double, ffi_type_double)
michael@0 101 DEFINE_CHAR_TYPE (char, char, ffi_type_uint8)
michael@0 102 DEFINE_CHAR_TYPE (signed_char, signed char, ffi_type_sint8)
michael@0 103 DEFINE_CHAR_TYPE (unsigned_char, unsigned char, ffi_type_uint8)
michael@0 104 DEFINE_JSCHAR_TYPE (jschar, jschar, ffi_type_uint16)
michael@0 105
michael@0 106 #undef CTYPES_SSIZE_T
michael@0 107 #undef CTYPES_FFI_BOOL
michael@0 108 #undef CTYPES_FFI_LONG
michael@0 109 #undef CTYPES_FFI_ULONG
michael@0 110 #undef CTYPES_FFI_SIZE_T
michael@0 111 #undef CTYPES_FFI_SSIZE_T
michael@0 112 #undef CTYPES_FFI_INTPTR_T
michael@0 113 #undef CTYPES_FFI_UINTPTR_T
michael@0 114
michael@0 115 #undef DEFINE_TYPE
michael@0 116 #undef DEFINE_CHAR_TYPE
michael@0 117 #undef DEFINE_JSCHAR_TYPE
michael@0 118 #undef DEFINE_BOOL_TYPE
michael@0 119 #undef DEFINE_INT_TYPE
michael@0 120 #undef DEFINE_WRAPPED_INT_TYPE
michael@0 121 #undef DEFINE_FLOAT_TYPE
michael@0 122

mercurial