From 74ab31b7f70bc34be5e5fb00a378166e72cd29bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Thu, 11 Apr 2019 18:01:04 +0200 Subject: [PATCH] vhacd: Fix -fpermissive build issue with MinGW Fixes #27926. --- thirdparty/vhacd/0002-fpermissive-fix.patch | 53 +++++++++++++++++++++ thirdparty/vhacd/inc/btScalar.h | 23 +++++++++ thirdparty/vhacd/src/btAlignedAllocator.cpp | 8 +++- 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 thirdparty/vhacd/0002-fpermissive-fix.patch diff --git a/thirdparty/vhacd/0002-fpermissive-fix.patch b/thirdparty/vhacd/0002-fpermissive-fix.patch new file mode 100644 index 00000000000..965df2944ab --- /dev/null +++ b/thirdparty/vhacd/0002-fpermissive-fix.patch @@ -0,0 +1,53 @@ +diff --git a/thirdparty/vhacd/inc/btScalar.h b/thirdparty/vhacd/inc/btScalar.h +index 487205062..52297cd78 100644 +--- a/thirdparty/vhacd/inc/btScalar.h ++++ b/thirdparty/vhacd/inc/btScalar.h +@@ -535,6 +535,29 @@ struct btTypedObject { + } + }; + ++// -- GODOT start -- ++// Cherry-picked from Bullet 2.88 to fix GH-27926 ++///align a pointer to the provided alignment, upwards ++template ++T *btAlignPointer(T *unalignedPtr, size_t alignment) ++{ ++ struct btConvertPointerSizeT ++ { ++ union { ++ T *ptr; ++ size_t integer; ++ }; ++ }; ++ btConvertPointerSizeT converter; ++ ++ const size_t bit_mask = ~(alignment - 1); ++ converter.ptr = unalignedPtr; ++ converter.integer += alignment - 1; ++ converter.integer &= bit_mask; ++ return converter.ptr; ++} ++// -- GODOT end -- ++ + // -- GODOT start -- + }; // namespace VHACD + // -- GODOT end -- +diff --git a/thirdparty/vhacd/src/btAlignedAllocator.cpp b/thirdparty/vhacd/src/btAlignedAllocator.cpp +index ce0e7f26f..8dee31e7e 100644 +--- a/thirdparty/vhacd/src/btAlignedAllocator.cpp ++++ b/thirdparty/vhacd/src/btAlignedAllocator.cpp +@@ -72,8 +72,12 @@ static inline void* btAlignedAllocDefault(size_t size, int32_t alignment) + + real = (char*)sAllocFunc(size + sizeof(void*) + (alignment - 1)); + if (real) { +- offset = (alignment - (unsigned long)(real + sizeof(void*))) & (alignment - 1); +- ret = (void*)((real + sizeof(void*)) + offset); ++ // -- GODOT start -- ++ // Synced with Bullet 2.88 to fix GH-27926 ++ //offset = (alignment - (unsigned long)(real + sizeof(void*))) & (alignment - 1); ++ //ret = (void*)((real + sizeof(void*)) + offset); ++ ret = btAlignPointer(real + sizeof(void *), alignment); ++ // -- GODOT end -- + *((void**)(ret)-1) = (void*)(real); + } + else { diff --git a/thirdparty/vhacd/inc/btScalar.h b/thirdparty/vhacd/inc/btScalar.h index 617fd7c44f5..3999a71521e 100644 --- a/thirdparty/vhacd/inc/btScalar.h +++ b/thirdparty/vhacd/inc/btScalar.h @@ -543,6 +543,29 @@ struct btTypedObject { } }; +// -- GODOT start -- +// Cherry-picked from Bullet 2.88 to fix GH-27926 +///align a pointer to the provided alignment, upwards +template +T *btAlignPointer(T *unalignedPtr, size_t alignment) +{ + struct btConvertPointerSizeT + { + union { + T *ptr; + size_t integer; + }; + }; + btConvertPointerSizeT converter; + + const size_t bit_mask = ~(alignment - 1); + converter.ptr = unalignedPtr; + converter.integer += alignment - 1; + converter.integer &= bit_mask; + return converter.ptr; +} +// -- GODOT end -- + // -- GODOT start -- }; // namespace VHACD // -- GODOT end -- diff --git a/thirdparty/vhacd/src/btAlignedAllocator.cpp b/thirdparty/vhacd/src/btAlignedAllocator.cpp index ce0e7f26f95..8dee31e7e36 100644 --- a/thirdparty/vhacd/src/btAlignedAllocator.cpp +++ b/thirdparty/vhacd/src/btAlignedAllocator.cpp @@ -72,8 +72,12 @@ static inline void* btAlignedAllocDefault(size_t size, int32_t alignment) real = (char*)sAllocFunc(size + sizeof(void*) + (alignment - 1)); if (real) { - offset = (alignment - (unsigned long)(real + sizeof(void*))) & (alignment - 1); - ret = (void*)((real + sizeof(void*)) + offset); + // -- GODOT start -- + // Synced with Bullet 2.88 to fix GH-27926 + //offset = (alignment - (unsigned long)(real + sizeof(void*))) & (alignment - 1); + //ret = (void*)((real + sizeof(void*)) + offset); + ret = btAlignPointer(real + sizeof(void *), alignment); + // -- GODOT end -- *((void**)(ret)-1) = (void*)(real); } else {