projects
/
babeltrace.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Rename: bt_put(), bt_get() -> bt_object_put_ref(), bt_object_get_ref()
[babeltrace.git]
/
python-plugin-provider
/
python-plugin-provider.c
diff --git
a/python-plugin-provider/python-plugin-provider.c
b/python-plugin-provider/python-plugin-provider.c
index c276aadff3bd31989e19bc0873faba6624a051a4..0ad6a4c30ad6182669ac88bf3ad065bd1aa0b577 100644
(file)
--- a/
python-plugin-provider/python-plugin-provider.c
+++ b/
python-plugin-provider/python-plugin-provider.c
@@
-24,19
+24,12
@@
* SOFTWARE.
*/
* SOFTWARE.
*/
-#define BT_LOG_OUTPUT_LEVEL python_plugin_provider_log_level
#define BT_LOG_TAG "PLUGIN-PY"
#define BT_LOG_TAG "PLUGIN-PY"
-#include <babeltrace/logging-internal.h>
-
-/*
- * Must be before the rest because some of the headers below could
- * contain logging statements which need this symbol when expanded.
- */
-static int python_plugin_provider_log_level = BT_LOG_NONE;
+#include "logging.h"
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/compiler-internal.h>
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/compiler-internal.h>
-#include <babeltrace/
ref
.h>
+#include <babeltrace/
object
.h>
#include <babeltrace/plugin/plugin.h>
#include <babeltrace/plugin/plugin-internal.h>
#include <babeltrace/graph/component-class.h>
#include <babeltrace/plugin/plugin.h>
#include <babeltrace/plugin/plugin-internal.h>
#include <babeltrace/graph/component-class.h>
@@
-64,13
+57,7
@@
enum python_state {
} python_state = PYTHON_STATE_NOT_INITED;
static PyObject *py_try_load_plugin_module_func = NULL;
} python_state = PYTHON_STATE_NOT_INITED;
static PyObject *py_try_load_plugin_module_func = NULL;
-
-static
-void __attribute__((constructor)) logging_ctor(void)
-{
- python_plugin_provider_log_level =
- bt_log_get_level_from_env("BABELTRACE_PYTHON_PLUGIN_PROVIDER_LOG_LEVEL");
-}
+static bool python_was_initialized_by_us;
static
void print_python_traceback_warn(void)
static
void print_python_traceback_warn(void)
@@
-94,7
+81,9
@@
void init_python(void)
{
PyObject *py_bt2_py_plugin_mod = NULL;
const char *dis_python_env;
{
PyObject *py_bt2_py_plugin_mod = NULL;
const char *dis_python_env;
+#ifndef __MINGW32__
sighandler_t old_sigint = signal(SIGINT, SIG_DFL);
sighandler_t old_sigint = signal(SIGINT, SIG_DFL);
+#endif
if (python_state != PYTHON_STATE_NOT_INITED) {
goto end;
if (python_state != PYTHON_STATE_NOT_INITED) {
goto end;
@@
-113,9
+102,14
@@
void init_python(void)
}
if (!Py_IsInitialized()) {
}
if (!Py_IsInitialized()) {
+ BT_LOGI_STR("Python interpreter is not initialized: initializing Python interpreter.");
Py_InitializeEx(0);
Py_InitializeEx(0);
+ python_was_initialized_by_us = true;
BT_LOGI("Initialized Python interpreter: version=\"%s\"",
Py_GetVersion());
BT_LOGI("Initialized Python interpreter: version=\"%s\"",
Py_GetVersion());
+ } else {
+ BT_LOGI("Python interpreter is already initialized: version=\"%s\"",
+ Py_GetVersion());
}
py_bt2_py_plugin_mod = PyImport_ImportModule("bt2.py_plugin");
}
py_bt2_py_plugin_mod = PyImport_ImportModule("bt2.py_plugin");
@@
-136,9
+130,11
@@
void init_python(void)
python_state = PYTHON_STATE_FULLY_INITIALIZED;
end:
python_state = PYTHON_STATE_FULLY_INITIALIZED;
end:
+#ifndef __MINGW32__
if (old_sigint != SIG_ERR) {
(void) signal(SIGINT, old_sigint);
}
if (old_sigint != SIG_ERR) {
(void) signal(SIGINT, old_sigint);
}
+#endif
print_python_traceback_warn();
pyerr_clear();
print_python_traceback_warn();
pyerr_clear();
@@
-148,7
+144,7
@@
end:
__attribute__((destructor)) static
void fini_python(void) {
__attribute__((destructor)) static
void fini_python(void) {
- if (Py_IsInitialized()) {
+ if (Py_IsInitialized()
&& python_was_initialized_by_us
) {
if (py_try_load_plugin_module_func) {
Py_DECREF(py_try_load_plugin_module_func);
py_try_load_plugin_module_func = NULL;
if (py_try_load_plugin_module_func) {
Py_DECREF(py_try_load_plugin_module_func);
py_try_load_plugin_module_func = NULL;
@@
-179,8
+175,8
@@
struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info)
const char *version_extra = NULL;
int ret;
const char *version_extra = NULL;
int ret;
-
assert
(plugin_info);
-
assert
(python_state == PYTHON_STATE_FULLY_INITIALIZED);
+
BT_ASSERT
(plugin_info);
+
BT_ASSERT
(python_state == PYTHON_STATE_FULLY_INITIALIZED);
py_name = PyObject_GetAttrString(plugin_info, "name");
if (!py_name) {
BT_LOGW("Cannot find `name` attribute in Python plugin info object: "
py_name = PyObject_GetAttrString(plugin_info, "name");
if (!py_name) {
BT_LOGW("Cannot find `name` attribute in Python plugin info object: "
@@
-271,9
+267,9
@@
struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info)
PyObject *py_minor = PyTuple_GetItem(py_version, 1);
PyObject *py_patch = PyTuple_GetItem(py_version, 2);
PyObject *py_minor = PyTuple_GetItem(py_version, 1);
PyObject *py_patch = PyTuple_GetItem(py_version, 2);
-
assert
(py_major);
-
assert
(py_minor);
-
assert
(py_patch);
+
BT_ASSERT
(py_major);
+
BT_ASSERT
(py_minor);
+
BT_ASSERT
(py_patch);
if (PyLong_Check(py_major)) {
major = PyLong_AsUnsignedLong(py_major);
if (PyLong_Check(py_major)) {
major = PyLong_AsUnsignedLong(py_major);
@@
-298,7
+294,7
@@
struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info)
if (PyTuple_Size(py_version) >= 4) {
PyObject *py_extra = PyTuple_GetItem(py_version, 3);
if (PyTuple_Size(py_version) >= 4) {
PyObject *py_extra = PyTuple_GetItem(py_version, 3);
-
assert
(py_extra);
+
BT_ASSERT
(py_extra);
if (PyUnicode_Check(py_extra)) {
version_extra = PyUnicode_AsUTF8(py_extra);
if (PyUnicode_Check(py_extra)) {
version_extra = PyUnicode_AsUTF8(py_extra);
@@
-342,7
+338,7
@@
struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info)
py_comp_class_addr =
PyList_GetItem(py_comp_class_addrs, i);
py_comp_class_addr =
PyList_GetItem(py_comp_class_addrs, i);
-
assert
(py_comp_class_addr);
+
BT_ASSERT
(py_comp_class_addr);
if (PyLong_Check(py_comp_class_addr)) {
comp_class = (struct bt_component_class *)
PyLong_AsUnsignedLongLong(py_comp_class_addr);
if (PyLong_Check(py_comp_class_addr)) {
comp_class = (struct bt_component_class *)
PyLong_AsUnsignedLongLong(py_comp_class_addr);
@@
-379,7
+375,7
@@
struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info)
error:
print_python_traceback_warn();
pyerr_clear();
error:
print_python_traceback_warn();
pyerr_clear();
- BT_
PU
T(plugin);
+ BT_
OBJECT_PUT_REF_AND_RESE
T(plugin);
end:
Py_XDECREF(py_name);
end:
Py_XDECREF(py_name);
@@
-400,7
+396,7
@@
struct bt_plugin_set *bt_plugin_python_create_all_from_file(const char *path)
gchar *basename = NULL;
size_t path_len;
gchar *basename = NULL;
size_t path_len;
-
assert
(path);
+
BT_ASSERT
(path);
if (python_state == PYTHON_STATE_CANNOT_INITIALIZE) {
/*
if (python_state == PYTHON_STATE_CANNOT_INITIALIZE) {
/*
@@
-496,10
+492,10
@@
struct bt_plugin_set *bt_plugin_python_create_all_from_file(const char *path)
goto end;
error:
goto end;
error:
- BT_
PU
T(plugin_set);
+ BT_
OBJECT_PUT_REF_AND_RESE
T(plugin_set);
end:
end:
- bt_
put
(plugin);
+ bt_
object_put_ref
(plugin);
Py_XDECREF(py_plugin_info);
g_free(basename);
return plugin_set;
Py_XDECREF(py_plugin_info);
g_free(basename);
return plugin_set;
This page took
0.025974 seconds
and
4
git commands to generate.