doc/api/libbabeltrace2/DoxygenLayout.xml: use `topics` tab
[babeltrace.git] / src / plugins / common / param-validation / param-validation.c
index ca80e888add31aa156ae4bbcec2c3730bb46d3d7..d187441628f6179a2e5afa31515aa93cc2ec4bf1 100644 (file)
@@ -1,23 +1,7 @@
 /*
- * Copyright 2019 EfficiOS Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
+ * SPDX-License-Identifier: MIT
  *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
+ * Copyright 2019 EfficiOS Inc.
  */
 
 #include "param-validation.h"
@@ -25,6 +9,7 @@
 #include <babeltrace2/babeltrace.h>
 #include <glib.h>
 #include <inttypes.h>
+#include <stdbool.h>
 
 #include "common/common.h"
 
@@ -95,7 +80,7 @@ void append_scope_to_string(GString *str,
                g_string_append_printf(str, "[%" PRIu64 "]", elem->array_index);
                break;
        default:
-               abort();
+               bt_common_abort();
        }
 }
 
@@ -116,12 +101,12 @@ enum bt_param_validation_status bt_param_validation_error(
 
                g_string_assign(str, "Error validating parameter `");
 
-               append_scope_to_string(str, &g_array_index(ctx->scope_stack,
+               append_scope_to_string(str, &bt_g_array_index(ctx->scope_stack,
                        struct validate_ctx_stack_element, 0), true);
 
                for (i = 1; i < ctx->scope_stack->len; i++) {
                        append_scope_to_string(str,
-                               &g_array_index(ctx->scope_stack,
+                               &bt_g_array_index(ctx->scope_stack,
                                        struct validate_ctx_stack_element, i), false);
                }
 
@@ -155,8 +140,8 @@ enum bt_param_validation_status validate_value(
                struct bt_param_validation_context *ctx);
 
 static
-bt_bool validate_map_value_entry(const char *key,
-               const bt_value *value, void *v_data)
+bt_value_map_foreach_entry_const_func_status validate_map_value_entry(
+               const char *key, const bt_value *value, void *v_data)
 {
        struct validate_map_value_data *data = v_data;
        const struct bt_param_validation_map_value_entry_descr *entry = NULL;
@@ -191,7 +176,9 @@ bt_bool validate_map_value_entry(const char *key,
        }
 
        /* Continue iterating if everything is good so far. */
-       return data->status == BT_PARAM_VALIDATION_STATUS_OK;
+       return data->status == BT_PARAM_VALIDATION_STATUS_OK ?
+               BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_OK :
+               BT_VALUE_MAP_FOREACH_ENTRY_CONST_FUNC_STATUS_INTERRUPT;
 }
 
 static
@@ -400,10 +387,10 @@ enum bt_param_validation_status bt_param_validation_validate(
        struct bt_param_validation_map_value_descr map_value_descr;
        enum bt_param_validation_status status;
 
-       ctx.error = NULL;
+       memset(&ctx, '\0', sizeof(ctx));
+
        ctx.scope_stack = g_array_new(FALSE, FALSE,
                sizeof(struct validate_ctx_stack_element));
-                       g_ptr_array_new_with_free_func(g_free);
        if (!ctx.scope_stack) {
                status = BT_PARAM_VALIDATION_STATUS_MEMORY_ERROR;
                goto end;
@@ -417,5 +404,9 @@ end:
        *error = ctx.error;
        ctx.error = NULL;
 
+       if (ctx.scope_stack) {
+               g_array_free(ctx.scope_stack, TRUE);
+       }
+
        return status;
 }
This page took 0.025408 seconds and 4 git commands to generate.