1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

made the predefined entities static predefined structures to avoid the

* entities.c legacy.c parser.c: made the predefined entities
  static predefined structures to avoid the work, memory and
  hazards associated to initialization/cleanup.
Daniel
This commit is contained in:
Daniel Veillard
2003-09-30 13:38:04 +00:00
parent 73b013fc17
commit d3a2e4c2b3
4 changed files with 86 additions and 70 deletions

View File

@ -1,3 +1,9 @@
Tue Sep 30 15:34:31 CEST 2003 Daniel Veillard <daniel@veillard.com>
* entities.c legacy.c parser.c: made the predefined entities
static predefined structures to avoid the work, memory and
hazards associated to initialization/cleanup.
Tue Sep 30 14:30:47 CEST 2003 Daniel Veillard <daniel@veillard.com>
* HTMLparser.c Makefile.am configure.in legacy.c parser.c

View File

@ -24,23 +24,41 @@
* The XML predefined entities.
*/
struct xmlPredefinedEntityValue {
const char *name;
const char *value;
static xmlEntity xmlEntityLt = {
NULL, XML_ENTITY_DECL, BAD_CAST "lt",
NULL, NULL, NULL, NULL, NULL, NULL,
BAD_CAST "<", BAD_CAST "<", 1,
XML_INTERNAL_PREDEFINED_ENTITY,
NULL, NULL, NULL, NULL, 0
};
static struct xmlPredefinedEntityValue xmlPredefinedEntityValues[] = {
{ "lt", "<" },
{ "gt", ">" },
{ "apos", "'" },
{ "quot", "\"" },
{ "amp", "&" }
static xmlEntity xmlEntityGt = {
NULL, XML_ENTITY_DECL, BAD_CAST "gt",
NULL, NULL, NULL, NULL, NULL, NULL,
BAD_CAST ">", BAD_CAST ">", 1,
XML_INTERNAL_PREDEFINED_ENTITY,
NULL, NULL, NULL, NULL, 0
};
static xmlEntity xmlEntityAmp = {
NULL, XML_ENTITY_DECL, BAD_CAST "amp",
NULL, NULL, NULL, NULL, NULL, NULL,
BAD_CAST "&", BAD_CAST "&", 1,
XML_INTERNAL_PREDEFINED_ENTITY,
NULL, NULL, NULL, NULL, 0
};
static xmlEntity xmlEntityQuot = {
NULL, XML_ENTITY_DECL, BAD_CAST "quot",
NULL, NULL, NULL, NULL, NULL, NULL,
BAD_CAST "\"", BAD_CAST "\"", 1,
XML_INTERNAL_PREDEFINED_ENTITY,
NULL, NULL, NULL, NULL, 0
};
static xmlEntity xmlEntityApos = {
NULL, XML_ENTITY_DECL, BAD_CAST "apos",
NULL, NULL, NULL, NULL, NULL, NULL,
BAD_CAST "'", BAD_CAST "'", 1,
XML_INTERNAL_PREDEFINED_ENTITY,
NULL, NULL, NULL, NULL, 0
};
/*
* TODO: This is GROSS, allocation of a 256 entry hash for
* a fixed number of 4 elements !
*/
static xmlHashTablePtr xmlPredefinedEntities = NULL;
/*
* xmlFreeEntity : clean-up an entity record.
@ -93,9 +111,7 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
table = dtd->pentities;
break;
case XML_INTERNAL_PREDEFINED_ENTITY:
if (xmlPredefinedEntities == NULL)
xmlPredefinedEntities = xmlHashCreate(8);
table = xmlPredefinedEntities;
return(NULL);
}
if (table == NULL)
return(NULL);
@ -139,48 +155,6 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
return(ret);
}
/**
* xmlInitializePredefinedEntities:
*
* Set up the predefined entities.
*/
void xmlInitializePredefinedEntities(void) {
unsigned int i;
xmlChar name[50];
xmlChar value[50];
const char *in;
xmlChar *out;
if (xmlPredefinedEntities != NULL) return;
xmlPredefinedEntities = xmlCreateEntitiesTable();
for (i = 0;i < sizeof(xmlPredefinedEntityValues) /
sizeof(xmlPredefinedEntityValues[0]);i++) {
in = xmlPredefinedEntityValues[i].name;
out = &name[0];
for (;(*out++ = (xmlChar) *in);)in++;
in = xmlPredefinedEntityValues[i].value;
out = &value[0];
for (;(*out++ = (xmlChar) *in);)in++;
xmlAddEntity(NULL, (const xmlChar *) &name[0],
XML_INTERNAL_PREDEFINED_ENTITY, NULL, NULL,
&value[0]);
}
}
/**
* xmlCleanupPredefinedEntities:
*
* Cleanup up the predefined entities table.
*/
void xmlCleanupPredefinedEntities(void) {
if (xmlPredefinedEntities == NULL) return;
xmlFreeEntitiesTable(xmlPredefinedEntities);
xmlPredefinedEntities = NULL;
}
/**
* xmlGetPredefinedEntity:
* @name: the entity name
@ -191,9 +165,30 @@ void xmlCleanupPredefinedEntities(void) {
*/
xmlEntityPtr
xmlGetPredefinedEntity(const xmlChar *name) {
if (xmlPredefinedEntities == NULL)
xmlInitializePredefinedEntities();
return((xmlEntityPtr) xmlHashLookup(xmlPredefinedEntities, name));
if (name == NULL) return(NULL);
switch (name[0]) {
case 'l':
if (xmlStrEqual(name, BAD_CAST "lt"))
return(&xmlEntityLt);
break;
case 'g':
if (xmlStrEqual(name, BAD_CAST "gt"))
return(&xmlEntityGt);
break;
case 'a':
if (xmlStrEqual(name, BAD_CAST "amp"))
return(&xmlEntityAmp);
if (xmlStrEqual(name, BAD_CAST "apos"))
return(&xmlEntityApos);
break;
case 'q':
if (xmlStrEqual(name, BAD_CAST "quot"))
return(&xmlEntityQuot);
break;
default:
break;
}
return(NULL);
}
/**
@ -397,10 +392,7 @@ xmlGetDocEntity(xmlDocPtr doc, const xmlChar *name) {
}
}
}
if (xmlPredefinedEntities == NULL)
xmlInitializePredefinedEntities();
table = xmlPredefinedEntities;
return(xmlGetEntityFromTable(table, name));
return(xmlGetPredefinedEntity(name));
}
/*

View File

@ -10,12 +10,14 @@
#define IN_LIBXML
#include "libxml.h"
#ifdef LIBXML_LEGACY_ENABLED
#include <string.h>
#include <libxml/tree.h>
#include <libxml/entities.h>
#include <libxml/SAX.h>
#include <libxml/parserInternals.h>
#ifdef LIBXML_LEGACY_ENABLED
void xmlUpgradeOldNs(xmlDocPtr doc);
/************************************************************************
@ -24,6 +26,24 @@ void xmlUpgradeOldNs(xmlDocPtr doc);
* *
************************************************************************/
/**
* xmlInitializePredefinedEntities:
*
* Set up the predefined entities.
* Deprecated call
*/
void xmlInitializePredefinedEntities(void) {
}
/**
* xmlCleanupPredefinedEntities:
*
* Cleanup up the predefined entities table.
* Deprecated call
*/
void xmlCleanupPredefinedEntities(void) {
}
static const char *xmlFeaturesList[] = {
"validate",
"load subset",

View File

@ -12022,7 +12022,6 @@ xmlInitParser(void) {
xmlInitThreads();
xmlInitMemory();
xmlInitCharEncodingHandlers();
xmlInitializePredefinedEntities();
xmlDefaultSAXHandlerInit();
xmlRegisterDefaultInputCallbacks();
#ifdef LIBXML_OUTPUT_ENABLED
@ -12055,7 +12054,6 @@ xmlCleanupParser(void) {
return;
xmlCleanupCharEncodingHandlers();
xmlCleanupPredefinedEntities();
#ifdef LIBXML_CATALOG_ENABLED
xmlCatalogCleanup();
#endif