1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-24 13:33:01 +03:00

Fix SetGenericErrorFunc and SetStructured clash

* include/libxml/globals.h globals.c global.data: define a new global
  variable (per thread) for structured error reporting, to not conflict
  with generic one
* error.c: when defined use the structured error report over any generic
  one
This commit is contained in:
Wang Lam
2009-08-24 17:34:25 +02:00
committed by Daniel Veillard
parent c78988acb7
commit 1de382eb06
4 changed files with 47 additions and 11 deletions

19
error.c
View File

@@ -132,7 +132,7 @@ xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
*/ */
void void
xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
xmlGenericErrorContext = ctx; xmlStructuredErrorContext = ctx;
xmlStructuredError = handler; xmlStructuredError = handler;
} }
@@ -471,7 +471,7 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
* if user has defined handler, change data ptr to user's choice * if user has defined handler, change data ptr to user's choice
*/ */
if (schannel != NULL) if (schannel != NULL)
data = xmlGenericErrorContext; data = xmlStructuredErrorContext;
} }
if ((domain == XML_FROM_VALID) && if ((domain == XML_FROM_VALID) &&
((channel == xmlParserValidityError) || ((channel == xmlParserValidityError) ||
@@ -593,20 +593,23 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel,
/* /*
* Find the callback channel if channel param is NULL * Find the callback channel if channel param is NULL
*/ */
if ((ctxt != NULL) && (channel == NULL) && (xmlStructuredError == NULL) && (ctxt->sax != NULL)) { if ((ctxt != NULL) && (channel == NULL) &&
(xmlStructuredError == NULL) && (ctxt->sax != NULL)) {
if (level == XML_ERR_WARNING) if (level == XML_ERR_WARNING)
channel = ctxt->sax->warning; channel = ctxt->sax->warning;
else else
channel = ctxt->sax->error; channel = ctxt->sax->error;
data = ctxt->userData; data = ctxt->userData;
} else if (channel == NULL) { } else if (channel == NULL) {
if ((schannel == NULL) && (xmlStructuredError != NULL)) if ((schannel == NULL) && (xmlStructuredError != NULL)) {
schannel = xmlStructuredError; schannel = xmlStructuredError;
else data = xmlStructuredErrorContext;
} else {
channel = xmlGenericError; channel = xmlGenericError;
if (!data) { if (!data) {
data = xmlGenericErrorContext; data = xmlGenericErrorContext;
} }
}
} }
if (schannel != NULL) { if (schannel != NULL) {
schannel(data, to); schannel(data, to);

View File

@@ -2,11 +2,13 @@
int,oldXMLWDcompatibility,, int,oldXMLWDcompatibility,,
xmlBufferAllocationScheme,xmlBufferAllocScheme,,1 xmlBufferAllocationScheme,xmlBufferAllocScheme,,1
int,xmlDefaultBufferSize,,1 int,xmlDefaultBufferSize,,1
xmlSAXHandler,xmlDefaultSAXHandler,, xmlSAXHandlerV1,xmlDefaultSAXHandler,,
xmlSAXLocator,xmlDefaultSAXLocator,, xmlSAXLocator,xmlDefaultSAXLocator,,
int,xmlDoValidityCheckingDefaultValue,,1 int,xmlDoValidityCheckingDefaultValue,,1
xmlGenericErrorFunc,xmlGenericError,, xmlGenericErrorFunc,xmlGenericError,,
xmlStructuredErrorFunc,xmlStructuredError,,
void *,xmlGenericErrorContext,, void *,xmlGenericErrorContext,,
void *,xmlStructuredErrorContext,,
int,xmlGetWarningsDefaultValue,,1 int,xmlGetWarningsDefaultValue,,1
int,xmlIndentTreeOutput,,1 int,xmlIndentTreeOutput,,1
const char *,xmlTreeIndentString,,1 const char *,xmlTreeIndentString,,1
@@ -23,3 +25,5 @@ int,xmlSaveNoEmptyTags,,1
int,xmlSubstituteEntitiesDefaultValue,,1 int,xmlSubstituteEntitiesDefaultValue,,1
xmlRegisterNodeFunc,xmlRegisterNodeDefaultValue,, xmlRegisterNodeFunc,xmlRegisterNodeDefaultValue,,
xmlDeregisterNodeFunc,xmlDeregisterNodeDefaultValue,, xmlDeregisterNodeFunc,xmlDeregisterNodeDefaultValue,,
xmlParserInputBufferCreateFilenameFunc,xmlParserInputBufferCreateFilenameValue,,
xmlOutputBufferCreateFilenameFunc,xmlOutputBufferCreateFilenameValue,,

View File

@@ -148,6 +148,7 @@ xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
#undef xmlGenericError #undef xmlGenericError
#undef xmlStructuredError #undef xmlStructuredError
#undef xmlGenericErrorContext #undef xmlGenericErrorContext
#undef xmlStructuredErrorContext
#undef xmlGetWarningsDefaultValue #undef xmlGetWarningsDefaultValue
#undef xmlIndentTreeOutput #undef xmlIndentTreeOutput
#undef xmlTreeIndentString #undef xmlTreeIndentString
@@ -314,6 +315,13 @@ static xmlStructuredErrorFunc xmlStructuredErrorThrDef = NULL;
*/ */
void *xmlGenericErrorContext = NULL; void *xmlGenericErrorContext = NULL;
static void *xmlGenericErrorContextThrDef = NULL; static void *xmlGenericErrorContextThrDef = NULL;
/**
* xmlStructuredErrorContext:
*
* Global setting passed to structured error callbacks
*/
void *xmlStructuredErrorContext = NULL;
static void *xmlStructuredErrorContextThrDef = NULL;
xmlError xmlLastError; xmlError xmlLastError;
/* /*
@@ -545,6 +553,7 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs)
gs->xmlGenericError = xmlGenericErrorThrDef; gs->xmlGenericError = xmlGenericErrorThrDef;
gs->xmlStructuredError = xmlStructuredErrorThrDef; gs->xmlStructuredError = xmlStructuredErrorThrDef;
gs->xmlGenericErrorContext = xmlGenericErrorContextThrDef; gs->xmlGenericErrorContext = xmlGenericErrorContextThrDef;
gs->xmlStructuredErrorContext = xmlStructuredErrorContextThrDef;
gs->xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef; gs->xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef;
gs->xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef; gs->xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef;
@@ -573,7 +582,7 @@ xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) {
void void
xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) {
xmlMutexLock(xmlThrDefMutex); xmlMutexLock(xmlThrDefMutex);
xmlGenericErrorContextThrDef = ctx; xmlStructuredErrorContextThrDef = ctx;
xmlStructuredErrorThrDef = handler; xmlStructuredErrorThrDef = handler;
xmlMutexUnlock(xmlThrDefMutex); xmlMutexUnlock(xmlThrDefMutex);
} }
@@ -876,6 +885,15 @@ __xmlGenericErrorContext(void) {
return (&xmlGetGlobalState()->xmlGenericErrorContext); return (&xmlGetGlobalState()->xmlGenericErrorContext);
} }
#undef xmlStructuredErrorContext
void * *
__xmlStructuredErrorContext(void) {
if (IS_MAIN_THREAD)
return (&xmlStructuredErrorContext);
else
return (&xmlGetGlobalState()->xmlStructuredErrorContext);
}
#undef xmlGetWarningsDefaultValue #undef xmlGetWarningsDefaultValue
int * int *
__xmlGetWarningsDefaultValue(void) { __xmlGetWarningsDefaultValue(void) {
@@ -910,7 +928,7 @@ int xmlThrDefIndentTreeOutput(int v) {
return ret; return ret;
} }
#undef xmlTreeIndentString #undef xmlTreeIndentString
const char * * const char * *
__xmlTreeIndentString(void) { __xmlTreeIndentString(void) {
if (IS_MAIN_THREAD) if (IS_MAIN_THREAD)

View File

@@ -76,6 +76,7 @@ XMLCALL xmlOutputBufferCreateFilenameDefault (xmlOutputBufferCreateFilenameFunc
#undef xmlGenericError #undef xmlGenericError
#undef xmlStructuredError #undef xmlStructuredError
#undef xmlGenericErrorContext #undef xmlGenericErrorContext
#undef xmlStructuredErrorContext
#undef xmlGetWarningsDefaultValue #undef xmlGetWarningsDefaultValue
#undef xmlIndentTreeOutput #undef xmlIndentTreeOutput
#undef xmlTreeIndentString #undef xmlTreeIndentString
@@ -158,6 +159,8 @@ struct _xmlGlobalState
xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue; xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue;
xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue; xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue;
void *xmlStructuredErrorContext;
}; };
#ifdef __cplusplus #ifdef __cplusplus
@@ -354,6 +357,14 @@ XMLPUBFUN void * * XMLCALL __xmlGenericErrorContext(void);
XMLPUBVAR void * xmlGenericErrorContext; XMLPUBVAR void * xmlGenericErrorContext;
#endif #endif
XMLPUBFUN void * * XMLCALL __xmlStructuredErrorContext(void);
#ifdef LIBXML_THREAD_ENABLED
#define xmlStructuredErrorContext \
(*(__xmlStructuredErrorContext()))
#else
LIBXML_DLL_IMPORT extern void * xmlStructuredErrorContext;
#endif
XMLPUBFUN int * XMLCALL __xmlGetWarningsDefaultValue(void); XMLPUBFUN int * XMLCALL __xmlGetWarningsDefaultValue(void);
#ifdef LIBXML_THREAD_ENABLED #ifdef LIBXML_THREAD_ENABLED
#define xmlGetWarningsDefaultValue \ #define xmlGetWarningsDefaultValue \