From adfa636b4bb8be4f3ed374ac4bc692e12eec3b3b Mon Sep 17 00:00:00 2001 From: Egor Zhdan Date: Fri, 23 May 2025 18:30:27 +0100 Subject: [PATCH] Make CNIOAtomics and CNIODarwin compatible with C++ interop (#3251) ### Motivation: This fixes linker errors such as ``` @nonobjc __C.catmc_nio_atomic_uint_least32_t_create_with_existing_storage(Swift.UnsafeMutablePointer<__C.catmc_nio_atomic_uint_least32_t>, Swift.UInt32) -> () in NIOAtomic.swift.o NOTE: found '_catmc_nio_atomic_uint_least32_t_create_with_existing_storage' in c-nioatomics.c.o, declaration possibly missing 'extern "C"' ``` when building with Swift/C++ interoperability enabled. ### Modifications: Wrapped the C declarations a couple of headers in `extern "C" { ... }` blocks. ### Result: The project builds successfully with Swift/C++ interop enabled. Co-authored-by: Cory Benfield --- Sources/CNIOAtomics/include/CNIOAtomics.h | 8 ++++++++ Sources/CNIODarwin/include/CNIODarwin.h | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/Sources/CNIOAtomics/include/CNIOAtomics.h b/Sources/CNIOAtomics/include/CNIOAtomics.h index 41daacb85..63efe4dc8 100644 --- a/Sources/CNIOAtomics/include/CNIOAtomics.h +++ b/Sources/CNIOAtomics/include/CNIOAtomics.h @@ -15,6 +15,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #define DECLARE_ATOMIC_OPERATIONS(type, name) \ struct catmc_atomic_ ## name; \ \ @@ -78,3 +82,7 @@ DECLARE_ATOMIC_OPERATIONS(intptr_t, intptr_t) DECLARE_ATOMIC_OPERATIONS(uintptr_t, uintptr_t) #undef DECLARE_ATOMIC_OPERATIONS + +#ifdef __cplusplus +} /* extern "C" */ +#endif diff --git a/Sources/CNIODarwin/include/CNIODarwin.h b/Sources/CNIODarwin/include/CNIODarwin.h index a4eac1152..c2599c308 100644 --- a/Sources/CNIODarwin/include/CNIODarwin.h +++ b/Sources/CNIODarwin/include/CNIODarwin.h @@ -24,6 +24,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + // Darwin platforms do not have a sendmmsg implementation available to them. This C module // provides a shim that implements sendmmsg on top of sendmsg. It also provides a shim for // recvmmsg, but does not actually implement that shim, instantly throwing errors if called. @@ -60,5 +64,9 @@ extern const unsigned long CNIODarwin_IOCTL_VM_SOCKETS_GET_LOCAL_CID; const char* CNIODarwin_dirent_dname(struct dirent* ent); +#ifdef __cplusplus +} /* extern "C" */ +#endif + #endif // __APPLE__ #endif // C_NIO_DARWIN_H