1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

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.
This commit is contained in:
Victor Stinner
2020-11-10 15:42:36 +01:00
committed by Nick Wellnhofer
parent f42a0524c6
commit ac5e99911a

View File

@ -11,6 +11,7 @@
* *
* daniel@veillard.com * daniel@veillard.com
*/ */
#define PY_SSIZE_T_CLEAN
#include <Python.h> #include <Python.h>
#include <fileobject.h> #include <fileobject.h>
/* #include "config.h" */ /* #include "config.h" */
@ -1048,10 +1049,10 @@ pythonCharacters(void *user_data, const xmlChar * ch, int len)
if (type != 0) { if (type != 0) {
if (type == 1) if (type == 1)
result = PyObject_CallMethod(handler, (char *) "characters", result = PyObject_CallMethod(handler, (char *) "characters",
(char *) "s#", ch, len); (char *) "s#", ch, (Py_ssize_t)len);
else if (type == 2) else if (type == 2)
result = PyObject_CallMethod(handler, (char *) "data", result = PyObject_CallMethod(handler, (char *) "data",
(char *) "s#", ch, len); (char *) "s#", ch, (Py_ssize_t)len);
if (PyErr_Occurred()) if (PyErr_Occurred())
PyErr_Print(); PyErr_Print();
Py_XDECREF(result); Py_XDECREF(result);
@ -1078,11 +1079,11 @@ pythonIgnorableWhitespace(void *user_data, const xmlChar * ch, int len)
result = result =
PyObject_CallMethod(handler, PyObject_CallMethod(handler,
(char *) "ignorableWhitespace", (char *) "ignorableWhitespace",
(char *) "s#", ch, len); (char *) "s#", ch, (Py_ssize_t)len);
else if (type == 2) else if (type == 2)
result = result =
PyObject_CallMethod(handler, (char *) "data", PyObject_CallMethod(handler, (char *) "data",
(char *) "s#", ch, len); (char *) "s#", ch, (Py_ssize_t)len);
Py_XDECREF(result); Py_XDECREF(result);
} }
} }
@ -1223,11 +1224,11 @@ pythonCdataBlock(void *user_data, const xmlChar * ch, int len)
if (type == 1) if (type == 1)
result = result =
PyObject_CallMethod(handler, (char *) "cdataBlock", PyObject_CallMethod(handler, (char *) "cdataBlock",
(char *) "s#", ch, len); (char *) "s#", ch, (Py_ssize_t)len);
else if (type == 2) else if (type == 2)
result = result =
PyObject_CallMethod(handler, (char *) "cdata", PyObject_CallMethod(handler, (char *) "cdata",
(char *) "s#", ch, len); (char *) "s#", ch, (Py_ssize_t)len);
if (PyErr_Occurred()) if (PyErr_Occurred())
PyErr_Print(); PyErr_Print();
Py_XDECREF(result); Py_XDECREF(result);