Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove uses of #ifdef CPL_HAS_GINT64 #11626

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions autotest/cpp/test_cpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1640,36 +1640,36 @@ TEST_F(test_cpl, CPLSM_unsigned)
{
}

ASSERT_EQ((CPLSM(static_cast<GUInt64>(2) * 1000 * 1000 * 1000) +
CPLSM(static_cast<GUInt64>(3) * 1000 * 1000 * 1000))
ASSERT_EQ((CPLSM(static_cast<uint64_t>(2) * 1000 * 1000 * 1000) +
CPLSM(static_cast<uint64_t>(3) * 1000 * 1000 * 1000))
.v(),
static_cast<GUInt64>(5) * 1000 * 1000 * 1000);
ASSERT_EQ((CPLSM(std::numeric_limits<GUInt64>::max() - 1) +
CPLSM(static_cast<GUInt64>(1)))
static_cast<uint64_t>(5) * 1000 * 1000 * 1000);
ASSERT_EQ((CPLSM(std::numeric_limits<uint64_t>::max() - 1) +
CPLSM(static_cast<uint64_t>(1)))
.v(),
std::numeric_limits<GUInt64>::max());
std::numeric_limits<uint64_t>::max());
try
{
(CPLSM(std::numeric_limits<GUInt64>::max()) +
CPLSM(static_cast<GUInt64>(1)));
(CPLSM(std::numeric_limits<uint64_t>::max()) +
CPLSM(static_cast<uint64_t>(1)));
}
catch (...)
{
}

