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

GDALCopyWords64(): tidy code #11254

Merged
merged 2 commits into from
Nov 12, 2024
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
24 changes: 16 additions & 8 deletions gcore/rasterio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GPtrDiff_t>(pSrcData) % nSrcDataTypeSize) != 0 ||
(reinterpret_cast<GPtrDiff_t>(pDstData) % nDstDataTypeSize) != 0 ||
((reinterpret_cast<uintptr_t>(pSrcData) % nSrcDataTypeSize) != 0 ||
(reinterpret_cast<uintptr_t>(pDstData) % nDstDataTypeSize) != 0 ||
(nSrcPixelStride % nSrcDataTypeSize) != 0 ||
(nDstPixelStride % nDstDataTypeSize) != 0))
{
Expand All @@ -3377,14 +3377,22 @@ void CPL_STDCALL GDALCopyWords64(const void *CPL_RESTRICT pSrcData,
}
else
{
#define ALIGN_PTR(ptr, align) \
((ptr) + ((align) - (reinterpret_cast<size_t>(ptr) % (align))) % (align))
const auto getAlignedPtr = [](GByte *ptr, int align)
{
return ptr +
((align - (reinterpret_cast<uintptr_t>(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,
Expand Down
2 changes: 1 addition & 1 deletion swig/csharp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}-$<CONFIG>.csproj" "${_CSHARP_PROJ}"
VERBATIM PRE_BUILD
VERBATIM
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${_CSHARP_TARGET_SUBDIR}/${_root}-$<CONFIG>.csproj"
OUTPUT ${_CSHARP_PROJ})
add_dotnet(
Expand Down
Loading