Skip to content

Commit adfa636

Browse files
egorzhdanLukasa
andauthored
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 <[email protected]>
1 parent b23163d commit adfa636

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Sources/CNIOAtomics/include/CNIOAtomics.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include <stdbool.h>
1616
#include <stdint.h>
1717

18+
#ifdef __cplusplus
19+
extern "C" {
20+
#endif
21+
1822
#define DECLARE_ATOMIC_OPERATIONS(type, name) \
1923
struct catmc_atomic_ ## name; \
2024
\
@@ -78,3 +82,7 @@ DECLARE_ATOMIC_OPERATIONS(intptr_t, intptr_t)
7882
DECLARE_ATOMIC_OPERATIONS(uintptr_t, uintptr_t)
7983

8084
#undef DECLARE_ATOMIC_OPERATIONS
85+
86+
#ifdef __cplusplus
87+
} /* extern "C" */
88+
#endif

Sources/CNIODarwin/include/CNIODarwin.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#include <sys/stat.h>
2525
#include <fts.h>
2626

27+
#ifdef __cplusplus
28+
extern "C" {
29+
#endif
30+
2731
// Darwin platforms do not have a sendmmsg implementation available to them. This C module
2832
// provides a shim that implements sendmmsg on top of sendmsg. It also provides a shim for
2933
// 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;
6064

6165
const char* CNIODarwin_dirent_dname(struct dirent* ent);
6266

67+
#ifdef __cplusplus
68+
} /* extern "C" */
69+
#endif
70+
6371
#endif // __APPLE__
6472
#endif // C_NIO_DARWIN_H

0 commit comments

Comments
 (0)