1 commit e4fb36841800038c289997432ca547c9bfef9db1
2 Author: Miro HronĨok <miro@hroncok.cz>
3 Date: Fri Feb 28 12:48:14 2020 +0100
5 Parenthesize Py<type>_Check() in ifs
7 In C, if expressions should be parenthesized.
8 PyLong_Check, PyUnicode_Check etc. happened to expand to a parenthesized
9 expression before, but that's not API to rely on.
11 Since Python 3.9.0a4 it needs to be parenthesized explicitly.
13 Fixes https://gitlab.gnome.org/GNOME/libxml2/issues/149
15 diff --git a/python/libxml.c b/python/libxml.c
16 index bc676c4e..81e709f3 100644
19 @@ -294,7 +294,7 @@ xmlPythonFileReadRaw (void * context, char * buffer, int len) {
20 lenread = PyBytes_Size(ret);
21 data = PyBytes_AsString(ret);
22 #ifdef PyUnicode_Check
23 - } else if PyUnicode_Check (ret) {
24 + } else if (PyUnicode_Check (ret)) {
25 #if PY_VERSION_HEX >= 0x03030000
28 @@ -359,7 +359,7 @@ xmlPythonFileRead (void * context, char * buffer, int len) {
29 lenread = PyBytes_Size(ret);
30 data = PyBytes_AsString(ret);
31 #ifdef PyUnicode_Check
32 - } else if PyUnicode_Check (ret) {
33 + } else if (PyUnicode_Check (ret)) {
34 #if PY_VERSION_HEX >= 0x03030000
37 diff --git a/python/types.c b/python/types.c
38 index c2bafeb1..ed284ec7 100644
41 @@ -602,16 +602,16 @@ libxml_xmlXPathObjectPtrConvert(PyObject *obj)
45 - if PyFloat_Check (obj) {
46 + if (PyFloat_Check (obj)) {
47 ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
48 - } else if PyLong_Check(obj) {
49 + } else if (PyLong_Check(obj)) {
51 ret = xmlXPathNewFloat((double) PyLong_AS_LONG(obj));
53 ret = xmlXPathNewFloat((double) PyInt_AS_LONG(obj));
56 - } else if PyBool_Check (obj) {
57 + } else if (PyBool_Check (obj)) {
60 ret = xmlXPathNewBoolean(1);
61 @@ -620,14 +620,14 @@ libxml_xmlXPathObjectPtrConvert(PyObject *obj)
62 ret = xmlXPathNewBoolean(0);
65 - } else if PyBytes_Check (obj) {
66 + } else if (PyBytes_Check (obj)) {
69 str = xmlStrndup((const xmlChar *) PyBytes_AS_STRING(obj),
70 PyBytes_GET_SIZE(obj));
71 ret = xmlXPathWrapString(str);
72 #ifdef PyUnicode_Check
73 - } else if PyUnicode_Check (obj) {
74 + } else if (PyUnicode_Check (obj)) {
75 #if PY_VERSION_HEX >= 0x03030000
78 @@ -650,7 +650,7 @@ libxml_xmlXPathObjectPtrConvert(PyObject *obj)
79 ret = xmlXPathWrapString(str);
82 - } else if PyList_Check (obj) {
83 + } else if (PyList_Check (obj)) {