diff options
author | David Robillard <d@drobilla.net> | 2019-04-13 20:21:40 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-04-13 20:21:40 +0200 |
commit | 4de972d203f804dd5b1ae5c82ca01359f7d285a6 (patch) | |
tree | 1912a58e979a7d17500a0223b514fb802475e54c | |
parent | 72b0caa0ca029b83a5a1ad87d9035faea7897c72 (diff) | |
download | serd-remove-message.tar.gz serd-remove-message.tar.bz2 serd-remove-message.zip |
WIP: Remove SerdMessageremove-message
-rw-r--r-- | .clang-tidy | 2 | ||||
-rw-r--r-- | serd/serd.h | 26 | ||||
-rw-r--r-- | serd/serd.hpp | 48 | ||||
-rw-r--r-- | src/reader.c | 10 | ||||
-rw-r--r-- | src/serdi.c | 14 | ||||
-rw-r--r-- | src/validate.c | 11 | ||||
-rw-r--r-- | src/world.c | 29 | ||||
-rw-r--r-- | tests/model_test.c | 24 |
8 files changed, 100 insertions, 64 deletions
diff --git a/.clang-tidy b/.clang-tidy index 4bc595ff..e7d1d72e 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -9,7 +9,6 @@ Checks: > -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-pointer-arithmetic, -cppcoreguidelines-pro-type-reinterpret-cast, - -cppcoreguidelines-pro-type-vararg, -fuchsia-default-arguments, -fuchsia-overloaded-operator, -google-readability-todo, @@ -19,7 +18,6 @@ Checks: > -hicpp-multiway-paths-covered, -hicpp-no-array-decay, -hicpp-signed-bitwise, - -hicpp-vararg, -llvm-header-guard, -readability-else-after-return, -readability-implicit-bool-conversion, diff --git a/serd/serd.h b/serd/serd.h index 3e2f8f45..42946b90 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -783,13 +783,20 @@ serd_node_free(SerdNode* node); Sink function for log messages @param handle Handle for user data. - @param msg Message description. -*/ -typedef SerdStatus (*SerdMessageFunc)(void* handle, const SerdMessage* msg); - -/** - Sink function for base URI changes + @param status Status code + @param level Log level + @param cursor Origin of message, or NULL + @param fmt Message format string (printf style) + @param args Arguments corresponding to fmt (printf style) +*/ +typedef SerdStatus (*SerdMessageFunc)(void* handle, + SerdStatus status, + SerdLogLevel level, + const SerdCursor* cursor, + const char* fmt, + va_list args); +/* Called whenever the base URI of the serialisation changes. */ typedef SerdStatus (*SerdBaseFunc)(void* handle, const SerdNode* uri); @@ -878,7 +885,12 @@ serd_world_set_message_sink(SerdWorld* world, /// Write a message to the log SERD_API SerdStatus -serd_world_log(const SerdWorld* world, const SerdMessage* msg); +serd_world_vlogf(const SerdWorld* world, + SerdStatus st, + SerdLogLevel level, + const SerdCursor* cursor, + const char* fmt, + va_list args); /// Write a message to the log SERD_API diff --git a/serd/serd.hpp b/serd/serd.hpp index 5084e1ad..112daa23 100644 --- a/serd/serd.hpp +++ b/serd/serd.hpp @@ -574,12 +574,6 @@ struct Message /** @} - @name Event Handlers - @{ -*/ - -/** - @} @name World @{ */ @@ -601,11 +595,6 @@ public: serd_world_set_message_sink(cobj(), s_message_sink, this); } - Status log(const SerdMessage* msg) - { - return static_cast<Status>(serd_world_log(cobj(), msg)); - } - SERD_LOG_FUNC(5, 6) Status log(const Status status, const LogLevel level, @@ -615,44 +604,49 @@ public: { va_list args; va_start(args, fmt); - const SerdMessage msg = {static_cast<SerdStatus>(status), - static_cast<SerdLogLevel>(level), - cursor, - fmt, - &args}; - const SerdStatus st = serd_world_log(cobj(), &msg); + + const SerdStatus st = serd_world_vlogf(cobj(), + static_cast<SerdStatus>(status), + static_cast<SerdLogLevel>(level), + cursor, + fmt, + args); va_end(args); return static_cast<Status>(st); } private: - static std::string format(const char* fmt, va_list* args) noexcept + static std::string format(const char* fmt, va_list args) noexcept { va_list args_copy; - va_copy(args_copy, *args); + va_copy(args_copy, args); const int n_bytes = vsnprintf(nullptr, 0, fmt, args_copy); va_end(args_copy); #if __cplusplus >= 201703L std::string result(n_bytes, '\0'); - vsnprintf(result.data(), n_bytes + 1, fmt, *args); + vsnprintf(result.data(), n_bytes + 1, fmt, args); #else std::vector<char> str(n_bytes + 1U, '\0'); - vsnprintf(str.data(), n_bytes + 1U, fmt, *args); + vsnprintf(str.data(), n_bytes + 1U, fmt, args); std::string result(str.data(), size_t(n_bytes)); #endif return result; } - static SerdStatus - s_message_sink(void* handle, const SerdMessage* msg) noexcept + static SerdStatus s_message_sink(void* handle, + SerdStatus status, + SerdLogLevel level, + const SerdCursor* cursor, + const char* fmt, + va_list args) noexcept { const auto* const self = static_cast<const World*>(handle); try { - Message message{static_cast<Status>(msg->status), - static_cast<LogLevel>(msg->level), - CursorView{msg->cursor}, - format(msg->fmt, msg->args)}; + Message message{static_cast<Status>(status), + static_cast<LogLevel>(level), + CursorView{cursor}, + format(fmt, args)}; return static_cast<SerdStatus>(self->_msg_sink(message)); } catch (...) { return SERD_ERR_INTERNAL; diff --git a/src/reader.c b/src/reader.c index 50784ffc..bf871940 100644 --- a/src/reader.c +++ b/src/reader.c @@ -39,10 +39,12 @@ r_err(SerdReader* reader, SerdStatus st, const char* fmt, ...) { va_list args; va_start(args, fmt); - const SerdMessage msg = { - st, SERD_LOG_LEVEL_ERROR, &reader->source.cur, fmt, &args - }; - serd_world_log(reader->world, &msg); + serd_world_vlogf(reader->world, + st, + SERD_LOG_LEVEL_ERROR, + &reader->source.cur, + fmt, + args); va_end(args); return st; } diff --git a/src/serdi.c b/src/serdi.c index 147a68c9..601824af 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -25,6 +25,7 @@ #endif #include <limits.h> +#include <stdarg.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> @@ -79,10 +80,19 @@ missing_arg(const char* name, char opt) } static SerdStatus -quiet_error_sink(void* handle, const SerdMessage* msg) +quiet_error_sink(void* handle, + SerdStatus status, + SerdLogLevel level, + const SerdCursor* cursor, + const char* fmt, + va_list args) { (void)handle; - (void)msg; + (void)status; + (void)level; + (void)cursor; + (void)fmt; + (void)args; return SERD_SUCCESS; } diff --git a/src/validate.c b/src/validate.c index a52f92b0..279ca117 100644 --- a/src/validate.c +++ b/src/validate.c @@ -125,12 +125,11 @@ report(ValidationContext* ctx, { va_list args; va_start(args, fmt); - const SerdMessage msg = { SERD_ERR_INVALID, - level, - serd_statement_get_cursor(statement), - fmt, - &args }; - serd_world_log(ctx->model->world, &msg); + serd_world_vlogf(ctx->model->world, SERD_ERR_INVALID, + level, + serd_statement_get_cursor(statement), + fmt, + args); va_end(args); ++ctx->n_errors; diff --git a/src/world.c b/src/world.c index f16b0f95..be4be551 100644 --- a/src/world.c +++ b/src/world.c @@ -51,24 +51,30 @@ serd_world_fopen(SerdWorld* world, const char* path, const char* mode) } SerdStatus -serd_world_log(const SerdWorld* world, const SerdMessage* msg) +serd_world_vlogf(const SerdWorld* world, + SerdStatus st, + SerdLogLevel level, + const SerdCursor* cursor, + const char* fmt, + va_list args) { - static const char* level_strings[] = { "note", "warning", "error" }; + static const char* const level_strings[] = { "note", "warning", "error" }; if (world->msg_func) { - world->msg_func(world->msg_handle, msg); + world->msg_func(world->msg_handle, st, level, cursor, fmt, args); } else { - fprintf(stderr, "%s: ", level_strings[msg->level]); - if (msg->cursor) { + fprintf(stderr, "%s: ", level_strings[level]); + if (cursor) { fprintf(stderr, "%s:%u:%u: ", - serd_node_get_string(msg->cursor->file), - msg->cursor->line, - msg->cursor->col); + serd_node_get_string(cursor->file), + cursor->line, + cursor->col); } - vfprintf(stderr, msg->fmt, *msg->args); + vfprintf(stderr, fmt, args); } - return msg->status; + + return st; } SerdStatus @@ -81,8 +87,7 @@ serd_world_logf(const SerdWorld* world, { va_list args; va_start(args, fmt); - const SerdMessage msg = {st, level, cursor, fmt, &args}; - serd_world_log(world, &msg); + serd_world_vlogf(world, st, level, cursor, fmt, args); va_end(args); return st; } diff --git a/tests/model_test.c b/tests/model_test.c index 60dc4579..9a4cd906 100644 --- a/tests/model_test.c +++ b/tests/model_test.c @@ -276,22 +276,38 @@ test_read(SerdWorld* world, } static SerdStatus -unexpected_error(void* handle, const SerdMessage* msg) +unexpected_error(void* handle, + SerdStatus status, + SerdLogLevel level, + const SerdCursor* cursor, + const char* fmt, + va_list args) { (void)handle; + (void)status; + (void)level; + (void)cursor; fprintf(stderr, "error: "); - vfprintf(stderr, msg->fmt, *msg->args); + vfprintf(stderr, fmt, args); return SERD_SUCCESS; } static SerdStatus -expected_error(void* handle, const SerdMessage* msg) +expected_error(void* handle, + SerdStatus status, + SerdLogLevel level, + const SerdCursor* cursor, + const char* fmt, + va_list args) { (void)handle; + (void)status; + (void)level; + (void)cursor; fprintf(stderr, "expected: "); - vfprintf(stderr, msg->fmt, *msg->args); + vfprintf(stderr, fmt, args); return SERD_SUCCESS; } |