fix-python39.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. From e4fb36841800038c289997432ca547c9bfef9db1 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
  5. In C, if expressions should be parenthesized.
  6. PyLong_Check, PyUnicode_Check etc. happened to expand to a parenthesized
  7. expression before, but that's not API to rely on.
  8. Since Python 3.9.0a4 it needs to be parenthesized explicitly.
  9. Fixes https://gitlab.gnome.org/GNOME/libxml2/issues/149
  10. Upstream-Status: Backport
  11. Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
  12. ---
  13. python/libxml.c | 4 ++--
  14. python/types.c | 12 ++++++------
  15. 2 files changed, 8 insertions(+), 8 deletions(-)
  16. diff --git a/python/libxml.c b/python/libxml.c
  17. index bc676c4e0..81e709f34 100644
  18. --- a/python/libxml.c
  19. +++ b/python/libxml.c
  20. @@ -294,7 +294,7 @@ xmlPythonFileReadRaw (void * context, char * buffer, int len) {
  21. lenread = PyBytes_Size(ret);
  22. data = PyBytes_AsString(ret);
  23. #ifdef PyUnicode_Check
  24. - } else if PyUnicode_Check (ret) {
  25. + } else if (PyUnicode_Check (ret)) {
  26. #if PY_VERSION_HEX >= 0x03030000
  27. Py_ssize_t size;
  28. const char *tmp;
  29. @@ -359,7 +359,7 @@ xmlPythonFileRead (void * context, char * buffer, int len) {
  30. lenread = PyBytes_Size(ret);
  31. data = PyBytes_AsString(ret);
  32. #ifdef PyUnicode_Check
  33. - } else if PyUnicode_Check (ret) {
  34. + } else if (PyUnicode_Check (ret)) {
  35. #if PY_VERSION_HEX >= 0x03030000
  36. Py_ssize_t size;
  37. const char *tmp;
  38. diff --git a/python/types.c b/python/types.c
  39. index c2bafeb19..ed284ec74 100644
  40. --- a/python/types.c
  41. +++ b/python/types.c
  42. @@ -602,16 +602,16 @@ libxml_xmlXPathObjectPtrConvert(PyObject *obj)
  43. if (obj == NULL) {
  44. return (NULL);
  45. }
  46. - if PyFloat_Check (obj) {
  47. + if (PyFloat_Check (obj)) {
  48. ret = xmlXPathNewFloat((double) PyFloat_AS_DOUBLE(obj));
  49. - } else if PyLong_Check(obj) {
  50. + } else if (PyLong_Check(obj)) {
  51. #ifdef PyLong_AS_LONG
  52. ret = xmlXPathNewFloat((double) PyLong_AS_LONG(obj));
  53. #else
  54. ret = xmlXPathNewFloat((double) PyInt_AS_LONG(obj));
  55. #endif
  56. #ifdef PyBool_Check
  57. - } else if PyBool_Check (obj) {
  58. + } else if (PyBool_Check (obj)) {
  59. if (obj == Py_True) {
  60. ret = xmlXPathNewBoolean(1);
  61. @@ -620,14 +620,14 @@ libxml_xmlXPathObjectPtrConvert(PyObject *obj)
  62. ret = xmlXPathNewBoolean(0);
  63. }
  64. #endif
  65. - } else if PyBytes_Check (obj) {
  66. + } else if (PyBytes_Check (obj)) {
  67. xmlChar *str;
  68. str = xmlStrndup((const xmlChar *) PyBytes_AS_STRING(obj),
  69. PyBytes_GET_SIZE(obj));
  70. ret = xmlXPathWrapString(str);
  71. #ifdef PyUnicode_Check
  72. - } else if PyUnicode_Check (obj) {
  73. + } else if (PyUnicode_Check (obj)) {
  74. #if PY_VERSION_HEX >= 0x03030000
  75. xmlChar *str;
  76. const char *tmp;
  77. @@ -650,7 +650,7 @@ libxml_xmlXPathObjectPtrConvert(PyObject *obj)
  78. ret = xmlXPathWrapString(str);
  79. #endif
  80. #endif
  81. - } else if PyList_Check (obj) {
  82. + } else if (PyList_Check (obj)) {
  83. int i;
  84. PyObject *node;
  85. xmlNodePtr cur;
  86. --
  87. GitLab