From bc765307ffed746e57f669fc4d38925f32b776f3 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Sun, 1 Oct 2000 18:23:35 +0000 Subject: [PATCH] Cleanups, 1 bug fix: - HTMLparser.c: fixed htmlStartCloseIndexinitialized init - entities.h: exported xmlInitializePredefinedEntities - parser.[ch] : added xmlInitParser() - parserInternals.h : had to export htmlInitAutoClose() Daniel --- ChangeLog | 7 +++++++ HTMLparser.c | 4 +++- entities.h | 1 + include/libxml/entities.h | 1 + include/libxml/parser.h | 3 ++- include/libxml/parserInternals.h | 7 +++++++ parser.c | 27 ++++++++++++++++++++++++++- parser.h | 3 ++- parserInternals.h | 7 +++++++ 9 files changed, 56 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8ce8e95e..eae1eea5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Oct 1 20:19:39 CEST 2000 Daniel Veillard + + * HTMLparser.c: fixed htmlStartCloseIndexinitialized init + * entities.h: exported xmlInitializePredefinedEntities + * parser.[ch] : added xmlInitParser() + * parserInternals.h : had to export htmlInitAutoClose() + Sun Oct 1 16:28:22 CEST 2000 Daniel Veillard * xpath.[ch] : fixed some serious XPath Predicate evaluation diff --git a/HTMLparser.c b/HTMLparser.c index 2bafa72c..6866c4b5 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -579,7 +579,8 @@ static int htmlStartCloseIndexinitialized = 0; * htmlInitAutoClose: * * Initialize the htmlStartCloseIndex for fast lookup of closing tags names. - * + * This is not reentrant. Call xmlInitParser() once before processing in + * case of use in multithreaded programs. */ void htmlInitAutoClose(void) { @@ -594,6 +595,7 @@ htmlInitAutoClose(void) { while (htmlStartClose[i] != NULL) i++; i++; } + htmlStartCloseIndexinitialized = 1; } /** diff --git a/entities.h b/entities.h index e5bcc1b5..2fad326b 100644 --- a/entities.h +++ b/entities.h @@ -86,6 +86,7 @@ struct _xmlEntitiesTable { * External functions : */ +void xmlInitializePredefinedEntities (void); xmlEntityPtr xmlAddDocEntity (xmlDocPtr doc, const xmlChar *name, int type, diff --git a/include/libxml/entities.h b/include/libxml/entities.h index e5bcc1b5..2fad326b 100644 --- a/include/libxml/entities.h +++ b/include/libxml/entities.h @@ -86,6 +86,7 @@ struct _xmlEntitiesTable { * External functions : */ +void xmlInitializePredefinedEntities (void); xmlEntityPtr xmlAddDocEntity (xmlDocPtr doc, const xmlChar *name, int type, diff --git a/include/libxml/parser.h b/include/libxml/parser.h index 7e0a37ab..740d202a 100644 --- a/include/libxml/parser.h +++ b/include/libxml/parser.h @@ -310,8 +310,9 @@ extern int xmlGetWarningsDefaultValue; /** - * Cleanup + * Init/Cleanup */ +void xmlInitParser (void); void xmlCleanupParser (void); /** diff --git a/include/libxml/parserInternals.h b/include/libxml/parserInternals.h index 8e64113f..7b85b8aa 100644 --- a/include/libxml/parserInternals.h +++ b/include/libxml/parserInternals.h @@ -287,6 +287,13 @@ int xmlCopyChar (int len, int val); void xmlNextChar (xmlParserCtxtPtr ctxt); void xmlParserInputShrink (xmlParserInputPtr in); + +#ifdef LIBXML_HTML_ENABLED +/* + * Actually comes from the HTML parser but launched from the init stuff + */ +void htmlInitAutoClose (void); +#endif #ifdef __cplusplus } #endif diff --git a/parser.c b/parser.c index 83e23501..3d9a2e7c 100644 --- a/parser.c +++ b/parser.c @@ -6909,7 +6909,7 @@ xmlParseDocument(xmlParserCtxtPtr ctxt) { xmlChar start[4]; xmlCharEncoding enc; - xmlDefaultSAXHandlerInit(); + xmlInitParser(); GROW; @@ -9477,6 +9477,30 @@ xmlParseDoc(xmlChar *cur) { * * ************************************************************************/ +static int xmlParserInitialized = 0; + +/** + * xmlInitParser: + * + * Initialization function for the XML parser. + * This is not reentrant. Call once before processing in case of + * use in multithreaded programs. + */ + +void +xmlInitParser(void) { + if (xmlParserInitialized) return; + + xmlInitCharEncodingHandlers(); + xmlInitializePredefinedEntities(); + xmlDefaultSAXHandlerInit(); +#ifdef LIBXML_HTML_ENABLED + htmlInitAutoClose(); + htmlDefaultSAXHandlerInit(); +#endif + xmlParserInitialized = 1; +} + /** * xmlCleanupParser: * @@ -9488,6 +9512,7 @@ xmlParseDoc(xmlChar *cur) { void xmlCleanupParser(void) { + xmlParserInitialized = 0; xmlCleanupCharEncodingHandlers(); xmlCleanupPredefinedEntities(); } diff --git a/parser.h b/parser.h index 7e0a37ab..740d202a 100644 --- a/parser.h +++ b/parser.h @@ -310,8 +310,9 @@ extern int xmlGetWarningsDefaultValue; /** - * Cleanup + * Init/Cleanup */ +void xmlInitParser (void); void xmlCleanupParser (void); /** diff --git a/parserInternals.h b/parserInternals.h index 8e64113f..7b85b8aa 100644 --- a/parserInternals.h +++ b/parserInternals.h @@ -287,6 +287,13 @@ int xmlCopyChar (int len, int val); void xmlNextChar (xmlParserCtxtPtr ctxt); void xmlParserInputShrink (xmlParserInputPtr in); + +#ifdef LIBXML_HTML_ENABLED +/* + * Actually comes from the HTML parser but launched from the init stuff + */ +void htmlInitAutoClose (void); +#endif #ifdef __cplusplus } #endif