Move to kernel style SPDX license identifiers
[babeltrace.git] / src / lib / trace-ir / attributes.c
index 4512880a5c6ec903f26e3f5af669a677a85dc653..924c71c43b3b1f92fd0794519f64af512434b7c1 100644 (file)
@@ -1,24 +1,8 @@
 /*
+ * SPDX-License-Identifier: MIT
+ *
  * Copyright (c) 2015 EfficiOS Inc. and Linux Foundation
  * Copyright (c) 2015 Philippe Proulx <pproulx@efficios.com>
- *
- * 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:
- *
- * 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.
  */
 
 #define BT_LOG_TAG "LIB/ATTRS"
@@ -28,7 +12,7 @@
 #include <babeltrace2/value.h>
 #include "lib/assert-pre.h"
 #include "lib/object.h"
-#include <babeltrace2/value-const.h>
+#include <babeltrace2/value.h>
 #include "lib/value.h"
 #include "attributes.h"
 #include <inttypes.h>
@@ -86,7 +70,6 @@ BT_HIDDEN
 const char *bt_attributes_get_field_name(const struct bt_value *attr_obj,
                uint64_t index)
 {
-       const char *ret = NULL;
        const struct bt_value *attr_field_obj = NULL;
        const struct bt_value *attr_field_name_obj = NULL;
 
@@ -94,59 +77,28 @@ const char *bt_attributes_get_field_name(const struct bt_value *attr_obj,
        BT_ASSERT_DBG(index < bt_value_array_get_length(attr_obj));
        attr_field_obj = bt_value_array_borrow_element_by_index_const(
                attr_obj, index);
-       if (!attr_field_obj) {
-               BT_LIB_LOGE_APPEND_CAUSE(
-                       "Cannot borrow attributes object's array value's element by index: "
-                       "%![value-]+v, index=%" PRIu64, attr_obj, index);
-               goto end;
-       }
 
        attr_field_name_obj =
                bt_value_array_borrow_element_by_index_const(attr_field_obj,
                        BT_ATTR_NAME_INDEX);
-       if (!attr_field_name_obj) {
-               BT_LIB_LOGE_APPEND_CAUSE(
-                       "Cannot get attribute array value's element by index: "
-                       "%![value-]+v, index=%" PRIu64, attr_field_obj,
-                       (uint64_t) BT_ATTR_NAME_INDEX);
-               goto end;
-       }
-
-       ret = bt_value_string_get(attr_field_name_obj);
 
-end:
-       return ret;
+       return bt_value_string_get(attr_field_name_obj);
 }
 
 BT_HIDDEN
 struct bt_value *bt_attributes_borrow_field_value(
                struct bt_value *attr_obj, uint64_t index)
 {
-       struct bt_value *value_obj = NULL;
        struct bt_value *attr_field_obj = NULL;
 
        BT_ASSERT_DBG(attr_obj);
        BT_ASSERT_DBG(index < bt_value_array_get_length(attr_obj));
+
        attr_field_obj =
                bt_value_array_borrow_element_by_index(attr_obj, index);
-       if (!attr_field_obj) {
-               BT_LIB_LOGE_APPEND_CAUSE(
-                       "Cannot get attributes object's array value's element by index: "
-                       "%![value-]+v, index=%" PRIu64, attr_obj, index);
-               goto end;
-       }
 
-       value_obj = bt_value_array_borrow_element_by_index(
-               attr_field_obj, BT_ATTR_VALUE_INDEX);
-       if (!value_obj) {
-               BT_LIB_LOGE_APPEND_CAUSE(
-                       "Cannot get attribute array value's element by index: "
-                       "%![value-]+v, index=%" PRIu64, attr_field_obj,
-                       (uint64_t) BT_ATTR_VALUE_INDEX);
-       }
-
-end:
-       return value_obj;
+       return bt_value_array_borrow_element_by_index( attr_field_obj,
+               BT_ATTR_VALUE_INDEX);
 }
 
 static
@@ -163,23 +115,10 @@ struct bt_value *bt_attributes_borrow_field_by_name(
 
                value_obj = bt_value_array_borrow_element_by_index(
                        attr_obj, i);
-               if (!value_obj) {
-                       BT_LIB_LOGE_APPEND_CAUSE(
-                               "Cannot get attributes object's array value's element by index: "
-                               "%![value-]+v, index=%" PRIu64, attr_obj, i);
-                       goto error;
-               }
 
                attr_field_name_obj =
                        bt_value_array_borrow_element_by_index(
                                value_obj, BT_ATTR_NAME_INDEX);
-               if (!attr_field_name_obj) {
-                       BT_LIB_LOGE_APPEND_CAUSE(
-                               "Cannot get attribute array value's element by index: "
-                               "%![value-]+v, index=%" PRIu64,
-                               value_obj, (int64_t) BT_ATTR_NAME_INDEX);
-                       goto error;
-               }
 
                field_name = bt_value_string_get(attr_field_name_obj);
 
@@ -191,10 +130,6 @@ struct bt_value *bt_attributes_borrow_field_by_name(
        }
 
        return value_obj;
-
-error:
-       value_obj = NULL;
-       return value_obj;
 }
 
 BT_HIDDEN
@@ -266,12 +201,6 @@ struct bt_value *bt_attributes_borrow_field_value_by_name(
 
        value_obj = bt_value_array_borrow_element_by_index(
                attr_field_obj, BT_ATTR_VALUE_INDEX);
-       if (!value_obj) {
-               BT_LIB_LOGE_APPEND_CAUSE(
-                       "Cannot get attribute array value's element by index: "
-                       "%![value-]+v, index=%" PRIu64, attr_field_obj,
-                       (uint64_t) BT_ATTR_VALUE_INDEX);
-       }
 
 end:
        return value_obj;
This page took 0.026943 seconds and 4 git commands to generate.