From 9c18b70ca48ceb779ca60de8a588272fd7b0933c Mon Sep 17 00:00:00 2001 From: erlingrj Date: Tue, 14 May 2024 11:09:59 +0200 Subject: [PATCH] Trace plugin returns pointer to struct, not struct. This avoids a c-linkage warning for CCpp+clang --- core/reactor_common.c | 20 ++++++++++---------- trace/api/trace.h | 10 +++++++++- trace/impl/src/trace_impl.c | 27 ++++++++++++--------------- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/core/reactor_common.c b/core/reactor_common.c index b3f1d7b4d..dd348a52a 100644 --- a/core/reactor_common.c +++ b/core/reactor_common.c @@ -1038,26 +1038,26 @@ int process_args(int argc, const char* argv[]) { * core runtime. */ #ifdef LF_TRACE -static void check_version(version_t version) { +static void check_version(const version_t* version) { #ifdef LF_SINGLE_THREADED - LF_ASSERT(version.build_config.single_threaded == TRIBOOL_TRUE || - version.build_config.single_threaded == TRIBOOL_DOES_NOT_MATTER, + LF_ASSERT(version->build_config.single_threaded == TRIBOOL_TRUE || + version->build_config.single_threaded == TRIBOOL_DOES_NOT_MATTER, "expected single-threaded version"); #else - LF_ASSERT(version.build_config.single_threaded == TRIBOOL_FALSE || - version.build_config.single_threaded == TRIBOOL_DOES_NOT_MATTER, + LF_ASSERT(version->build_config.single_threaded == TRIBOOL_FALSE || + version->build_config.single_threaded == TRIBOOL_DOES_NOT_MATTER, "expected multi-threaded version"); #endif #ifdef NDEBUG - LF_ASSERT(version.build_config.build_type_is_debug == TRIBOOL_FALSE || - version.build_config.build_type_is_debug == TRIBOOL_DOES_NOT_MATTER, + LF_ASSERT(version->build_config.build_type_is_debug == TRIBOOL_FALSE || + version->build_config.build_type_is_debug == TRIBOOL_DOES_NOT_MATTER, "expected release version"); #else - LF_ASSERT(version.build_config.build_type_is_debug == TRIBOOL_TRUE || - version.build_config.build_type_is_debug == TRIBOOL_DOES_NOT_MATTER, + LF_ASSERT(version->build_config.build_type_is_debug == TRIBOOL_TRUE || + version->build_config.build_type_is_debug == TRIBOOL_DOES_NOT_MATTER, "expected debug version"); #endif - LF_ASSERT(version.build_config.log_level == LOG_LEVEL || version.build_config.log_level == INT_MAX, + LF_ASSERT(version->build_config.log_level == LOG_LEVEL || version->build_config.log_level == INT_MAX, "expected log level %d", LOG_LEVEL); // assert(!version.core_version_name || strcmp(version.core_version_name, CORE_SHA) == 0); // TODO: provide CORE_SHA } diff --git a/trace/api/trace.h b/trace/api/trace.h index e3955bcca..e5223c036 100644 --- a/trace/api/trace.h +++ b/trace/api/trace.h @@ -1,6 +1,10 @@ #ifndef TRACE_H #define TRACE_H +#ifdef __cplusplus +extern "C" { +#endif + #include #include @@ -10,7 +14,7 @@ * @brief Return a description of the compile-time properties of the current * plugin. */ -version_t lf_version_tracing(); +const version_t* lf_version_tracing(); /** * Identifier for what is in the object table. @@ -82,4 +86,8 @@ void lf_tracing_tracepoint(int worker, trace_record_nodeps_t* tr); */ void lf_tracing_global_shutdown(); +#ifdef __cplusplus +} +#endif + #endif // TRACE_H diff --git a/trace/impl/src/trace_impl.c b/trace/impl/src/trace_impl.c index fa78b3ffa..895247e87 100644 --- a/trace/impl/src/trace_impl.c +++ b/trace/impl/src/trace_impl.c @@ -24,6 +24,17 @@ static lf_platform_mutex_ptr_t trace_mutex; static trace_t trace; static int process_id; static int64_t start_time; +static version_t version = {.build_config = + { + .single_threaded = TRIBOOL_DOES_NOT_MATTER, +#ifdef NDEBUG + .build_type_is_debug = TRIBOOL_FALSE, +#else + .build_type_is_debug = TRIBOOL_TRUE, +#endif + .log_level = LOG_LEVEL, + }, + .core_version_name = NULL}; // PRIVATE HELPERS *********************************************************** @@ -192,21 +203,7 @@ static void stop_trace(trace_t* trace) { // IMPLEMENTATION OF VERSION API ********************************************* -version_t lf_version_tracing() { - return (version_t){ - .build_config = - (build_config_t){ - .single_threaded = TRIBOOL_DOES_NOT_MATTER, -#ifdef NDEBUG - .build_type_is_debug = TRIBOOL_FALSE, -#else - .build_type_is_debug = TRIBOOL_TRUE, -#endif - .log_level = LOG_LEVEL, - }, - .core_version_name = NULL, - }; -} +const version_t* lf_version_tracing() { return &version; } // IMPLEMENTATION OF TRACE API ***********************************************