[llvm] [orc-rt] Wrap C API implementation in `extern "C" {..}` blocks (PR #222846)
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 22:51:55 PDT 2026
https://github.com/lhames created https://github.com/llvm/llvm-project/pull/222846
Adopt a consistent style for C API implementation: A banner comment and an `extern "C" { ... }` block around the definitions.
>From 42b138d6b5cf632ba9aceac3be9d89c80a88138c Mon Sep 17 00:00:00 2001
From: Lang Hames <lhames at apple.com>
Date: Fri, 11 Sep 2026 15:48:34 +1000
Subject: [PATCH] [orc-rt] Wrap C API implementation in `extern "C" {..}`
blocks
Adopt a consistent style for C API implementation: A banner comment and
an `extern "C" { ... }` block around the definitions.
---
orc-rt/lib/bedrock/Session.cpp | 13 +++++++++----
orc-rt/lib/support/Error.cpp | 24 +++++++++++++-----------
orc-rt/lib/support/Logging.cpp | 6 ++++++
orc-rt/lib/support/Logging_oslog.cpp | 9 +++++++--
orc-rt/lib/support/Logging_printf.cpp | 11 ++++++++---
5 files changed, 43 insertions(+), 20 deletions(-)
diff --git a/orc-rt/lib/bedrock/Session.cpp b/orc-rt/lib/bedrock/Session.cpp
index 9dd00ec3cc516..4f58964289c87 100644
--- a/orc-rt/lib/bedrock/Session.cpp
+++ b/orc-rt/lib/bedrock/Session.cpp
@@ -431,10 +431,13 @@ void Session::wrapperReturn(orc_rt_SessionRef S,
// --- C API Implementation ---
-extern "C" void orc_rt_Session_callController(
- orc_rt_SessionRef S, orc_rt_ControllerHandlerTag T,
- orc_rt_WrapperFunctionBuffer ArgBytes,
- orc_rt_Session_CallControllerReturn Return, void *ReturnCtx) {
+extern "C" {
+
+void orc_rt_Session_callController(orc_rt_SessionRef S,
+ orc_rt_ControllerHandlerTag T,
+ orc_rt_WrapperFunctionBuffer ArgBytes,
+ orc_rt_Session_CallControllerReturn Return,
+ void *ReturnCtx) {
unwrap(S)->callController(
[S, Return, ReturnCtx](WrapperFunctionBuffer ResultBytes) {
Return(S, ResultBytes.release(), ReturnCtx);
@@ -442,4 +445,6 @@ extern "C" void orc_rt_Session_callController(
T, WrapperFunctionBuffer(ArgBytes));
}
+} // extern "C"
+
} // namespace orc_rt
diff --git a/orc-rt/lib/support/Error.cpp b/orc-rt/lib/support/Error.cpp
index 49566e1e2238f..0c246d2fc5769 100644
--- a/orc-rt/lib/support/Error.cpp
+++ b/orc-rt/lib/support/Error.cpp
@@ -48,35 +48,37 @@ std::string ExceptionError::toString() const noexcept {
#endif // ORC_RT_ENABLE_EXCEPTIONS
-extern "C" orc_rt_Error_TypeId
-orc_rt_Error_getTypeId(orc_rt_ErrorRef Err) noexcept {
+// --- C API Implementation ---
+
+extern "C" {
+
+orc_rt_Error_TypeId orc_rt_Error_getTypeId(orc_rt_ErrorRef Err) noexcept {
assert(Err && "Err must not be null");
return reinterpret_cast<ErrorInfoBase *>(Err)->dynamicClassID();
}
-extern "C" void orc_rt_Error_consume(orc_rt_ErrorRef Err) noexcept {
+void orc_rt_Error_consume(orc_rt_ErrorRef Err) noexcept {
consumeError(unwrap(Err));
}
-extern "C" void orc_rt_Error_cantFail(orc_rt_ErrorRef Err) noexcept {
+void orc_rt_Error_cantFail(orc_rt_ErrorRef Err) noexcept {
cantFail(unwrap(Err));
}
-extern "C" char *orc_rt_Error_toString(orc_rt_ErrorRef Err) noexcept {
+char *orc_rt_Error_toString(orc_rt_ErrorRef Err) noexcept {
return strdup(toString(unwrap(Err)).c_str());
}
-extern "C" void orc_rt_Error_freeErrorMessage(char *ErrMsg) noexcept {
- free(ErrMsg);
-}
+void orc_rt_Error_freeErrorMessage(char *ErrMsg) noexcept { free(ErrMsg); }
-extern "C" orc_rt_Error_TypeId orc_rt_StringError_getTypeId(void) noexcept {
+orc_rt_Error_TypeId orc_rt_StringError_getTypeId(void) noexcept {
return StringError::classID();
}
-extern "C" orc_rt_ErrorRef
-orc_rt_StringError_create(const char *ErrMsg) noexcept {
+orc_rt_ErrorRef orc_rt_StringError_create(const char *ErrMsg) noexcept {
return wrap(make_error<StringError>(ErrMsg));
}
+} // extern "C"
+
} // namespace orc_rt
diff --git a/orc-rt/lib/support/Logging.cpp b/orc-rt/lib/support/Logging.cpp
index d019dae7b576e..1141c034a3e01 100644
--- a/orc-rt/lib/support/Logging.cpp
+++ b/orc-rt/lib/support/Logging.cpp
@@ -27,6 +27,10 @@ static const char *LevelNames[] = {
static_assert(std::size(LevelNames) == ORC_RT_LOG_LEVEL_COUNT,
"LevelNames array is the wrong size");
+// --- C API Implementation ---
+
+extern "C" {
+
const char *orc_rt_log_Category_getName(orc_rt_log_Category Cat) noexcept {
if (Cat < 0 || Cat >= orc_rt_log_Category_Count)
return nullptr;
@@ -60,3 +64,5 @@ orc_rt_log_Level orc_rt_log_Level_parse(const char *Str) noexcept {
return -1;
}
+
+} // extern "C"
diff --git a/orc-rt/lib/support/Logging_oslog.cpp b/orc-rt/lib/support/Logging_oslog.cpp
index 05f6ad85bf859..aaacf6c45806f 100644
--- a/orc-rt/lib/support/Logging_oslog.cpp
+++ b/orc-rt/lib/support/Logging_oslog.cpp
@@ -20,12 +20,15 @@
#include <os/log.h>
+// --- C API Implementation ---
+
+extern "C" {
+
// Cache for the inline accessor (declared in Logging.h). Zero-initialized, so
// no static constructor runs; slots are filled lazily by the cold path below.
os_log_t orc_rt_log_OSLogHandles[orc_rt_log_Category_Count];
-extern "C" os_log_t
-orc_rt_log_osLogHandleSlow(orc_rt_log_Category Category) noexcept {
+os_log_t orc_rt_log_osLogHandleSlow(orc_rt_log_Category Category) noexcept {
// Category is already range-checked by the inline caller.
//
// ORC rt logs to the "org.llvm.orc-rt" subsystem.
@@ -43,3 +46,5 @@ orc_rt_log_osLogHandleSlow(orc_rt_log_Category Category) noexcept {
__ATOMIC_RELEASE);
return Handle;
}
+
+} // extern "C"
diff --git a/orc-rt/lib/support/Logging_printf.cpp b/orc-rt/lib/support/Logging_printf.cpp
index 17c455fa4da7d..5042571f4e712 100644
--- a/orc-rt/lib/support/Logging_printf.cpp
+++ b/orc-rt/lib/support/Logging_printf.cpp
@@ -85,9 +85,12 @@ constexpr size_t LogBufferSize = 1024;
} // namespace
-extern "C" void orc_rt_log_printf(orc_rt_log_Level Level,
- orc_rt_log_Category Category, const char *Fmt,
- ...) noexcept {
+// --- C API Implementation ---
+
+extern "C" {
+
+void orc_rt_log_printf(orc_rt_log_Level Level, orc_rt_log_Category Category,
+ const char *Fmt, ...) noexcept {
if (Level < runtimeLevel())
return;
@@ -120,3 +123,5 @@ extern "C" void orc_rt_log_printf(orc_rt_log_Level Level,
// written atomically with respect to other threads logging to the same sink.
std::fwrite(Buf, 1, Len, sink());
}
+
+} // extern "C"
More information about the llvm-commits
mailing list