mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-03-23 02:50:08 +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:
parent
fc26934eb0
commit
45470611b0
@ -10144,7 +10144,7 @@ Could we use @subtypes for this?'/>
|
||||
</function>
|
||||
<function name='xmlGetLastError' file='xmlerror' module='error'>
|
||||
<info>Get the last global error registered. This is per thread if compiled with thread support.</info>
|
||||
<return type='xmlErrorPtr' info='NULL if no error occurred or a pointer to the error'/>
|
||||
<return type='const xmlError *' info='NULL if no error occurred or a pointer to the error'/>
|
||||
</function>
|
||||
<function name='xmlGetLineNo' file='tree' module='tree'>
|
||||
<info>Get line number of @node. Try to override the limitation of lines being store in 16 bits ints if XML_PARSE_BIG_LINES parser option was used</info>
|
||||
|
6
error.c
6
error.c
@ -880,9 +880,9 @@ xmlParserValidityWarning(void *ctx, const char *msg, ...)
|
||||
* Get the last global error registered. This is per thread if compiled
|
||||
* with thread support.
|
||||
*
|
||||
* Returns NULL if no error occurred or a pointer to the error
|
||||
* Returns a pointer to the error
|
||||
*/
|
||||
xmlErrorPtr
|
||||
const xmlError *
|
||||
xmlGetLastError(void)
|
||||
{
|
||||
if (xmlLastError.code == XML_ERR_OK)
|
||||
@ -981,7 +981,7 @@ xmlCtxtResetLastError(void *ctx)
|
||||
* Returns 0 in case of success and -1 in case of error.
|
||||
*/
|
||||
int
|
||||
xmlCopyError(xmlErrorPtr from, xmlErrorPtr to) {
|
||||
xmlCopyError(const xmlError *from, xmlErrorPtr to) {
|
||||
char *message, *file, *str1, *str2, *str3;
|
||||
|
||||
if ((from == NULL) || (to == NULL))
|
||||
|
@ -928,7 +928,7 @@ XMLPUBFUN void
|
||||
/*
|
||||
* Extended error information routines
|
||||
*/
|
||||
XMLPUBFUN xmlErrorPtr
|
||||
XMLPUBFUN const xmlError *
|
||||
xmlGetLastError (void);
|
||||
XMLPUBFUN void
|
||||
xmlResetLastError (void);
|
||||
@ -939,7 +939,7 @@ XMLPUBFUN void
|
||||
XMLPUBFUN void
|
||||
xmlResetError (xmlErrorPtr err);
|
||||
XMLPUBFUN int
|
||||
xmlCopyError (xmlErrorPtr from,
|
||||
xmlCopyError (const xmlError *from,
|
||||
xmlErrorPtr to);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -240,6 +240,7 @@ py_types = {
|
||||
'xmlCatalogPtr': ('O', "catalog", "xmlCatalogPtr", "xmlCatalogPtr"),
|
||||
'FILE *': ('O', "File", "FILEPtr", "FILE *"),
|
||||
'xmlURIPtr': ('O', "URI", "xmlURIPtr", "xmlURIPtr"),
|
||||
'const xmlError *': ('O', "Error", "xmlErrorPtr", "const xmlError *"),
|
||||
'xmlErrorPtr': ('O', "Error", "xmlErrorPtr", "xmlErrorPtr"),
|
||||
'xmlOutputBufferPtr': ('O', "outputBuffer", "xmlOutputBufferPtr", "xmlOutputBufferPtr"),
|
||||
'xmlParserInputBufferPtr': ('O', "inputBuffer", "xmlParserInputBufferPtr", "xmlParserInputBufferPtr"),
|
||||
@ -737,6 +738,7 @@ classes_type = {
|
||||
"xmlValidCtxtPtr": ("._o", "ValidCtxt(_obj=%s)", "ValidCtxt"),
|
||||
"xmlCatalogPtr": ("._o", "catalog(_obj=%s)", "catalog"),
|
||||
"xmlURIPtr": ("._o", "URI(_obj=%s)", "URI"),
|
||||
"const xmlError *": ("._o", "Error(_obj=%s)", "Error"),
|
||||
"xmlErrorPtr": ("._o", "Error(_obj=%s)", "Error"),
|
||||
"xmlOutputBufferPtr": ("._o", "outputBuffer(_obj=%s)", "outputBuffer"),
|
||||
"xmlParserInputBufferPtr": ("._o", "inputBuffer(_obj=%s)", "inputBuffer"),
|
||||
|
@ -290,7 +290,7 @@ PyObject * libxml_xmlSchemaPtrWrap(xmlSchemaPtr ctxt);
|
||||
PyObject * libxml_xmlSchemaParserCtxtPtrWrap(xmlSchemaParserCtxtPtr ctxt);
|
||||
PyObject * libxml_xmlSchemaValidCtxtPtrWrap(xmlSchemaValidCtxtPtr valid);
|
||||
#endif /* LIBXML_SCHEMAS_ENABLED */
|
||||
PyObject * libxml_xmlErrorPtrWrap(xmlErrorPtr error);
|
||||
PyObject * libxml_xmlErrorPtrWrap(const xmlError *error);
|
||||
PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args);
|
||||
PyObject * libxml_xmlRegisterInputCallback(PyObject *self, PyObject *args);
|
||||
PyObject * libxml_xmlUnregisterInputCallback(PyObject *self, PyObject *args);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ xmlconfTestNotNSWF(const char *id, const char *filename, int options) {
|
||||
nb_errors++;
|
||||
ret = 0;
|
||||
} else {
|
||||
xmlError *error = xmlGetLastError();
|
||||
const xmlError *error = xmlGetLastError();
|
||||
|
||||
if ((error->code == XML_ERR_OK) ||
|
||||
(error->domain != XML_FROM_NAMESPACE)) {
|
||||
|
@ -10545,7 +10545,7 @@ doc_load:
|
||||
* TODO: (2.2) is not supported.
|
||||
*/
|
||||
if (doc == NULL) {
|
||||
xmlErrorPtr lerr;
|
||||
const xmlError *lerr;
|
||||
lerr = xmlGetLastError();
|
||||
/*
|
||||
* Check if this a parser error, or if the document could
|
||||
|
Loading…
x
Reference in New Issue
Block a user