32 #ifndef CPL_BASE_H_INCLUDED 33 #define CPL_BASE_H_INCLUDED 45 #if defined(_WIN32) && !defined(WIN32) 49 #if defined(_WINDOWS) && !defined(WIN32) 58 # ifndef _CRT_SECURE_NO_DEPRECATE 59 # define _CRT_SECURE_NO_DEPRECATE 61 # ifndef _CRT_NONSTDC_NO_DEPRECATE 62 # define _CRT_NONSTDC_NO_DEPRECATE 66 #include "cpl_config.h" 73 #if !defined(SIZEOF_INT) || SIZEOF_INT != 4 74 #error "Unexpected value for SIZEOF_INT" 77 #if !defined(SIZEOF_UNSIGNED_LONG) || (SIZEOF_UNSIGNED_LONG != 4 && SIZEOF_UNSIGNED_LONG != 8) 78 #error "Unexpected value for SIZEOF_UNSIGNED_LONG" 81 #if !defined(SIZEOF_VOIDP) || (SIZEOF_VOIDP != 4 && SIZEOF_VOIDP != 8) 82 #error "Unexpected value for SIZEOF_VOIDP" 95 #if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE) 96 # define _LARGEFILE64_SOURCE 1 105 #if defined(HAVE_ICONV) 106 # define CPL_RECODE_ICONV 109 #define CPL_RECODE_STUB 119 #if defined(__MINGW32__) 120 #ifndef __MSVCRT_VERSION__ 121 #define __MSVCRT_VERSION__ 0x0700 126 #if defined(GDAL_COMPILATION) && defined(__sun__) && (__STDC_VERSION__ + 0) >= 201112L && (_XOPEN_SOURCE + 0) < 600 130 #define _XOPEN_SOURCE 600 147 #if defined(HAVE_ERRNO_H) 160 # include <strings.h> 163 #if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG) 165 # include <dbmalloc.h> 168 #if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H) 170 # include <dmalloc.h> 185 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) 186 # if !(__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1900)) 187 # error Must have C++11 or newer. 189 # if __cplusplus >= 201402L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) 190 # define HAVE_CXX14 1 192 # if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) 193 # define HAVE_CXX17 1 200 #if UINT_MAX == 65535 221 #define CPL_STATIC_CAST(type, expr) static_cast<type>(expr) 222 #define CPL_REINTERPRET_CAST(type, expr) reinterpret_cast<type>(expr) 224 #define CPL_STATIC_CAST(type, expr) ((type)(expr)) 225 #define CPL_REINTERPRET_CAST(type, expr) ((type)(expr)) 233 #if defined(WIN32) && defined(_MSC_VER) 234 #define VSI_LARGE_API_SUPPORTED 247 #define GINTBIG_MIN (CPL_STATIC_CAST(GIntBig, 0x80000000) << 32) 249 #define GINTBIG_MAX ((CPL_STATIC_CAST(GIntBig, 0x7FFFFFFF) << 32) | 0xFFFFFFFFU) 251 #define GUINTBIG_MAX ((CPL_STATIC_CAST(GUIntBig, 0xFFFFFFFFU) << 32) | 0xFFFFFFFFU) 254 #define CPL_HAS_GINT64 1 265 #define GINT64_MIN GINTBIG_MIN 267 #define GINT64_MAX GINTBIG_MAX 269 #define GUINT64_MAX GUINTBIG_MAX 273 #error "64bit integer support required" 277 #if SIZEOF_VOIDP == 8 285 #ifdef GDAL_COMPILATION 288 typedef uintptr_t GUIntptr_t;
289 #elif SIZEOF_VOIDP == 8 292 typedef unsigned int GUIntptr_t;
295 #define CPL_IS_ALIGNED(ptr, quant) ((CPL_REINTERPRET_CAST(GUIntptr_t, CPL_STATIC_CAST(const void*, ptr)) % (quant)) == 0) 299 #if defined(__MSVCRT__) || (defined(WIN32) && defined(_MSC_VER)) 300 #define CPL_FRMT_GB_WITHOUT_PREFIX "I64" 303 #define CPL_FRMT_GB_WITHOUT_PREFIX "ll" 305 #define CPL_FRMT_GB_WITHOUT_PREFIX "l" 309 #define CPL_FRMT_GIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "d" 311 #define CPL_FRMT_GUIB "%" CPL_FRMT_GB_WITHOUT_PREFIX "u" 314 #define GUINTBIG_TO_DOUBLE(x) CPL_STATIC_CAST(double, x) 318 #ifdef COMPAT_WITH_ICC_CONVERSION_CHECK 319 #define CPL_INT64_FITS_ON_INT32(x) ((x) >= INT_MIN && (x) <= INT_MAX) 321 #define CPL_INT64_FITS_ON_INT32(x) (CPL_STATIC_CAST(GIntBig, CPL_STATIC_CAST(int, x)) == (x)) 330 # define CPL_C_START extern "C" { 339 #if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL) 340 # define CPL_DLL __declspec(dllexport) 342 # if defined(USE_GCC_VISIBILITY_FLAG) 343 # define CPL_DLL __attribute__ ((visibility("default"))) 352 #ifdef CPL_OPTIONAL_APIS 353 # define CPL_ODLL CPL_DLL 360 #if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL) 361 # define CPL_STDCALL __stdcall 369 # define FORCE_CDECL __cdecl 377 #if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER) 378 #define HAS_CPL_INLINE 1 379 #define CPL_INLINE __inline 380 #elif defined(__SUNPRO_CC) 381 #define HAS_CPL_INLINE 1 382 #define CPL_INLINE inline 390 # define MIN(a,b) (((a)<(b)) ? (a) : (b)) 392 # define MAX(a,b) (((a)>(b)) ? (a) : (b)) 397 # define ABS(x) (((x)<0) ? (-1*(x)) : (x)) 402 # define M_PI 3.14159265358979323846 413 # define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001) 422 #if defined(AFL_FRIENDLY) && defined(__GNUC__) 424 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
425 __attribute__((always_inline));
427 static inline int CPL_afl_friendly_memcmp(
const void* ptr1,
const void* ptr2,
size_t len)
429 const unsigned char* bptr1 = (
const unsigned char*)ptr1;
430 const unsigned char* bptr2 = (
const unsigned char*)ptr2;
433 unsigned char b1 = *(bptr1++);
434 unsigned char b2 = *(bptr2++);
435 if( b1 != b2 )
return b1 - b2;
440 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
441 __attribute__((always_inline));
443 static inline int CPL_afl_friendly_strcmp(
const char* ptr1,
const char* ptr2)
445 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
446 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
449 unsigned char ch1 = *(usptr1++);
450 unsigned char ch2 = *(usptr2++);
451 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
455 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
456 __attribute__((always_inline));
458 static inline int CPL_afl_friendly_strncmp(
const char* ptr1,
const char* ptr2,
size_t len)
460 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
461 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
464 unsigned char ch1 = *(usptr1++);
465 unsigned char ch2 = *(usptr2++);
466 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
471 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
472 __attribute__((always_inline));
474 static inline int CPL_afl_friendly_strcasecmp(
const char* ptr1,
const char* ptr2)
476 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
477 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
480 unsigned char ch1 = *(usptr1++);
481 unsigned char ch2 = *(usptr2++);
482 ch1 = (
unsigned char)toupper(ch1);
483 ch2 = (
unsigned char)toupper(ch2);
484 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
488 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
489 __attribute__((always_inline));
491 static inline int CPL_afl_friendly_strncasecmp(
const char* ptr1,
const char* ptr2,
size_t len)
493 const unsigned char* usptr1 = (
const unsigned char*)ptr1;
494 const unsigned char* usptr2 = (
const unsigned char*)ptr2;
497 unsigned char ch1 = *(usptr1++);
498 unsigned char ch2 = *(usptr2++);
499 ch1 = (
unsigned char)toupper(ch1);
500 ch2 = (
unsigned char)toupper(ch2);
501 if( ch1 == 0 || ch1 != ch2 )
return ch1 - ch2;
506 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
507 __attribute__((always_inline));
509 static inline char* CPL_afl_friendly_strstr(
const char* haystack,
const char* needle)
511 const char* ptr_haystack = haystack;
514 const char* ptr_haystack2 = ptr_haystack;
515 const char* ptr_needle = needle;
518 char ch1 = *(ptr_haystack2++);
519 char ch2 = *(ptr_needle++);
521 return (
char*)ptr_haystack;
525 if( *ptr_haystack == 0 )
533 #define memcmp CPL_afl_friendly_memcmp 534 #define strcmp CPL_afl_friendly_strcmp 535 #define strncmp CPL_afl_friendly_strncmp 536 #define strcasecmp CPL_afl_friendly_strcasecmp 537 #define strncasecmp CPL_afl_friendly_strncasecmp 538 #define strstr CPL_afl_friendly_strstr 543 # define STRCASECMP(a,b) (stricmp(a,b)) 544 # define STRNCASECMP(a,b,n) (strnicmp(a,b,n)) 547 # define STRCASECMP(a,b) (strcasecmp(a,b)) 549 # define STRNCASECMP(a,b,n) (strncasecmp(a,b,n)) 552 # define EQUALN(a,b,n) (STRNCASECMP(a,b,n)==0) 554 # define EQUAL(a,b) (STRCASECMP(a,b)==0) 561 #ifndef STARTS_WITH_CI 563 #define STARTS_WITH(a,b) (strncmp(a,b,strlen(b)) == 0) 565 #define STARTS_WITH_CI(a,b) EQUALN(a,b,strlen(b)) 569 #ifndef CPL_THREADLOCAL 570 # define CPL_THREADLOCAL 585 # define CPLIsNan(x) _isnan(x) 586 # define CPLIsInf(x) (!_isnan(x) && !_finite(x)) 587 # define CPLIsFinite(x) _finite(x) 588 #elif defined(__GNUC__) && ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 4 ) ) 591 # define CPLIsNan(x) __builtin_isnan(x) 592 # define CPLIsInf(x) __builtin_isinf(x) 593 # define CPLIsFinite(x) __builtin_isfinite(x) 594 #elif defined(__cplusplus) && defined(HAVE_STD_IS_NAN) && HAVE_STD_IS_NAN 599 static inline int CPLIsNan(
float f) {
return std::isnan(f); }
600 static inline int CPLIsNan(
double f) {
return std::isnan(f); }
601 static inline int CPLIsInf(
float f) {
return std::isinf(f); }
602 static inline int CPLIsInf(
double f) {
return std::isinf(f); }
603 static inline int CPLIsFinite(
float f) {
return std::isfinite(f); }
604 static inline int CPLIsFinite(
double f) {
return std::isfinite(f); }
608 #if defined(__cplusplus) && defined(__GNUC__) && defined(__linux) && !defined(__ANDROID__) && !defined(CPL_SUPRESS_CPLUSPLUS) 612 static inline int CPLIsNan(
float f) {
return __isnanf(f); }
613 static inline int CPLIsNan(
double f) {
return __isnan(f); }
614 static inline int CPLIsInf(
float f) {
return __isinff(f); }
615 static inline int CPLIsInf(
double f) {
return __isinf(f); }
616 static inline int CPLIsFinite(
float f) {
return !__isnanf(f) && !__isinff(f); }
617 static inline int CPLIsFinite(
double f) {
return !__isnan(f) && !__isinf(f); }
620 # define CPLIsNan(x) isnan(x) 621 # if defined(isinf) || defined(__FreeBSD__) 623 # define CPLIsInf(x) isinf(x) 625 # define CPLIsFinite(x) (!isnan(x) && !isinf(x)) 626 # elif defined(__sun__) 628 # define CPLIsInf(x) (!finite(x) && !isnan(x)) 629 # define CPLIsFinite(x) finite(x) 631 # define CPLIsInf(x) (0) 632 # define CPLIsFinite(x) (!isnan(x)) 645 #if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB) 649 #if ! ( defined(CPL_LSB) || defined(CPL_MSB) ) 654 # define CPL_IS_LSB 1 656 # define CPL_IS_LSB 0 660 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) 665 template <
bool b>
struct CPLStaticAssert {};
666 template<>
struct CPLStaticAssert<true>
668 static void my_function() {}
673 #define CPL_STATIC_ASSERT(x) CPLStaticAssert<x>::my_function() 674 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) CPL_STATIC_ASSERT(x) 678 #define CPL_STATIC_ASSERT_IF_AVAILABLE(x) 688 #define CPL_SWAP16(x) CPL_STATIC_CAST(GUInt16, (CPL_STATIC_CAST(GUInt16, x) << 8) | (CPL_STATIC_CAST(GUInt16, x) >> 8) ) 690 #if defined(HAVE_GCC_BSWAP) && (defined(__i386__) || defined(__x86_64__)) 694 #include <x86intrin.h> 696 #define CPL_SWAP32(x) CPL_STATIC_CAST(GUInt32, __builtin_bswap32(CPL_STATIC_CAST(GUInt32, x))) 698 #define CPL_SWAP64(x) CPL_STATIC_CAST(GUInt64, __builtin_bswap64(CPL_STATIC_CAST(GUInt64, x))) 699 #elif defined(_MSC_VER) 700 #define CPL_SWAP32(x) CPL_STATIC_CAST(GUInt32, _byteswap_ulong(CPL_STATIC_CAST(GUInt32, x))) 701 #define CPL_SWAP64(x) CPL_STATIC_CAST(GUInt64, _byteswap_uint64(CPL_STATIC_CAST(GUInt64, x))) 704 #define CPL_SWAP32(x) \ 705 CPL_STATIC_CAST(GUInt32, \ 706 ((CPL_STATIC_CAST(GUInt32, x) & 0x000000ffU) << 24) | \ 707 ((CPL_STATIC_CAST(GUInt32, x) & 0x0000ff00U) << 8) | \ 708 ((CPL_STATIC_CAST(GUInt32, x) & 0x00ff0000U) >> 8) | \ 709 ((CPL_STATIC_CAST(GUInt32, x) & 0xff000000U) >> 24) ) 712 #define CPL_SWAP64(x) \ 713 ((CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, x))) << 32) | \ 714 (CPL_STATIC_CAST(GUInt64, CPL_SWAP32(CPL_STATIC_CAST(GUInt32, CPL_STATIC_CAST(GUInt64, x) >> 32))))) 719 #define CPL_SWAP16PTR(x) \ 721 GByte byTemp, *_pabyDataT = CPL_REINTERPRET_CAST(GByte*, x); \ 722 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2); \ 724 byTemp = _pabyDataT[0]; \ 725 _pabyDataT[0] = _pabyDataT[1]; \ 726 _pabyDataT[1] = byTemp; \ 729 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)) 732 #define CPL_SWAP32PTR(x) \ 734 GByte byTemp, *_pabyDataT = CPL_REINTERPRET_CAST(GByte*, x); \ 735 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \ 737 byTemp = _pabyDataT[0]; \ 738 _pabyDataT[0] = _pabyDataT[3]; \ 739 _pabyDataT[3] = byTemp; \ 740 byTemp = _pabyDataT[1]; \ 741 _pabyDataT[1] = _pabyDataT[2]; \ 742 _pabyDataT[2] = byTemp; \ 746 #define CPL_SWAP64PTR(x) \ 748 GByte byTemp, *_pabyDataT = CPL_REINTERPRET_CAST(GByte*, x); \ 749 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \ 751 byTemp = _pabyDataT[0]; \ 752 _pabyDataT[0] = _pabyDataT[7]; \ 753 _pabyDataT[7] = byTemp; \ 754 byTemp = _pabyDataT[1]; \ 755 _pabyDataT[1] = _pabyDataT[6]; \ 756 _pabyDataT[6] = byTemp; \ 757 byTemp = _pabyDataT[2]; \ 758 _pabyDataT[2] = _pabyDataT[5]; \ 759 _pabyDataT[5] = byTemp; \ 760 byTemp = _pabyDataT[3]; \ 761 _pabyDataT[3] = _pabyDataT[4]; \ 762 _pabyDataT[4] = byTemp; \ 768 #define CPL_SWAP32PTR(x) \ 772 memcpy(&_n32, _lx, 4); \ 773 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4); \ 774 _n32 = CPL_SWAP32(_n32); \ 775 memcpy(_lx, &_n32, 4); \ 779 #define CPL_SWAP64PTR(x) \ 783 memcpy(&_n64, _lx, 8); \ 784 CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8); \ 785 _n64 = CPL_SWAP64(_n64); \ 786 memcpy(_lx, &_n64, 8); \ 792 #define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p) 795 # define CPL_MSBWORD16(x) (x) 796 # define CPL_LSBWORD16(x) CPL_SWAP16(x) 797 # define CPL_MSBWORD32(x) (x) 798 # define CPL_LSBWORD32(x) CPL_SWAP32(x) 799 # define CPL_MSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2) 800 # define CPL_LSBPTR16(x) CPL_SWAP16PTR(x) 801 # define CPL_MSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4) 802 # define CPL_LSBPTR32(x) CPL_SWAP32PTR(x) 803 # define CPL_MSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8) 804 # define CPL_LSBPTR64(x) CPL_SWAP64PTR(x) 807 # define CPL_LSBWORD16(x) (x) 809 # define CPL_MSBWORD16(x) CPL_SWAP16(x) 811 # define CPL_LSBWORD32(x) (x) 813 # define CPL_MSBWORD32(x) CPL_SWAP32(x) 815 # define CPL_LSBPTR16(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 2) 817 # define CPL_MSBPTR16(x) CPL_SWAP16PTR(x) 819 # define CPL_LSBPTR32(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 4) 821 # define CPL_MSBPTR32(x) CPL_SWAP32PTR(x) 823 # define CPL_LSBPTR64(x) CPL_STATIC_ASSERT_IF_AVAILABLE(sizeof(*(x)) == 1 || sizeof(*(x)) == 8) 825 # define CPL_MSBPTR64(x) CPL_SWAP64PTR(x) 831 #define CPL_LSBINT16PTR(x) ((*CPL_REINTERPRET_CAST(const GByte*, x)) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+1) << 8)) 836 #define CPL_LSBINT32PTR(x) ((*CPL_REINTERPRET_CAST(const GByte*, x)) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+1) << 8) | \ 837 (*((CPL_REINTERPRET_CAST(const GByte*, x))+2) << 16) | (*((CPL_REINTERPRET_CAST(const GByte*, x))+3) << 24)) 840 #define CPL_LSBSINT16PTR(x) CPL_STATIC_CAST(GInt16,CPL_LSBINT16PTR(x)) 843 #define CPL_LSBUINT16PTR(x) CPL_STATIC_CAST(GUInt16, CPL_LSBINT16PTR(x)) 846 #define CPL_LSBSINT32PTR(x) CPL_STATIC_CAST(GInt32, CPL_LSBINT32PTR(x)) 849 #define CPL_LSBUINT32PTR(x) CPL_STATIC_CAST(GUInt32, CPL_LSBINT32PTR(x)) 853 #ifndef UNREFERENCED_PARAM 854 # ifdef UNREFERENCED_PARAMETER 855 # define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param) 857 # define UNREFERENCED_PARAM(param) ((void)param) 871 #ifndef DISABLE_CVSID 872 #if defined(__GNUC__) && __GNUC__ >= 4 873 # define CPL_CVSID(string) static const char cpl_cvsid[] __attribute__((used)) = string; 875 # define CPL_CVSID(string) static const char cpl_cvsid[] = string; \ 876 static const char *cvsid_aw() { return( cvsid_aw() ? NULL : cpl_cvsid ); } 879 # define CPL_CVSID(string) 884 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) && !(defined(__MINGW64__) && __GNUC__ == 4 && __GNUC_MINOR__ == 6) 886 # define CPL_NULL_TERMINATED __attribute__((__sentinel__)) 889 # define CPL_NULL_TERMINATED 892 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP) 894 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__printf__, format_idx, arg_idx))) 896 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx ) __attribute__((__format__ (__scanf__, format_idx, arg_idx))) 899 #define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx ) 901 #define CPL_SCAN_FUNC_FORMAT( format_idx, arg_idx ) 904 #if defined(_MSC_VER) && (defined(GDAL_COMPILATION) || defined(CPL_ENABLE_MSVC_ANNOTATIONS)) 908 # define CPL_FORMAT_STRING(arg) _Printf_format_string_ arg 911 # define CPL_SCANF_FORMAT_STRING(arg) _Scanf_format_string_ arg 914 # define CPL_FORMAT_STRING(arg) arg 916 # define CPL_SCANF_FORMAT_STRING(arg) arg 919 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) 921 #define CPL_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 924 #define CPL_WARN_UNUSED_RESULT 927 #if defined(__GNUC__) && __GNUC__ >= 4 929 # define CPL_UNUSED __attribute((__unused__)) 936 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP) 938 #define CPL_NO_RETURN __attribute__((noreturn)) 941 #define CPL_NO_RETURN 946 #ifndef __has_attribute 947 #define __has_attribute(x) 0 // Compatibility with non-clang compilers. 952 #if ((defined(__GNUC__) && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 9))) || __has_attribute(returns_nonnull)) && !defined(DOXYGEN_SKIP) && !defined(__INTEL_COMPILER) 954 # define CPL_RETURNS_NONNULL __attribute__((returns_nonnull)) 957 # define CPL_RETURNS_NONNULL 960 #if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP) 962 #define CPL_RESTRICT __restrict__ 968 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) 972 # define CPL_OVERRIDE override 975 # define CPL_FINAL final 982 # define CPL_DISALLOW_COPY_ASSIGN(ClassName) \ 983 ClassName( const ClassName & ) = delete; \ 984 ClassName &operator=( const ClassName & ) = delete; 988 #if !defined(DOXYGEN_SKIP) 989 #if defined(__has_extension) 990 #if __has_extension(attribute_deprecated_with_message) 992 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated(x))) 994 #define CPL_WARN_DEPRECATED(x) 996 #elif defined(__GNUC__) 997 #define CPL_WARN_DEPRECATED(x) __attribute__ ((deprecated)) 999 #define CPL_WARN_DEPRECATED(x) 1003 #if !defined(_MSC_VER) && !defined(__APPLE__) && !defined(_FORTIFY_SOURCE) 1005 # if defined(GDAL_COMPILATION) && defined(WARN_STANDARD_PRINTF) 1006 int vsnprintf(
char *str,
size_t size,
const char* fmt, va_list args)
1007 CPL_WARN_DEPRECATED(
"Use CPLvsnprintf() instead");
1008 int snprintf(
char *str,
size_t size,
const char* fmt, ...)
1011 int sprintf(
char *str, const
char* fmt, ...)
1014 # elif defined(GDAL_COMPILATION) && !defined(DONT_DEPRECATE_SPRINTF) 1015 int sprintf(
char *str,
const char* fmt, ...)
1016 CPL_PRINT_FUNC_FORMAT(2, 3)
1017 CPL_WARN_DEPRECATED("Use snprintf() or
CPLsnprintf() instead");
1022 #if defined(MAKE_SANITIZE_HAPPY) || !(defined(__i386__) || defined(__x86_64__) || defined(_M_IX86) || defined(_M_X64)) 1024 #define CPL_CPU_REQUIRES_ALIGNED_ACCESS 1028 #if defined(__cplusplus) 1030 #define CPL_ARRAYSIZE(array) \ 1031 ((sizeof(array) / sizeof(*(array))) / \ 1032 static_cast<size_t>(!(sizeof(array) % sizeof(*(array))))) 1035 template<
class T>
static void CPL_IGNORE_RET_VAL(T) {}
1036 inline static bool CPL_TO_BOOL(
int x) {
return x != 0; }
1041 #if (((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || (defined(__clang__) && __clang_major__ >= 3)) && !defined(_MSC_VER)) 1042 #define HAVE_GCC_DIAGNOSTIC_PUSH 1045 #if ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) && !defined(_MSC_VER)) 1046 #define HAVE_GCC_SYSTEM_HEADER 1049 #if ((defined(__clang__) && (__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >=7))) || __GNUC__ >= 7) 1051 # define CPL_FALLTHROUGH [[clang::fallthrough]]; 1054 # define CPL_FALLTHROUGH 1062 #if defined(__cplusplus) && defined(DEBUG_BOOL) && !defined(DO_NOT_USE_DEBUG_BOOL) && !defined(CPL_SUPRESS_CPLUSPLUS) 1064 class MSVCPedanticBool
1067 friend bool operator== (
const bool& one,
const MSVCPedanticBool& other);
1068 friend bool operator!= (
const bool& one,
const MSVCPedanticBool& other);
1071 MSVCPedanticBool(
int bIn);
1076 MSVCPedanticBool() {}
1077 MSVCPedanticBool(
bool bIn) : b(bIn) {}
1078 MSVCPedanticBool(
const MSVCPedanticBool& other) : b(other.b) {}
1080 MSVCPedanticBool& operator= (
const MSVCPedanticBool& other) { b = other.b;
return *
this; }
1081 MSVCPedanticBool& operator&= (
const MSVCPedanticBool& other) { b &= other.b;
return *
this; }
1082 MSVCPedanticBool& operator|= (
const MSVCPedanticBool& other) { b |= other.b;
return *
this; }
1084 bool operator== (
const bool& other)
const {
return b == other; }
1085 bool operator!= (
const bool& other)
const {
return b != other; }
1086 bool operator< (
const bool& other)
const {
return b < other; }
1087 bool operator== (
const MSVCPedanticBool& other)
const {
return b == other.b; }
1088 bool operator!= (
const MSVCPedanticBool& other)
const {
return b != other.b; }
1089 bool operator< (
const MSVCPedanticBool& other)
const {
return b < other.b; }
1091 bool operator! ()
const {
return !b; }
1092 operator bool()
const {
return b; }
1093 operator int()
const {
return b; }
1094 operator GIntBig()
const {
return b; }
1097 inline bool operator== (
const bool& one,
const MSVCPedanticBool& other) {
return one == other.b; }
1098 inline bool operator!= (
const bool& one,
const MSVCPedanticBool& other) {
return one != other.b; }
1109 #include <algorithm> 1110 #include <functional> 1114 #include <unordered_map> 1116 #include <unordered_set> 1128 #define EMULATED_BOOL int 1131 #define bool MSVCPedanticBool 1135 #define VOLATILE_BOOL bool 1147 #define EMULATED_BOOL bool 1148 #define VOLATILE_BOOL volatile bool 1152 #if __clang_major__ >= 4 || (__clang_major__ == 3 && __clang_minor__ >= 8) 1153 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW __attribute__((no_sanitize("unsigned-integer-overflow"))) 1155 #define CPL_NOSANITIZE_UNSIGNED_INT_OVERFLOW 1160 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) 1161 #define CPL_NULLPTR nullptr 1163 #define CPL_NULLPTR NULL 1172 #if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS) && !defined(DOXYGEN_SKIP) #define CPL_C_START
Macro to start a block of C symbols.
Definition: cpl_port.h:330
int GBool
Type for boolean values (alias to int)
Definition: cpl_port.h:217
int GInt32
Int32 type.
Definition: cpl_port.h:205
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:207
short GInt16
Int16 type.
Definition: cpl_port.h:211
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:215
#define CPL_PRINT_FUNC_FORMAT(format_idx, arg_idx)
Tag a function to have printf() formatting.
Definition: cpl_port.h:899
GUIntBig GUInt64
Unsigned 64 bit integer type.
Definition: cpl_port.h:262
GIntBig GPtrDiff_t
Integer type large enough to hold the difference between 2 addresses.
Definition: cpl_port.h:279
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1179
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition: cpl_port.h:244
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:213
int CPLsnprintf(char *str, size_t size, const char *fmt,...)
snprintf() wrapper that is not sensitive to LC_NUMERIC settings.
Definition: cpl_string.cpp:1337
#define CPL_C_END
Macro to end a block of C symbols.
Definition: cpl_port.h:332
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:241
GIntBig GInt64
Signed 64 bit integer type.
Definition: cpl_port.h:260