X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Fnative_bt_autodisc.i.h;h=d6a4d24bbe1ae0d3f089ee6639ac8ca081111d43;hb=827e42e017fc5f525aa39a3851bf2e7e50e887aa;hp=e09f54e768b803f713e82380fb44c8a4395be3d1;hpb=f3c9a159782f70dbd0e5dedb37e4a1ef8a6d304e;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/native_bt_autodisc.i.h b/src/bindings/python/bt2/bt2/native_bt_autodisc.i.h index e09f54e7..d6a4d24b 100644 --- a/src/bindings/python/bt2/bt2/native_bt_autodisc.i.h +++ b/src/bindings/python/bt2/bt2/native_bt_autodisc.i.h @@ -1,25 +1,7 @@ /* - * The MIT License (MIT) + * SPDX-License-Identifier: MIT * * Copyright (c) 2016 Philippe Proulx - * - * 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. */ #include @@ -47,6 +29,7 @@ * This function can also return None, if it failed to allocate memory * for the return value and status code. */ +static bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs, const bt_plugin_set *plugin_set) { @@ -60,18 +43,20 @@ bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs, bt_value *components_list = NULL; bt_value *component_info = NULL; bt_value_map_insert_entry_status insert_entry_status; + const bt_error *error = NULL; BT_ASSERT(bt_value_get_type(inputs) == BT_VALUE_TYPE_ARRAY); - for (i = 0; i < bt_value_array_get_size(inputs); i++) { + for (i = 0; i < bt_value_array_get_length(inputs); i++) { const bt_value *elem = bt_value_array_borrow_element_by_index_const(inputs, i); BT_ASSERT(bt_value_get_type(elem) == BT_VALUE_TYPE_STRING); } result = bt_value_map_create(); if (!result) { - static const char * const err = "Failed to create a map value."; - BT_LOGE_STR(err); - BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name, err); +#define BT_FMT "Failed to create a map value." + BT_LOGE_STR(BT_FMT); + BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name, BT_FMT); +#undef BT_FMT PyErr_NoMemory(); goto end; } @@ -102,7 +87,8 @@ bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs, plugin_count, NULL, bt_python_bindings_bt2_log_level, - &auto_disc); + &auto_disc, + NULL); if (status != 0) { BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name, "Failed to auto discover sources."); @@ -126,7 +112,7 @@ bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs, } for (i = 0; i < auto_disc.results->len; i++) { - struct auto_source_discovery_result *result = + struct auto_source_discovery_result *autodisc_result = g_ptr_array_index(auto_disc.results, i); bt_value_array_append_element_status append_element_status; @@ -139,7 +125,7 @@ bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs, } append_element_status = bt_value_array_append_string_element( - component_info, result->plugin_name); + component_info, autodisc_result->plugin_name); if (append_element_status != BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK) { BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name, "Failed to append one array element."); @@ -148,7 +134,7 @@ bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs, } append_element_status = bt_value_array_append_string_element( - component_info, result->source_cc_name); + component_info, autodisc_result->source_cc_name); if (append_element_status != BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK) { BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name, "Failed to append one array element."); @@ -157,7 +143,7 @@ bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs, } append_element_status = bt_value_array_append_element( - component_info, result->inputs); + component_info, autodisc_result->inputs); if (append_element_status != BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK) { BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name, "Failed to append one array element."); @@ -166,7 +152,7 @@ bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs, } append_element_status = bt_value_array_append_element( - component_info, result->original_input_indices); + component_info, autodisc_result->original_input_indices); if (append_element_status != BT_VALUE_ARRAY_APPEND_ELEMENT_STATUS_OK) { BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(module_name, "Failed to append one array element."); @@ -193,11 +179,23 @@ error: end: if (result) { + /* + * If an error happened, we must clear the error temporarily + * while we insert the status in the map. + */ + error = bt_current_thread_take_error(); insert_entry_status = bt_value_map_insert_signed_integer_entry(result, "status", status); - if (insert_entry_status != BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { + if (insert_entry_status == BT_VALUE_MAP_INSERT_ENTRY_STATUS_OK) { + if (error) { + bt_current_thread_move_error(error); + error = NULL; + } + } else { BT_VALUE_PUT_REF_AND_RESET(result); PyErr_NoMemory(); } + + } auto_source_discovery_fini(&auto_disc); @@ -205,5 +203,9 @@ end: bt_value_put_ref(components_list); bt_value_put_ref(component_info); + if (error) { + bt_error_release(error); + } + return result; }