Tidy python3 conditional code
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
./configure PYTHON_VERSION=3 CFLAGS='-g3 -O0' CXXFLAGS='-g3 -O0' --enable-python-plugins $@
|
#./configure PYTHON_VERSION=3 CFLAGS='-g3 -O0' CXXFLAGS='-g3 -O0' --enable-python-plugins $@
|
||||||
#./configure CFLAGS='-g3 -O0' CXXFLAGS='-g3 -O0' --enable-python-plugins $@
|
./configure CFLAGS='-g3 -O0' CXXFLAGS='-g3 -O0' --enable-python-plugins $@
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ python_api_cons_alert(PyObject *self, PyObject *args)
|
|||||||
disable_python_threads();
|
disable_python_threads();
|
||||||
|
|
||||||
return Py_BuildValue("");
|
return Py_BuildValue("");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
@@ -130,11 +129,7 @@ python_api_register_command(PyObject *self, PyObject *args)
|
|||||||
Py_ssize_t i = 0;
|
Py_ssize_t i = 0;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
PyObject *item = PyList_GetItem(synopsis, i);
|
PyObject *item = PyList_GetItem(synopsis, i);
|
||||||
#if PY_MAJOR_VERSION >= 3
|
char *c_item = python_object_to_string(item);
|
||||||
char *c_item = PyBytes_AS_STRING(PyUnicode_AsUTF8String(item));
|
|
||||||
#else
|
|
||||||
char *c_item = PyString_AsString(item);
|
|
||||||
#endif
|
|
||||||
c_synopsis[i] = c_item;
|
c_synopsis[i] = c_item;
|
||||||
}
|
}
|
||||||
c_synopsis[len] = NULL;
|
c_synopsis[len] = NULL;
|
||||||
@@ -149,19 +144,11 @@ python_api_register_command(PyObject *self, PyObject *args)
|
|||||||
return Py_BuildValue("");
|
return Py_BuildValue("");
|
||||||
}
|
}
|
||||||
PyObject *arg = PyList_GetItem(item, 0);
|
PyObject *arg = PyList_GetItem(item, 0);
|
||||||
#if PY_MAJOR_VERSION >= 3
|
char *c_arg = python_object_to_string(arg);
|
||||||
char *c_arg = PyBytes_AS_STRING(PyUnicode_AsUTF8String(arg));
|
|
||||||
#else
|
|
||||||
char *c_arg = PyString_AsString(arg);
|
|
||||||
#endif
|
|
||||||
PyObject *desc = PyList_GetItem(item, 1);
|
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
|
||||||
char *c_desc = PyBytes_AS_STRING(PyUnicode_AsUTF8String(desc));
|
|
||||||
#else
|
|
||||||
char *c_desc = PyString_AsString(desc);
|
|
||||||
#endif
|
|
||||||
c_arguments[i][0] = c_arg;
|
c_arguments[i][0] = c_arg;
|
||||||
|
|
||||||
|
PyObject *desc = PyList_GetItem(item, 1);
|
||||||
|
char *c_desc = python_object_to_string(desc);
|
||||||
c_arguments[i][1] = c_desc;
|
c_arguments[i][1] = c_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,11 +160,7 @@ python_api_register_command(PyObject *self, PyObject *args)
|
|||||||
i = 0;
|
i = 0;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
PyObject *item = PyList_GetItem(examples, i);
|
PyObject *item = PyList_GetItem(examples, i);
|
||||||
#if PY_MAJOR_VERSION >= 3
|
char *c_item = python_object_to_string(item);
|
||||||
char *c_item = PyBytes_AS_STRING(PyUnicode_AsUTF8String(item));
|
|
||||||
#else
|
|
||||||
char *c_item = PyString_AsString(item);
|
|
||||||
#endif
|
|
||||||
c_examples[i] = c_item;
|
c_examples[i] = c_item;
|
||||||
}
|
}
|
||||||
c_examples[len] = NULL;
|
c_examples[len] = NULL;
|
||||||
@@ -236,11 +219,7 @@ python_api_completer_add(PyObject *self, PyObject *args)
|
|||||||
Py_ssize_t i = 0;
|
Py_ssize_t i = 0;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
PyObject *item = PyList_GetItem(items, i);
|
PyObject *item = PyList_GetItem(items, i);
|
||||||
#if PY_MAJOR_VERSION >= 3
|
char *c_item = python_object_to_string(item);
|
||||||
char *c_item = PyBytes_AS_STRING(PyUnicode_AsUTF8String(item));
|
|
||||||
#else
|
|
||||||
char *c_item = PyString_AsString(item);
|
|
||||||
#endif
|
|
||||||
c_items[i] = c_item;
|
c_items[i] = c_item;
|
||||||
}
|
}
|
||||||
c_items[len] = NULL;
|
c_items[len] = NULL;
|
||||||
@@ -273,11 +252,7 @@ python_api_completer_remove(PyObject *self, PyObject *args)
|
|||||||
Py_ssize_t i = 0;
|
Py_ssize_t i = 0;
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
PyObject *item = PyList_GetItem(items, i);
|
PyObject *item = PyList_GetItem(items, i);
|
||||||
#if PY_MAJOR_VERSION >= 3
|
char *c_item = python_object_to_string(item);
|
||||||
char *c_item = PyBytes_AS_STRING(PyUnicode_AsUTF8String(item));
|
|
||||||
#else
|
|
||||||
char *c_item = PyString_AsString(item);
|
|
||||||
#endif
|
|
||||||
c_items[i] = c_item;
|
c_items[i] = c_item;
|
||||||
}
|
}
|
||||||
c_items[len] = NULL;
|
c_items[len] = NULL;
|
||||||
@@ -891,14 +866,20 @@ _python_plugin_name(void)
|
|||||||
{
|
{
|
||||||
PyThreadState *ts = PyThreadState_Get();
|
PyThreadState *ts = PyThreadState_Get();
|
||||||
PyFrameObject *frame = ts->frame;
|
PyFrameObject *frame = ts->frame;
|
||||||
#if PY_MAJOR_VERSION >= 3
|
char const* filename = python_object_to_string(frame->f_code->co_filename);
|
||||||
char const *filename = PyBytes_AS_STRING(PyUnicode_AsUTF8String(frame->f_code->co_filename));
|
|
||||||
#else
|
|
||||||
char const* filename = PyString_AsString(frame->f_code->co_filename);
|
|
||||||
#endif
|
|
||||||
gchar **split = g_strsplit(filename, "/", 0);
|
gchar **split = g_strsplit(filename, "/", 0);
|
||||||
char *plugin_name = strdup(split[g_strv_length(split)-1]);
|
char *plugin_name = strdup(split[g_strv_length(split)-1]);
|
||||||
g_strfreev(split);
|
g_strfreev(split);
|
||||||
|
|
||||||
return plugin_name;
|
return plugin_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
python_object_to_string(void *obj)
|
||||||
|
{
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
return PyBytes_AS_STRING(PyUnicode_AsUTF8String(obj));
|
||||||
|
#else
|
||||||
|
return PyString_AsString(obj);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,4 +43,6 @@ void python_command_callback(PluginCommand *command, gchar **args);
|
|||||||
void python_timed_callback(PluginTimedFunction *timed_function);
|
void python_timed_callback(PluginTimedFunction *timed_function);
|
||||||
void python_window_callback(PluginWindowCallback *window_callback, char *tag, char *line);
|
void python_window_callback(PluginWindowCallback *window_callback, char *tag, char *line);
|
||||||
|
|
||||||
|
char* python_object_to_string(void *obj);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -47,6 +47,8 @@
|
|||||||
static PyThreadState *thread_state;
|
static PyThreadState *thread_state;
|
||||||
static GHashTable *loaded_modules;
|
static GHashTable *loaded_modules;
|
||||||
|
|
||||||
|
static char* _python_parse_string_result(PyObject *result);
|
||||||
|
|
||||||
void
|
void
|
||||||
allow_python_threads()
|
allow_python_threads()
|
||||||
{
|
{
|
||||||
@@ -284,33 +286,10 @@ python_pre_chat_message_display_hook(ProfPlugin *plugin, const char *const jid,
|
|||||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
python_check_error();
|
python_check_error();
|
||||||
Py_XDECREF(p_function);
|
Py_XDECREF(p_function);
|
||||||
|
char *result_str = _python_parse_string_result(result);
|
||||||
|
allow_python_threads();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
return result_str;
|
||||||
if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyBytes_AS_STRING(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (PyUnicode_Check(result)) {
|
|
||||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyString_AsString(result));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,33 +333,10 @@ python_pre_chat_message_send_hook(ProfPlugin *plugin, const char * const jid, co
|
|||||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
python_check_error();
|
python_check_error();
|
||||||
Py_XDECREF(p_function);
|
Py_XDECREF(p_function);
|
||||||
|
char *result_str = _python_parse_string_result(result);
|
||||||
|
allow_python_threads();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
return result_str;
|
||||||
if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyBytes_AS_STRING(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (PyUnicode_Check(result)) {
|
|
||||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyString_AsString(result));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,33 +380,10 @@ python_pre_room_message_display_hook(ProfPlugin *plugin, const char * const room
|
|||||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
python_check_error();
|
python_check_error();
|
||||||
Py_XDECREF(p_function);
|
Py_XDECREF(p_function);
|
||||||
|
char *result_str = _python_parse_string_result(result);
|
||||||
|
allow_python_threads();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
return result_str;
|
||||||
if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyBytes_AS_STRING(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (PyUnicode_Check(result)) {
|
|
||||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyString_AsString(result));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -495,33 +428,10 @@ python_pre_room_message_send_hook(ProfPlugin *plugin, const char *const room, co
|
|||||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
python_check_error();
|
python_check_error();
|
||||||
Py_XDECREF(p_function);
|
Py_XDECREF(p_function);
|
||||||
|
char *result_str = _python_parse_string_result(result);
|
||||||
|
allow_python_threads();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
return result_str;
|
||||||
if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyBytes_AS_STRING(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (PyUnicode_Check(result)) {
|
|
||||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyString_AsString(result));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,33 +498,10 @@ python_pre_priv_message_display_hook(ProfPlugin *plugin, const char *const room,
|
|||||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
python_check_error();
|
python_check_error();
|
||||||
Py_XDECREF(p_function);
|
Py_XDECREF(p_function);
|
||||||
|
char *result_str = _python_parse_string_result(result);
|
||||||
|
allow_python_threads();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
return result_str;
|
||||||
if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyBytes_AS_STRING(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (PyUnicode_Check(result)) {
|
|
||||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyString_AsString(result));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,33 +547,10 @@ python_pre_priv_message_send_hook(ProfPlugin *plugin, const char *const room, co
|
|||||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
python_check_error();
|
python_check_error();
|
||||||
Py_XDECREF(p_function);
|
Py_XDECREF(p_function);
|
||||||
|
char *result_str = _python_parse_string_result(result);
|
||||||
|
allow_python_threads();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
return result_str;
|
||||||
if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyBytes_AS_STRING(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (PyUnicode_Check(result)) {
|
|
||||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyString_AsString(result));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -731,33 +595,10 @@ python_on_message_stanza_send_hook(ProfPlugin *plugin, const char *const text)
|
|||||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
python_check_error();
|
python_check_error();
|
||||||
Py_XDECREF(p_function);
|
Py_XDECREF(p_function);
|
||||||
|
char *result_str = _python_parse_string_result(result);
|
||||||
|
allow_python_threads();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
return result_str;
|
||||||
if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyBytes_AS_STRING(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (PyUnicode_Check(result)) {
|
|
||||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyString_AsString(result));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -809,33 +650,10 @@ python_on_presence_stanza_send_hook(ProfPlugin *plugin, const char *const text)
|
|||||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
python_check_error();
|
python_check_error();
|
||||||
Py_XDECREF(p_function);
|
Py_XDECREF(p_function);
|
||||||
|
char *result_str = _python_parse_string_result(result);
|
||||||
|
allow_python_threads();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
return result_str;
|
||||||
if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyBytes_AS_STRING(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (PyUnicode_Check(result)) {
|
|
||||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyString_AsString(result));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -887,33 +705,10 @@ python_on_iq_stanza_send_hook(ProfPlugin *plugin, const char *const text)
|
|||||||
PyObject *result = PyObject_CallObject(p_function, p_args);
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
python_check_error();
|
python_check_error();
|
||||||
Py_XDECREF(p_function);
|
Py_XDECREF(p_function);
|
||||||
|
char *result_str = _python_parse_string_result(result);
|
||||||
|
allow_python_threads();
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
return result_str;
|
||||||
if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyBytes_AS_STRING(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (PyUnicode_Check(result)) {
|
|
||||||
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else if (result != Py_None) {
|
|
||||||
char *result_str = strdup(PyString_AsString(result));
|
|
||||||
Py_XDECREF(result);
|
|
||||||
allow_python_threads();
|
|
||||||
return result_str;
|
|
||||||
} else {
|
|
||||||
allow_python_threads();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1063,3 +858,29 @@ python_shutdown(void)
|
|||||||
g_hash_table_destroy(loaded_modules);
|
g_hash_table_destroy(loaded_modules);
|
||||||
Py_Finalize();
|
Py_Finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char*
|
||||||
|
_python_parse_string_result(PyObject *result)
|
||||||
|
{
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
if (result != Py_None) {
|
||||||
|
char *result_str = strdup(PyBytes_AS_STRING(PyUnicode_AsUTF8String(result)));
|
||||||
|
Py_XDECREF(result);
|
||||||
|
return result_str;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (PyUnicode_Check(result)) {
|
||||||
|
char *result_str = strdup(PyString_AsString(PyUnicode_AsUTF8String(result)));
|
||||||
|
Py_XDECREF(result);
|
||||||
|
return result_str;
|
||||||
|
} else if (result != Py_None) {
|
||||||
|
char *result_str = strdup(PyString_AsString(result));
|
||||||
|
Py_XDECREF(result);
|
||||||
|
return result_str;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user