ASSERT_EQ((CPLSM(static_cast<GUInt64>(2) * 1000 * 1000 * 1000) *
CPLSM(static_cast<GUInt64>(3) * 1000 * 1000 * 1000))
ASSERT_EQ((CPLSM(static_cast<uint64_t>(2) * 1000 * 1000 * 1000) *
CPLSM(static_cast<uint64_t>(3) * 1000 * 1000 * 1000))
.v(),
static_cast<GUInt64>(6) * 1000 * 1000 * 1000 * 1000 * 1000 *
static_cast<uint64_t>(6) * 1000 * 1000 * 1000 * 1000 * 1000 *
1000);
ASSERT_EQ((CPLSM(std::numeric_limits<GUInt64>::max()) *
CPLSM(static_cast<GUInt64>(1)))
ASSERT_EQ((CPLSM(std::numeric_limits<uint64_t>::max()) *
CPLSM(static_cast<uint64_t>(1)))
.v(),
std::numeric_limits<GUInt64>::max());
std::numeric_limits<uint64_t>::max());
try
{
(CPLSM(std::numeric_limits<GUInt64>::max()) *
CPLSM(static_cast<GUInt64>(2)));
(CPLSM(std::numeric_limits<uint64_t>::max()) *
CPLSM(static_cast<uint64_t>(2)));
}
catch (...)
{
Expand Down
5 changes: 3 additions & 2 deletions frmts/eeda/eedadataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "eeda.h"

#include <algorithm>
#include <cinttypes>
#include <vector>
#include <map>
#include <set>
Expand Down Expand Up @@ -778,7 +779,7 @@ CPLString GDALEEDALayer::BuildFilter(swq_expr_node *poNode, bool bIsAndTopLevel)
poNode->papoSubExpr[1]->field_type == SWQ_INTEGER64)
{
osFilter +=
CPLSPrintf(CPL_FRMT_GIB, poNode->papoSubExpr[1]->int_value);
CPLSPrintf("%" PRId64, poNode->papoSubExpr[1]->int_value);
}
else if (poNode->papoSubExpr[1]->field_type == SWQ_FLOAT)
{
Expand Down Expand Up @@ -869,7 +870,7 @@ CPLString GDALEEDALayer::BuildFilter(swq_expr_node *poNode, bool bIsAndTopLevel)
poNode->papoSubExpr[i]->field_type == SWQ_INTEGER64)
{
osFilter +=
CPLSPrintf(CPL_FRMT_GIB, poNode->papoSubExpr[i]->int_value);
CPLSPrintf("%" PRId64, poNode->papoSubExpr[i]->int_value);
}
else if (poNode->papoSubExpr[i]->field_type == SWQ_FLOAT)
{
Expand Down
2 changes: 1 addition & 1 deletion frmts/pds/pdsdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ int PDSDataset::ParseImage(const CPLString &osPrefix,
int nPixelOffset;
vsi_l_offset nBandOffset;

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

try
{
Expand Down
36 changes: 18 additions & 18 deletions frmts/pds/vicardataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2630,15 +2630,15 @@ GDALDataset *VICARDataset::Open(GDALOpenInfo *poOpenInfo)
/* Compute the line offsets. */
/* -------------------------------------------------------------------- */

GUInt64 nPixelOffset;
GUInt64 nLineOffset;
GUInt64 nBandOffset;
GUInt64 nImageOffsetWithoutNBB;
GUInt64 nNBB;
GUInt64 nImageSize;
uint64_t nPixelOffset;
uint64_t nLineOffset;
uint64_t nBandOffset;
uint64_t nImageOffsetWithoutNBB;
uint64_t nNBB;
uint64_t nImageSize;
if (!GetSpacings(poDS->oKeywords, nPixelOffset, nLineOffset, nBandOffset,
nImageOffsetWithoutNBB, nNBB, nImageSize) ||
nImageOffsetWithoutNBB > std::numeric_limits<GUInt64>::max() -
nImageOffsetWithoutNBB > std::numeric_limits<uint64_t>::max() -
(nNBB + nBandOffset * (nBands - 1)))
{
CPLDebug("VICAR", "Invalid spacings found");
Expand Down Expand Up @@ -3076,22 +3076,22 @@ GDALDataType VICARDataset::GetDataTypeFromFormat(const char *pszFormat)
/************************************************************************/

bool VICARDataset::GetSpacings(const VICARKeywordHandler &keywords,
GUInt64 &nPixelOffset, GUInt64 &nLineOffset,
GUInt64 &nBandOffset,
GUInt64 &nImageOffsetWithoutNBB, GUInt64 &nNBB,
GUInt64 &nImageSize)
uint64_t &nPixelOffset, uint64_t &nLineOffset,
uint64_t &nBandOffset,
uint64_t &nImageOffsetWithoutNBB, uint64_t &nNBB,
uint64_t &nImageSize)
{
const GDALDataType eDataType =
GetDataTypeFromFormat(keywords.GetKeyword("FORMAT", ""));
if (eDataType == GDT_Unknown)
return false;
const GUInt64 nItemSize = GDALGetDataTypeSizeBytes(eDataType);
const uint64_t nItemSize = GDALGetDataTypeSizeBytes(eDataType);
const char *value = keywords.GetKeyword("ORG", "BSQ");
// number of bytes of binary prefix before each record
nNBB = atoi(keywords.GetKeyword("NBB", ""));
const GUInt64 nCols64 = atoi(keywords.GetKeyword("NS", ""));
const GUInt64 nRows64 = atoi(keywords.GetKeyword("NL", ""));
const GUInt64 nBands64 = atoi(keywords.GetKeyword("NB", ""));
const uint64_t nCols64 = atoi(keywords.GetKeyword("NS", ""));
const uint64_t nRows64 = atoi(keywords.GetKeyword("NL", ""));
const uint64_t nBands64 = atoi(keywords.GetKeyword("NB", ""));
try
{
if (EQUAL(value, "BIP"))
Expand Down Expand Up @@ -3130,9 +3130,9 @@ bool VICARDataset::GetSpacings(const VICARKeywordHandler &keywords,
return false;
}

const GUInt64 nLabelSize = atoi(keywords.GetKeyword("LBLSIZE", ""));
const GUInt64 nRecordSize = atoi(keywords.GetKeyword("RECSIZE", ""));
const GUInt64 nNLB = atoi(keywords.GetKeyword("NLB", ""));
const uint64_t nLabelSize = atoi(keywords.GetKeyword("LBLSIZE", ""));
const uint64_t nRecordSize = atoi(keywords.GetKeyword("RECSIZE", ""));
const uint64_t nNLB = atoi(keywords.GetKeyword("NLB", ""));
try
{
nImageOffsetWithoutNBB =
Expand Down
8 changes: 4 additions & 4 deletions frmts/pds/vicardataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ class VICARDataset final : public RawDataset

static GDALDataType GetDataTypeFromFormat(const char *pszFormat);
static bool GetSpacings(const VICARKeywordHandler &keywords,
GUInt64 &nPixelOffset, GUInt64 &nLineOffset,
GUInt64 &nBandOffset,
GUInt64 &nImageOffsetWithoutNBB, GUInt64 &nNBB,
GUInt64 &nImageSize);
uint64_t &nPixelOffset, uint64_t &nLineOffset,
uint64_t &nBandOffset,
uint64_t &nImageOffsetWithoutNBB, uint64_t &nNBB,
uint64_t &nImageSize);
};

#endif // VICARDATASET_H
14 changes: 7 additions & 7 deletions frmts/pds/vicarkeywordhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ bool VICARKeywordHandler::Ingest(VSILFILE *fp, const GByte *pabyHeader)
/* There is a EOL! e.G. h4231_0000.nd4.06 */
/* -------------------------------------------------------------------- */

GUInt64 nPixelOffset;
GUInt64 nLineOffset;
GUInt64 nBandOffset;
GUInt64 nImageOffsetWithoutNBB;
GUInt64 nNBB;
GUInt64 nImageSize;
uint64_t nPixelOffset;
uint64_t nLineOffset;
uint64_t nBandOffset;
uint64_t nImageOffsetWithoutNBB;
uint64_t nNBB;
uint64_t nImageSize;
if (!VICARDataset::GetSpacings(*this, nPixelOffset, nLineOffset,
nBandOffset, nImageOffsetWithoutNBB, nNBB,
nImageSize))
Expand All @@ -128,7 +128,7 @@ bool VICARKeywordHandler::Ingest(VSILFILE *fp, const GByte *pabyHeader)
const vsi_l_offset nEOCI = (nEOCI2 << 32) | nEOCI1;

if (nImageOffsetWithoutNBB >
std::numeric_limits<GUInt64>::max() - nImageSize)
std::numeric_limits<uint64_t>::max() - nImageSize)
{
CPLError(CE_Failure, CPLE_AppDefined, "Invalid label values");
return false;
Expand Down
12 changes: 6 additions & 6 deletions frmts/rmf/rmfdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1418,15 +1418,15 @@ RMFDataset *RMFDataset::Open(GDALOpenInfo *poOpenInfo, RMFDataset *poParentDS,
bool bInvalidTileSize;
try
{
GUInt64 nMaxTileBits =
(CPLSM(static_cast<GUInt64>(2)) *
CPLSM(static_cast<GUInt64>(poDS->sHeader.nTileWidth)) *
CPLSM(static_cast<GUInt64>(poDS->sHeader.nTileHeight)) *
CPLSM(static_cast<GUInt64>(poDS->sHeader.nBitDepth)))
uint64_t nMaxTileBits =
(CPLSM(static_cast<uint64_t>(2)) *
CPLSM(static_cast<uint64_t>(poDS->sHeader.nTileWidth)) *
CPLSM(static_cast<uint64_t>(poDS->sHeader.nTileHeight)) *
CPLSM(static_cast<uint64_t>(poDS->sHeader.nBitDepth)))
.v();
bInvalidTileSize =
(nMaxTileBits >
static_cast<GUInt64>(std::numeric_limits<GUInt32>::max()));
static_cast<uint64_t>(std::numeric_limits<GUInt32>::max()));
}
catch (...)
{
Expand Down
14 changes: 1 addition & 13 deletions gcore/gdaljp2box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,9 @@ int GDALJP2Box::ReadBox()
if (VSIFReadL(abyXLBox, 8, 1, fpVSIL) != 1)
return FALSE;

#ifdef CPL_HAS_GINT64
CPL_MSBPTR64(abyXLBox);
memcpy(&nBoxLength, abyXLBox, 8);
#else
// In case we lack a 64 bit integer type
if (abyXLBox[0] != 0 || abyXLBox[1] != 0 || abyXLBox[2] != 0 ||
abyXLBox[3] != 0)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Box size requires a 64 bit integer type");
return FALSE;
}
CPL_MSBPTR32(abyXLBox + 4);
memcpy(&nBoxLength, abyXLBox + 4, 4);
#endif

if (nBoxLength < 0)
{
CPLDebug("GDALJP2", "Invalid length for box %s", szBoxType);
Expand Down
28 changes: 14 additions & 14 deletions gcore/gdalmultidim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1887,8 +1887,8 @@ bool GDALAbstractMDArray::CheckReadWriteParams(
bool bOK;
try
{
newStride = (CPLSM(static_cast<GUInt64>(stride)) *
CPLSM(static_cast<GUInt64>(count[i])))
newStride = (CPLSM(static_cast<uint64_t>(stride)) *
CPLSM(static_cast<uint64_t>(count[i])))
.v();
bOK = static_cast<size_t>(newStride) == newStride &&
newStride < std::numeric_limits<size_t>::max() / 2;
Expand Down Expand Up @@ -1934,9 +1934,9 @@ bool GDALAbstractMDArray::CheckReadWriteParams(
{
try
{
bOverflow = (CPLSM(static_cast<GUInt64>(arrayStartIdx[i])) +
CPLSM(static_cast<GUInt64>(count[i] - 1)) *
CPLSM(static_cast<GUInt64>(arrayStep[i])))
bOverflow = (CPLSM(static_cast<uint64_t>(arrayStartIdx[i])) +
CPLSM(static_cast<uint64_t>(count[i] - 1)) *
CPLSM(static_cast<uint64_t>(arrayStep[i])))
.v() >= dims[i]->GetSize();
}
catch (...)
Expand All @@ -1960,10 +1960,10 @@ bool GDALAbstractMDArray::CheckReadWriteParams(
{
bOverflow =
arrayStartIdx[i] <
(CPLSM(static_cast<GUInt64>(count[i] - 1)) *
(CPLSM(static_cast<uint64_t>(count[i] - 1)) *
CPLSM(arrayStep[i] == std::numeric_limits<GInt64>::min()
? (static_cast<GUInt64>(1) << 63)
: static_cast<GUInt64>(-arrayStep[i])))
? (static_cast<uint64_t>(1) << 63)
: static_cast<uint64_t>(-arrayStep[i])))
.v();
}
catch (...)
Expand Down Expand Up @@ -2002,10 +2002,10 @@ bool GDALAbstractMDArray::CheckReadWriteParams(
{
try
{
nOffset = (CPLSM(static_cast<GUInt64>(nOffset)) +
CPLSM(static_cast<GUInt64>(bufferStride[i])) *
CPLSM(static_cast<GUInt64>(count[i] - 1)) *
CPLSM(static_cast<GUInt64>(elementSize)))
nOffset = (CPLSM(static_cast<uint64_t>(nOffset)) +
CPLSM(static_cast<uint64_t>(bufferStride[i])) *
CPLSM(static_cast<uint64_t>(count[i] - 1)) *
CPLSM(static_cast<uint64_t>(elementSize)))
.v();
}
catch (...)
Expand Down Expand Up @@ -2272,8 +2272,8 @@ GUInt64 GDALAbstractMDArray::GetTotalElementsCount() const
{
try
{
nElts = (CPLSM(static_cast<GUInt64>(nElts)) *
CPLSM(static_cast<GUInt64>(dim->GetSize())))
nElts = (CPLSM(static_cast<uint64_t>(nElts)) *
CPLSM(static_cast<uint64_t>(dim->GetSize())))
.v();
}
catch (...)
Expand Down
6 changes: 0 additions & 6 deletions gcore/gdalrasterband.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4987,8 +4987,6 @@ CPLErr CPL_STDCALL GDALGetRasterStatistics(GDALRasterBandH hBand, int bApproxOK,
pdfStdDev);
}

#ifdef CPL_HAS_GINT64

/************************************************************************/
/* GDALUInt128 */
/************************************************************************/
Expand Down Expand Up @@ -6021,8 +6019,6 @@ struct ComputeStatisticsInternal<GUInt16, COMPUTE_OTHER_STATS>
// (defined(__x86_64__) || defined(_M_X64)) && (defined(__GNUC__) ||
// defined(_MSC_VER))

#endif // CPL_HAS_GINT64

/************************************************************************/
/* GetPixelValue() */
/************************************************************************/
Expand Down Expand Up @@ -6431,7 +6427,6 @@ CPLErr GDALRasterBand::ComputeStatistics(int bApproxOK, double *pdfMin,
if (nSampleRate == 1)
bApproxOK = false;

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

GByte *pabyMaskData = nullptr;
if (poMaskBand)
Expand Down
2 changes: 0 additions & 2 deletions gcore/rasterio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2067,7 +2067,6 @@ void CPL_STDCALL GDALSwapWords(void *pData, int nWordSize, int nWordCount,

case 8:
CPLAssert(nWordSkip >= 8 || nWordCount == 1);
#ifdef CPL_HAS_GINT64
if (CPL_IS_ALIGNED(pabyData, 8) && (nWordSkip % 8) == 0)
{
for (int i = 0; i < nWordCount; i++)
Expand All @@ -2078,7 +2077,6 @@ void CPL_STDCALL GDALSwapWords(void *pData, int nWordSize, int nWordCount,
}
}
else
#endif
{
for (int i = 0; i < nWordCount; i++)
{
Expand Down
18 changes: 9 additions & 9 deletions gcore/rawdataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1760,17 +1760,17 @@ bool RAWDatasetCheckMemoryUsage(int nXSize, int nYSize, int nBands, int nDTSize,
try
{
nExpectedFileSize =
(CPLSM(static_cast<GUInt64>(nHeaderSize)) +
CPLSM(static_cast<GUInt64>(nBandOffset)) *
CPLSM(static_cast<GUInt64>(nBands - 1)) +
(CPLSM(static_cast<uint64_t>(nHeaderSize)) +
CPLSM(static_cast<uint64_t>(nBandOffset)) *
CPLSM(static_cast<uint64_t>(nBands - 1)) +
(nLineOffset >= 0
? CPLSM(static_cast<GUInt64>(nYSize - 1)) *
CPLSM(static_cast<GUInt64>(nLineOffset))
: CPLSM(static_cast<GUInt64>(0))) +
? CPLSM(static_cast<uint64_t>(nYSize - 1)) *
CPLSM(static_cast<uint64_t>(nLineOffset))
: CPLSM(static_cast<uint64_t>(0))) +
(nPixelOffset >= 0
? CPLSM(static_cast<GUInt64>(nXSize - 1)) *
CPLSM(static_cast<GUInt64>(nPixelOffset))
: CPLSM(static_cast<GUInt64>(0))))
? CPLSM(static_cast<uint64_t>(nXSize - 1)) *
CPLSM(static_cast<uint64_t>(nPixelOffset))
: CPLSM(static_cast<uint64_t>(0))))
.v();
}
catch (...)
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogr_swq.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class CPL_UNSTABLE_API swq_expr_node

/* only for SNT_CONSTANT */
int is_null = false;
GIntBig int_value = 0;
int64_t int_value = 0;
double float_value = 0.0;
OGRGeometry *geometry_value = nullptr;

Expand Down
Loading
Loading