1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/common/putilimp.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,607 @@ 1.4 +/* 1.5 +****************************************************************************** 1.6 +* 1.7 +* Copyright (C) 1997-2013, International Business Machines 1.8 +* Corporation and others. All Rights Reserved. 1.9 +* 1.10 +****************************************************************************** 1.11 +* 1.12 +* FILE NAME : putilimp.h 1.13 +* 1.14 +* Date Name Description 1.15 +* 10/17/04 grhoten Move internal functions from putil.h to this file. 1.16 +****************************************************************************** 1.17 +*/ 1.18 + 1.19 +#ifndef PUTILIMP_H 1.20 +#define PUTILIMP_H 1.21 + 1.22 +#include "unicode/utypes.h" 1.23 +#include "unicode/putil.h" 1.24 + 1.25 +/** 1.26 + * \def U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC 1.27 + * Nearly all CPUs and compilers implement a right-shift of a signed integer 1.28 + * as an Arithmetic Shift Right which copies the sign bit (the Most Significant Bit (MSB)) 1.29 + * into the vacated bits (sign extension). 1.30 + * For example, (int32_t)0xfff5fff3>>4 becomes 0xffff5fff and -1>>1=-1. 1.31 + * 1.32 + * This can be useful for storing a signed value in the upper bits 1.33 + * and another bit field in the lower bits. 1.34 + * The signed value can be retrieved by simple right-shifting. 1.35 + * 1.36 + * This is consistent with the Java language. 1.37 + * 1.38 + * However, the C standard allows compilers to implement a right-shift of a signed integer 1.39 + * as a Logical Shift Right which copies a 0 into the vacated bits. 1.40 + * For example, (int32_t)0xfff5fff3>>4 becomes 0x0fff5fff and -1>>1=0x7fffffff. 1.41 + * 1.42 + * Code that depends on the natural behavior should be guarded with this macro, 1.43 + * with an alternate path for unusual platforms. 1.44 + * @internal 1.45 + */ 1.46 +#ifdef U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC 1.47 + /* Use the predefined value. */ 1.48 +#else 1.49 + /* 1.50 + * Nearly all CPUs & compilers implement a right-shift of a signed integer 1.51 + * as an Arithmetic Shift Right (with sign extension). 1.52 + */ 1.53 +# define U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC 1 1.54 +#endif 1.55 + 1.56 +/** Define this to 1 if your platform supports IEEE 754 floating point, 1.57 + to 0 if it does not. */ 1.58 +#ifndef IEEE_754 1.59 +# define IEEE_754 1 1.60 +#endif 1.61 + 1.62 +/** 1.63 + * uintptr_t is an optional part of the standard definitions in stdint.h. 1.64 + * The opengroup.org documentation for stdint.h says 1.65 + * "On XSI-conformant systems, the intptr_t and uintptr_t types are required; 1.66 + * otherwise, they are optional." 1.67 + * We assume that when uintptr_t is defined, UINTPTR_MAX is defined as well. 1.68 + * 1.69 + * Do not use ptrdiff_t since it is signed. size_t is unsigned. 1.70 + */ 1.71 +/* TODO: This check fails on some z environments. Filed a ticket #9357 for this. */ 1.72 +#if !defined(__intptr_t_defined) && !defined(UINTPTR_MAX) && (U_PLATFORM != U_PF_OS390) 1.73 +typedef size_t uintptr_t; 1.74 +#endif 1.75 + 1.76 +/** 1.77 + * \def U_HAVE_MSVC_2003_OR_EARLIER 1.78 + * Flag for workaround of MSVC 2003 optimization bugs 1.79 + * @internal 1.80 + */ 1.81 +#if !defined(U_HAVE_MSVC_2003_OR_EARLIER) && defined(_MSC_VER) && (_MSC_VER < 1400) 1.82 +#define U_HAVE_MSVC_2003_OR_EARLIER 1.83 +#endif 1.84 + 1.85 +/*===========================================================================*/ 1.86 +/** @{ Information about POSIX support */ 1.87 +/*===========================================================================*/ 1.88 + 1.89 +#ifdef U_HAVE_NL_LANGINFO_CODESET 1.90 + /* Use the predefined value. */ 1.91 +#elif U_PLATFORM_HAS_WIN32_API 1.92 +# define U_HAVE_NL_LANGINFO_CODESET 0 1.93 +#else 1.94 +# define U_HAVE_NL_LANGINFO_CODESET 1 1.95 +#endif 1.96 + 1.97 +#ifdef U_NL_LANGINFO_CODESET 1.98 + /* Use the predefined value. */ 1.99 +#elif !U_HAVE_NL_LANGINFO_CODESET 1.100 +# define U_NL_LANGINFO_CODESET -1 1.101 +#elif U_PLATFORM == U_PF_OS400 1.102 + /* not defined */ 1.103 +#else 1.104 +# define U_NL_LANGINFO_CODESET CODESET 1.105 +#endif 1.106 + 1.107 +#ifdef U_TZSET 1.108 + /* Use the predefined value. */ 1.109 +#elif U_PLATFORM_USES_ONLY_WIN32_API 1.110 +# define U_TZSET _tzset 1.111 +#elif U_PLATFORM == U_PF_OS400 1.112 + /* not defined */ 1.113 +#else 1.114 +# define U_TZSET tzset 1.115 +#endif 1.116 + 1.117 +#if defined(U_TIMEZONE) || defined(U_HAVE_TIMEZONE) 1.118 + /* Use the predefined value. */ 1.119 +#elif U_PLATFORM == U_PF_ANDROID 1.120 +# define U_TIMEZONE timezone 1.121 +#elif U_PLATFORM_IS_LINUX_BASED 1.122 +# if !defined(__UCLIBC__) 1.123 + /* __timezone is only available in glibc */ 1.124 +# define U_TIMEZONE __timezone 1.125 +# endif 1.126 +#elif U_PLATFORM_USES_ONLY_WIN32_API 1.127 +# define U_TIMEZONE _timezone 1.128 +#elif U_PLATFORM == U_PF_BSD && !defined(__NetBSD__) 1.129 + /* not defined */ 1.130 +#elif U_PLATFORM == U_PF_OS400 1.131 + /* not defined */ 1.132 +#elif U_PLATFORM == U_PF_IPHONE 1.133 + /* not defined */ 1.134 +#else 1.135 +# define U_TIMEZONE timezone 1.136 +#endif 1.137 + 1.138 +#ifdef U_TZNAME 1.139 + /* Use the predefined value. */ 1.140 +#elif U_PLATFORM_USES_ONLY_WIN32_API 1.141 +# define U_TZNAME _tzname 1.142 +#elif U_PLATFORM == U_PF_OS400 1.143 + /* not defined */ 1.144 +#else 1.145 +# define U_TZNAME tzname 1.146 +#endif 1.147 + 1.148 +#ifdef U_HAVE_MMAP 1.149 + /* Use the predefined value. */ 1.150 +#elif U_PLATFORM_HAS_WIN32_API 1.151 +# define U_HAVE_MMAP 0 1.152 +#else 1.153 +# define U_HAVE_MMAP 1 1.154 +#endif 1.155 + 1.156 +#ifdef U_HAVE_POPEN 1.157 + /* Use the predefined value. */ 1.158 +#elif U_PLATFORM_USES_ONLY_WIN32_API 1.159 +# define U_HAVE_POPEN 0 1.160 +#elif U_PLATFORM == U_PF_OS400 1.161 +# define U_HAVE_POPEN 0 1.162 +#else 1.163 +# define U_HAVE_POPEN 1 1.164 +#endif 1.165 + 1.166 +/** 1.167 + * \def U_HAVE_DIRENT_H 1.168 + * Defines whether dirent.h is available. 1.169 + * @internal 1.170 + */ 1.171 +#ifdef U_HAVE_DIRENT_H 1.172 + /* Use the predefined value. */ 1.173 +#elif U_PLATFORM_HAS_WIN32_API 1.174 +# define U_HAVE_DIRENT_H 0 1.175 +#else 1.176 +# define U_HAVE_DIRENT_H 1 1.177 +#endif 1.178 + 1.179 +/** @} */ 1.180 + 1.181 +/*===========================================================================*/ 1.182 +/** @{ GCC built in functions for atomic memory operations */ 1.183 +/*===========================================================================*/ 1.184 + 1.185 +/** 1.186 + * \def U_HAVE_GCC_ATOMICS 1.187 + * @internal 1.188 + */ 1.189 +#ifdef U_HAVE_GCC_ATOMICS 1.190 + /* Use the predefined value. */ 1.191 +#elif U_PLATFORM == U_PF_MINGW 1.192 + #define U_HAVE_GCC_ATOMICS 0 1.193 +#elif U_GCC_MAJOR_MINOR >= 404 || defined(__clang__) 1.194 + /* TODO: Intel icc and IBM xlc on AIX also support gcc atomics. (Intel originated them.) 1.195 + * Add them for these compilers. 1.196 + * Note: Clang sets __GNUC__ defines for version 4.2, so misses the 4.4 test here. 1.197 + */ 1.198 +# define U_HAVE_GCC_ATOMICS 1 1.199 +#else 1.200 +# define U_HAVE_GCC_ATOMICS 0 1.201 +#endif 1.202 + 1.203 +/** @} */ 1.204 + 1.205 +/** 1.206 + * \def U_HAVE_STD_ATOMICS 1.207 + * Defines whether the standard C++11 <atomic> is available. 1.208 + * ICU will use this when avialable, 1.209 + * otherwise will fall back to compiler or platform specific alternatives. 1.210 + * @internal 1.211 + */ 1.212 +#ifdef U_HAVE_STD_ATOMICS 1.213 + /* Use the predefined value. */ 1.214 +#elif !defined(__cplusplus) || __cplusplus<201103L 1.215 + /* Not C++11, disable use of atomics */ 1.216 +# define U_HAVE_STD_ATOMICS 0 1.217 +#elif __clang__ && __clang_major__==3 && __clang_minor__<=1 1.218 + /* Clang 3.1, has atomic variable initializer bug. */ 1.219 +# define U_HAVE_STD_ATOMICS 0 1.220 +#else 1.221 + /* U_HAVE_ATOMIC is typically set by an autoconf test of #include <atomic> */ 1.222 + /* Can be set manually, or left undefined, on platforms without autoconf. */ 1.223 +# if defined(U_HAVE_ATOMIC) && U_HAVE_ATOMIC 1.224 +# define U_HAVE_STD_ATOMICS 1 1.225 +# else 1.226 +# define U_HAVE_STD_ATOMICS 0 1.227 +# endif 1.228 +#endif 1.229 + 1.230 + 1.231 +/*===========================================================================*/ 1.232 +/** @{ Code alignment */ 1.233 +/*===========================================================================*/ 1.234 + 1.235 +/** 1.236 + * \def U_ALIGN_CODE 1.237 + * This is used to align code fragments to a specific byte boundary. 1.238 + * This is useful for getting consistent performance test results. 1.239 + * @internal 1.240 + */ 1.241 +#ifdef U_ALIGN_CODE 1.242 + /* Use the predefined value. */ 1.243 +#elif defined(_MSC_VER) && defined(_M_IX86) && !defined(_MANAGED) 1.244 +# define U_ALIGN_CODE(boundarySize) __asm align boundarySize 1.245 +#else 1.246 +# define U_ALIGN_CODE(boundarySize) 1.247 +#endif 1.248 + 1.249 +/** @} */ 1.250 + 1.251 +/*===========================================================================*/ 1.252 +/** @{ Programs used by ICU code */ 1.253 +/*===========================================================================*/ 1.254 + 1.255 +/** 1.256 + * \def U_MAKE_IS_NMAKE 1.257 + * Defines whether the "make" program is Windows nmake. 1.258 + */ 1.259 +#ifdef U_MAKE_IS_NMAKE 1.260 + /* Use the predefined value. */ 1.261 +#elif U_PLATFORM == U_PF_WINDOWS 1.262 +# define U_MAKE_IS_NMAKE 1 1.263 +#else 1.264 +# define U_MAKE_IS_NMAKE 0 1.265 +#endif 1.266 + 1.267 +/** @} */ 1.268 + 1.269 +/*==========================================================================*/ 1.270 +/* Platform utilities */ 1.271 +/*==========================================================================*/ 1.272 + 1.273 +/** 1.274 + * Platform utilities isolates the platform dependencies of the 1.275 + * libarary. For each platform which this code is ported to, these 1.276 + * functions may have to be re-implemented. 1.277 + */ 1.278 + 1.279 +/** 1.280 + * Floating point utility to determine if a double is Not a Number (NaN). 1.281 + * @internal 1.282 + */ 1.283 +U_INTERNAL UBool U_EXPORT2 uprv_isNaN(double d); 1.284 +/** 1.285 + * Floating point utility to determine if a double has an infinite value. 1.286 + * @internal 1.287 + */ 1.288 +U_INTERNAL UBool U_EXPORT2 uprv_isInfinite(double d); 1.289 +/** 1.290 + * Floating point utility to determine if a double has a positive infinite value. 1.291 + * @internal 1.292 + */ 1.293 +U_INTERNAL UBool U_EXPORT2 uprv_isPositiveInfinity(double d); 1.294 +/** 1.295 + * Floating point utility to determine if a double has a negative infinite value. 1.296 + * @internal 1.297 + */ 1.298 +U_INTERNAL UBool U_EXPORT2 uprv_isNegativeInfinity(double d); 1.299 +/** 1.300 + * Floating point utility that returns a Not a Number (NaN) value. 1.301 + * @internal 1.302 + */ 1.303 +U_INTERNAL double U_EXPORT2 uprv_getNaN(void); 1.304 +/** 1.305 + * Floating point utility that returns an infinite value. 1.306 + * @internal 1.307 + */ 1.308 +U_INTERNAL double U_EXPORT2 uprv_getInfinity(void); 1.309 + 1.310 +/** 1.311 + * Floating point utility to truncate a double. 1.312 + * @internal 1.313 + */ 1.314 +U_INTERNAL double U_EXPORT2 uprv_trunc(double d); 1.315 +/** 1.316 + * Floating point utility to calculate the floor of a double. 1.317 + * @internal 1.318 + */ 1.319 +U_INTERNAL double U_EXPORT2 uprv_floor(double d); 1.320 +/** 1.321 + * Floating point utility to calculate the ceiling of a double. 1.322 + * @internal 1.323 + */ 1.324 +U_INTERNAL double U_EXPORT2 uprv_ceil(double d); 1.325 +/** 1.326 + * Floating point utility to calculate the absolute value of a double. 1.327 + * @internal 1.328 + */ 1.329 +U_INTERNAL double U_EXPORT2 uprv_fabs(double d); 1.330 +/** 1.331 + * Floating point utility to calculate the fractional and integer parts of a double. 1.332 + * @internal 1.333 + */ 1.334 +U_INTERNAL double U_EXPORT2 uprv_modf(double d, double* pinteger); 1.335 +/** 1.336 + * Floating point utility to calculate the remainder of a double divided by another double. 1.337 + * @internal 1.338 + */ 1.339 +U_INTERNAL double U_EXPORT2 uprv_fmod(double d, double y); 1.340 +/** 1.341 + * Floating point utility to calculate d to the power of exponent (d^exponent). 1.342 + * @internal 1.343 + */ 1.344 +U_INTERNAL double U_EXPORT2 uprv_pow(double d, double exponent); 1.345 +/** 1.346 + * Floating point utility to calculate 10 to the power of exponent (10^exponent). 1.347 + * @internal 1.348 + */ 1.349 +U_INTERNAL double U_EXPORT2 uprv_pow10(int32_t exponent); 1.350 +/** 1.351 + * Floating point utility to calculate the maximum value of two doubles. 1.352 + * @internal 1.353 + */ 1.354 +U_INTERNAL double U_EXPORT2 uprv_fmax(double d, double y); 1.355 +/** 1.356 + * Floating point utility to calculate the minimum value of two doubles. 1.357 + * @internal 1.358 + */ 1.359 +U_INTERNAL double U_EXPORT2 uprv_fmin(double d, double y); 1.360 +/** 1.361 + * Private utility to calculate the maximum value of two integers. 1.362 + * @internal 1.363 + */ 1.364 +U_INTERNAL int32_t U_EXPORT2 uprv_max(int32_t d, int32_t y); 1.365 +/** 1.366 + * Private utility to calculate the minimum value of two integers. 1.367 + * @internal 1.368 + */ 1.369 +U_INTERNAL int32_t U_EXPORT2 uprv_min(int32_t d, int32_t y); 1.370 + 1.371 +#if U_IS_BIG_ENDIAN 1.372 +# define uprv_isNegative(number) (*((signed char *)&(number))<0) 1.373 +#else 1.374 +# define uprv_isNegative(number) (*((signed char *)&(number)+sizeof(number)-1)<0) 1.375 +#endif 1.376 + 1.377 +/** 1.378 + * Return the largest positive number that can be represented by an integer 1.379 + * type of arbitrary bit length. 1.380 + * @internal 1.381 + */ 1.382 +U_INTERNAL double U_EXPORT2 uprv_maxMantissa(void); 1.383 + 1.384 +/** 1.385 + * Floating point utility to calculate the logarithm of a double. 1.386 + * @internal 1.387 + */ 1.388 +U_INTERNAL double U_EXPORT2 uprv_log(double d); 1.389 + 1.390 +/** 1.391 + * Does common notion of rounding e.g. uprv_floor(x + 0.5); 1.392 + * @param x the double number 1.393 + * @return the rounded double 1.394 + * @internal 1.395 + */ 1.396 +U_INTERNAL double U_EXPORT2 uprv_round(double x); 1.397 + 1.398 +#if 0 1.399 +/** 1.400 + * Returns the number of digits after the decimal point in a double number x. 1.401 + * 1.402 + * @param x the double number 1.403 + * @return the number of digits after the decimal point in a double number x. 1.404 + * @internal 1.405 + */ 1.406 +/*U_INTERNAL int32_t U_EXPORT2 uprv_digitsAfterDecimal(double x);*/ 1.407 +#endif 1.408 + 1.409 +#if !U_CHARSET_IS_UTF8 1.410 +/** 1.411 + * Please use ucnv_getDefaultName() instead. 1.412 + * Return the default codepage for this platform and locale. 1.413 + * This function can call setlocale() on Unix platforms. Please read the 1.414 + * platform documentation on setlocale() before calling this function. 1.415 + * @return the default codepage for this platform 1.416 + * @internal 1.417 + */ 1.418 +U_INTERNAL const char* U_EXPORT2 uprv_getDefaultCodepage(void); 1.419 +#endif 1.420 + 1.421 +/** 1.422 + * Please use uloc_getDefault() instead. 1.423 + * Return the default locale ID string by querying ths system, or 1.424 + * zero if one cannot be found. 1.425 + * This function can call setlocale() on Unix platforms. Please read the 1.426 + * platform documentation on setlocale() before calling this function. 1.427 + * @return the default locale ID string 1.428 + * @internal 1.429 + */ 1.430 +U_INTERNAL const char* U_EXPORT2 uprv_getDefaultLocaleID(void); 1.431 + 1.432 +/** 1.433 + * Time zone utilities 1.434 + * 1.435 + * Wrappers for C runtime library functions relating to timezones. 1.436 + * The t_tzset() function (similar to tzset) uses the current setting 1.437 + * of the environment variable TZ to assign values to three global 1.438 + * variables: daylight, timezone, and tzname. These variables have the 1.439 + * following meanings, and are declared in <time.h>. 1.440 + * 1.441 + * daylight Nonzero if daylight-saving-time zone (DST) is specified 1.442 + * in TZ; otherwise, 0. Default value is 1. 1.443 + * timezone Difference in seconds between coordinated universal 1.444 + * time and local time. E.g., -28,800 for PST (GMT-8hrs) 1.445 + * tzname(0) Three-letter time-zone name derived from TZ environment 1.446 + * variable. E.g., "PST". 1.447 + * tzname(1) Three-letter DST zone name derived from TZ environment 1.448 + * variable. E.g., "PDT". If DST zone is omitted from TZ, 1.449 + * tzname(1) is an empty string. 1.450 + * 1.451 + * Notes: For example, to set the TZ environment variable to correspond 1.452 + * to the current time zone in Germany, you can use one of the 1.453 + * following statements: 1.454 + * 1.455 + * set TZ=GST1GDT 1.456 + * set TZ=GST+1GDT 1.457 + * 1.458 + * If the TZ value is not set, t_tzset() attempts to use the time zone 1.459 + * information specified by the operating system. Under Windows NT 1.460 + * and Windows 95, this information is specified in the Control Panel's 1.461 + * Date/Time application. 1.462 + * @internal 1.463 + */ 1.464 +U_INTERNAL void U_EXPORT2 uprv_tzset(void); 1.465 + 1.466 +/** 1.467 + * Difference in seconds between coordinated universal 1.468 + * time and local time. E.g., -28,800 for PST (GMT-8hrs) 1.469 + * @return the difference in seconds between coordinated universal time and local time. 1.470 + * @internal 1.471 + */ 1.472 +U_INTERNAL int32_t U_EXPORT2 uprv_timezone(void); 1.473 + 1.474 +/** 1.475 + * tzname(0) Three-letter time-zone name derived from TZ environment 1.476 + * variable. E.g., "PST". 1.477 + * tzname(1) Three-letter DST zone name derived from TZ environment 1.478 + * variable. E.g., "PDT". If DST zone is omitted from TZ, 1.479 + * tzname(1) is an empty string. 1.480 + * @internal 1.481 + */ 1.482 +U_INTERNAL const char* U_EXPORT2 uprv_tzname(int n); 1.483 + 1.484 +/** 1.485 + * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970. 1.486 + * This function is affected by 'faketime' and should be the bottleneck for all user-visible ICU time functions. 1.487 + * @return the UTC time measured in milliseconds 1.488 + * @internal 1.489 + */ 1.490 +U_INTERNAL UDate U_EXPORT2 uprv_getUTCtime(void); 1.491 + 1.492 +/** 1.493 + * Get UTC (GMT) time measured in milliseconds since 0:00 on 1/1/1970. 1.494 + * This function is not affected by 'faketime', so it should only be used by low level test functions- not by anything that 1.495 + * exposes time to the end user. 1.496 + * @return the UTC time measured in milliseconds 1.497 + * @internal 1.498 + */ 1.499 +U_INTERNAL UDate U_EXPORT2 uprv_getRawUTCtime(void); 1.500 + 1.501 +/** 1.502 + * Determine whether a pathname is absolute or not, as defined by the platform. 1.503 + * @param path Pathname to test 1.504 + * @return TRUE if the path is absolute 1.505 + * @internal (ICU 3.0) 1.506 + */ 1.507 +U_INTERNAL UBool U_EXPORT2 uprv_pathIsAbsolute(const char *path); 1.508 + 1.509 +/** 1.510 + * Use U_MAX_PTR instead of this function. 1.511 + * @param void pointer to test 1.512 + * @return the largest possible pointer greater than the base 1.513 + * @internal (ICU 3.8) 1.514 + */ 1.515 +U_INTERNAL void * U_EXPORT2 uprv_maximumPtr(void *base); 1.516 + 1.517 +/** 1.518 + * Maximum value of a (void*) - use to indicate the limit of an 'infinite' buffer. 1.519 + * In fact, buffer sizes must not exceed 2GB so that the difference between 1.520 + * the buffer limit and the buffer start can be expressed in an int32_t. 1.521 + * 1.522 + * The definition of U_MAX_PTR must fulfill the following conditions: 1.523 + * - return the largest possible pointer greater than base 1.524 + * - return a valid pointer according to the machine architecture (AS/400, 64-bit, etc.) 1.525 + * - avoid wrapping around at high addresses 1.526 + * - make sure that the returned pointer is not farther from base than 0x7fffffff bytes 1.527 + * 1.528 + * @param base The beginning of a buffer to find the maximum offset from 1.529 + * @internal 1.530 + */ 1.531 +#ifndef U_MAX_PTR 1.532 +# if U_PLATFORM == U_PF_OS390 && !defined(_LP64) 1.533 + /* We have 31-bit pointers. */ 1.534 +# define U_MAX_PTR(base) ((void *)0x7fffffff) 1.535 +# elif U_PLATFORM == U_PF_OS400 1.536 +# define U_MAX_PTR(base) uprv_maximumPtr((void *)base) 1.537 +# elif 0 1.538 + /* 1.539 + * For platforms where pointers are scalar values (which is normal, but unlike i5/OS) 1.540 + * but that do not define uintptr_t. 1.541 + * 1.542 + * However, this does not work on modern compilers: 1.543 + * The C++ standard does not define pointer overflow, and allows compilers to 1.544 + * assume that p+u>p for any pointer p and any integer u>0. 1.545 + * Thus, modern compilers optimize away the ">" comparison. 1.546 + * (See ICU tickets #7187 and #8096.) 1.547 + */ 1.548 +# define U_MAX_PTR(base) \ 1.549 + ((void *)(((char *)(base)+0x7fffffffu) > (char *)(base) \ 1.550 + ? ((char *)(base)+0x7fffffffu) \ 1.551 + : (char *)-1)) 1.552 +# else 1.553 + /* Default version. C++ standard compliant for scalar pointers. */ 1.554 +# define U_MAX_PTR(base) \ 1.555 + ((void *)(((uintptr_t)(base)+0x7fffffffu) > (uintptr_t)(base) \ 1.556 + ? ((uintptr_t)(base)+0x7fffffffu) \ 1.557 + : (uintptr_t)-1)) 1.558 +# endif 1.559 +#endif 1.560 + 1.561 +/* Dynamic Library Functions */ 1.562 + 1.563 +typedef void (UVoidFunction)(void); 1.564 + 1.565 +#if U_ENABLE_DYLOAD 1.566 +/** 1.567 + * Load a library 1.568 + * @internal (ICU 4.4) 1.569 + */ 1.570 +U_INTERNAL void * U_EXPORT2 uprv_dl_open(const char *libName, UErrorCode *status); 1.571 + 1.572 +/** 1.573 + * Close a library 1.574 + * @internal (ICU 4.4) 1.575 + */ 1.576 +U_INTERNAL void U_EXPORT2 uprv_dl_close( void *lib, UErrorCode *status); 1.577 + 1.578 +/** 1.579 + * Extract a symbol from a library (function) 1.580 + * @internal (ICU 4.8) 1.581 + */ 1.582 +U_INTERNAL UVoidFunction* U_EXPORT2 uprv_dlsym_func( void *lib, const char *symbolName, UErrorCode *status); 1.583 + 1.584 +/** 1.585 + * Extract a symbol from a library (function) 1.586 + * Not implemented, no clients. 1.587 + * @internal 1.588 + */ 1.589 +/* U_INTERNAL void * U_EXPORT2 uprv_dlsym_data( void *lib, const char *symbolName, UErrorCode *status); */ 1.590 + 1.591 +#endif 1.592 + 1.593 +/** 1.594 + * Define malloc and related functions 1.595 + * @internal 1.596 + */ 1.597 +#if U_PLATFORM == U_PF_OS400 1.598 +# define uprv_default_malloc(x) _C_TS_malloc(x) 1.599 +# define uprv_default_realloc(x,y) _C_TS_realloc(x,y) 1.600 +# define uprv_default_free(x) _C_TS_free(x) 1.601 +/* also _C_TS_calloc(x) */ 1.602 +#else 1.603 +/* C defaults */ 1.604 +# define uprv_default_malloc(x) malloc(x) 1.605 +# define uprv_default_realloc(x,y) realloc(x,y) 1.606 +# define uprv_default_free(x) free(x) 1.607 +#endif 1.608 + 1.609 + 1.610 +#endif