Skip to content

Commit 1de42be

Browse files
committed
Improve .clang-format setup
This change fixes a few idiosyncrasies in clang-format integration: - extern/ code should not be formatted - All other code, including meshoptimizer.h/gltfpack.h, should be - Fix indentation issues because of extern "C" block - Work around clang-format bug wrt calling convention qualifiers
1 parent b9e9f54 commit 1de42be

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

.clang-format

+2
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ BreakConstructorInitializersBeforeComma: true
1111
NamespaceIndentation: None
1212
AlignEscapedNewlines: DontAlign
1313
AlignAfterOpenBracket: DontAlign
14+
IndentExternBlock: NoIndent
15+
Macros: [MESHOPTIMIZER_ALLOC_CALLCONV=&_&]

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ nanite: $(DEMO)
123123
$(DEMO) -n $(files)
124124

125125
format:
126-
clang-format -i $(LIBRARY_SOURCES) $(DEMO_SOURCES) $(GLTFPACK_SOURCES)
126+
clang-format -i src/*.h src/*.cpp demo/*.cpp gltf/*.h gltf/*.cpp
127127

128128
formatjs:
129129
prettier -w js/*.js gltf/*.js demo/*.html js/*.ts

extern/.clang-format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DisableFormat: true

src/allocator.cpp

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

4-
void meshopt_setAllocator(void*(MESHOPTIMIZER_ALLOC_CALLCONV* allocate)(size_t), void(MESHOPTIMIZER_ALLOC_CALLCONV* deallocate)(void*))
4+
void meshopt_setAllocator(void* (MESHOPTIMIZER_ALLOC_CALLCONV* allocate)(size_t), void (MESHOPTIMIZER_ALLOC_CALLCONV* deallocate)(void*))
55
{
66
meshopt_Allocator::Storage::allocate = allocate;
77
meshopt_Allocator::Storage::deallocate = deallocate;

src/meshoptimizer.h

+7-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535

3636
/* C interface */
3737
#ifdef __cplusplus
38-
extern "C" {
38+
extern "C"
39+
{
3940
#endif
4041

4142
/**
@@ -601,7 +602,7 @@ MESHOPTIMIZER_EXPERIMENTAL void meshopt_spatialSortTriangles(unsigned int* desti
601602
* Note that all algorithms only allocate memory for temporary use.
602603
* allocate/deallocate are always called in a stack-like order - last pointer to be allocated is deallocated first.
603604
*/
604-
MESHOPTIMIZER_API void meshopt_setAllocator(void* (MESHOPTIMIZER_ALLOC_CALLCONV *allocate)(size_t), void (MESHOPTIMIZER_ALLOC_CALLCONV *deallocate)(void*));
605+
MESHOPTIMIZER_API void meshopt_setAllocator(void* (MESHOPTIMIZER_ALLOC_CALLCONV* allocate)(size_t), void (MESHOPTIMIZER_ALLOC_CALLCONV* deallocate)(void*));
605606

606607
#ifdef __cplusplus
607608
} /* extern "C" */
@@ -749,8 +750,8 @@ class meshopt_Allocator
749750
template <typename T>
750751
struct StorageT
751752
{
752-
static void* (MESHOPTIMIZER_ALLOC_CALLCONV *allocate)(size_t);
753-
static void (MESHOPTIMIZER_ALLOC_CALLCONV *deallocate)(void*);
753+
static void* (MESHOPTIMIZER_ALLOC_CALLCONV* allocate)(size_t);
754+
static void (MESHOPTIMIZER_ALLOC_CALLCONV* deallocate)(void*);
754755
};
755756

756757
typedef StorageT<void> Storage;
@@ -790,9 +791,9 @@ class meshopt_Allocator
790791

791792
// This makes sure that allocate/deallocate are lazily generated in translation units that need them and are deduplicated by the linker
792793
template <typename T>
793-
void* (MESHOPTIMIZER_ALLOC_CALLCONV *meshopt_Allocator::StorageT<T>::allocate)(size_t) = operator new;
794+
void* (MESHOPTIMIZER_ALLOC_CALLCONV* meshopt_Allocator::StorageT<T>::allocate)(size_t) = operator new;
794795
template <typename T>
795-
void (MESHOPTIMIZER_ALLOC_CALLCONV *meshopt_Allocator::StorageT<T>::deallocate)(void*) = operator delete;
796+
void (MESHOPTIMIZER_ALLOC_CALLCONV* meshopt_Allocator::StorageT<T>::deallocate)(void*) = operator delete;
796797
#endif
797798

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

0 commit comments

Comments
 (0)