diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2014-07-12 14:51:39 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2014-07-12 14:51:39 +0200 |
commit | 3ec3fb4e8dc5078b1680d2509aae12384a163d93 (patch) | |
tree | bb6656b6a1b1fa96986c71b618765f58297f07d9 /src | |
parent | c5710c6f247747e17edbc1f5356cd14327594af4 (diff) | |
download | weechat-3ec3fb4e8dc5078b1680d2509aae12384a163d93.zip |
python: fix read of return value for callbacks returning an integer in Python 2.x (closes #125)
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/python/weechat-python.c | 4 | ||||
-rw-r--r-- | src/plugins/python/weechat-python.h | 8 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/plugins/python/weechat-python.c b/src/plugins/python/weechat-python.c index 8992e8450..aaf6f9210 100644 --- a/src/plugins/python/weechat-python.c +++ b/src/plugins/python/weechat-python.c @@ -391,11 +391,11 @@ weechat_python_exec (struct t_plugin_script *script, ret_value = NULL; Py_XDECREF(rc); } - else if ((ret_type == WEECHAT_SCRIPT_EXEC_INT) && (PyLong_Check (rc))) + else if ((ret_type == WEECHAT_SCRIPT_EXEC_INT) && (PY_INTEGER_CHECK(rc))) { ret_int = malloc (sizeof (*ret_int)); if (ret_int) - *ret_int = (int) PyLong_AsLong(rc); + *ret_int = (int) PyLong_AsLong (rc); ret_value = ret_int; Py_XDECREF(rc); } diff --git a/src/plugins/python/weechat-python.h b/src/plugins/python/weechat-python.h index 73c8105ca..355e08ad5 100644 --- a/src/plugins/python/weechat-python.h +++ b/src/plugins/python/weechat-python.h @@ -34,6 +34,14 @@ #define PyUnicode_FromString PyString_FromString #endif +#if PY_MAJOR_VERSION >= 3 +/* check of integer with Python >= 3.x */ +#define PY_INTEGER_CHECK(x) (PyLong_Check(x)) +#else +/* check of integer with Python <= 2.x */ +#define PY_INTEGER_CHECK(x) (PyInt_Check(x) || PyLong_Check(x)) +#endif + extern struct t_weechat_plugin *weechat_python_plugin; extern int python_quiet; |