Skip to content

Commit

Permalink
Fix compiler error in CoreFoundation when building in C++ mode (#5081)
Browse files Browse the repository at this point in the history
`__CFAllocatorRespectsHintZeroWhenAllocating` has two declarations in different headers: `ForFoundationOnly.h` and `ForSwiftFoundationOnly.h`. One of the declarations was under `extern "C"` block, the other one wasn't. Clang accepts this in C language mode, but it is a hard compiler error in C++ language mode due to a linkage mismatch.

This was blocking clients from using CoreFoundation in Swift projects that enable C++ interoperability.

This change makes sure that both declarations of `__CFAllocatorRespectsHintZeroWhenAllocating` are under `extern "C"` blocks.
  • Loading branch information
egorzhdan authored Sep 3, 2024
1 parent ef225c7 commit c820f72
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/CoreFoundation/include/ForFoundationOnly.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ CF_IMPLICIT_BRIDGING_DISABLED
#include <mach/mach_time.h>
#endif

_CF_EXPORT_SCOPE_BEGIN

#if __BLOCKS__
/* These functions implement standard error handling for reallocation. Their parameters match their unsafe variants (realloc/CFAllocatorReallocate). They differ from reallocf as they provide a chance for you to clean up a buffers contents (in addition to freeing the buffer, etc.)
Expand All @@ -69,10 +71,13 @@ CF_EXPORT void *_Nonnull __CFSafelyReallocateWithAllocator(CFAllocatorRef _Nulla
#endif

Boolean __CFAllocatorRespectsHintZeroWhenAllocating(CFAllocatorRef _Nullable allocator);

typedef CF_ENUM(CFOptionFlags, _CFAllocatorHint) {
_CFAllocatorHintZeroWhenAllocating = 1
};

_CF_EXPORT_SCOPE_END

#define NSISARGTYPE void * _Nullable

#pragma mark - CFBundle
Expand Down

0 comments on commit c820f72

Please sign in to comment.