Skip to content

Commit ff1195a

Browse files
committed
allocator: ensure only one non-lazy instance of allocate/deallocate exists
This fixes a bunch of link-time warnings with Apple Clang. Signed-off-by: Steven Noonan <[email protected]>
1 parent 83a484f commit ff1195a

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/allocator.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// This file is part of meshoptimizer library; see meshoptimizer.h for version/license details
22
#include "meshoptimizer.h"
33

4+
meshopt_alloc_t meshopt_Allocator::Storage::allocate = operator new;
5+
meshopt_dealloc_t meshopt_Allocator::Storage::deallocate = operator delete;
6+
47
void meshopt_setAllocator(void* (MESHOPTIMIZER_ALLOC_CALLCONV* allocate)(size_t), void (MESHOPTIMIZER_ALLOC_CALLCONV* deallocate)(void*))
58
{
69
meshopt_Allocator::Storage::allocate = allocate;

src/meshoptimizer.h

+6-12
Original file line numberDiff line numberDiff line change
@@ -813,18 +813,18 @@ inline int meshopt_quantizeSnorm(float v, int N)
813813

814814
/* Internal implementation helpers */
815815
#ifdef __cplusplus
816+
typedef void* (MESHOPTIMIZER_ALLOC_CALLCONV *meshopt_alloc_t)(size_t);
817+
typedef void (MESHOPTIMIZER_ALLOC_CALLCONV *meshopt_dealloc_t)(void*);
818+
816819
class meshopt_Allocator
817820
{
818821
public:
819-
template <typename T>
820-
struct StorageT
822+
struct Storage
821823
{
822-
static void* (MESHOPTIMIZER_ALLOC_CALLCONV* allocate)(size_t);
823-
static void (MESHOPTIMIZER_ALLOC_CALLCONV* deallocate)(void*);
824+
static meshopt_alloc_t allocate;
825+
static meshopt_dealloc_t deallocate;
824826
};
825827

826-
typedef StorageT<void> Storage;
827-
828828
meshopt_Allocator()
829829
: blocks()
830830
, count(0)
@@ -857,12 +857,6 @@ class meshopt_Allocator
857857
void* blocks[24];
858858
size_t count;
859859
};
860-
861-
// This makes sure that allocate/deallocate are lazily generated in translation units that need them and are deduplicated by the linker
862-
template <typename T>
863-
void* (MESHOPTIMIZER_ALLOC_CALLCONV* meshopt_Allocator::StorageT<T>::allocate)(size_t) = operator new;
864-
template <typename T>
865-
void (MESHOPTIMIZER_ALLOC_CALLCONV* meshopt_Allocator::StorageT<T>::deallocate)(void*) = operator delete;
866860
#endif
867861

868862
/* Inline implementation for C++ templated wrappers */

0 commit comments

Comments
 (0)