From fce0166f410c4398c5f762948ac7b65419a6a580 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 12 Nov 2024 22:02:22 +0100 Subject: [PATCH 1/2] CMake: fix swig/csharp/CMakeLists.txt compatibility with CMake 3.31 that no longer accept invalid PRE_BUILD keyword in OUTPUT form of add_custom_command() per https://cmake.org/cmake/help/latest/policy/CMP0175.html Should fix error of https://github.com/OSGeo/gdal/actions/runs/11805369849/job/32887659405?pr=11254 --- swig/csharp/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swig/csharp/CMakeLists.txt b/swig/csharp/CMakeLists.txt index ea9c5bb985d7..b0b861eebabd 100644 --- a/swig/csharp/CMakeLists.txt +++ b/swig/csharp/CMakeLists.txt @@ -237,7 +237,7 @@ function (gdal_csharp_dll) add_custom_command( COMMAND ${CMAKE_COMMAND} -E "copy_if_different" "${CMAKE_CURRENT_BINARY_DIR}/${_CSHARP_TARGET_SUBDIR}/${_root}-$.csproj" "${_CSHARP_PROJ}" - VERBATIM PRE_BUILD + VERBATIM DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_CSHARP_TARGET_SUBDIR}/${_root}-$.csproj" OUTPUT ${_CSHARP_PROJ}) add_dotnet( From 2ce3df2e0b34a6fe215fc6e49e1a158c1954d8c9 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 12 Nov 2024 21:38:24 +0100 Subject: [PATCH 2/2] GDALCopyWords64(): tidy code Technically it is safer to cast a pointer to uintptr_t than our custom type. At least, it better documents the intent. In practice, I doubt this changes much. --- gcore/rasterio.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/gcore/rasterio.cpp b/gcore/rasterio.cpp index c46df08b9b88..2bc36f23f9f7 100644 --- a/gcore/rasterio.cpp +++ b/gcore/rasterio.cpp @@ -3360,8 +3360,8 @@ void CPL_STDCALL GDALCopyWords64(const void *CPL_RESTRICT pSrcData, assert(nSrcDataTypeSize != 0); assert(nDstDataTypeSize != 0); if (!(eSrcType == eDstType && nSrcPixelStride == nDstPixelStride) && - ((reinterpret_cast(pSrcData) % nSrcDataTypeSize) != 0 || - (reinterpret_cast(pDstData) % nDstDataTypeSize) != 0 || + ((reinterpret_cast(pSrcData) % nSrcDataTypeSize) != 0 || + (reinterpret_cast(pDstData) % nDstDataTypeSize) != 0 || (nSrcPixelStride % nSrcDataTypeSize) != 0 || (nDstPixelStride % nDstDataTypeSize) != 0)) { @@ -3377,14 +3377,22 @@ void CPL_STDCALL GDALCopyWords64(const void *CPL_RESTRICT pSrcData, } else { -#define ALIGN_PTR(ptr, align) \ - ((ptr) + ((align) - (reinterpret_cast(ptr) % (align))) % (align)) + const auto getAlignedPtr = [](GByte *ptr, int align) + { + return ptr + + ((align - (reinterpret_cast(ptr) % align)) % + align); + }; + // The largest we need is for CFloat64 (16 bytes), so 32 bytes to // be sure to get correctly aligned pointer. - GByte abySrcBuffer[32]; - GByte abyDstBuffer[32]; - GByte *pabySrcBuffer = ALIGN_PTR(abySrcBuffer, nSrcDataTypeSize); - GByte *pabyDstBuffer = ALIGN_PTR(abyDstBuffer, nDstDataTypeSize); + constexpr size_t SIZEOF_CFLOAT64 = 2 * sizeof(double); + GByte abySrcBuffer[2 * SIZEOF_CFLOAT64]; + GByte abyDstBuffer[2 * SIZEOF_CFLOAT64]; + GByte *pabySrcBuffer = + getAlignedPtr(abySrcBuffer, nSrcDataTypeSize); + GByte *pabyDstBuffer = + getAlignedPtr(abyDstBuffer, nDstDataTypeSize); for (decltype(nWordCount) i = 0; i < nWordCount; i++) { memcpy(pabySrcBuffer,