Skip to content

Commit 91e8da5

Browse files
committed
Remove uses of #ifdef CPL_HAS_GINT64
The code base has assumed for many many years that we have access to 64-bit integer types.
1 parent 87d8e06 commit 91e8da5

20 files changed

+165
-215
lines changed

autotest/cpp/test_cpl.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,36 +1640,36 @@ TEST_F(test_cpl, CPLSM_unsigned)
16401640
{
16411641
}
16421642

1643-
ASSERT_EQ((CPLSM(static_cast<GUInt64>(2) * 1000 * 1000 * 1000) +
1644-
CPLSM(static_cast<GUInt64>(3) * 1000 * 1000 * 1000))
1643+
ASSERT_EQ((CPLSM(static_cast<uint64_t>(2) * 1000 * 1000 * 1000) +
1644+
CPLSM(static_cast<uint64_t>(3) * 1000 * 1000 * 1000))
16451645
.v(),
1646-
static_cast<GUInt64>(5) * 1000 * 1000 * 1000);
1647-
ASSERT_EQ((CPLSM(std::numeric_limits<GUInt64>::max() - 1) +
1648-
CPLSM(static_cast<GUInt64>(1)))
1646+
static_cast<uint64_t>(5) * 1000 * 1000 * 1000);
1647+
ASSERT_EQ((CPLSM(std::numeric_limits<uint64_t>::max() - 1) +
1648+
CPLSM(static_cast<uint64_t>(1)))
16491649
.v(),
1650-
std::numeric_limits<GUInt64>::max());
1650+
std::numeric_limits<uint64_t>::max());
16511651
try
16521652
{
1653-
(CPLSM(std::numeric_limits<GUInt64>::max()) +
1654-
CPLSM(static_cast<GUInt64>(1)));
1653+
(CPLSM(std::numeric_limits<uint64_t>::max()) +
1654+
CPLSM(static_cast<uint64_t>(1)));
16551655
}
16561656
catch (...)
16571657
{
16581658
}
16591659

