X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Fnative_bt_autodisc.i.h;h=f1629efb957d2b6264e5bb3c13df8839d25967c4;hb=ae2be88d24ae6f9d73b3c3aeb7b316283e4bde60;hp=612c9328fd8c6a60a05a528e08a735d2318e0600;hpb=7c7301d5827bd10ec7c34da7ffc5fe74e5047d38;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 612c9328..f1629efb 100644 --- a/src/bindings/python/bt2/bt2/native_bt_autodisc.i.h +++ b/src/bindings/python/bt2/bt2/native_bt_autodisc.i.h @@ -1,27 +1,12 @@ /* - * 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. */ +#ifndef BABELTRACE_BINDINGS_PYTHON_BT2_BT2_NATIVE_BT_AUTODISC_I_H +#define BABELTRACE_BINDINGS_PYTHON_BT2_BT2_NATIVE_BT_AUTODISC_I_H + #include #include @@ -61,6 +46,7 @@ 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_length(inputs); i++) { @@ -70,9 +56,10 @@ bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs, 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 +89,7 @@ bt_value *bt_bt2_auto_discover_source_components(const bt_value *inputs, plugins, plugin_count, NULL, - bt_python_bindings_bt2_log_level, + (bt_logging_level) bt_python_bindings_bt2_log_level, &auto_disc, NULL); if (status != 0) { @@ -195,11 +182,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); @@ -207,5 +206,11 @@ end: bt_value_put_ref(components_list); bt_value_put_ref(component_info); + if (error) { + bt_error_release(error); + } + return result; } + +#endif /* BABELTRACE_BINDINGS_PYTHON_BT2_BT2_NATIVE_BT_AUTODISC_I_H */