1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-18 16:08:59 +03:00

error: Make xmlGetLastError return a const error

This is a slight break of the API, but users really shouldn't modify the
global error struct. The goal is to make xmlLastError use static buffers
for its strings eventually. This should warn people if they're abusing
the struct.
This commit is contained in:
Nick Wellnhofer
2023-09-21 23:52:52 +02:00
parent fc26934eb0
commit 45470611b0
8 changed files with 29 additions and 11 deletions

View File

@@ -8,6 +8,7 @@
*/
#include "libxml_wrap.h"
#include <libxml/xpathInternals.h>
#include <string.h>
#if PY_MAJOR_VERSION >= 3
#define PY_IMPORT_STRING_SIZE PyUnicode_FromStringAndSize
@@ -963,15 +964,30 @@ libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid)
}
#endif /* LIBXML_SCHEMAS_ENABLED */
static void
libxml_xmlDestructError(PyObject *cap) {
xmlErrorPtr err = (xmlErrorPtr) PyCapsule_GetPointer(cap, "xmlErrorPtr");
xmlResetError(err);
xmlFree(err);
}
PyObject *
libxml_xmlErrorPtrWrap(xmlErrorPtr error)
libxml_xmlErrorPtrWrap(const xmlError *error)
{
PyObject *ret;
xmlErrorPtr copy;
if (error == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
ret = PyCapsule_New((void *) error, (char *) "xmlErrorPtr", NULL);
copy = xmlMalloc(sizeof(*copy));
if (copy == NULL) {
Py_INCREF(Py_None);
return (Py_None);
}
memset(copy, 0, sizeof(*copy));
xmlCopyError(error, copy);
ret = PyCapsule_New(copy, "xmlErrorPtr", libxml_xmlDestructError);
return (ret);
}