1660-
ASSERT_EQ((CPLSM(static_cast<GUInt64>(2) * 1000 * 1000 * 1000) *
1661-
CPLSM(static_cast<GUInt64>(3) * 1000 * 1000 * 1000))
1660+
ASSERT_EQ((CPLSM(static_cast<uint64_t>(2) * 1000 * 1000 * 1000) *
1661+
CPLSM(static_cast<uint64_t>(3) * 1000 * 1000 * 1000))
16621662
.v(),
1663-
static_cast<GUInt64>(6) * 1000 * 1000 * 1000 * 1000 * 1000 *
1663+
static_cast<uint64_t>(6) * 1000 * 1000 * 1000 * 1000 * 1000 *
16641664
1000);
1665-
ASSERT_EQ((CPLSM(std::numeric_limits<GUInt64>::max()) *
1666-
CPLSM(static_cast<GUInt64>(1)))
1665+
ASSERT_EQ((CPLSM(std::numeric_limits<uint64_t>::max()) *
1666+
CPLSM(static_cast<uint64_t>(1)))
16671667
.v(),
1668-
std::numeric_limits<GUInt64>::max());
1668+
std::numeric_limits<uint64_t>::max());
16691669
try
16701670
{
1671-
(CPLSM(std::numeric_limits<GUInt64>::max()) *
1672-
CPLSM(static_cast<GUInt64>(2)));
1671+
(CPLSM(std::numeric_limits<uint64_t>::max()) *
1672+
CPLSM(static_cast<uint64_t>(2)));
16731673
}
16741674
catch (...)
16751675
{

frmts/eeda/eedadataset.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "eeda.h"
2020

2121
#include <algorithm>
22+
#include <cinttypes>
2223
#include <vector>
2324
#include <map>
2425
#include <set>
@@ -778,7 +779,7 @@ CPLString GDALEEDALayer::BuildFilter(swq_expr_node *poNode, bool bIsAndTopLevel)
778779
poNode->papoSubExpr[1]->field_type == SWQ_INTEGER64)
779780
{
780781
osFilter +=
781-
CPLSPrintf(CPL_FRMT_GIB, poNode->papoSubExpr[1]->int_value);
782+
CPLSPrintf("%" PRId64, poNode->papoSubExpr[1]->int_value);
782783
}
783784
else if (poNode->papoSubExpr[1]->field_type == SWQ_FLOAT)
784785
{
@@ -869,7 +870,7 @@ CPLString GDALEEDALayer::BuildFilter(swq_expr_node *poNode, bool bIsAndTopLevel)
869870
poNode->papoSubExpr[i]->field_type == SWQ_INTEGER64)
870871
{
871872
osFilter +=
872-
CPLSPrintf(CPL_FRMT_GIB, poNode->papoSubExpr[i]->int_value);
873+
CPLSPrintf("%" PRId64, poNode->papoSubExpr[i]->int_value);
873874
}
874875
else if (poNode->papoSubExpr[i]->field_type == SWQ_FLOAT)
875876
{

frmts/pds/pdsdataset.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1201,7 +1201,7 @@ int PDSDataset::ParseImage(const CPLString &osPrefix,
12011201
int nPixelOffset;
12021202
vsi_l_offset nBandOffset;
12031203

1204-
const auto CPLSM64 = [](int x) { return CPLSM(static_cast<GInt64>(x)); };
1204+
const auto CPLSM64 = [](int x) { return CPLSM(static_cast<int64_t>(x)); };
12051205

12061206
try
12071207
{

frmts/pds/vicardataset.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2630,15 +2630,15 @@ GDALDataset *VICARDataset::Open(GDALOpenInfo *poOpenInfo)
26302630
/* Compute the line offsets. */
26312631
/* -------------------------------------------------------------------- */
26322632

2633-
GUInt64 nPixelOffset;
2634-
GUInt64 nLineOffset;
2635-
GUInt64 nBandOffset;
2636-
GUInt64 nImageOffsetWithoutNBB;
2637-
GUInt64 nNBB;
2638-
GUInt64 nImageSize;
2633+
uint64_t nPixelOffset;
2634+
uint64_t nLineOffset;
2635+
uint64_t nBandOffset;
2636+
uint64_t nImageOffsetWithoutNBB;
2637+
uint64_t nNBB;
2638+
uint64_t nImageSize;
26392639
if (!GetSpacings(poDS->oKeywords, nPixelOffset, nLineOffset, nBandOffset,
26402640
nImageOffsetWithoutNBB, nNBB, nImageSize) ||
2641-
nImageOffsetWithoutNBB > std::numeric_limits<GUInt64>::max() -
2641+
nImageOffsetWithoutNBB > std::numeric_limits<uint64_t>::max() -
26422642
(nNBB + nBandOffset * (nBands - 1)))
26432643
{
26442644
CPLDebug("VICAR", "Invalid spacings found");
@@ -3076,22 +3076,22 @@ GDALDataType VICARDataset::GetDataTypeFromFormat(const char *pszFormat)
30763076
/************************************************************************/
30773077

30783078
bool VICARDataset::GetSpacings(const VICARKeywordHandler &keywords,
3079-
GUInt64 &nPixelOffset, GUInt64 &nLineOffset,
3080-
GUInt64 &nBandOffset,
3081-
GUInt64 &nImageOffsetWithoutNBB, GUInt64 &nNBB,
3082-
GUInt64 &nImageSize)
3079+
uint64_t &nPixelOffset, uint64_t &nLineOffset,
3080+
uint64_t &nBandOffset,
3081+
uint64_t &nImageOffsetWithoutNBB, uint64_t &nNBB,
3082+
uint64_t &nImageSize)
30833083
{
30843084
const GDALDataType eDataType =
30853085
GetDataTypeFromFormat(keywords.GetKeyword("FORMAT", ""));
30863086
if (eDataType == GDT_Unknown)
30873087
return false;
3088-
const GUInt64 nItemSize = GDALGetDataTypeSizeBytes(eDataType);
3088+
const uint64_t nItemSize = GDALGetDataTypeSizeBytes(eDataType);
30893089
const char *value = keywords.GetKeyword("ORG", "BSQ");
30903090
// number of bytes of binary prefix before each record
30913091
nNBB = atoi(keywords.GetKeyword("NBB", ""));
3092-
const GUInt64 nCols64 = atoi(keywords.GetKeyword("NS", ""));
3093-
const GUInt64 nRows64 = atoi(keywords.GetKeyword("NL", ""));
3094-
const GUInt64 nBands64 = atoi(keywords.GetKeyword("NB", ""));
3092+
const uint64_t nCols64 = atoi(keywords.GetKeyword("NS", ""));
3093+
const uint64_t nRows64 = atoi(keywords.GetKeyword("NL", ""));
3094+
const uint64_t nBands64 = atoi(keywords.GetKeyword("NB", ""));
30953095
try
30963096
{
30973097
if (EQUAL(value, "BIP"))
@@ -3130,9 +3130,9 @@ bool VICARDataset::GetSpacings(const VICARKeywordHandler &keywords,
31303130
return false;
31313131
}
31323132

3133-
const GUInt64 nLabelSize = atoi(keywords.GetKeyword("LBLSIZE", ""));
3134-
const GUInt64 nRecordSize = atoi(keywords.GetKeyword("RECSIZE", ""));
3135-
const GUInt64 nNLB = atoi(keywords.GetKeyword("NLB", ""));
3133+
const uint64_t nLabelSize = atoi(keywords.GetKeyword("LBLSIZE", ""));
3134+
const uint64_t nRecordSize = atoi(keywords.GetKeyword("RECSIZE", ""));
3135+
const uint64_t nNLB = atoi(keywords.GetKeyword("NLB", ""));
31363136
try
31373137
{
31383138
nImageOffsetWithoutNBB =

frmts/pds/vicardataset.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ class VICARDataset final : public RawDataset
132132

133133
static GDALDataType GetDataTypeFromFormat(const char *pszFormat);
134134
static bool GetSpacings(const VICARKeywordHandler &keywords,
135-
GUInt64 &nPixelOffset, GUInt64 &nLineOffset,
136-
GUInt64 &nBandOffset,
137-
GUInt64 &nImageOffsetWithoutNBB, GUInt64 &nNBB,
138-
GUInt64 &nImageSize);
135+
uint64_t &nPixelOffset, uint64_t &nLineOffset,
136+
uint64_t &nBandOffset,
137+
uint64_t &nImageOffsetWithoutNBB, uint64_t &nNBB,
138+
uint64_t &nImageSize);
139139
};
140140

141141
#endif // VICARDATASET_H

frmts/pds/vicarkeywordhandler.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ bool VICARKeywordHandler::Ingest(VSILFILE *fp, const GByte *pabyHeader)
109109
/* There is a EOL! e.G. h4231_0000.nd4.06 */
110110
/* -------------------------------------------------------------------- */
111111

112-
GUInt64 nPixelOffset;
113-
GUInt64 nLineOffset;
114-
GUInt64 nBandOffset;
115-
GUInt64 nImageOffsetWithoutNBB;
116-
GUInt64 nNBB;
117-
GUInt64 nImageSize;
112+
uint64_t nPixelOffset;
113+
uint64_t nLineOffset;
114+
uint64_t nBandOffset;
115+
uint64_t nImageOffsetWithoutNBB;
116+
uint64_t nNBB;
117+
uint64_t nImageSize;
118118
if (!VICARDataset::GetSpacings(*this, nPixelOffset, nLineOffset,
119119
nBandOffset, nImageOffsetWithoutNBB, nNBB,
120120
nImageSize))
@@ -128,7 +128,7 @@ bool VICARKeywordHandler::Ingest(VSILFILE *fp, const GByte *pabyHeader)
128128
const vsi_l_offset nEOCI = (nEOCI2 << 32) | nEOCI1;
129129

130130
if (nImageOffsetWithoutNBB >
131-
std::numeric_limits<GUInt64>::max() - nImageSize)
131+
std::numeric_limits<uint64_t>::max() - nImageSize)
132132
{
133133
CPLError(CE_Failure, CPLE_AppDefined, "Invalid label values");
134134
return false;

frmts/rmf/rmfdataset.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,15 +1418,15 @@ RMFDataset *RMFDataset::Open(GDALOpenInfo *poOpenInfo, RMFDataset *poParentDS,
14181418
bool bInvalidTileSize;
14191419
try
14201420
{
1421-
GUInt64 nMaxTileBits =
1422-
(CPLSM(static_cast<GUInt64>(2)) *
1423-
CPLSM(static_cast<GUInt64>(poDS->sHeader.nTileWidth)) *
1424-
CPLSM(static_cast<GUInt64>(poDS->sHeader.nTileHeight)) *
1425-
CPLSM(static_cast<GUInt64>(poDS->sHeader.nBitDepth)))
1421+
uint64_t nMaxTileBits =
1422+
(CPLSM(static_cast<uint64_t>(2)) *
1423+
CPLSM(static_cast<uint64_t>(poDS->sHeader.nTileWidth)) *
1424+
CPLSM(static_cast<uint64_t>(poDS->sHeader.nTileHeight)) *
1425+
CPLSM(static_cast<uint64_t>(poDS->sHeader.nBitDepth)))
14261426
.v();
14271427
bInvalidTileSize =
14281428
(nMaxTileBits >
1429-
static_cast<GUInt64>(std::numeric_limits<GUInt32>::max()));
1429+
static_cast<uint64_t>(std::numeric_limits<GUInt32>::max()));
14301430
}
14311431
catch (...)
14321432
{

gcore/gdaljp2box.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,9 @@ int GDALJP2Box::ReadBox()
155155
if (VSIFReadL(abyXLBox, 8, 1, fpVSIL) != 1)
156156
return FALSE;
157157

158-
#ifdef CPL_HAS_GINT64
159158
CPL_MSBPTR64(abyXLBox);
160159
memcpy(&nBoxLength, abyXLBox, 8);
161-
#else
162-
// In case we lack a 64 bit integer type
163-
if (abyXLBox[0] != 0 || abyXLBox[1] != 0 || abyXLBox[2] != 0 ||
164-
abyXLBox[3] != 0)
165-
{
166-
CPLError(CE_Failure, CPLE_AppDefined,
167-
"Box size requires a 64 bit integer type");
168-
return FALSE;
169-
}
170-
CPL_MSBPTR32(abyXLBox + 4);
171-
memcpy(&nBoxLength, abyXLBox + 4, 4);
172-
#endif
160+
173161
if (nBoxLength < 0)
174162
{
175163
CPLDebug("GDALJP2", "Invalid length for box %s", szBoxType);

gcore/gdalmultidim.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,8 +1887,8 @@ bool GDALAbstractMDArray::CheckReadWriteParams(
18871887
bool bOK;
18881888
try
18891889
{
1890-
newStride = (CPLSM(static_cast<GUInt64>(stride)) *
1891-
CPLSM(static_cast<GUInt64>(count[i])))
1890+
newStride = (CPLSM(static_cast<uint64_t>(stride)) *
1891+
CPLSM(static_cast<uint64_t>(count[i])))
18921892
.v();
18931893
bOK = static_cast<size_t>(newStride) == newStride &&
18941894
newStride < std::numeric_limits<size_t>::max() / 2;
@@ -1934,9 +1934,9 @@ bool GDALAbstractMDArray::CheckReadWriteParams(
19341934
{
19351935
try
19361936
{
1937-
bOverflow = (CPLSM(static_cast<GUInt64>(arrayStartIdx[i])) +
1938-
CPLSM(static_cast<GUInt64>(count[i] - 1)) *
1939-
CPLSM(static_cast<GUInt64>(arrayStep[i])))
1937+
bOverflow = (CPLSM(static_cast<uint64_t>(arrayStartIdx[i])) +
1938+
CPLSM(static_cast<uint64_t>(count[i] - 1)) *
1939+
CPLSM(static_cast<uint64_t>(arrayStep[i])))
19401940
.v() >= dims[i]->GetSize();
19411941
}
19421942
catch (...)
@@ -1960,10 +1960,10 @@ bool GDALAbstractMDArray::CheckReadWriteParams(
19601960
{
19611961
bOverflow =
19621962
arrayStartIdx[i] <
1963-
(CPLSM(static_cast<GUInt64>(count[i] - 1)) *
1963+
(CPLSM(static_cast<uint64_t>(count[i] - 1)) *
19641964
CPLSM(arrayStep[i] == std::numeric_limits<GInt64>::min()
1965-
? (static_cast<GUInt64>(1) << 63)
1966-
: static_cast<GUInt64>(-arrayStep[i])))
1965+
? (static_cast<uint64_t>(1) << 63)
1966+
: static_cast<uint64_t>(-arrayStep[i])))
19671967
.v();
19681968
}
19691969
catch (...)
@@ -2002,10 +2002,10 @@ bool GDALAbstractMDArray::CheckReadWriteParams(
20022002
{
20032003
try
20042004
{
2005-
nOffset = (CPLSM(static_cast<GUInt64>(nOffset)) +
2006-
CPLSM(static_cast<GUInt64>(bufferStride[i])) *
2007-
CPLSM(static_cast<GUInt64>(count[i] - 1)) *
2008-
CPLSM(static_cast<GUInt64>(elementSize)))
2005+
nOffset = (CPLSM(static_cast<uint64_t>(nOffset)) +
2006+
CPLSM(static_cast<uint64_t>(bufferStride[i])) *
2007+
CPLSM(static_cast<uint64_t>(count[i] - 1)) *
2008+
CPLSM(static_cast<uint64_t>(elementSize)))
20092009
.v();
20102010
}
20112011
catch (...)
@@ -2272,8 +2272,8 @@ GUInt64 GDALAbstractMDArray::GetTotalElementsCount() const
22722272
{
22732273
try
22742274
{
2275-
nElts = (CPLSM(static_cast<GUInt64>(nElts)) *
2276-
CPLSM(static_cast<GUInt64>(dim->GetSize())))
2275+
nElts = (CPLSM(static_cast<uint64_t>(nElts)) *
2276+
CPLSM(static_cast<uint64_t>(dim->GetSize())))
22772277
.v();
22782278
}
22792279
catch (...)

gcore/gdalrasterband.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4987,8 +4987,6 @@ CPLErr CPL_STDCALL GDALGetRasterStatistics(GDALRasterBandH hBand, int bApproxOK,
49874987
pdfStdDev);
49884988
}
49894989

4990-
#ifdef CPL_HAS_GINT64
4991-
49924990
/************************************************************************/
49934991
/* GDALUInt128 */
49944992
/************************************************************************/
@@ -6021,8 +6019,6 @@ struct ComputeStatisticsInternal<GUInt16, COMPUTE_OTHER_STATS>
60216019
// (defined(__x86_64__) || defined(_M_X64)) && (defined(__GNUC__) ||
60226020
// defined(_MSC_VER))
60236021

6024-
#endif // CPL_HAS_GINT64
6025-
60266022
/************************************************************************/
60276023
/* GetPixelValue() */
60286024
/************************************************************************/
@@ -6431,7 +6427,6 @@ CPLErr GDALRasterBand::ComputeStatistics(int bApproxOK, double *pdfMin,
64316427
if (nSampleRate == 1)
64326428
bApproxOK = false;
64336429

6434-
#ifdef CPL_HAS_GINT64
64356430
// Particular case for GDT_Byte that only use integral types for all
64366431
// intermediate computations. Only possible if the number of pixels
64376432
// explored is lower than GUINTBIG_MAX / (255*255), so that nSumSquare
@@ -6580,7 +6575,6 @@ CPLErr GDALRasterBand::ComputeStatistics(int bApproxOK, double *pdfMin,
65806575
"in sampling.");
65816576
return CE_Failure;
65826577
}
6583-
#endif
65846578

65856579
GByte *pabyMaskData = nullptr;
65866580
if (poMaskBand)

0 commit comments

Comments
 (0)