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

Migrate from PyEval_ to PyObject_

PyEval_ functions are deprecated.

Fixes #208.
This commit is contained in:
Nick Wellnhofer
2022-08-29 17:21:19 +02:00
parent ae2b802150
commit b1a0961858
2 changed files with 18 additions and 19 deletions

View File

@ -42,8 +42,7 @@ gcc:minimum:
gcc:python3: gcc:python3:
extends: .test extends: .test
variables: variables:
# TODO: Re-enable the warning after #208 is fixed. CFLAGS: "-O2"
CFLAGS: "-O2 -Wno-error=deprecated-declarations"
PYTHON: "/usr/bin/python3" PYTHON: "/usr/bin/python3"
gcc:static: gcc:static:

View File

@ -257,7 +257,7 @@ xmlPythonFileCloseRaw (void * context) {
#endif #endif
file = (PyObject *) context; file = (PyObject *) context;
if (file == NULL) return(-1); if (file == NULL) return(-1);
ret = PyEval_CallMethod(file, (char *) "close", (char *) "()"); ret = PyObject_CallMethod(file, (char *) "close", (char *) "()");
if (ret != NULL) { if (ret != NULL) {
Py_DECREF(ret); Py_DECREF(ret);
} }
@ -287,7 +287,7 @@ xmlPythonFileReadRaw (void * context, char * buffer, int len) {
#endif #endif
file = (PyObject *) context; file = (PyObject *) context;
if (file == NULL) return(-1); if (file == NULL) return(-1);
ret = PyEval_CallMethod(file, (char *) "read", (char *) "(i)", len); ret = PyObject_CallMethod(file, (char *) "read", (char *) "(i)", len);
if (ret == NULL) { if (ret == NULL) {
printf("xmlPythonFileReadRaw: result is NULL\n"); printf("xmlPythonFileReadRaw: result is NULL\n");
return(-1); return(-1);
@ -352,7 +352,7 @@ xmlPythonFileRead (void * context, char * buffer, int len) {
#endif #endif
file = (PyObject *) context; file = (PyObject *) context;
if (file == NULL) return(-1); if (file == NULL) return(-1);
ret = PyEval_CallMethod(file, (char *) "io_read", (char *) "(i)", len); ret = PyObject_CallMethod(file, (char *) "io_read", (char *) "(i)", len);
if (ret == NULL) { if (ret == NULL) {
printf("xmlPythonFileRead: result is NULL\n"); printf("xmlPythonFileRead: result is NULL\n");
return(-1); return(-1);
@ -420,10 +420,10 @@ xmlPythonFileWrite (void * context, const char * buffer, int len) {
string = PY_IMPORT_STRING_SIZE(buffer, len); string = PY_IMPORT_STRING_SIZE(buffer, len);
if (string == NULL) return(-1); if (string == NULL) return(-1);
if (PyObject_HasAttrString(file, (char *) "io_write")) { if (PyObject_HasAttrString(file, (char *) "io_write")) {
ret = PyEval_CallMethod(file, (char *) "io_write", (char *) "(O)", ret = PyObject_CallMethod(file, (char *) "io_write", (char *) "(O)",
string); string);
} else if (PyObject_HasAttrString(file, (char *) "write")) { } else if (PyObject_HasAttrString(file, (char *) "write")) {
ret = PyEval_CallMethod(file, (char *) "write", (char *) "(O)", ret = PyObject_CallMethod(file, (char *) "write", (char *) "(O)",
string); string);
} }
Py_DECREF(string); Py_DECREF(string);
@ -459,9 +459,9 @@ xmlPythonFileClose (void * context) {
file = (PyObject *) context; file = (PyObject *) context;
if (file == NULL) return(-1); if (file == NULL) return(-1);
if (PyObject_HasAttrString(file, (char *) "io_close")) { if (PyObject_HasAttrString(file, (char *) "io_close")) {
ret = PyEval_CallMethod(file, (char *) "io_close", (char *) "()"); ret = PyObject_CallMethod(file, (char *) "io_close", (char *) "()");
} else if (PyObject_HasAttrString(file, (char *) "flush")) { } else if (PyObject_HasAttrString(file, (char *) "flush")) {
ret = PyEval_CallMethod(file, (char *) "flush", (char *) "()"); ret = PyObject_CallMethod(file, (char *) "flush", (char *) "()");
} }
if (ret != NULL) { if (ret != NULL) {
Py_DECREF(ret); Py_DECREF(ret);
@ -1648,7 +1648,7 @@ libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg,
Py_XINCREF(libxml_xmlPythonErrorFuncCtxt); Py_XINCREF(libxml_xmlPythonErrorFuncCtxt);
message = libxml_charPtrConstWrap(str); message = libxml_charPtrConstWrap(str);
PyTuple_SetItem(list, 1, message); PyTuple_SetItem(list, 1, message);
result = PyEval_CallObject(libxml_xmlPythonErrorFuncHandler, list); result = PyObject_CallObject(libxml_xmlPythonErrorFuncHandler, list);
Py_XDECREF(list); Py_XDECREF(list);
Py_XDECREF(result); Py_XDECREF(result);
} }
@ -1736,7 +1736,7 @@ libxml_xmlParserCtxtGenericErrorFuncHandler(void *ctx, int severity, char *str)
PyTuple_SetItem(list, 2, libxml_intWrap(severity)); PyTuple_SetItem(list, 2, libxml_intWrap(severity));
PyTuple_SetItem(list, 3, Py_None); PyTuple_SetItem(list, 3, Py_None);
Py_INCREF(Py_None); Py_INCREF(Py_None);
result = PyEval_CallObject(pyCtxt->f, list); result = PyObject_CallObject(pyCtxt->f, list);
if (result == NULL) if (result == NULL)
{ {
/* TODO: manage for the exception to be propagated... */ /* TODO: manage for the exception to be propagated... */
@ -1922,7 +1922,7 @@ libxml_xmlValidCtxtGenericErrorFuncHandler(void *ctx, ATTRIBUTE_UNUSED int sever
PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
PyTuple_SetItem(list, 1, pyCtxt->arg); PyTuple_SetItem(list, 1, pyCtxt->arg);
Py_XINCREF(pyCtxt->arg); Py_XINCREF(pyCtxt->arg);
result = PyEval_CallObject(pyCtxt->error, list); result = PyObject_CallObject(pyCtxt->error, list);
if (result == NULL) if (result == NULL)
{ {
/* TODO: manage for the exception to be propagated... */ /* TODO: manage for the exception to be propagated... */
@ -1949,7 +1949,7 @@ libxml_xmlValidCtxtGenericWarningFuncHandler(void *ctx, ATTRIBUTE_UNUSED int sev
PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
PyTuple_SetItem(list, 1, pyCtxt->arg); PyTuple_SetItem(list, 1, pyCtxt->arg);
Py_XINCREF(pyCtxt->arg); Py_XINCREF(pyCtxt->arg);
result = PyEval_CallObject(pyCtxt->warn, list); result = PyObject_CallObject(pyCtxt->warn, list);
if (result == NULL) if (result == NULL)
{ {
/* TODO: manage for the exception to be propagated... */ /* TODO: manage for the exception to be propagated... */
@ -2084,7 +2084,7 @@ libxml_xmlTextReaderErrorCallback(void *arg,
PyTuple_SetItem(list, 1, libxml_charPtrConstWrap(msg)); PyTuple_SetItem(list, 1, libxml_charPtrConstWrap(msg));
PyTuple_SetItem(list, 2, libxml_intWrap(severity)); PyTuple_SetItem(list, 2, libxml_intWrap(severity));
PyTuple_SetItem(list, 3, libxml_xmlTextReaderLocatorPtrWrap(locator)); PyTuple_SetItem(list, 3, libxml_xmlTextReaderLocatorPtrWrap(locator));
result = PyEval_CallObject(pyCtxt->f, list); result = PyObject_CallObject(pyCtxt->f, list);
if (result == NULL) if (result == NULL)
{ {
/* TODO: manage for the exception to be propagated... */ /* TODO: manage for the exception to be propagated... */
@ -2279,7 +2279,7 @@ libxml_xmlXPathFuncCallback(xmlXPathParserContextPtr ctxt, int nargs)
cur = libxml_xmlXPathObjectPtrWrap(obj); cur = libxml_xmlXPathObjectPtrWrap(obj);
PyTuple_SetItem(list, i + 1, cur); PyTuple_SetItem(list, i + 1, cur);
} }
result = PyEval_CallObject(current_function, list); result = PyObject_CallObject(current_function, list);
Py_DECREF(list); Py_DECREF(list);
obj = libxml_xmlXPathObjectPtrConvert(result); obj = libxml_xmlXPathObjectPtrConvert(result);
@ -3156,7 +3156,7 @@ libxml_xmlRelaxNGValidityGenericErrorFuncHandler(void *ctx, char *str)
PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
PyTuple_SetItem(list, 1, pyCtxt->arg); PyTuple_SetItem(list, 1, pyCtxt->arg);
Py_XINCREF(pyCtxt->arg); Py_XINCREF(pyCtxt->arg);
result = PyEval_CallObject(pyCtxt->error, list); result = PyObject_CallObject(pyCtxt->error, list);
if (result == NULL) if (result == NULL)
{ {
/* TODO: manage for the exception to be propagated... */ /* TODO: manage for the exception to be propagated... */
@ -3183,7 +3183,7 @@ libxml_xmlRelaxNGValidityGenericWarningFuncHandler(void *ctx, char *str)
PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
PyTuple_SetItem(list, 1, pyCtxt->arg); PyTuple_SetItem(list, 1, pyCtxt->arg);
Py_XINCREF(pyCtxt->arg); Py_XINCREF(pyCtxt->arg);
result = PyEval_CallObject(pyCtxt->warn, list); result = PyObject_CallObject(pyCtxt->warn, list);
if (result == NULL) if (result == NULL)
{ {
/* TODO: manage for the exception to be propagated... */ /* TODO: manage for the exception to be propagated... */
@ -3320,7 +3320,7 @@ libxml_xmlSchemaValidityGenericErrorFuncHandler(void *ctx, char *str)
PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
PyTuple_SetItem(list, 1, pyCtxt->arg); PyTuple_SetItem(list, 1, pyCtxt->arg);
Py_XINCREF(pyCtxt->arg); Py_XINCREF(pyCtxt->arg);
result = PyEval_CallObject(pyCtxt->error, list); result = PyObject_CallObject(pyCtxt->error, list);
if (result == NULL) if (result == NULL)
{ {
/* TODO: manage for the exception to be propagated... */ /* TODO: manage for the exception to be propagated... */
@ -3347,7 +3347,7 @@ libxml_xmlSchemaValidityGenericWarningFuncHandler(void *ctx, char *str)
PyTuple_SetItem(list, 0, libxml_charPtrWrap(str)); PyTuple_SetItem(list, 0, libxml_charPtrWrap(str));
PyTuple_SetItem(list, 1, pyCtxt->arg); PyTuple_SetItem(list, 1, pyCtxt->arg);
Py_XINCREF(pyCtxt->arg); Py_XINCREF(pyCtxt->arg);
result = PyEval_CallObject(pyCtxt->warn, list); result = PyObject_CallObject(pyCtxt->warn, list);
if (result == NULL) if (result == NULL)
{ {
/* TODO: manage for the exception to be propagated... */ /* TODO: manage for the exception to be propagated... */