Skip to content

Commit 4961c97

Browse files
jckingcopybara-github
authored andcommitted
Fix declaration of free_sized and/or free_aligned_sized to be compatible with glibc
PiperOrigin-RevId: 770797067 Change-Id: I86bcf594fd03220c1373a42a13684519daefdfdc
1 parent 0d1ce94 commit 4961c97

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

tcmalloc/libc_override.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ extern "C" {
166166
void* malloc(size_t size) TCMALLOC_NOTHROW
167167
TCMALLOC_ALIAS(TCMallocInternalMalloc);
168168
void free(void* ptr) TCMALLOC_NOTHROW TCMALLOC_ALIAS(TCMallocInternalFree);
169-
void free_sized(void* ptr, size_t size)
169+
void free_sized(void* ptr, size_t size) TCMALLOC_NOTHROW
170170
TCMALLOC_ALIAS(TCMallocInternalFreeSized);
171-
void free_aligned_sized(void* ptr, size_t align, size_t size)
171+
void free_aligned_sized(void* ptr, size_t align, size_t size) TCMALLOC_NOTHROW
172172
TCMALLOC_ALIAS(TCMallocInternalFreeAlignedSized);
173173
void sdallocx(void* ptr, size_t size, int flags) noexcept
174174
TCMALLOC_ALIAS(TCMallocInternalSdallocx);

tcmalloc/malloc_extension.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,13 @@ ABSL_ATTRIBUTE_WEAK ABSL_ATTRIBUTE_NOINLINE void sdallocx(void* ptr, size_t,
802802
free(ptr);
803803
}
804804

805-
ABSL_ATTRIBUTE_WEAK ABSL_ATTRIBUTE_NOINLINE void free_sized(void* ptr, size_t) {
805+
ABSL_ATTRIBUTE_WEAK ABSL_ATTRIBUTE_NOINLINE void free_sized(void* ptr, size_t)
806+
TCMALLOC_FREE_SIZED_NOEXCEPT {
806807
free(ptr);
807808
}
808809

809-
ABSL_ATTRIBUTE_WEAK ABSL_ATTRIBUTE_NOINLINE void free_aligned_sized(void* ptr,
810-
size_t,
811-
size_t) {
810+
ABSL_ATTRIBUTE_WEAK ABSL_ATTRIBUTE_NOINLINE void free_aligned_sized(
811+
void* ptr, size_t, size_t) TCMALLOC_FREE_SIZED_NOEXCEPT {
812812
free(ptr);
813813
}
814814

tcmalloc/malloc_extension.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,13 +706,20 @@ extern "C" [[nodiscard]] size_t nallocx(size_t size, int flags) noexcept;
706706
// uses the size to improve deallocation performance.
707707
extern "C" void sdallocx(void* ptr, size_t size, int flags) noexcept;
708708

709+
#if defined(__GLIBC__)
710+
#define TCMALLOC_FREE_SIZED_NOEXCEPT noexcept
711+
#else
712+
#define TCMALLOC_FREE_SIZED_NOEXCEPT
713+
#endif
714+
709715
#if !defined(__STDC_VERSION_STDLIB_H__) || __STDC_VERSION_STDLIB_H__ < 202311L
710716
// Frees ptr allocated with malloc(size) introduced in C23.
711-
extern "C" void free_sized(void* ptr, size_t size);
717+
extern "C" void free_sized(void* ptr, size_t size) TCMALLOC_FREE_SIZED_NOEXCEPT;
712718

713719
// Frees ptr allocated with aligned_alloc/posix_memalign with the specified size
714720
// and alignment introduced in C23.
715-
extern "C" void free_aligned_sized(void* ptr, size_t alignment, size_t size);
721+
extern "C" void free_aligned_sized(void* ptr, size_t alignment,
722+
size_t size) TCMALLOC_FREE_SIZED_NOEXCEPT;
716723
#endif
717724

718725
// Define __sized_ptr_t in the global namespace so that it can be named by the

0 commit comments

Comments
 (0)