platform.h 28 KB

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