|
83 | 83 | #endif
|
84 | 84 | #include <string>
|
85 | 85 |
|
| 86 | +#if __cplusplus >= 202002L |
| 87 | +#include <type_traits> // For std::endian |
| 88 | +#endif |
| 89 | + |
86 | 90 | #include "cpl_config.h"
|
87 | 91 | #include "cpl_multiproc.h"
|
88 | 92 | #include "cpl_string.h"
|
@@ -186,8 +190,6 @@ void *CPLMalloc(size_t nSize)
|
186 | 190 | if (nSize == 0)
|
187 | 191 | return nullptr;
|
188 | 192 |
|
189 |
| - CPLVerifyConfiguration(); |
190 |
| - |
191 | 193 | if ((nSize >> (8 * sizeof(nSize) - 1)) != 0)
|
192 | 194 | {
|
193 | 195 | // coverity[dead_error_begin]
|
@@ -1564,33 +1566,36 @@ int CPLPrintTime(char *pszBuffer, int nMaxLen, const char *pszFormat,
|
1564 | 1566 | void CPLVerifyConfiguration()
|
1565 | 1567 |
|
1566 | 1568 | {
|
1567 |
| - static bool verified = false; |
1568 |
| - if (verified) |
1569 |
| - { |
1570 |
| - return; |
1571 |
| - } |
1572 |
| - verified = true; |
1573 |
| - |
1574 | 1569 | /* -------------------------------------------------------------------- */
|
1575 | 1570 | /* Verify data types. */
|
1576 | 1571 | /* -------------------------------------------------------------------- */
|
1577 |
| - CPL_STATIC_ASSERT(sizeof(GInt32) == 4); |
1578 |
| - CPL_STATIC_ASSERT(sizeof(GInt16) == 2); |
1579 |
| - CPL_STATIC_ASSERT(sizeof(GByte) == 1); |
| 1572 | + static_assert(sizeof(short) == 2); // We unfortunately rely on this |
| 1573 | + static_assert(sizeof(int) == 4); // We unfortunately rely on this |
| 1574 | + static_assert(sizeof(float) == 4); // We unfortunately rely on this |
| 1575 | + static_assert(sizeof(double) == 8); // We unfortunately rely on this |
| 1576 | + static_assert(sizeof(GInt64) == 8); |
| 1577 | + static_assert(sizeof(GInt32) == 4); |
| 1578 | + static_assert(sizeof(GInt16) == 2); |
| 1579 | + static_assert(sizeof(GByte) == 1); |
1580 | 1580 |
|
1581 | 1581 | /* -------------------------------------------------------------------- */
|
1582 | 1582 | /* Verify byte order */
|
1583 | 1583 | /* -------------------------------------------------------------------- */
|
1584 |
| - GInt32 nTest = 1; |
1585 |
| - |
1586 | 1584 | #ifdef CPL_LSB
|
1587 |
| - if (reinterpret_cast<GByte *>(&nTest)[0] != 1) |
| 1585 | +#if __cplusplus >= 202002L |
| 1586 | + static_assert(std::endian::native == std::endian::little); |
| 1587 | +#elif defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) |
| 1588 | + static_assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__); |
1588 | 1589 | #endif
|
1589 |
| -#ifdef CPL_MSB |
1590 |
| - if (reinterpret_cast<GByte *>(&nTest)[3] != 1) |
| 1590 | +#elif defined(CPL_MSB) |
| 1591 | +#if __cplusplus >= 202002L |
| 1592 | + static_assert(std::endian::native == std::endian::big); |
| 1593 | +#elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) |
| 1594 | + static_assert(__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__); |
| 1595 | +#endif |
| 1596 | +#else |
| 1597 | +#error "CPL_LSB or CPL_MSB must be defined" |
1591 | 1598 | #endif
|
1592 |
| - CPLError(CE_Fatal, CPLE_AppDefined, |
1593 |
| - "CPLVerifyConfiguration(): byte order set wrong."); |
1594 | 1599 | }
|
1595 | 1600 |
|
1596 | 1601 | #ifdef DEBUG_CONFIG_OPTIONS
|
|
0 commit comments