feat: Turn into macros to log line numbers correctly

See the comment on the macro
This commit is contained in:
icex2 2024-08-15 11:34:31 +02:00
parent f990d839af
commit dbd1a4c3e0
6 changed files with 19 additions and 37 deletions

View File

@ -118,21 +118,6 @@ const char *core_property_node_result_to_str(core_property_node_result_t result)
default:
return "Undefined error";
}
void core_property_node_fatal_on_error(core_property_node_result_t result)
{
switch (result) {
case CORE_PROPERTY_NODE_RESULT_SUCCESS:
return;
case CORE_PROPERTY_NODE_RESULT_ERROR_INTERNAL:
case CORE_PROPERTY_NODE_RESULT_NODE_NOT_FOUND:
default:
log_fatal(
"Operation on property failed: %s",
core_property_node_result_to_str(result));
}
}
}
core_property_node_result_t core_property_node_name_get(

View File

@ -18,6 +18,15 @@
// Guestimate, should be long enough, I hope?
#define CORE_PROPERTY_NODE_PATH_LEN_MAX 4096
// Macro to allow inlining of the caller function and line numbers
// to make debugging easier
#define core_property_node_fatal_on_error(result) \
if (result != CORE_PROPERTY_NODE_RESULT_SUCCESS) { \
log_fatal( \
"Operation on property-node failed: %s", \
core_property_node_result_to_str(result)); \
} \
typedef struct core_property_node core_property_node_t;
typedef enum core_property_node_result {
@ -209,7 +218,6 @@ void core_property_node_api_get(core_property_node_api_t *impl);
const char *
core_property_node_result_to_str(core_property_node_result_t result);
void core_property_node_fatal_on_error(core_property_node_result_t result);
core_property_node_result_t core_property_node_name_get(
const core_property_node_t *node, char *name, size_t len);

View File

@ -91,23 +91,6 @@ const char *core_property_result_to_str(core_property_result_t result)
}
}
void core_property_fatal_on_error(core_property_result_t result)
{
switch (result) {
case CORE_PROPERTY_RESULT_SUCCESS:
return;
case CORE_PROPERTY_RESULT_ERROR_INTERNAL:
case CORE_PROPERTY_RESULT_ERROR_ALLOC:
case CORE_PROPERTY_RESULT_NOT_FOUND:
case CORE_PROPERTY_RESULT_ERROR_PERMISSIONS:
case CORE_PROPERTY_RESULT_ERROR_READ:
default:
log_fatal(
"Operation on property failed: %s",
core_property_result_to_str(result));
}
}
core_property_result_t
core_property_create(size_t size, core_property_t **property)
{

View File

@ -7,7 +7,14 @@
#include "api/core/log.h"
#define CORE_PROPERTY_RESULT_IS_ERROR(x) (x > CORE_PROPERTY_RESULT_SUCCESS)
// Macro to allow inlining of the caller function and line numbers
// to make debugging easier
#define core_property_fatal_on_error(result) \
if (result != CORE_PROPERTY_RESULT_SUCCESS) { \
log_fatal( \
"Operation on property failed: %s", \
core_property_result_to_str(result)); \
} \
typedef struct core_property {
// Have size known, but not contents, to allow for stack allocations
@ -65,7 +72,6 @@ void core_property_api_set(const core_property_api_t *api);
void core_property_api_get(core_property_api_t *api);
const char *core_property_result_to_str(core_property_result_t result);
void core_property_fatal_on_error(core_property_result_t result);
core_property_result_t
core_property_create(size_t size, core_property_t **property);

View File

@ -27,7 +27,7 @@ static void _ea3_ident_config_root_get(
log_assert(node);
result = core_property_root_node_get(property, node);
core_property_fatal_on_error(result);
core_property_node_fatal_on_error(result);
result = core_property_node_name_get(node, node_name, sizeof(node_name));
core_property_node_fatal_on_error(result);

View File

@ -133,7 +133,7 @@ static void _launcher_bootstrap_config_options_override(
core_property_free(&config->property);
result =
core_property_file_load(options->config_path, &config->property);
core_property_node_fatal_on_error(result);
core_property_fatal_on_error(result);
}
if (options->selector) {