1 From edc7b6abb0c125eeb888748c334897f60aab0854 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
3 Date: Fri, 28 Feb 2020 12:48:14 +0100
4 Subject: [PATCH] Parenthesize Py<type>_Check() in ifs
6 In C, if expressions should be parenthesized.
7 PyLong_Check, PyUnicode_Check etc. happened to expand to a parenthesized
8 expression before, but that's not API to rely on.
10 Since Python 3.9.0a4 it needs to be parenthesized explicitly.
12 Fixes https://gitlab.gnome.org/GNOME/libxml2/issues/149
14 python/libxml.c | 4 ++--
15 python/types.c | 12 ++++++------
16 2 files changed, 8 insertions(+), 8 deletions(-)
18 diff --git a/python/libxml.c b/python/libxml.c
19 index bc676c4e..81e709f3 100644
22 @@ -294,7 +294,7 @@ xmlPythonFileReadRaw (void * context, char * buffer, int len) {
23 lenread = PyBytes_Size(ret);
24 data = PyBytes_AsString(ret);
25 #ifdef PyUnicode_Check
26 - } else if PyUnicode_Check (ret) {
27 + } else if (PyUnicode_Check (ret)) {
28 #if PY_VERSION_HEX >= 0x03030000
31 @@ -359,7 +359,7 @@ xmlPythonFileRead (void * context, char * buffer, int len) {
32 lenread = PyBytes_Size(ret);
33 data = PyBytes_AsString(ret);
34 #ifdef PyUnicode_Check
35 - } else if PyUnicode_Check (ret) {
36 + } else if (PyUnicode_Check (ret)) {
37 #if PY_VERSION_HEX >= 0x03030000
40 diff --git a/python/types.c b/python/types.c
41 index c2bafeb1..ed284ec7 100644
44 @@ -602,16 +602,16 @@ libxml_xmlXPathObjectPtrConvert(PyObject *obj)
48 - if PyFloat_Check (obj) {
49 + if (PyFloat_Check (obj)) {
50 ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
51 - } else if PyLong_Check(obj) {
52 + } else if (PyLong_Check(obj)) {
54 ret = xmlXPathNewFloat((double) PyLong_AS_LONG(obj));
56 ret = xmlXPathNewFloat((double) PyInt_AS_LONG(obj));
59 - } else if PyBool_Check (obj) {
60 + } else if (PyBool_Check (obj)) {
63 ret = xmlXPathNewBoolean(1);
64 @@ -620,14 +620,14 @@ libxml_xmlXPathObjectPtrConvert(PyObject *obj)
65 ret = xmlXPathNewBoolean(0);
68 - } else if PyBytes_Check (obj) {
69 + } else if (PyBytes_Check (obj)) {
72 str = xmlStrndup((const xmlChar *) PyBytes_AS_STRING(obj),
73 PyBytes_GET_SIZE(obj));
74 ret = xmlXPathWrapString(str);
75 #ifdef PyUnicode_Check
76 - } else if PyUnicode_Check (obj) {
77 + } else if (PyUnicode_Check (obj)) {
78 #if PY_VERSION_HEX >= 0x03030000
81 @@ -650,7 +650,7 @@ libxml_xmlXPathObjectPtrConvert(PyObject *obj)
82 ret = xmlXPathWrapString(str);
85 - } else if PyList_Check (obj) {
86 + } else if (PyList_Check (obj)) {