diff --git a/ChangeLog.asciidoc b/ChangeLog.asciidoc index a8f2fb204..3d1c7ccf2 100644 --- a/ChangeLog.asciidoc +++ b/ChangeLog.asciidoc @@ -154,6 +154,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] * irc: fix parsing of nick in host when '!' is not found (bug #41640) * lua: fix interpreter used after unload of a script * perl: fix context used after unload of a script +* python: fix read of return value for callbacks returning an integer + in Python 2.x (closes #125) * python: fix interpreter used after unload of a script * relay: fix crash when closing relay buffers (closes #57, closes #78) * relay: check pointers received in hdata command to prevent crashes with bad 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;