Skip to content

Commit

Permalink
log: don't pass va_list around, but a gpointer
Browse files Browse the repository at this point in the history
Modifying the va_list arg in sub-functions does not work on all
platforms.
  • Loading branch information
gicmo committed Mar 6, 2018
1 parent 694d145 commit e641940
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions boltd/bolt-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ bolt_log_ctx_find_field (const BoltLogCtx *ctx,
static void
handle_device_field (BoltLogCtx *ctx,
const char *key,
va_list args)
gpointer ptr)
{
BoltDevice *dev = va_arg (args, BoltDevice *);
BoltDevice *dev = BOLT_DEVICE (ptr);
BoltStatus status;
GLogField *field;

Expand All @@ -209,12 +209,11 @@ handle_device_field (BoltLogCtx *ctx,
static void
handle_gerror_field (BoltLogCtx *ctx,
const char *key,
va_list args)
gpointer ptr)
{
const GError *error;
const GError *error = ptr;
GLogField *field;

error = va_arg (args, GError *);
ctx->error = error;

bolt_log_ctx_next_field (ctx, &field);
Expand All @@ -236,9 +235,9 @@ handle_gerror_field (BoltLogCtx *ctx,
static void
handle_topic_field (BoltLogCtx *ctx,
const char *key,
va_list args)
gpointer ptr)
{
const char *value = va_arg (args, const char *);
const char *value = ptr;
GLogField *field;

bolt_log_ctx_next_field (ctx, &field);
Expand All @@ -253,19 +252,20 @@ handle_topic_field (BoltLogCtx *ctx,
static gboolean
handle_special_field (BoltLogCtx *ctx,
const char *key,
va_list args)
gpointer ptr)
{
gboolean handled = TRUE;

key++; /* remove the special key indicator */

if (g_str_has_prefix (key, "device"))
handle_device_field (ctx, key, args);
handle_device_field (ctx, key, ptr);
else if (g_str_equal (key, "error"))
handle_gerror_field (ctx, key, args);
handle_gerror_field (ctx, key, ptr);
else if (g_str_equal (key, "topic"))
handle_topic_field (ctx, key, args);
handle_topic_field (ctx, key, ptr);
else

handled = FALSE;

return handled;
Expand All @@ -274,17 +274,16 @@ handle_special_field (BoltLogCtx *ctx,
static gboolean
handle_passthrough_field (BoltLogCtx *ctx,
const char *key,
va_list args)
const char *val)
{
const char *value = va_arg (args, const char *);
GLogField *field;

key++; /* remove the pass-through key indicator */

bolt_log_ctx_next_field (ctx, &field);

field->key = key;
field->value = value;
field->value = val;
field->length = -1;

return TRUE;
Expand Down Expand Up @@ -323,11 +322,19 @@ bolt_logv (const char *domain,
gboolean handled;

if (*key == LOG_SPECIAL_CHAR)
handled = handle_special_field (&ctx, key, args);
{
gpointer ptr = va_arg (args, gpointer);
handled = handle_special_field (&ctx, key, ptr);
}
else if (*key == LOG_PASSTHROUGH_CHAR)
handled = handle_passthrough_field (&ctx, key, args);
{
const char *val = va_arg (args, const char *);
handled = handle_passthrough_field (&ctx, key, val);
}
else
break;
{
break;
}

if (!handled)
internal_error ("unknown field: %s", key);
Expand Down

0 comments on commit e641940

Please sign in to comment.