X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Fpython-plugin-provider%2Fpython-plugin-provider.c;h=e6e31099713393acfb35e864529ad581bd0a7193;hb=6375b9429f8332f3eacc2ec795aa1924c73d9cc8;hp=5bdcbfcd78c035ec4bbbd0a4249d8b7c077d1efb;hpb=19bbdc9bfcbbfabb1f04dad12ff1df5d7075bf11;p=babeltrace.git diff --git a/src/python-plugin-provider/python-plugin-provider.c b/src/python-plugin-provider/python-plugin-provider.c index 5bdcbfcd..e6e31099 100644 --- a/src/python-plugin-provider/python-plugin-provider.c +++ b/src/python-plugin-provider/python-plugin-provider.c @@ -1,40 +1,25 @@ /* - * python-plugin-provider.c - * - * Babeltrace Python plugin provider + * SPDX-License-Identifier: MIT * * Copyright 2017 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. + * Babeltrace Python plugin provider */ #define BT_LOG_TAG "LIB/PLUGIN-PY" - #include "lib/logging.h" + +#include "python-plugin-provider.h" + #include "common/macros.h" #include "compat/compiler.h" -#include +#include #include "lib/plugin/plugin.h" #include -#include +#include #include "lib/graph/component-class.h" #include "py-common/py-common.h" +#include #include #include #include @@ -46,7 +31,7 @@ #define PYTHON_PLUGIN_FILE_EXT ".py" #define PYTHON_PLUGIN_FILE_EXT_LEN (sizeof(PYTHON_PLUGIN_FILE_EXT) - 1) -enum python_state { +static enum python_state { /* init_python() not called yet */ PYTHON_STATE_NOT_INITED, @@ -72,14 +57,14 @@ void append_python_traceback_error_cause(void) GString *exc = NULL; if (Py_IsInitialized() && PyErr_Occurred()) { - exc = bt_py_common_format_exception(BT_LOG_OUTPUT_LEVEL); + exc = bt_py_common_format_current_exception(BT_LOG_OUTPUT_LEVEL); if (!exc) { BT_LOGE_STR("Failed to format Python exception."); goto end; } (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN( - "Babeltrace library", "%s", exc->str); + BT_LIB_LOG_LIBBABELTRACE2_NAME, "%s", exc->str); } end: @@ -94,14 +79,14 @@ void log_python_traceback(int log_level) GString *exc = NULL; if (Py_IsInitialized() && PyErr_Occurred()) { - exc = bt_py_common_format_exception(BT_LOG_OUTPUT_LEVEL); + exc = bt_py_common_format_current_exception(BT_LOG_OUTPUT_LEVEL); if (!exc) { BT_LOGE_STR("Failed to format Python exception."); goto end; } BT_LOG_WRITE(log_level, BT_LOG_TAG, - "Exception occured: Python traceback:\n%s", exc->str); + "Exception occurred: Python traceback:\n%s", exc->str); } end: @@ -140,17 +125,19 @@ int init_python(void) ret = BT_FUNC_STATUS_ERROR; goto end; default: - abort(); + bt_common_abort(); } /* * User can disable Python plugin support with the - * BABELTRACE_DISABLE_PYTHON_PLUGINS environment variable set to - * 1. + * `LIBBABELTRACE2_DISABLE_PYTHON_PLUGINS` environment variable + * set to 1. */ - dis_python_env = getenv("BABELTRACE_DISABLE_PYTHON_PLUGINS"); + dis_python_env = getenv("LIBBABELTRACE2_DISABLE_PYTHON_PLUGINS"); if (dis_python_env && strcmp(dis_python_env, "1") == 0) { - BT_LOGI_STR("Python plugin support is disabled because `BABELTRACE_DISABLE_PYTHON_PLUGINS=1`."); + BT_LOGI_STR("Python plugin support is disabled because the " + "`LIBBABELTRACE2_DISABLE_PYTHON_PLUGINS` environment " + "variable is set to `1`."); python_state = PYTHON_STATE_WONT_INITIALIZE; ret = BT_FUNC_STATUS_NOT_FOUND; goto end; @@ -250,9 +237,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot find `name` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot find `name` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -268,9 +255,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot find `author` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot find `author` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -286,9 +273,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot find `description` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot find `description` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -304,9 +291,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot find `license` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot find `license` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -322,9 +309,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot find `version` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot find `version` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -341,9 +328,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot find `comp_class_addrs` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot find `comp_class_addrs` attribute in Python plugin info object: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -360,9 +347,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot decode Python plugin name string: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot decode Python plugin name string: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -377,9 +364,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Plugin name is not a string: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Plugin name is not a string: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -396,9 +383,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot decode Python plugin author string: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot decode Python plugin author string: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -416,9 +403,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot decode Python plugin description string: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot decode Python plugin description string: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -436,9 +423,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot decode Python plugin license string: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot decode Python plugin license string: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -477,9 +464,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Invalid Python plugin version format: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Invalid Python plugin version format: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -502,9 +489,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, BT_LIB_LOGW_APPEND_CAUSE( "Cannot decode Python plugin version's extra string: " "py-plugin-info-addr=%p", plugin_info); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot decode Python plugin version's extra string: " "py-plugin-info-addr=%p", plugin_info); status = BT_FUNC_STATUS_NOT_FOUND; @@ -558,9 +545,9 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, "Component class address is not an integer in Python plugin info object: " "py-plugin-info-addr=%p, index=%zu", plugin_info, i); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Component class address is not an integer in Python plugin info object: " "py-plugin-info-addr=%p, index=%zu", plugin_info, i); @@ -584,7 +571,7 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info, bt_plugin_get_name(*plugin_out), comp_class, bt_component_class_get_name(comp_class), - bt_component_class_type_string( + bt_common_component_class_type_string( bt_component_class_get_type(comp_class))); goto error; } @@ -637,7 +624,9 @@ int bt_plugin_python_create_all_from_file(const char *path, * Python plugins are disabled, so it's simply not * found. */ - BT_LOGI_STR("Python plugin support was disabled previously because `BABELTRACE_DISABLE_PYTHON_PLUGINS=1`."); + BT_LOGI_STR("Python plugin support was disabled previously " + "because the `LIBBABELTRACE2_DISABLE_PYTHON_PLUGINS` " + "environment variable is set to `1`."); status = BT_FUNC_STATUS_NOT_FOUND; goto error; } @@ -700,9 +689,9 @@ int bt_plugin_python_create_all_from_file(const char *path, append_python_traceback_error_cause(); BT_LIB_LOGW_APPEND_CAUSE( "Cannot load Python plugin: path=\"%s\"", path); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { - BT_LIB_LOGI( + BT_LIB_LOGW( "Cannot load Python plugin: path=\"%s\"", path); status = BT_FUNC_STATUS_NOT_FOUND; } @@ -750,7 +739,7 @@ int bt_plugin_python_create_all_from_file(const char *path, error: BT_ASSERT(status != BT_FUNC_STATUS_OK); - log_python_traceback(fail_on_load_error ? BT_LOG_WARNING : BT_LOG_INFO); + log_python_traceback(BT_LOG_WARNING); pyerr_clear(); BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out);