[libxml2] Convert python/libxml.c to PY_SSIZE_T_CLEAN



commit ac5e99911a45ad6f57a6aa7b33fd2de9da72aa72
Author: Victor Stinner <vstinner python org>
Date:   Tue Nov 10 15:42:36 2020 +0100

    Convert python/libxml.c to PY_SSIZE_T_CLEAN
    
    Define PY_SSIZE_T_CLEAN macro in python/libxml.c and cast the string
    length (int len) explicitly to Py_ssize_t when passing a string to a
    function call using PyObject_CallMethod() with the "s#" format.

 python/libxml.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
---
diff --git a/python/libxml.c b/python/libxml.c
index 81e709f3..3b66bd61 100644
--- a/python/libxml.c
+++ b/python/libxml.c
@@ -11,6 +11,7 @@
  *
  * daniel veillard com
  */
+#define PY_SSIZE_T_CLEAN
 #include <Python.h>
 #include <fileobject.h>
 /* #include "config.h" */
@@ -1048,10 +1049,10 @@ pythonCharacters(void *user_data, const xmlChar * ch, int len)
     if (type != 0) {
         if (type == 1)
             result = PyObject_CallMethod(handler, (char *) "characters",
-                                         (char *) "s#", ch, len);
+                                         (char *) "s#", ch, (Py_ssize_t)len);
         else if (type == 2)
             result = PyObject_CallMethod(handler, (char *) "data",
-                                         (char *) "s#", ch, len);
+                                         (char *) "s#", ch, (Py_ssize_t)len);
         if (PyErr_Occurred())
             PyErr_Print();
         Py_XDECREF(result);
@@ -1078,11 +1079,11 @@ pythonIgnorableWhitespace(void *user_data, const xmlChar * ch, int len)
             result =
                 PyObject_CallMethod(handler,
                                     (char *) "ignorableWhitespace",
-                                    (char *) "s#", ch, len);
+                                    (char *) "s#", ch, (Py_ssize_t)len);
         else if (type == 2)
             result =
                 PyObject_CallMethod(handler, (char *) "data",
-                                    (char *) "s#", ch, len);
+                                    (char *) "s#", ch, (Py_ssize_t)len);
         Py_XDECREF(result);
     }
 }
@@ -1223,11 +1224,11 @@ pythonCdataBlock(void *user_data, const xmlChar * ch, int len)
         if (type == 1)
             result =
                 PyObject_CallMethod(handler, (char *) "cdataBlock",
-                                    (char *) "s#", ch, len);
+                                    (char *) "s#", ch, (Py_ssize_t)len);
         else if (type == 2)
             result =
                 PyObject_CallMethod(handler, (char *) "cdata",
-                                    (char *) "s#", ch, len);
+                                    (char *) "s#", ch, (Py_ssize_t)len);
         if (PyErr_Occurred())
             PyErr_Print();
         Py_XDECREF(result);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]