mirror of
https://gitlab.gnome.org/GNOME/libxml2
synced 2025-03-28 21:33:13 +00:00
error: Make xmlLastError const
This commit is contained in:
parent
eb66d03ef7
commit
79e119954c
20
error.c
20
error.c
@ -17,6 +17,7 @@
|
|||||||
#include <libxml/xmlmemory.h>
|
#include <libxml/xmlmemory.h>
|
||||||
|
|
||||||
#include "private/error.h"
|
#include "private/error.h"
|
||||||
|
#include "private/globals.h"
|
||||||
#include "private/string.h"
|
#include "private/string.h"
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@ -635,7 +636,7 @@ void
|
|||||||
xmlRaiseMemoryError(xmlStructuredErrorFunc schannel, xmlGenericErrorFunc channel,
|
xmlRaiseMemoryError(xmlStructuredErrorFunc schannel, xmlGenericErrorFunc channel,
|
||||||
void *data, int domain, xmlError *error)
|
void *data, int domain, xmlError *error)
|
||||||
{
|
{
|
||||||
xmlError *lastError = &xmlLastError;
|
xmlError *lastError = xmlGetLastErrorInternal();
|
||||||
|
|
||||||
xmlResetLastError();
|
xmlResetLastError();
|
||||||
lastError->domain = domain;
|
lastError->domain = domain;
|
||||||
@ -694,7 +695,7 @@ xmlVRaiseError(xmlStructuredErrorFunc schannel,
|
|||||||
{
|
{
|
||||||
xmlParserCtxtPtr ctxt = NULL;
|
xmlParserCtxtPtr ctxt = NULL;
|
||||||
/* xmlLastError is a macro retrieving the per-thread global. */
|
/* xmlLastError is a macro retrieving the per-thread global. */
|
||||||
xmlErrorPtr lastError = &xmlLastError;
|
xmlErrorPtr lastError = xmlGetLastErrorInternal();
|
||||||
xmlErrorPtr to = lastError;
|
xmlErrorPtr to = lastError;
|
||||||
|
|
||||||
if (code == XML_ERR_OK)
|
if (code == XML_ERR_OK)
|
||||||
@ -919,9 +920,11 @@ xmlParserValidityWarning(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
|
|||||||
const xmlError *
|
const xmlError *
|
||||||
xmlGetLastError(void)
|
xmlGetLastError(void)
|
||||||
{
|
{
|
||||||
if (xmlLastError.code == XML_ERR_OK)
|
const xmlError *error = xmlGetLastErrorInternal();
|
||||||
return (NULL);
|
|
||||||
return (&xmlLastError);
|
if (error->code == XML_ERR_OK)
|
||||||
|
return(NULL);
|
||||||
|
return(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -960,9 +963,10 @@ xmlResetError(xmlErrorPtr err)
|
|||||||
void
|
void
|
||||||
xmlResetLastError(void)
|
xmlResetLastError(void)
|
||||||
{
|
{
|
||||||
if (xmlLastError.code == XML_ERR_OK)
|
xmlError *error = xmlGetLastErrorInternal();
|
||||||
return;
|
|
||||||
xmlResetError(&xmlLastError);
|
if (error->code != XML_ERR_OK)
|
||||||
|
xmlResetError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
31
globals.c
31
globals.c
@ -79,6 +79,8 @@ struct _xmlGlobalState {
|
|||||||
unsigned localRngState[2];
|
unsigned localRngState[2];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
xmlError lastError;
|
||||||
|
|
||||||
#define XML_OP XML_DECLARE_MEMBER
|
#define XML_OP XML_DECLARE_MEMBER
|
||||||
XML_GLOBALS_ALLOC
|
XML_GLOBALS_ALLOC
|
||||||
XML_GLOBALS_ERROR
|
XML_GLOBALS_ERROR
|
||||||
@ -679,7 +681,7 @@ xmlFreeGlobalState(void *state)
|
|||||||
* But the xmlError struct is fully public and widely used,
|
* But the xmlError struct is fully public and widely used,
|
||||||
* so changes are dangerous.
|
* so changes are dangerous.
|
||||||
*/
|
*/
|
||||||
xmlResetError(&(gs->gs_xmlLastError));
|
xmlResetError(&gs->lastError);
|
||||||
#ifndef USE_TLS
|
#ifndef USE_TLS
|
||||||
free(state);
|
free(state);
|
||||||
#endif
|
#endif
|
||||||
@ -723,10 +725,10 @@ static void
|
|||||||
xmlInitGlobalState(xmlGlobalStatePtr gs) {
|
xmlInitGlobalState(xmlGlobalStatePtr gs) {
|
||||||
xmlMutexLock(&xmlThrDefMutex);
|
xmlMutexLock(&xmlThrDefMutex);
|
||||||
|
|
||||||
#ifdef LIBXML_THREAD_ENABLED
|
|
||||||
gs->localRngState[0] = xmlGlobalRandom();
|
gs->localRngState[0] = xmlGlobalRandom();
|
||||||
gs->localRngState[1] = xmlGlobalRandom();
|
gs->localRngState[1] = xmlGlobalRandom();
|
||||||
#endif
|
|
||||||
|
memset(&gs->lastError, 0, sizeof(xmlError));
|
||||||
|
|
||||||
gs->gs_xmlDoValidityCheckingDefaultValue =
|
gs->gs_xmlDoValidityCheckingDefaultValue =
|
||||||
xmlDoValidityCheckingDefaultValueThrDef;
|
xmlDoValidityCheckingDefaultValueThrDef;
|
||||||
@ -761,7 +763,6 @@ xmlInitGlobalState(xmlGlobalStatePtr gs) {
|
|||||||
xmlParserInputBufferCreateFilenameValueThrDef;
|
xmlParserInputBufferCreateFilenameValueThrDef;
|
||||||
gs->gs_xmlOutputBufferCreateFilenameValue =
|
gs->gs_xmlOutputBufferCreateFilenameValue =
|
||||||
xmlOutputBufferCreateFilenameValueThrDef;
|
xmlOutputBufferCreateFilenameValueThrDef;
|
||||||
memset(&gs->gs_xmlLastError, 0, sizeof(xmlError));
|
|
||||||
|
|
||||||
xmlMutexUnlock(&xmlThrDefMutex);
|
xmlMutexUnlock(&xmlThrDefMutex);
|
||||||
|
|
||||||
@ -857,7 +858,14 @@ XML_GLOBALS_PARSER
|
|||||||
XML_GLOBALS_TREE
|
XML_GLOBALS_TREE
|
||||||
#undef XML_OP
|
#undef XML_OP
|
||||||
|
|
||||||
#ifdef LIBXML_THREAD_ENABLED
|
const xmlError *
|
||||||
|
__xmlLastError(void) {
|
||||||
|
if (IS_MAIN_THREAD)
|
||||||
|
return(&xmlLastError);
|
||||||
|
else
|
||||||
|
return(&xmlGetThreadLocalStorage(0)->lastError);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlGetLocalRngState:
|
* xmlGetLocalRngState:
|
||||||
*
|
*
|
||||||
@ -870,7 +878,6 @@ xmlGetLocalRngState(void) {
|
|||||||
else
|
else
|
||||||
return(xmlGetThreadLocalStorage(0)->localRngState);
|
return(xmlGetThreadLocalStorage(0)->localRngState);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* For backward compatibility */
|
/* For backward compatibility */
|
||||||
|
|
||||||
@ -941,6 +948,18 @@ xmlCheckThreadLocalStorage(void) {
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xmlError *
|
||||||
|
xmlGetLastErrorInternal(void) {
|
||||||
|
#ifdef LIBXML_THREAD_ENABLED
|
||||||
|
if (IS_MAIN_THREAD)
|
||||||
|
return(&xmlLastError);
|
||||||
|
else
|
||||||
|
return(&xmlGetThreadLocalStorage(0)->lastError);
|
||||||
|
#else
|
||||||
|
return(&xmlLastError);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/** DOC_DISABLE */
|
/** DOC_DISABLE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -865,8 +865,16 @@ typedef void (*xmlGenericErrorFunc) (void *ctx,
|
|||||||
typedef void (*xmlStructuredErrorFunc) (void *userData, const xmlError *error);
|
typedef void (*xmlStructuredErrorFunc) (void *userData, const xmlError *error);
|
||||||
|
|
||||||
/** DOC_DISABLE */
|
/** DOC_DISABLE */
|
||||||
|
#if defined(LIBXML_THREAD_ENABLED)
|
||||||
|
XML_DEPRECATED
|
||||||
|
XMLPUBFUN const xmlError *
|
||||||
|
__xmlLastError(void);
|
||||||
|
#elif !defined(IN_LIBXML)
|
||||||
|
XML_DEPRECATED
|
||||||
|
XMLPUBVAR const xmlError xmlLastError;
|
||||||
|
#endif
|
||||||
|
|
||||||
#define XML_GLOBALS_ERROR \
|
#define XML_GLOBALS_ERROR \
|
||||||
XML_OP(xmlLastError, xmlError, XML_DEPRECATED) \
|
|
||||||
XML_OP(xmlGenericError, xmlGenericErrorFunc, XML_NO_ATTR) \
|
XML_OP(xmlGenericError, xmlGenericErrorFunc, XML_NO_ATTR) \
|
||||||
XML_OP(xmlGenericErrorContext, void *, XML_NO_ATTR) \
|
XML_OP(xmlGenericErrorContext, void *, XML_NO_ATTR) \
|
||||||
XML_OP(xmlStructuredError, xmlStructuredErrorFunc, XML_NO_ATTR) \
|
XML_OP(xmlStructuredError, xmlStructuredErrorFunc, XML_NO_ATTR) \
|
||||||
|
@ -6,6 +6,9 @@ xmlInitGlobalsInternal(void);
|
|||||||
XML_HIDDEN void
|
XML_HIDDEN void
|
||||||
xmlCleanupGlobalsInternal(void);
|
xmlCleanupGlobalsInternal(void);
|
||||||
|
|
||||||
|
XML_HIDDEN xmlError *
|
||||||
|
xmlGetLastErrorInternal(void);
|
||||||
|
|
||||||
#ifdef LIBXML_THREAD_ENABLED
|
#ifdef LIBXML_THREAD_ENABLED
|
||||||
XML_HIDDEN unsigned *
|
XML_HIDDEN unsigned *
|
||||||
xmlGetLocalRngState(void);
|
xmlGetLocalRngState(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user