1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

parser: Make some module init/cleanup functions private

This commit is contained in:
Nick Wellnhofer 2022-11-24 20:52:57 +01:00
parent cecd364dd2
commit 9dbf137455
6 changed files with 69 additions and 28 deletions

View File

@ -22,6 +22,7 @@
#include <libxml/threads.h>
#include "private/error.h"
#include "private/globals.h"
#include "private/threads.h"
#include "private/tree.h"
@ -44,13 +45,18 @@ static xmlMutexPtr xmlThrDefMutex = NULL;
/**
* xmlInitGlobals:
*
* DEPRECATED: This function will be made private. Call xmlInitParser to
* initialize the library.
* DEPRECATED: Alias for xmlInitParser.
*/
void xmlInitGlobals(void) {
xmlInitParser();
}
/**
* xmlInitGlobalsInternal:
*
* Additional initialisation for multi-threading
*/
void xmlInitGlobals(void)
{
void xmlInitGlobalsInternal(void) {
if (xmlThrDefMutex == NULL)
xmlThrDefMutex = xmlNewMutex();
}
@ -506,7 +512,7 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs)
* Perform initialization as required by libxml
*/
if (xmlThrDefMutex == NULL)
xmlInitGlobals();
xmlInitGlobalsInternal();
xmlMutexLock(xmlThrDefMutex);
@ -569,15 +575,20 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs)
/**
* xmlCleanupGlobals:
*
* DEPRECATED: This function will be made private. Call xmlCleanupParser
* DEPRECATED: This function is a no-op. Call xmlCleanupParser
* to free global state but see the warnings there. xmlCleanupParser
* should be only called once at program exit. In most cases, you don't
* have call cleanup functions at all.
*/
void xmlCleanupGlobals(void) {
}
/**
* xmlCleanupGlobalsInternal:
*
* Additional cleanup for multi-threading
*/
void xmlCleanupGlobals(void)
{
void xmlCleanupGlobalsInternal(void) {
xmlResetError(&xmlLastError);
if (xmlThrDefMutex != NULL) {

View File

@ -4,8 +4,10 @@ EXTRA_DIST = \
enc.h \
entities.h \
error.h \
globals.h \
html.h \
io.h \
memory.h \
parser.h \
regexp.h \
save.h \

View File

@ -0,0 +1,7 @@
#ifndef XML_GLOBALS_H_PRIVATE__
#define XML_GLOBALS_H_PRIVATE__
void xmlInitGlobalsInternal(void);
void xmlCleanupGlobalsInternal(void);
#endif /* XML_GLOBALS_H_PRIVATE__ */

7
include/private/memory.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef XML_MEMORY_H_PRIVATE__
#define XML_MEMORY_H_PRIVATE__
void xmlInitMemoryInternal(void);
void xmlCleanupMemoryInternal(void);
#endif /* XML_MEMORY_H_PRIVATE__ */

View File

@ -78,8 +78,10 @@
#include "private/buf.h"
#include "private/enc.h"
#include "private/error.h"
#include "private/globals.h"
#include "private/html.h"
#include "private/io.h"
#include "private/memory.h"
#include "private/parser.h"
#include "private/threads.h"
@ -14494,17 +14496,14 @@ xmlInitParser(void) {
if (xmlParserInitialized == 0) {
#endif
xmlInitThreads();
xmlInitGlobals();
xmlInitMemory();
xmlInitGlobalsInternal();
xmlInitMemoryInternal();
xmlInitializeDict();
xmlInitCharEncodingHandlers();
xmlRegisterDefaultInputCallbacks();
#ifdef LIBXML_OUTPUT_ENABLED
xmlRegisterDefaultOutputCallbacks();
#endif /* LIBXML_OUTPUT_ENABLED */
#ifdef LIBXML_HTML_ENABLED
htmlInitAutoClose();
#endif
#if defined(LIBXML_XPATH_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
xmlXPathInit();
#endif
@ -14555,9 +14554,9 @@ xmlCleanupParser(void) {
xmlSchemaCleanupTypes();
xmlRelaxNGCleanupTypes();
#endif
xmlCleanupGlobals();
xmlCleanupGlobalsInternal();
xmlCleanupThreads(); /* must be last if called not from the main thread */
xmlCleanupMemory();
xmlCleanupMemoryInternal();
xmlParserInitialized = 0;
}

View File

@ -31,6 +31,8 @@
#include <libxml/xmlerror.h>
#include <libxml/threads.h>
#include "private/memory.h"
static int xmlMemInitialized = 0;
static unsigned long debugMemSize = 0;
static unsigned long debugMemBlocks = 0;
@ -147,7 +149,7 @@ xmlMallocLoc(size_t size, const char * file, int line)
MEMHDR *p;
void *ret;
if (!xmlMemInitialized) xmlInitMemory();
if (!xmlMemInitialized) xmlInitMemoryInternal();
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
"Malloc(%d)\n",size);
@ -223,7 +225,7 @@ xmlMallocAtomicLoc(size_t size, const char * file, int line)
MEMHDR *p;
void *ret;
if (!xmlMemInitialized) xmlInitMemory();
if (!xmlMemInitialized) xmlInitMemoryInternal();
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
"Malloc(%d)\n",size);
@ -320,7 +322,7 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
if (ptr == NULL)
return(xmlMallocLoc(size, file, line));
if (!xmlMemInitialized) xmlInitMemory();
if (!xmlMemInitialized) xmlInitMemoryInternal();
TEST_POINT
p = CLIENT_2_HDR(ptr);
@ -493,7 +495,7 @@ xmlMemStrdupLoc(const char *str, const char *file, int line)
size_t size = strlen(str) + 1;
MEMHDR *p;
if (!xmlMemInitialized) xmlInitMemory();
if (!xmlMemInitialized) xmlInitMemoryInternal();
TEST_POINT
if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
@ -935,16 +937,23 @@ xmlMemoryDump(void)
/**
* xmlInitMemory:
*
* DEPRECATED: This function will be made private. Call xmlInitParser to
* initialize the library.
* DEPRECATED: Alias for xmlInitParser.
*/
int
xmlInitMemory(void) {
xmlInitParser();
return(0);
}
/**
* xmlInitMemoryInternal:
*
* Initialize the memory layer.
*
* Returns 0 on success
*/
int
xmlInitMemory(void)
{
void
xmlInitMemoryInternal(void) {
char *breakpoint;
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
@ -954,7 +963,7 @@ xmlInitMemory(void)
This is really not good code (see Bug 130419). Suggestions for
improvement will be welcome!
*/
if (xmlMemInitialized) return(-1);
if (xmlMemInitialized) return;
xmlMemInitialized = 1;
xmlMemMutex = xmlNewMutex();
@ -971,22 +980,28 @@ xmlInitMemory(void)
xmlGenericError(xmlGenericErrorContext,
"xmlInitMemory() Ok\n");
#endif
return(0);
}
/**
* xmlCleanupMemory:
*
* DEPRECATED: This function will be made private. Call xmlCleanupParser
* DEPRECATED: This function is a no-op. Call xmlCleanupParser
* to free global state but see the warnings there. xmlCleanupParser
* should be only called once at program exit. In most cases, you don't
* have call cleanup functions at all.
*/
void
xmlCleanupMemory(void) {
}
/**
* xmlCleanupMemoryInternal:
*
* Free up all the memory allocated by the library for its own
* use. This should not be called by user level code.
*/
void
xmlCleanupMemory(void) {
xmlCleanupMemoryInternal(void) {
#ifdef DEBUG_MEMORY
xmlGenericError(xmlGenericErrorContext,
"xmlCleanupMemory()\n");