mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-28 23:14:57 +03:00
catalog: Fix initialization
Initialize mutex via xmlInitParser. Fix some other initialization calls.
This commit is contained in:
56
catalog.c
56
catalog.c
@@ -38,6 +38,7 @@
|
|||||||
#include <libxml/xmlerror.h>
|
#include <libxml/xmlerror.h>
|
||||||
#include <libxml/threads.h>
|
#include <libxml/threads.h>
|
||||||
|
|
||||||
|
#include "private/cata.h"
|
||||||
#include "private/buf.h"
|
#include "private/buf.h"
|
||||||
#include "private/error.h"
|
#include "private/error.h"
|
||||||
|
|
||||||
@@ -169,7 +170,7 @@ static xmlCatalogPtr xmlDefaultCatalog = NULL;
|
|||||||
static xmlRMutexPtr xmlCatalogMutex = NULL;
|
static xmlRMutexPtr xmlCatalogMutex = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Whether the catalog support was initialized.
|
* Whether the default system catalog was initialized.
|
||||||
*/
|
*/
|
||||||
static int xmlCatalogInitialized = 0;
|
static int xmlCatalogInitialized = 0;
|
||||||
|
|
||||||
@@ -3056,41 +3057,31 @@ xmlCatalogIsEmpty(xmlCatalogPtr catal) {
|
|||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlInitializeCatalogData:
|
* xmlInitCatalogInternal:
|
||||||
*
|
*
|
||||||
* Do the catalog initialization only of global data, doesn't try to load
|
* Do the catalog initialization only of global data, doesn't try to load
|
||||||
* any catalog actually.
|
* any catalog actually.
|
||||||
* this function is not thread safe, catalog initialization should
|
|
||||||
* preferably be done once at startup
|
|
||||||
*/
|
*/
|
||||||
static void
|
void
|
||||||
xmlInitializeCatalogData(void) {
|
xmlInitCatalogInternal(void) {
|
||||||
if (xmlCatalogInitialized != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (getenv("XML_DEBUG_CATALOG"))
|
if (getenv("XML_DEBUG_CATALOG"))
|
||||||
xmlDebugCatalogs = 1;
|
xmlDebugCatalogs = 1;
|
||||||
xmlCatalogMutex = xmlNewRMutex();
|
xmlCatalogMutex = xmlNewRMutex();
|
||||||
|
|
||||||
xmlCatalogInitialized = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlInitializeCatalog:
|
* xmlInitializeCatalog:
|
||||||
*
|
*
|
||||||
* Do the catalog initialization.
|
* Load the default system catalog.
|
||||||
* this function is not thread safe, catalog initialization should
|
|
||||||
* preferably be done once at startup
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
xmlInitializeCatalog(void) {
|
xmlInitializeCatalog(void) {
|
||||||
if (xmlCatalogInitialized != 0)
|
if (xmlCatalogInitialized != 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
xmlInitializeCatalogData();
|
xmlInitParser();
|
||||||
xmlRMutexLock(xmlCatalogMutex);
|
|
||||||
|
|
||||||
if (getenv("XML_DEBUG_CATALOG"))
|
xmlRMutexLock(xmlCatalogMutex);
|
||||||
xmlDebugCatalogs = 1;
|
|
||||||
|
|
||||||
if (xmlDefaultCatalog == NULL) {
|
if (xmlDefaultCatalog == NULL) {
|
||||||
const char *catalogs;
|
const char *catalogs;
|
||||||
@@ -3152,8 +3143,7 @@ xmlLoadCatalog(const char *filename)
|
|||||||
int ret;
|
int ret;
|
||||||
xmlCatalogPtr catal;
|
xmlCatalogPtr catal;
|
||||||
|
|
||||||
if (!xmlCatalogInitialized)
|
xmlInitParser();
|
||||||
xmlInitializeCatalogData();
|
|
||||||
|
|
||||||
xmlRMutexLock(xmlCatalogMutex);
|
xmlRMutexLock(xmlCatalogMutex);
|
||||||
|
|
||||||
@@ -3228,9 +3218,6 @@ xmlLoadCatalogs(const char *pathss) {
|
|||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
xmlCatalogCleanup(void) {
|
xmlCatalogCleanup(void) {
|
||||||
if (xmlCatalogInitialized == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
xmlRMutexLock(xmlCatalogMutex);
|
xmlRMutexLock(xmlCatalogMutex);
|
||||||
if (xmlDebugCatalogs)
|
if (xmlDebugCatalogs)
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
@@ -3244,6 +3231,15 @@ xmlCatalogCleanup(void) {
|
|||||||
xmlDebugCatalogs = 0;
|
xmlDebugCatalogs = 0;
|
||||||
xmlCatalogInitialized = 0;
|
xmlCatalogInitialized = 0;
|
||||||
xmlRMutexUnlock(xmlCatalogMutex);
|
xmlRMutexUnlock(xmlCatalogMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xmlCleanupCatalogInternal:
|
||||||
|
*
|
||||||
|
* Free global data.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
xmlCleanupCatalogInternal(void) {
|
||||||
xmlFreeRMutex(xmlCatalogMutex);
|
xmlFreeRMutex(xmlCatalogMutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3365,7 +3361,7 @@ xmlCatalogAdd(const xmlChar *type, const xmlChar *orig, const xmlChar *replace)
|
|||||||
int res = -1;
|
int res = -1;
|
||||||
|
|
||||||
if (!xmlCatalogInitialized)
|
if (!xmlCatalogInitialized)
|
||||||
xmlInitializeCatalogData();
|
xmlInitializeCatalog();
|
||||||
|
|
||||||
xmlRMutexLock(xmlCatalogMutex);
|
xmlRMutexLock(xmlCatalogMutex);
|
||||||
/*
|
/*
|
||||||
@@ -3552,9 +3548,6 @@ void
|
|||||||
xmlCatalogFreeLocal(void *catalogs) {
|
xmlCatalogFreeLocal(void *catalogs) {
|
||||||
xmlCatalogEntryPtr catal;
|
xmlCatalogEntryPtr catal;
|
||||||
|
|
||||||
if (!xmlCatalogInitialized)
|
|
||||||
xmlInitializeCatalog();
|
|
||||||
|
|
||||||
catal = (xmlCatalogEntryPtr) catalogs;
|
catal = (xmlCatalogEntryPtr) catalogs;
|
||||||
if (catal != NULL)
|
if (catal != NULL)
|
||||||
xmlFreeCatalogEntryList(catal);
|
xmlFreeCatalogEntryList(catal);
|
||||||
@@ -3574,8 +3567,7 @@ void *
|
|||||||
xmlCatalogAddLocal(void *catalogs, const xmlChar *URL) {
|
xmlCatalogAddLocal(void *catalogs, const xmlChar *URL) {
|
||||||
xmlCatalogEntryPtr catal, add;
|
xmlCatalogEntryPtr catal, add;
|
||||||
|
|
||||||
if (!xmlCatalogInitialized)
|
xmlInitParser();
|
||||||
xmlInitializeCatalog();
|
|
||||||
|
|
||||||
if (URL == NULL)
|
if (URL == NULL)
|
||||||
return(catalogs);
|
return(catalogs);
|
||||||
@@ -3617,9 +3609,6 @@ xmlCatalogLocalResolve(void *catalogs, const xmlChar *pubID,
|
|||||||
xmlCatalogEntryPtr catal;
|
xmlCatalogEntryPtr catal;
|
||||||
xmlChar *ret;
|
xmlChar *ret;
|
||||||
|
|
||||||
if (!xmlCatalogInitialized)
|
|
||||||
xmlInitializeCatalog();
|
|
||||||
|
|
||||||
if ((pubID == NULL) && (sysID == NULL))
|
if ((pubID == NULL) && (sysID == NULL))
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
@@ -3661,9 +3650,6 @@ xmlCatalogLocalResolveURI(void *catalogs, const xmlChar *URI) {
|
|||||||
xmlCatalogEntryPtr catal;
|
xmlCatalogEntryPtr catal;
|
||||||
xmlChar *ret;
|
xmlChar *ret;
|
||||||
|
|
||||||
if (!xmlCatalogInitialized)
|
|
||||||
xmlInitializeCatalog();
|
|
||||||
|
|
||||||
if (URI == NULL)
|
if (URI == NULL)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
buf.h \
|
buf.h \
|
||||||
|
cata.h \
|
||||||
dict.h \
|
dict.h \
|
||||||
enc.h \
|
enc.h \
|
||||||
entities.h \
|
entities.h \
|
||||||
|
|||||||
13
include/private/cata.h
Normal file
13
include/private/cata.h
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef XML_CATA_H_PRIVATE__
|
||||||
|
#define XML_CATA_H_PRIVATE__
|
||||||
|
|
||||||
|
#ifdef LIBXML_CATALOG_ENABLED
|
||||||
|
|
||||||
|
XML_HIDDEN void
|
||||||
|
xmlInitCatalogInternal(void);
|
||||||
|
XML_HIDDEN void
|
||||||
|
xmlCleanupCatalogInternal(void);
|
||||||
|
|
||||||
|
#endif /* LIBXML_CATALOG_ENABLED */
|
||||||
|
|
||||||
|
#endif /* XML_CATA_H_PRIVATE__ */
|
||||||
@@ -27,6 +27,7 @@
|
|||||||
#include <note.h>
|
#include <note.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "private/cata.h"
|
||||||
#include "private/dict.h"
|
#include "private/dict.h"
|
||||||
#include "private/enc.h"
|
#include "private/enc.h"
|
||||||
#include "private/globals.h"
|
#include "private/globals.h"
|
||||||
@@ -592,6 +593,9 @@ xmlInitParser(void) {
|
|||||||
xmlInitXPathInternal();
|
xmlInitXPathInternal();
|
||||||
#endif
|
#endif
|
||||||
xmlInitIOCallbacks();
|
xmlInitIOCallbacks();
|
||||||
|
#ifdef LIBXML_CATALOG_ENABLED
|
||||||
|
xmlInitCatalogInternal();
|
||||||
|
#endif
|
||||||
|
|
||||||
xmlParserInnerInitialized = 1;
|
xmlParserInnerInitialized = 1;
|
||||||
}
|
}
|
||||||
@@ -632,6 +636,7 @@ xmlCleanupParser(void) {
|
|||||||
xmlCleanupCharEncodingHandlers();
|
xmlCleanupCharEncodingHandlers();
|
||||||
#ifdef LIBXML_CATALOG_ENABLED
|
#ifdef LIBXML_CATALOG_ENABLED
|
||||||
xmlCatalogCleanup();
|
xmlCatalogCleanup();
|
||||||
|
xmlCleanupCatalogInternal();
|
||||||
#endif
|
#endif
|
||||||
#ifdef LIBXML_SCHEMAS_ENABLED
|
#ifdef LIBXML_SCHEMAS_ENABLED
|
||||||
xmlSchemaCleanupTypes();
|
xmlSchemaCleanupTypes();
|
||||||
|
|||||||
Reference in New Issue
Block a user