| 1 | // © 2016 and later: Unicode, Inc. and others. |
| 2 | // License & terms of use: http://www.unicode.org/copyright.html |
| 3 | /* |
| 4 | ****************************************************************************** |
| 5 | * |
| 6 | * Copyright (C) 1997-2016, International Business Machines |
| 7 | * Corporation and others. All Rights Reserved. |
| 8 | * |
| 9 | ****************************************************************************** |
| 10 | * |
| 11 | * FILE NAME : platform.h |
| 12 | * |
| 13 | * Date Name Description |
| 14 | * 05/13/98 nos Creation (content moved here from ptypes.h). |
| 15 | * 03/02/99 stephen Added AS400 support. |
| 16 | * 03/30/99 stephen Added Linux support. |
| 17 | * 04/13/99 stephen Reworked for autoconf. |
| 18 | ****************************************************************************** |
| 19 | */ |
| 20 | |
| 21 | #ifndef _PLATFORM_H |
| 22 | #define _PLATFORM_H |
| 23 | |
| 24 | #include "unicode/uconfig.h" |
| 25 | #include "unicode/uvernum.h" |
| 26 | |
| 27 | /** |
| 28 | * \file |
| 29 | * \brief Basic types for the platform. |
| 30 | * |
| 31 | * This file used to be generated by autoconf/configure. |
| 32 | * Starting with ICU 49, platform.h is a normal source file, |
| 33 | * to simplify cross-compiling and working with non-autoconf/make build systems. |
| 34 | * |
| 35 | * When a value in this file does not work on a platform, then please |
| 36 | * try to derive it from the U_PLATFORM value |
| 37 | * (for which we might need a new value constant in rare cases) |
| 38 | * and/or from other macros that are predefined by the compiler |
| 39 | * or defined in standard (POSIX or platform or compiler) headers. |
| 40 | * |
| 41 | * As a temporary workaround, you can add an explicit <code>#define</code> for some macros |
| 42 | * before it is first tested, or add an equivalent -D macro definition |
| 43 | * to the compiler's command line. |
| 44 | * |
| 45 | * Note: Some compilers provide ways to show the predefined macros. |
| 46 | * For example, with gcc you can compile an empty .c file and have the compiler |
| 47 | * print the predefined macros with |
| 48 | * \code |
| 49 | * gcc -E -dM -x c /dev/null | sort |
| 50 | * \endcode |
| 51 | * (You can provide an actual empty .c file rather than /dev/null. |
| 52 | * <code>-x c++</code> is for C++.) |
| 53 | */ |
| 54 | |
| 55 | /** |
| 56 | * Define some things so that they can be documented. |
| 57 | * @internal |
| 58 | */ |
| 59 | #ifdef U_IN_DOXYGEN |
| 60 | /* |
| 61 | * Problem: "platform.h:335: warning: documentation for unknown define U_HAVE_STD_STRING found." means that U_HAVE_STD_STRING is not documented. |
| 62 | * Solution: #define any defines for non @internal API here, so that they are visible in the docs. If you just set PREDEFINED in Doxyfile.in, they won't be documented. |
| 63 | */ |
| 64 | |
| 65 | /* None for now. */ |
| 66 | #endif |
| 67 | |
| 68 | /** |
| 69 | * \def U_PLATFORM |
| 70 | * The U_PLATFORM macro defines the platform we're on. |
| 71 | * |
| 72 | * We used to define one different, value-less macro per platform. |
| 73 | * That made it hard to know the set of relevant platforms and macros, |
| 74 | * and hard to deal with variants of platforms. |
| 75 | * |
| 76 | * Starting with ICU 49, we define platforms as numeric macros, |
| 77 | * with ranges of values for related platforms and their variants. |
| 78 | * The U_PLATFORM macro is set to one of these values. |
| 79 | * |
| 80 | * Historical note from the Solaris Wikipedia article: |
| 81 | * AT&T and Sun collaborated on a project to merge the most popular Unix variants |
| 82 | * on the market at that time: BSD, System V, and Xenix. |
| 83 | * This became Unix System V Release 4 (SVR4). |
| 84 | * |
| 85 | * @internal |
| 86 | */ |
| 87 | |
| 88 | /** Unknown platform. @internal */ |
| 89 | #define U_PF_UNKNOWN 0 |
| 90 | /** Windows @internal */ |
| 91 | #define U_PF_WINDOWS 1000 |
| 92 | /** MinGW. Windows, calls to Win32 API, but using GNU gcc and binutils. @internal */ |
| 93 | #define U_PF_MINGW 1800 |
| 94 | /** |
| 95 | * Cygwin. Windows, calls to cygwin1.dll for Posix functions, |
| 96 | * using MSVC or GNU gcc and binutils. |
| 97 | * @internal |
| 98 | */ |
| 99 | #define U_PF_CYGWIN 1900 |
| 100 | /* Reserve 2000 for U_PF_UNIX? */ |
| 101 | /** HP-UX is based on UNIX System V. @internal */ |
| 102 | #define U_PF_HPUX 2100 |
| 103 | /** Solaris is a Unix operating system based on SVR4. @internal */ |
| 104 | #define U_PF_SOLARIS 2600 |
| 105 | /** BSD is a UNIX operating system derivative. @internal */ |
| 106 | #define U_PF_BSD 3000 |
| 107 | /** AIX is based on UNIX System V Releases and 4.3 BSD. @internal */ |
| 108 | #define U_PF_AIX 3100 |
| 109 | /** IRIX is based on UNIX System V with BSD extensions. @internal */ |
| 110 | #define U_PF_IRIX 3200 |
| 111 | /** |
| 112 | * Darwin is a POSIX-compliant operating system, composed of code developed by Apple, |
| 113 | * as well as code derived from NeXTSTEP, BSD, and other projects, |
| 114 | * built around the Mach kernel. |
| 115 | * Darwin forms the core set of components upon which Mac OS X, Apple TV, and iOS are based. |
| 116 | * (Original description modified from WikiPedia.) |
| 117 | * @internal |
| 118 | */ |
| 119 | #define U_PF_DARWIN 3500 |
| 120 | /** iPhone OS (iOS) is a derivative of Mac OS X. @internal */ |
| 121 | #define U_PF_IPHONE 3550 |
| 122 | /** QNX is a commercial Unix-like real-time operating system related to BSD. @internal */ |
| 123 | #define U_PF_QNX 3700 |
| 124 | /** Linux is a Unix-like operating system. @internal */ |
| 125 | #define U_PF_LINUX 4000 |
| 126 | /** |
| 127 | * Native Client is pretty close to Linux. |
| 128 | * See https://developer.chrome.com/native-client and |
| 129 | * http://www.chromium.org/nativeclient |
| 130 | * @internal |
| 131 | */ |
| 132 | #define U_PF_BROWSER_NATIVE_CLIENT 4020 |
| 133 | /** Android is based on Linux. @internal */ |
| 134 | #define U_PF_ANDROID 4050 |
| 135 | /* Maximum value for Linux-based platform is 4499 */ |
| 136 | /** z/OS is the successor to OS/390 which was the successor to MVS. @internal */ |
| 137 | #define U_PF_OS390 9000 |
| 138 | /** "IBM i" is the current name of what used to be i5/OS and earlier OS/400. @internal */ |
| 139 | #define U_PF_OS400 9400 |
| 140 | |
| 141 | #ifdef U_PLATFORM |
| 142 | /* Use the predefined value. */ |
| 143 | #elif defined(__MINGW32__) |
| 144 | # define U_PLATFORM U_PF_MINGW |
| 145 | #elif defined(__CYGWIN__) |
| 146 | # define U_PLATFORM U_PF_CYGWIN |
| 147 | #elif defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) |
| 148 | # define U_PLATFORM U_PF_WINDOWS |
| 149 | #elif defined(__ANDROID__) |
| 150 | # define U_PLATFORM U_PF_ANDROID |
| 151 | /* Android wchar_t support depends on the API level. */ |
| 152 | # include <android/api-level.h> |
| 153 | #elif defined(__pnacl__) || defined(__native_client__) |
| 154 | # define U_PLATFORM U_PF_BROWSER_NATIVE_CLIENT |
| 155 | #elif defined(linux) || defined(__linux__) || defined(__linux) |
| 156 | # define U_PLATFORM U_PF_LINUX |
| 157 | #elif defined(__APPLE__) && defined(__MACH__) |
| 158 | # include <TargetConditionals.h> |
| 159 | # if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE /* variant of TARGET_OS_MAC */ |
| 160 | # define U_PLATFORM U_PF_IPHONE |
| 161 | # else |
| 162 | # define U_PLATFORM U_PF_DARWIN |
| 163 | # endif |
| 164 | #elif defined(BSD) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__MirBSD__) |
| 165 | # if defined(__FreeBSD__) |
| 166 | # include <sys/endian.h> |
| 167 | # endif |
| 168 | # define U_PLATFORM U_PF_BSD |
| 169 | #elif defined(sun) || defined(__sun) |
| 170 | /* Check defined(__SVR4) || defined(__svr4__) to distinguish Solaris from SunOS? */ |
| 171 | # define U_PLATFORM U_PF_SOLARIS |
| 172 | # if defined(__GNUC__) |
| 173 | /* Solaris/GCC needs this header file to get the proper endianness. Normally, this |
| 174 | * header file is included with stddef.h but on Solairs/GCC, the GCC version of stddef.h |
| 175 | * is included which does not include this header file. |
| 176 | */ |
| 177 | # include <sys/isa_defs.h> |
| 178 | # endif |
| 179 | #elif defined(_AIX) || defined(__TOS_AIX__) |
| 180 | # define U_PLATFORM U_PF_AIX |
| 181 | #elif defined(_hpux) || defined(hpux) || defined(__hpux) |
| 182 | # define U_PLATFORM U_PF_HPUX |
| 183 | #elif defined(sgi) || defined(__sgi) |
| 184 | # define U_PLATFORM U_PF_IRIX |
| 185 | #elif defined(__QNX__) || defined(__QNXNTO__) |
| 186 | # define U_PLATFORM U_PF_QNX |
| 187 | #elif defined(__TOS_MVS__) |
| 188 | # define U_PLATFORM U_PF_OS390 |
| 189 | #elif defined(__OS400__) || defined(__TOS_OS400__) |
| 190 | # define U_PLATFORM U_PF_OS400 |
| 191 | #else |
| 192 | # define U_PLATFORM U_PF_UNKNOWN |
| 193 | #endif |
| 194 | |
| 195 | /** |
| 196 | * \def CYGWINMSVC |
| 197 | * Defined if this is Windows with Cygwin, but using MSVC rather than gcc. |
| 198 | * Otherwise undefined. |
| 199 | * @internal |
| 200 | */ |
| 201 | /* Commented out because this is already set in mh-cygwin-msvc |
| 202 | #if U_PLATFORM == U_PF_CYGWIN && defined(_MSC_VER) |
| 203 | # define CYGWINMSVC |
| 204 | #endif |
| 205 | */ |
| 206 | |
| 207 | /** |
| 208 | * \def U_PLATFORM_USES_ONLY_WIN32_API |
| 209 | * Defines whether the platform uses only the Win32 API. |
| 210 | * Set to 1 for Windows/MSVC and MinGW but not Cygwin. |
| 211 | * @internal |
| 212 | */ |
| 213 | #ifdef U_PLATFORM_USES_ONLY_WIN32_API |
| 214 | /* Use the predefined value. */ |
| 215 | #elif (U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_MINGW) || defined(CYGWINMSVC) |
| 216 | # define U_PLATFORM_USES_ONLY_WIN32_API 1 |
| 217 | #else |
| 218 | /* Cygwin implements POSIX. */ |
| 219 | # define U_PLATFORM_USES_ONLY_WIN32_API 0 |
| 220 | #endif |
| 221 | |
| 222 | /** |
| 223 | * \def U_PLATFORM_HAS_WIN32_API |
| 224 | * Defines whether the Win32 API is available on the platform. |
| 225 | * Set to 1 for Windows/MSVC, MinGW and Cygwin. |
| 226 | * @internal |
| 227 | */ |
| 228 | #ifdef U_PLATFORM_HAS_WIN32_API |
| 229 | /* Use the predefined value. */ |
| 230 | #elif U_PF_WINDOWS <= U_PLATFORM && U_PLATFORM <= U_PF_CYGWIN |
| 231 | # define U_PLATFORM_HAS_WIN32_API 1 |
| 232 | #else |
| 233 | # define U_PLATFORM_HAS_WIN32_API 0 |
| 234 | #endif |
| 235 | |
| 236 | /** |
| 237 | * \def U_PLATFORM_HAS_WINUWP_API |
| 238 | * Defines whether target is intended for Universal Windows Platform API |
| 239 | * Set to 1 for Windows10 Release Solution Configuration |
| 240 | * @internal |
| 241 | */ |
| 242 | #ifdef U_PLATFORM_HAS_WINUWP_API |
| 243 | /* Use the predefined value. */ |
| 244 | #else |
| 245 | # define U_PLATFORM_HAS_WINUWP_API 0 |
| 246 | #endif |
| 247 | |
| 248 | /** |
| 249 | * \def U_PLATFORM_IMPLEMENTS_POSIX |
| 250 | * Defines whether the platform implements (most of) the POSIX API. |
| 251 | * Set to 1 for Cygwin and most other platforms. |
| 252 | * @internal |
| 253 | */ |
| 254 | #ifdef U_PLATFORM_IMPLEMENTS_POSIX |
| 255 | /* Use the predefined value. */ |
| 256 | #elif U_PLATFORM_USES_ONLY_WIN32_API |
| 257 | # define U_PLATFORM_IMPLEMENTS_POSIX 0 |
| 258 | #else |
| 259 | # define U_PLATFORM_IMPLEMENTS_POSIX 1 |
| 260 | #endif |
| 261 | |
| 262 | /** |
| 263 | * \def U_PLATFORM_IS_LINUX_BASED |
| 264 | * Defines whether the platform is Linux or one of its derivatives. |
| 265 | * @internal |
| 266 | */ |
| 267 | #ifdef U_PLATFORM_IS_LINUX_BASED |
| 268 | /* Use the predefined value. */ |
| 269 | #elif U_PF_LINUX <= U_PLATFORM && U_PLATFORM <= 4499 |
| 270 | # define U_PLATFORM_IS_LINUX_BASED 1 |
| 271 | #else |
| 272 | # define U_PLATFORM_IS_LINUX_BASED 0 |
| 273 | #endif |
| 274 | |
| 275 | /** |
| 276 | * \def U_PLATFORM_IS_DARWIN_BASED |
| 277 | * Defines whether the platform is Darwin or one of its derivatives. |
| 278 | * @internal |
| 279 | */ |
| 280 | #ifdef U_PLATFORM_IS_DARWIN_BASED |
| 281 | /* Use the predefined value. */ |
| 282 | #elif U_PF_DARWIN <= U_PLATFORM && U_PLATFORM <= U_PF_IPHONE |
| 283 | # define U_PLATFORM_IS_DARWIN_BASED 1 |
| 284 | #else |
| 285 | # define U_PLATFORM_IS_DARWIN_BASED 0 |
| 286 | #endif |
| 287 | |
| 288 | /** |
| 289 | * \def U_HAVE_STDINT_H |
| 290 | * Defines whether stdint.h is available. It is a C99 standard header. |
| 291 | * We used to include inttypes.h which includes stdint.h but we usually do not need |
| 292 | * the additional definitions from inttypes.h. |
| 293 | * @internal |
| 294 | */ |
| 295 | #ifdef U_HAVE_STDINT_H |
| 296 | /* Use the predefined value. */ |
| 297 | #elif U_PLATFORM_USES_ONLY_WIN32_API |
| 298 | # if defined(__BORLANDC__) || U_PLATFORM == U_PF_MINGW || (defined(_MSC_VER) && _MSC_VER>=1600) |
| 299 | /* Windows Visual Studio 9 and below do not have stdint.h & inttypes.h, but VS 2010 adds them. */ |
| 300 | # define U_HAVE_STDINT_H 1 |
| 301 | # else |
| 302 | # define U_HAVE_STDINT_H 0 |
| 303 | # endif |
| 304 | #elif U_PLATFORM == U_PF_SOLARIS |
| 305 | /* Solaris has inttypes.h but not stdint.h. */ |
| 306 | # define U_HAVE_STDINT_H 0 |
| 307 | #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER) |
| 308 | /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */ |
| 309 | # define U_HAVE_STDINT_H 0 |
| 310 | #else |
| 311 | # define U_HAVE_STDINT_H 1 |
| 312 | #endif |
| 313 | |
| 314 | /** |
| 315 | * \def U_HAVE_INTTYPES_H |
| 316 | * Defines whether inttypes.h is available. It is a C99 standard header. |
| 317 | * We include inttypes.h where it is available but stdint.h is not. |
| 318 | * @internal |
| 319 | */ |
| 320 | #ifdef U_HAVE_INTTYPES_H |
| 321 | /* Use the predefined value. */ |
| 322 | #elif U_PLATFORM == U_PF_SOLARIS |
| 323 | /* Solaris has inttypes.h but not stdint.h. */ |
| 324 | # define U_HAVE_INTTYPES_H 1 |
| 325 | #elif U_PLATFORM == U_PF_AIX && !defined(_AIX51) && defined(_POWER) |
| 326 | /* PPC AIX <= 4.3 has inttypes.h but not stdint.h. */ |
| 327 | # define U_HAVE_INTTYPES_H 1 |
| 328 | #else |
| 329 | /* Most platforms have both inttypes.h and stdint.h, or neither. */ |
| 330 | # define U_HAVE_INTTYPES_H U_HAVE_STDINT_H |
| 331 | #endif |
| 332 | |
| 333 | /** |
| 334 | * \def U_IOSTREAM_SOURCE |
| 335 | * Defines what support for C++ streams is available. |
| 336 | * |
| 337 | * If U_IOSTREAM_SOURCE is set to 199711, then <iostream> is available |
| 338 | * (the ISO/IEC C++ FDIS was published in November 1997), and then |
| 339 | * one should qualify streams using the std namespace in ICU header |
| 340 | * files. |
| 341 | * Starting with ICU 49, this is the only supported version. |
| 342 | * |
| 343 | * If U_IOSTREAM_SOURCE is set to 198506, then <iostream.h> is |
| 344 | * available instead (in June 1985 Stroustrup published |
| 345 | * "An Extensible I/O Facility for C++" at the summer USENIX conference). |
| 346 | * Starting with ICU 49, this version is not supported any more. |
| 347 | * |
| 348 | * If U_IOSTREAM_SOURCE is 0 (or any value less than 199711), |
| 349 | * then C++ streams are not available and |
| 350 | * support for them will be silently suppressed in ICU. |
| 351 | * |
| 352 | * @internal |
| 353 | */ |
| 354 | #ifndef U_IOSTREAM_SOURCE |
| 355 | #define U_IOSTREAM_SOURCE 199711 |
| 356 | #endif |
| 357 | |
| 358 | /*===========================================================================*/ |
| 359 | /** @{ Compiler and environment features */ |
| 360 | /*===========================================================================*/ |
| 361 | |
| 362 | /** |
| 363 | * \def U_GCC_MAJOR_MINOR |
| 364 | * Indicates whether the compiler is gcc (test for != 0), |
| 365 | * and if so, contains its major (times 100) and minor version numbers. |
| 366 | * If the compiler is not gcc, then U_GCC_MAJOR_MINOR == 0. |
| 367 | * |
| 368 | * For example, for testing for whether we have gcc, and whether it's 4.6 or higher, |
| 369 | * use "#if U_GCC_MAJOR_MINOR >= 406". |
| 370 | * @internal |
| 371 | */ |
| 372 | #ifdef __GNUC__ |
| 373 | # define U_GCC_MAJOR_MINOR (__GNUC__ * 100 + __GNUC_MINOR__) |
| 374 | #else |
| 375 | # define U_GCC_MAJOR_MINOR 0 |
| 376 | #endif |
| 377 | |
| 378 | /** |
| 379 | * \def U_IS_BIG_ENDIAN |
| 380 | * Determines the endianness of the platform. |
| 381 | * @internal |
| 382 | */ |
| 383 | #ifdef U_IS_BIG_ENDIAN |
| 384 | /* Use the predefined value. */ |
| 385 | #elif defined(BYTE_ORDER) && defined(BIG_ENDIAN) |
| 386 | # define U_IS_BIG_ENDIAN (BYTE_ORDER == BIG_ENDIAN) |
| 387 | #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) |
| 388 | /* gcc */ |
| 389 | # define U_IS_BIG_ENDIAN (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) |
| 390 | #elif defined(__BIG_ENDIAN__) || defined(_BIG_ENDIAN) |
| 391 | # define U_IS_BIG_ENDIAN 1 |
| 392 | #elif defined(__LITTLE_ENDIAN__) || defined(_LITTLE_ENDIAN) |
| 393 | # define U_IS_BIG_ENDIAN 0 |
| 394 | #elif U_PLATFORM == U_PF_OS390 || U_PLATFORM == U_PF_OS400 || defined(__s390__) || defined(__s390x__) |
| 395 | /* These platforms do not appear to predefine any endianness macros. */ |
| 396 | # define U_IS_BIG_ENDIAN 1 |
| 397 | #elif defined(_PA_RISC1_0) || defined(_PA_RISC1_1) || defined(_PA_RISC2_0) |
| 398 | /* HPPA do not appear to predefine any endianness macros. */ |
| 399 | # define U_IS_BIG_ENDIAN 1 |
| 400 | #elif defined(sparc) || defined(__sparc) || defined(__sparc__) |
| 401 | /* Some sparc based systems (e.g. Linux) do not predefine any endianness macros. */ |
| 402 | # define U_IS_BIG_ENDIAN 1 |
| 403 | #else |
| 404 | # define U_IS_BIG_ENDIAN 0 |
| 405 | #endif |
| 406 | |
| 407 | /** |
| 408 | * \def U_HAVE_PLACEMENT_NEW |
| 409 | * Determines whether to override placement new and delete for STL. |
| 410 | * @stable ICU 2.6 |
| 411 | */ |
| 412 | #ifdef U_HAVE_PLACEMENT_NEW |
| 413 | /* Use the predefined value. */ |
| 414 | #elif defined(__BORLANDC__) |
| 415 | # define U_HAVE_PLACEMENT_NEW 0 |
| 416 | #else |
| 417 | # define U_HAVE_PLACEMENT_NEW 1 |
| 418 | #endif |
| 419 | |
| 420 | /** |
| 421 | * \def U_HAVE_DEBUG_LOCATION_NEW |
| 422 | * Define this to define the MFC debug version of the operator new. |
| 423 | * |
| 424 | * @stable ICU 3.4 |
| 425 | */ |
| 426 | #ifdef U_HAVE_DEBUG_LOCATION_NEW |
| 427 | /* Use the predefined value. */ |
| 428 | #elif defined(_MSC_VER) |
| 429 | # define U_HAVE_DEBUG_LOCATION_NEW 1 |
| 430 | #else |
| 431 | # define U_HAVE_DEBUG_LOCATION_NEW 0 |
| 432 | #endif |
| 433 | |
| 434 | /* Compatibility with compilers other than clang: http://clang.llvm.org/docs/LanguageExtensions.html */ |
| 435 | #ifndef __has_attribute |
| 436 | # define __has_attribute(x) 0 |
| 437 | #endif |
| 438 | #ifndef __has_cpp_attribute |
| 439 | # define __has_cpp_attribute(x) 0 |
| 440 | #endif |
| 441 | #ifndef __has_builtin |
| 442 | # define __has_builtin(x) 0 |
| 443 | #endif |
| 444 | #ifndef __has_feature |
| 445 | # define __has_feature(x) 0 |
| 446 | #endif |
| 447 | #ifndef __has_extension |
| 448 | # define __has_extension(x) 0 |
| 449 | #endif |
| 450 | #ifndef __has_warning |
| 451 | # define __has_warning(x) 0 |
| 452 | #endif |
| 453 | |
| 454 | /** |
| 455 | * \def U_MALLOC_ATTR |
| 456 | * Attribute to mark functions as malloc-like |
| 457 | * @internal |
| 458 | */ |
| 459 | #if defined(__GNUC__) && __GNUC__>=3 |
| 460 | # define U_MALLOC_ATTR __attribute__ ((__malloc__)) |
| 461 | #else |
| 462 | # define U_MALLOC_ATTR |
| 463 | #endif |
| 464 | |
| 465 | /** |
| 466 | * \def U_ALLOC_SIZE_ATTR |
| 467 | * Attribute to specify the size of the allocated buffer for malloc-like functions |
| 468 | * @internal |
| 469 | */ |
| 470 | #if (defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) || __has_attribute(alloc_size) |
| 471 | # define U_ALLOC_SIZE_ATTR(X) __attribute__ ((alloc_size(X))) |
| 472 | # define U_ALLOC_SIZE_ATTR2(X,Y) __attribute__ ((alloc_size(X,Y))) |
| 473 | #else |
| 474 | # define U_ALLOC_SIZE_ATTR(X) |
| 475 | # define U_ALLOC_SIZE_ATTR2(X,Y) |
| 476 | #endif |
| 477 | |
| 478 | /** |
| 479 | * \def U_CPLUSPLUS_VERSION |
| 480 | * 0 if no C++; 1, 11, 14, ... if C++. |
| 481 | * Support for specific features cannot always be determined by the C++ version alone. |
| 482 | * @internal |
| 483 | */ |
| 484 | #ifdef U_CPLUSPLUS_VERSION |
| 485 | # if U_CPLUSPLUS_VERSION != 0 && !defined(__cplusplus) |
| 486 | # undef U_CPLUSPLUS_VERSION |
| 487 | # define U_CPLUSPLUS_VERSION 0 |
| 488 | # endif |
| 489 | /* Otherwise use the predefined value. */ |
| 490 | #elif !defined(__cplusplus) |
| 491 | # define U_CPLUSPLUS_VERSION 0 |
| 492 | #elif __cplusplus >= 201402L |
| 493 | # define U_CPLUSPLUS_VERSION 14 |
| 494 | #elif __cplusplus >= 201103L |
| 495 | # define U_CPLUSPLUS_VERSION 11 |
| 496 | #else |
| 497 | // C++98 or C++03 |
| 498 | # define U_CPLUSPLUS_VERSION 1 |
| 499 | #endif |
| 500 | |
| 501 | #if (U_PLATFORM == U_PF_AIX || U_PLATFORM == U_PF_OS390) && defined(__cplusplus) &&(U_CPLUSPLUS_VERSION < 11) |
| 502 | // add in std::nullptr_t |
| 503 | namespace std { |
| 504 | typedef decltype(nullptr) nullptr_t; |
| 505 | }; |
| 506 | #endif |
| 507 | |
| 508 | /** |
| 509 | * \def U_HAVE_RVALUE_REFERENCES |
| 510 | * Set to 1 if the compiler supports rvalue references. |
| 511 | * C++11 feature, necessary for move constructor & move assignment. |
| 512 | * @internal |
| 513 | */ |
| 514 | #ifdef U_HAVE_RVALUE_REFERENCES |
| 515 | /* Use the predefined value. */ |
| 516 | #elif U_CPLUSPLUS_VERSION >= 11 || __has_feature(cxx_rvalue_references) \ |
| 517 | || defined(__GXX_EXPERIMENTAL_CXX0X__) \ |
| 518 | || (defined(_MSC_VER) && _MSC_VER >= 1600) /* Visual Studio 2010 */ |
| 519 | # define U_HAVE_RVALUE_REFERENCES 1 |
| 520 | #else |
| 521 | # define U_HAVE_RVALUE_REFERENCES 0 |
| 522 | #endif |
| 523 | |
| 524 | /** |
| 525 | * \def U_NOEXCEPT |
| 526 | * "noexcept" if supported, otherwise empty. |
| 527 | * Some code, especially STL containers, uses move semantics of objects only |
| 528 | * if the move constructor and the move operator are declared as not throwing exceptions. |
| 529 | * @internal |
| 530 | */ |
| 531 | #ifdef U_NOEXCEPT |
| 532 | /* Use the predefined value. */ |
| 533 | #elif defined(_HAS_EXCEPTIONS) && !_HAS_EXCEPTIONS /* Visual Studio */ |
| 534 | # define U_NOEXCEPT |
| 535 | #elif U_CPLUSPLUS_VERSION >= 11 || __has_feature(cxx_noexcept) || __has_extension(cxx_noexcept) \ |
| 536 | || (defined(_MSC_VER) && _MSC_VER >= 1900) /* Visual Studio 2015 */ |
| 537 | # define U_NOEXCEPT noexcept |
| 538 | #else |
| 539 | # define U_NOEXCEPT |
| 540 | #endif |
| 541 | |
| 542 | /** |
| 543 | * \def U_FALLTHROUGH |
| 544 | * Annotate intentional fall-through between switch labels. |
| 545 | * http://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough |
| 546 | * @internal |
| 547 | */ |
| 548 | #ifndef __cplusplus |
| 549 | // Not for C. |
| 550 | #elif defined(U_FALLTHROUGH) |
| 551 | // Use the predefined value. |
| 552 | #elif defined(__clang__) |
| 553 | // Test for compiler vs. feature separately. |
| 554 | // Other compilers might choke on the feature test. |
| 555 | # if __has_cpp_attribute(clang::fallthrough) || \ |
| 556 | (__has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")) |
| 557 | # define U_FALLTHROUGH [[clang::fallthrough]] |
| 558 | # endif |
| 559 | #endif |
| 560 | |
| 561 | #ifndef U_FALLTHROUGH |
| 562 | # define U_FALLTHROUGH |
| 563 | #endif |
| 564 | |
| 565 | /** @} */ |
| 566 | |
| 567 | /*===========================================================================*/ |
| 568 | /** @{ Character data types */ |
| 569 | /*===========================================================================*/ |
| 570 | |
| 571 | /** |
| 572 | * U_CHARSET_FAMILY is equal to this value when the platform is an ASCII based platform. |
| 573 | * @stable ICU 2.0 |
| 574 | */ |
| 575 | #define U_ASCII_FAMILY 0 |
| 576 | |
| 577 | /** |
| 578 | * U_CHARSET_FAMILY is equal to this value when the platform is an EBCDIC based platform. |
| 579 | * @stable ICU 2.0 |
| 580 | */ |
| 581 | #define U_EBCDIC_FAMILY 1 |
| 582 | |
| 583 | /** |
| 584 | * \def U_CHARSET_FAMILY |
| 585 | * |
| 586 | * <p>These definitions allow to specify the encoding of text |
| 587 | * in the char data type as defined by the platform and the compiler. |
| 588 | * It is enough to determine the code point values of "invariant characters", |
| 589 | * which are the ones shared by all encodings that are in use |
| 590 | * on a given platform.</p> |
| 591 | * |
| 592 | * <p>Those "invariant characters" should be all the uppercase and lowercase |
| 593 | * latin letters, the digits, the space, and "basic punctuation". |
| 594 | * Also, '\\n', '\\r', '\\t' should be available.</p> |
| 595 | * |
| 596 | * <p>The list of "invariant characters" is:<br> |
| 597 | * \code |
| 598 | * A-Z a-z 0-9 SPACE " % & ' ( ) * + , - . / : ; < = > ? _ |
| 599 | * \endcode |
| 600 | * <br> |
| 601 | * (52 letters + 10 numbers + 20 punc/sym/space = 82 total)</p> |
| 602 | * |
| 603 | * <p>This matches the IBM Syntactic Character Set (CS 640).</p> |
| 604 | * |
| 605 | * <p>In other words, all the graphic characters in 7-bit ASCII should |
| 606 | * be safely accessible except the following:</p> |
| 607 | * |
| 608 | * \code |
| 609 | * '\' <backslash> |
| 610 | * '[' <left bracket> |
| 611 | * ']' <right bracket> |
| 612 | * '{' <left brace> |
| 613 | * '}' <right brace> |
| 614 | * '^' <circumflex> |
| 615 | * '~' <tilde> |
| 616 | * '!' <exclamation mark> |
| 617 | * '#' <number sign> |
| 618 | * '|' <vertical line> |
| 619 | * '$' <dollar sign> |
| 620 | * '@' <commercial at> |
| 621 | * '`' <grave accent> |
| 622 | * \endcode |
| 623 | * @stable ICU 2.0 |
| 624 | */ |
| 625 | #ifdef U_CHARSET_FAMILY |
| 626 | /* Use the predefined value. */ |
| 627 | #elif U_PLATFORM == U_PF_OS390 && (!defined(__CHARSET_LIB) || !__CHARSET_LIB) |
| 628 | # define U_CHARSET_FAMILY U_EBCDIC_FAMILY |
| 629 | #elif U_PLATFORM == U_PF_OS400 && !defined(__UTF32__) |
| 630 | # define U_CHARSET_FAMILY U_EBCDIC_FAMILY |
| 631 | #else |
| 632 | # define U_CHARSET_FAMILY U_ASCII_FAMILY |
| 633 | #endif |
| 634 | |
| 635 | /** |
| 636 | * \def U_CHARSET_IS_UTF8 |
| 637 | * |
| 638 | * Hardcode the default charset to UTF-8. |
| 639 | * |
| 640 | * If this is set to 1, then |
| 641 | * - ICU will assume that all non-invariant char*, StringPiece, std::string etc. |
| 642 | * contain UTF-8 text, regardless of what the system API uses |
| 643 | * - some ICU code will use fast functions like u_strFromUTF8() |
| 644 | * rather than the more general and more heavy-weight conversion API (ucnv.h) |
| 645 | * - ucnv_getDefaultName() always returns "UTF-8" |
| 646 | * - ucnv_setDefaultName() is disabled and will not change the default charset |
| 647 | * - static builds of ICU are smaller |
| 648 | * - more functionality is available with the UCONFIG_NO_CONVERSION build-time |
| 649 | * configuration option (see unicode/uconfig.h) |
| 650 | * - the UCONFIG_NO_CONVERSION build option in uconfig.h is more usable |
| 651 | * |
| 652 | * @stable ICU 4.2 |
| 653 | * @see UCONFIG_NO_CONVERSION |
| 654 | */ |
| 655 | #ifdef U_CHARSET_IS_UTF8 |
| 656 | /* Use the predefined value. */ |
| 657 | #elif U_PLATFORM == U_PF_ANDROID || U_PLATFORM_IS_DARWIN_BASED |
| 658 | # define U_CHARSET_IS_UTF8 1 |
| 659 | #else |
| 660 | # define U_CHARSET_IS_UTF8 0 |
| 661 | #endif |
| 662 | |
| 663 | /** @} */ |
| 664 | |
| 665 | /*===========================================================================*/ |
| 666 | /** @{ Information about wchar support */ |
| 667 | /*===========================================================================*/ |
| 668 | |
| 669 | /** |
| 670 | * \def U_HAVE_WCHAR_H |
| 671 | * Indicates whether <wchar.h> is available (1) or not (0). Set to 1 by default. |
| 672 | * |
| 673 | * @stable ICU 2.0 |
| 674 | */ |
| 675 | #ifdef U_HAVE_WCHAR_H |
| 676 | /* Use the predefined value. */ |
| 677 | #elif U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9 |
| 678 | /* |
| 679 | * Android before Gingerbread (Android 2.3, API level 9) did not support wchar_t. |
| 680 | * The type and header existed, but the library functions did not work as expected. |
| 681 | * The size of wchar_t was 1 but L"xyz" string literals had 32-bit units anyway. |
| 682 | */ |
| 683 | # define U_HAVE_WCHAR_H 0 |
| 684 | #else |
| 685 | # define U_HAVE_WCHAR_H 1 |
| 686 | #endif |
| 687 | |
| 688 | /** |
| 689 | * \def U_SIZEOF_WCHAR_T |
| 690 | * U_SIZEOF_WCHAR_T==sizeof(wchar_t) |
| 691 | * |
| 692 | * @stable ICU 2.0 |
| 693 | */ |
| 694 | #ifdef U_SIZEOF_WCHAR_T |
| 695 | /* Use the predefined value. */ |
| 696 | #elif (U_PLATFORM == U_PF_ANDROID && __ANDROID_API__ < 9) |
| 697 | /* |
| 698 | * Classic Mac OS and Mac OS X before 10.3 (Panther) did not support wchar_t or wstring. |
| 699 | * Newer Mac OS X has size 4. |
| 700 | */ |
| 701 | # define U_SIZEOF_WCHAR_T 1 |
| 702 | #elif U_PLATFORM_HAS_WIN32_API || U_PLATFORM == U_PF_CYGWIN |
| 703 | # define U_SIZEOF_WCHAR_T 2 |
| 704 | #elif U_PLATFORM == U_PF_AIX |
| 705 | /* |
| 706 | * AIX 6.1 information, section "Wide character data representation": |
| 707 | * "... the wchar_t datatype is 32-bit in the 64-bit environment and |
| 708 | * 16-bit in the 32-bit environment." |
| 709 | * and |
| 710 | * "All locales use Unicode for their wide character code values (process code), |
| 711 | * except the IBM-eucTW codeset." |
| 712 | */ |
| 713 | # ifdef __64BIT__ |
| 714 | # define U_SIZEOF_WCHAR_T 4 |
| 715 | # else |
| 716 | # define U_SIZEOF_WCHAR_T 2 |
| 717 | # endif |
| 718 | #elif U_PLATFORM == U_PF_OS390 |
| 719 | /* |
| 720 | * z/OS V1R11 information center, section "LP64 | ILP32": |
| 721 | * "In 31-bit mode, the size of long and pointers is 4 bytes and the size of wchar_t is 2 bytes. |
| 722 | * Under LP64, the size of long and pointer is 8 bytes and the size of wchar_t is 4 bytes." |
| 723 | */ |
| 724 | # ifdef _LP64 |
| 725 | # define U_SIZEOF_WCHAR_T 4 |
| 726 | # else |
| 727 | # define U_SIZEOF_WCHAR_T 2 |
| 728 | # endif |
| 729 | #elif U_PLATFORM == U_PF_OS400 |
| 730 | # if defined(__UTF32__) |
| 731 | /* |
| 732 | * LOCALETYPE(*LOCALEUTF) is specified. |
| 733 | * Wide-character strings are in UTF-32, |
| 734 | * narrow-character strings are in UTF-8. |
| 735 | */ |
| 736 | # define U_SIZEOF_WCHAR_T 4 |
| 737 | # elif defined(__UCS2__) |
| 738 | /* |
| 739 | * LOCALETYPE(*LOCALEUCS2) is specified. |
| 740 | * Wide-character strings are in UCS-2, |
| 741 | * narrow-character strings are in EBCDIC. |
| 742 | */ |
| 743 | # define U_SIZEOF_WCHAR_T 2 |
| 744 | #else |
| 745 | /* |
| 746 | * LOCALETYPE(*CLD) or LOCALETYPE(*LOCALE) is specified. |
| 747 | * Wide-character strings are in 16-bit EBCDIC, |
| 748 | * narrow-character strings are in EBCDIC. |
| 749 | */ |
| 750 | # define U_SIZEOF_WCHAR_T 2 |
| 751 | # endif |
| 752 | #else |
| 753 | # define U_SIZEOF_WCHAR_T 4 |
| 754 | #endif |
| 755 | |
| 756 | #ifndef U_HAVE_WCSCPY |
| 757 | #define U_HAVE_WCSCPY U_HAVE_WCHAR_H |
| 758 | #endif |
| 759 | |
| 760 | /** @} */ |
| 761 | |
| 762 | /** |
| 763 | * \def U_HAVE_CHAR16_T |
| 764 | * Defines whether the char16_t type is available for UTF-16 |
| 765 | * and u"abc" UTF-16 string literals are supported. |
| 766 | * This is a new standard type and standard string literal syntax in C++0x |
| 767 | * but has been available in some compilers before. |
| 768 | * @internal |
| 769 | */ |
| 770 | #ifdef U_HAVE_CHAR16_T |
| 771 | /* Use the predefined value. */ |
| 772 | #else |
| 773 | /* |
| 774 | * Notes: |
| 775 | * Visual Studio 10 (_MSC_VER>=1600) defines char16_t but |
| 776 | * does not support u"abc" string literals. |
| 777 | * gcc 4.4 defines the __CHAR16_TYPE__ macro to a usable type but |
| 778 | * does not support u"abc" string literals. |
| 779 | * C++11 and C11 require support for UTF-16 literals |
| 780 | * TODO: Fix for plain C. Doesn't work on Mac. |
| 781 | */ |
| 782 | # if U_CPLUSPLUS_VERSION >= 11 || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) |
| 783 | # define U_HAVE_CHAR16_T 1 |
| 784 | # else |
| 785 | # define U_HAVE_CHAR16_T 0 |
| 786 | # endif |
| 787 | #endif |
| 788 | |
| 789 | /** |
| 790 | * @{ |
| 791 | * \def U_DECLARE_UTF16 |
| 792 | * Do not use this macro because it is not defined on all platforms. |
| 793 | * Use the UNICODE_STRING or U_STRING_DECL macros instead. |
| 794 | * @internal |
| 795 | */ |
| 796 | #ifdef U_DECLARE_UTF16 |
| 797 | /* Use the predefined value. */ |
| 798 | #elif U_HAVE_CHAR16_T \ |
| 799 | || (defined(__xlC__) && defined(__IBM_UTF_LITERAL) && U_SIZEOF_WCHAR_T != 2) \ |
| 800 | || (defined(__HP_aCC) && __HP_aCC >= 035000) \ |
| 801 | || (defined(__HP_cc) && __HP_cc >= 111106) |
| 802 | # define U_DECLARE_UTF16(string) u ## string |
| 803 | #elif U_SIZEOF_WCHAR_T == 2 \ |
| 804 | && (U_CHARSET_FAMILY == 0 || (U_PF_OS390 <= U_PLATFORM && U_PLATFORM <= U_PF_OS400 && defined(__UCS2__))) |
| 805 | # define U_DECLARE_UTF16(string) L ## string |
| 806 | #else |
| 807 | /* Leave U_DECLARE_UTF16 undefined. See unistr.h. */ |
| 808 | #endif |
| 809 | |
| 810 | /** @} */ |
| 811 | |
| 812 | /*===========================================================================*/ |
| 813 | /** @{ Symbol import-export control */ |
| 814 | /*===========================================================================*/ |
| 815 | |
| 816 | #ifdef U_EXPORT |
| 817 | /* Use the predefined value. */ |
| 818 | #elif defined(U_STATIC_IMPLEMENTATION) |
| 819 | # define U_EXPORT |
| 820 | #elif defined(__GNUC__) |
| 821 | # define U_EXPORT __attribute__((visibility("default"))) |
| 822 | #elif (defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x550) \ |
| 823 | || (defined(__SUNPRO_C) && __SUNPRO_C >= 0x550) |
| 824 | # define U_EXPORT __global |
| 825 | /*#elif defined(__HP_aCC) || defined(__HP_cc) |
| 826 | # define U_EXPORT __declspec(dllexport)*/ |
| 827 | #elif defined(_MSC_VER) |
| 828 | # define U_EXPORT __declspec(dllexport) |
| 829 | #else |
| 830 | # define U_EXPORT |
| 831 | #endif |
| 832 | |
| 833 | /* U_CALLCONV is releated to U_EXPORT2 */ |
| 834 | #ifdef U_EXPORT2 |
| 835 | /* Use the predefined value. */ |
| 836 | #elif defined(_MSC_VER) |
| 837 | # define U_EXPORT2 __cdecl |
| 838 | #else |
| 839 | # define U_EXPORT2 |
| 840 | #endif |
| 841 | |
| 842 | #ifdef U_IMPORT |
| 843 | /* Use the predefined value. */ |
| 844 | #elif defined(_MSC_VER) |
| 845 | /* Windows needs to export/import data. */ |
| 846 | # define U_IMPORT __declspec(dllimport) |
| 847 | #else |
| 848 | # define U_IMPORT |
| 849 | #endif |
| 850 | |
| 851 | /** |
| 852 | * \def U_CALLCONV |
| 853 | * Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary |
| 854 | * in callback function typedefs to make sure that the calling convention |
| 855 | * is compatible. |
| 856 | * |
| 857 | * This is only used for non-ICU-API functions. |
| 858 | * When a function is a public ICU API, |
| 859 | * you must use the U_CAPI and U_EXPORT2 qualifiers. |
| 860 | * |
| 861 | * Please note, you need to use U_CALLCONV after the *. |
| 862 | * |
| 863 | * NO : "static const char U_CALLCONV *func( . . . )" |
| 864 | * YES: "static const char* U_CALLCONV func( . . . )" |
| 865 | * |
| 866 | * @stable ICU 2.0 |
| 867 | */ |
| 868 | #if U_PLATFORM == U_PF_OS390 && defined(__cplusplus) |
| 869 | # define U_CALLCONV __cdecl |
| 870 | #else |
| 871 | # define U_CALLCONV U_EXPORT2 |
| 872 | #endif |
| 873 | |
| 874 | /* @} */ |
| 875 | |
| 876 | #endif |