Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* |
michael@0 | 8 | ** File: jstypes.h |
michael@0 | 9 | ** Description: Definitions of NSPR's basic types |
michael@0 | 10 | ** |
michael@0 | 11 | ** Prototypes and macros used to make up for deficiencies in ANSI environments |
michael@0 | 12 | ** that we have found. |
michael@0 | 13 | ** |
michael@0 | 14 | ** Since we do not wrap <stdlib.h> and all the other standard headers, authors |
michael@0 | 15 | ** of portable code will not know in general that they need these definitions. |
michael@0 | 16 | ** Instead of requiring these authors to find the dependent uses in their code |
michael@0 | 17 | ** and take the following steps only in those C files, we take steps once here |
michael@0 | 18 | ** for all C files. |
michael@0 | 19 | **/ |
michael@0 | 20 | |
michael@0 | 21 | #ifndef jstypes_h |
michael@0 | 22 | #define jstypes_h |
michael@0 | 23 | |
michael@0 | 24 | #include "mozilla/Attributes.h" |
michael@0 | 25 | #include "mozilla/Types.h" |
michael@0 | 26 | |
michael@0 | 27 | // jstypes.h is (or should be!) included by every file in SpiderMonkey. |
michael@0 | 28 | // js-config.h and jsversion.h also should be included by every file. |
michael@0 | 29 | // So include them here. |
michael@0 | 30 | // XXX: including them in js/RequiredDefines.h should be a better option, since |
michael@0 | 31 | // that is by definition the header file that should be included in all |
michael@0 | 32 | // SpiderMonkey code. However, Gecko doesn't do this! See bug 909576. |
michael@0 | 33 | #include "js-config.h" |
michael@0 | 34 | #include "jsversion.h" |
michael@0 | 35 | |
michael@0 | 36 | /*********************************************************************** |
michael@0 | 37 | ** MACROS: JS_EXTERN_API |
michael@0 | 38 | ** JS_EXPORT_API |
michael@0 | 39 | ** DESCRIPTION: |
michael@0 | 40 | ** These are only for externally visible routines and globals. For |
michael@0 | 41 | ** internal routines, just use "extern" for type checking and that |
michael@0 | 42 | ** will not export internal cross-file or forward-declared symbols. |
michael@0 | 43 | ** Define a macro for declaring procedures return types. We use this to |
michael@0 | 44 | ** deal with windoze specific type hackery for DLL definitions. Use |
michael@0 | 45 | ** JS_EXTERN_API when the prototype for the method is declared. Use |
michael@0 | 46 | ** JS_EXPORT_API for the implementation of the method. |
michael@0 | 47 | ** |
michael@0 | 48 | ** Example: |
michael@0 | 49 | ** in dowhim.h |
michael@0 | 50 | ** JS_EXTERN_API( void ) DoWhatIMean( void ); |
michael@0 | 51 | ** in dowhim.c |
michael@0 | 52 | ** JS_EXPORT_API( void ) DoWhatIMean( void ) { return; } |
michael@0 | 53 | ** |
michael@0 | 54 | ** |
michael@0 | 55 | ***********************************************************************/ |
michael@0 | 56 | |
michael@0 | 57 | #define JS_EXTERN_API(type) extern MOZ_EXPORT type |
michael@0 | 58 | #define JS_EXPORT_API(type) MOZ_EXPORT type |
michael@0 | 59 | #define JS_EXPORT_DATA(type) MOZ_EXPORT type |
michael@0 | 60 | #define JS_IMPORT_API(type) MOZ_IMPORT_API type |
michael@0 | 61 | #define JS_IMPORT_DATA(type) MOZ_IMPORT_DATA type |
michael@0 | 62 | |
michael@0 | 63 | /* |
michael@0 | 64 | * The linkage of JS API functions differs depending on whether the file is |
michael@0 | 65 | * used within the JS library or not. Any source file within the JS |
michael@0 | 66 | * interpreter should define EXPORT_JS_API whereas any client of the library |
michael@0 | 67 | * should not. STATIC_JS_API is used to build JS as a static library. |
michael@0 | 68 | */ |
michael@0 | 69 | #if defined(STATIC_JS_API) |
michael@0 | 70 | # define JS_PUBLIC_API(t) t |
michael@0 | 71 | # define JS_PUBLIC_DATA(t) t |
michael@0 | 72 | #elif defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) |
michael@0 | 73 | # define JS_PUBLIC_API(t) MOZ_EXPORT t |
michael@0 | 74 | # define JS_PUBLIC_DATA(t) MOZ_EXPORT t |
michael@0 | 75 | #else |
michael@0 | 76 | # define JS_PUBLIC_API(t) MOZ_IMPORT_API t |
michael@0 | 77 | # define JS_PUBLIC_DATA(t) MOZ_IMPORT_DATA t |
michael@0 | 78 | #endif |
michael@0 | 79 | |
michael@0 | 80 | #if defined(STATIC_JS_API) || defined(EXPORT_JS_API) || defined(STATIC_EXPORTABLE_JS_API) |
michael@0 | 81 | # define JS_FRIEND_API(t) MOZ_EXPORT t |
michael@0 | 82 | # define JS_FRIEND_DATA(t) MOZ_EXPORT t |
michael@0 | 83 | #else |
michael@0 | 84 | # define JS_FRIEND_API(t) MOZ_IMPORT_API t |
michael@0 | 85 | # define JS_FRIEND_DATA(t) MOZ_IMPORT_DATA t |
michael@0 | 86 | #endif |
michael@0 | 87 | |
michael@0 | 88 | #if defined(_MSC_VER) && defined(_M_IX86) |
michael@0 | 89 | #define JS_FASTCALL __fastcall |
michael@0 | 90 | #elif defined(__GNUC__) && defined(__i386__) |
michael@0 | 91 | #define JS_FASTCALL __attribute__((fastcall)) |
michael@0 | 92 | #else |
michael@0 | 93 | #define JS_FASTCALL |
michael@0 | 94 | #define JS_NO_FASTCALL |
michael@0 | 95 | #endif |
michael@0 | 96 | |
michael@0 | 97 | /*********************************************************************** |
michael@0 | 98 | ** MACROS: JS_BEGIN_MACRO |
michael@0 | 99 | ** JS_END_MACRO |
michael@0 | 100 | ** DESCRIPTION: |
michael@0 | 101 | ** Macro body brackets so that macros with compound statement definitions |
michael@0 | 102 | ** behave syntactically more like functions when called. |
michael@0 | 103 | ***********************************************************************/ |
michael@0 | 104 | #define JS_BEGIN_MACRO do { |
michael@0 | 105 | |
michael@0 | 106 | #if defined(_MSC_VER) && _MSC_VER >= 1400 |
michael@0 | 107 | # define JS_END_MACRO \ |
michael@0 | 108 | } __pragma(warning(push)) __pragma(warning(disable:4127)) \ |
michael@0 | 109 | while (0) __pragma(warning(pop)) |
michael@0 | 110 | #else |
michael@0 | 111 | # define JS_END_MACRO } while (0) |
michael@0 | 112 | #endif |
michael@0 | 113 | |
michael@0 | 114 | /*********************************************************************** |
michael@0 | 115 | ** MACROS: JS_BIT |
michael@0 | 116 | ** JS_BITMASK |
michael@0 | 117 | ** DESCRIPTION: |
michael@0 | 118 | ** Bit masking macros. XXX n must be <= 31 to be portable |
michael@0 | 119 | ***********************************************************************/ |
michael@0 | 120 | #define JS_BIT(n) ((uint32_t)1 << (n)) |
michael@0 | 121 | #define JS_BITMASK(n) (JS_BIT(n) - 1) |
michael@0 | 122 | |
michael@0 | 123 | /*********************************************************************** |
michael@0 | 124 | ** MACROS: JS_HOWMANY |
michael@0 | 125 | ** JS_ROUNDUP |
michael@0 | 126 | ** DESCRIPTION: |
michael@0 | 127 | ** Commonly used macros for operations on compatible types. |
michael@0 | 128 | ***********************************************************************/ |
michael@0 | 129 | #define JS_HOWMANY(x,y) (((x)+(y)-1)/(y)) |
michael@0 | 130 | #define JS_ROUNDUP(x,y) (JS_HOWMANY(x,y)*(y)) |
michael@0 | 131 | |
michael@0 | 132 | #include "jscpucfg.h" |
michael@0 | 133 | |
michael@0 | 134 | /* |
michael@0 | 135 | * Define JS_64BIT iff we are building in an environment with 64-bit |
michael@0 | 136 | * addresses. |
michael@0 | 137 | */ |
michael@0 | 138 | #ifdef _MSC_VER |
michael@0 | 139 | # if defined(_M_X64) || defined(_M_AMD64) |
michael@0 | 140 | # define JS_64BIT |
michael@0 | 141 | # endif |
michael@0 | 142 | #elif defined(__GNUC__) |
michael@0 | 143 | /* Additional GCC defines are when running on Solaris, AIX, and HPUX */ |
michael@0 | 144 | # if defined(__x86_64__) || defined(__sparcv9) || \ |
michael@0 | 145 | defined(__64BIT__) || defined(__LP64__) |
michael@0 | 146 | # define JS_64BIT |
michael@0 | 147 | # endif |
michael@0 | 148 | #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) /* Sun Studio C/C++ */ |
michael@0 | 149 | # if defined(__x86_64) || defined(__sparcv9) |
michael@0 | 150 | # define JS_64BIT |
michael@0 | 151 | # endif |
michael@0 | 152 | #elif defined(__xlc__) || defined(__xlC__) /* IBM XL C/C++ */ |
michael@0 | 153 | # if defined(__64BIT__) |
michael@0 | 154 | # define JS_64BIT |
michael@0 | 155 | # endif |
michael@0 | 156 | #elif defined(__HP_cc) || defined(__HP_aCC) /* HP-UX cc/aCC */ |
michael@0 | 157 | # if defined(__LP64__) |
michael@0 | 158 | # define JS_64BIT |
michael@0 | 159 | # endif |
michael@0 | 160 | #else |
michael@0 | 161 | # error "Implement me" |
michael@0 | 162 | #endif |
michael@0 | 163 | |
michael@0 | 164 | /*********************************************************************** |
michael@0 | 165 | ** MACROS: JS_ARRAY_LENGTH |
michael@0 | 166 | ** JS_ARRAY_END |
michael@0 | 167 | ** DESCRIPTION: |
michael@0 | 168 | ** Macros to get the number of elements and the pointer to one past the |
michael@0 | 169 | ** last element of a C array. Use them like this: |
michael@0 | 170 | ** |
michael@0 | 171 | ** jschar buf[10], *s; |
michael@0 | 172 | ** JSString *str; |
michael@0 | 173 | ** ... |
michael@0 | 174 | ** for (s = buf; s != JS_ARRAY_END(buf); ++s) *s = ...; |
michael@0 | 175 | ** ... |
michael@0 | 176 | ** str = JS_NewStringCopyN(cx, buf, JS_ARRAY_LENGTH(buf)); |
michael@0 | 177 | ** ... |
michael@0 | 178 | ** |
michael@0 | 179 | ***********************************************************************/ |
michael@0 | 180 | |
michael@0 | 181 | #define JS_ARRAY_LENGTH(array) (sizeof (array) / sizeof (array)[0]) |
michael@0 | 182 | #define JS_ARRAY_END(array) ((array) + JS_ARRAY_LENGTH(array)) |
michael@0 | 183 | |
michael@0 | 184 | #define JS_BITS_PER_BYTE 8 |
michael@0 | 185 | #define JS_BITS_PER_BYTE_LOG2 3 |
michael@0 | 186 | |
michael@0 | 187 | #if defined(JS_64BIT) |
michael@0 | 188 | # define JS_BITS_PER_WORD 64 |
michael@0 | 189 | #else |
michael@0 | 190 | # define JS_BITS_PER_WORD 32 |
michael@0 | 191 | #endif |
michael@0 | 192 | |
michael@0 | 193 | /*********************************************************************** |
michael@0 | 194 | ** MACROS: JS_FUNC_TO_DATA_PTR |
michael@0 | 195 | ** JS_DATA_TO_FUNC_PTR |
michael@0 | 196 | ** DESCRIPTION: |
michael@0 | 197 | ** Macros to convert between function and data pointers assuming that |
michael@0 | 198 | ** they have the same size. Use them like this: |
michael@0 | 199 | ** |
michael@0 | 200 | ** JSPropertyOp nativeGetter; |
michael@0 | 201 | ** JSObject *scriptedGetter; |
michael@0 | 202 | ** ... |
michael@0 | 203 | ** scriptedGetter = JS_FUNC_TO_DATA_PTR(JSObject *, nativeGetter); |
michael@0 | 204 | ** ... |
michael@0 | 205 | ** nativeGetter = JS_DATA_TO_FUNC_PTR(JSPropertyOp, scriptedGetter); |
michael@0 | 206 | ** |
michael@0 | 207 | ***********************************************************************/ |
michael@0 | 208 | |
michael@0 | 209 | #ifdef __GNUC__ |
michael@0 | 210 | # define JS_FUNC_TO_DATA_PTR(type, fun) (__extension__ (type) (size_t) (fun)) |
michael@0 | 211 | # define JS_DATA_TO_FUNC_PTR(type, ptr) (__extension__ (type) (size_t) (ptr)) |
michael@0 | 212 | #else |
michael@0 | 213 | /* Use an extra (void *) cast for MSVC. */ |
michael@0 | 214 | # define JS_FUNC_TO_DATA_PTR(type, fun) ((type) (void *) (fun)) |
michael@0 | 215 | # define JS_DATA_TO_FUNC_PTR(type, ptr) ((type) (void *) (ptr)) |
michael@0 | 216 | #endif |
michael@0 | 217 | |
michael@0 | 218 | #ifdef __GNUC__ |
michael@0 | 219 | # define JS_EXTENSION __extension__ |
michael@0 | 220 | # define JS_EXTENSION_(s) __extension__ ({ s; }) |
michael@0 | 221 | #else |
michael@0 | 222 | # define JS_EXTENSION |
michael@0 | 223 | # define JS_EXTENSION_(s) s |
michael@0 | 224 | #endif |
michael@0 | 225 | |
michael@0 | 226 | #endif /* jstypes_h */ |