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:
@ -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>
|
Tue Sep 30 14:30:47 CEST 2003 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* HTMLparser.c Makefile.am configure.in legacy.c parser.c
|
* HTMLparser.c Makefile.am configure.in legacy.c parser.c
|
||||||
|
126
entities.c
126
entities.c
@ -24,23 +24,41 @@
|
|||||||
* The XML predefined entities.
|
* The XML predefined entities.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct xmlPredefinedEntityValue {
|
static xmlEntity xmlEntityLt = {
|
||||||
const char *name;
|
NULL, XML_ENTITY_DECL, BAD_CAST "lt",
|
||||||
const char *value;
|
NULL, NULL, NULL, NULL, NULL, NULL,
|
||||||
|
BAD_CAST "<", BAD_CAST "<", 1,
|
||||||
|
XML_INTERNAL_PREDEFINED_ENTITY,
|
||||||
|
NULL, NULL, NULL, NULL, 0
|
||||||
};
|
};
|
||||||
static struct xmlPredefinedEntityValue xmlPredefinedEntityValues[] = {
|
static xmlEntity xmlEntityGt = {
|
||||||
{ "lt", "<" },
|
NULL, XML_ENTITY_DECL, BAD_CAST "gt",
|
||||||
{ "gt", ">" },
|
NULL, NULL, NULL, NULL, NULL, NULL,
|
||||||
{ "apos", "'" },
|
BAD_CAST ">", BAD_CAST ">", 1,
|
||||||
{ "quot", "\"" },
|
XML_INTERNAL_PREDEFINED_ENTITY,
|
||||||
{ "amp", "&" }
|
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.
|
* xmlFreeEntity : clean-up an entity record.
|
||||||
@ -93,9 +111,7 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
|
|||||||
table = dtd->pentities;
|
table = dtd->pentities;
|
||||||
break;
|
break;
|
||||||
case XML_INTERNAL_PREDEFINED_ENTITY:
|
case XML_INTERNAL_PREDEFINED_ENTITY:
|
||||||
if (xmlPredefinedEntities == NULL)
|
return(NULL);
|
||||||
xmlPredefinedEntities = xmlHashCreate(8);
|
|
||||||
table = xmlPredefinedEntities;
|
|
||||||
}
|
}
|
||||||
if (table == NULL)
|
if (table == NULL)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
@ -139,48 +155,6 @@ xmlAddEntity(xmlDtdPtr dtd, const xmlChar *name, int type,
|
|||||||
return(ret);
|
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:
|
* xmlGetPredefinedEntity:
|
||||||
* @name: the entity name
|
* @name: the entity name
|
||||||
@ -191,9 +165,30 @@ void xmlCleanupPredefinedEntities(void) {
|
|||||||
*/
|
*/
|
||||||
xmlEntityPtr
|
xmlEntityPtr
|
||||||
xmlGetPredefinedEntity(const xmlChar *name) {
|
xmlGetPredefinedEntity(const xmlChar *name) {
|
||||||
if (xmlPredefinedEntities == NULL)
|
if (name == NULL) return(NULL);
|
||||||
xmlInitializePredefinedEntities();
|
switch (name[0]) {
|
||||||
return((xmlEntityPtr) xmlHashLookup(xmlPredefinedEntities, name));
|
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)
|
return(xmlGetPredefinedEntity(name));
|
||||||
xmlInitializePredefinedEntities();
|
|
||||||
table = xmlPredefinedEntities;
|
|
||||||
return(xmlGetEntityFromTable(table, name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
22
legacy.c
22
legacy.c
@ -10,12 +10,14 @@
|
|||||||
#define IN_LIBXML
|
#define IN_LIBXML
|
||||||
#include "libxml.h"
|
#include "libxml.h"
|
||||||
|
|
||||||
|
#ifdef LIBXML_LEGACY_ENABLED
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include <libxml/entities.h>
|
#include <libxml/entities.h>
|
||||||
#include <libxml/SAX.h>
|
#include <libxml/SAX.h>
|
||||||
#include <libxml/parserInternals.h>
|
#include <libxml/parserInternals.h>
|
||||||
|
|
||||||
#ifdef LIBXML_LEGACY_ENABLED
|
|
||||||
void xmlUpgradeOldNs(xmlDocPtr doc);
|
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[] = {
|
static const char *xmlFeaturesList[] = {
|
||||||
"validate",
|
"validate",
|
||||||
"load subset",
|
"load subset",
|
||||||
|
2
parser.c
2
parser.c
@ -12022,7 +12022,6 @@ xmlInitParser(void) {
|
|||||||
xmlInitThreads();
|
xmlInitThreads();
|
||||||
xmlInitMemory();
|
xmlInitMemory();
|
||||||
xmlInitCharEncodingHandlers();
|
xmlInitCharEncodingHandlers();
|
||||||
xmlInitializePredefinedEntities();
|
|
||||||
xmlDefaultSAXHandlerInit();
|
xmlDefaultSAXHandlerInit();
|
||||||
xmlRegisterDefaultInputCallbacks();
|
xmlRegisterDefaultInputCallbacks();
|
||||||
#ifdef LIBXML_OUTPUT_ENABLED
|
#ifdef LIBXML_OUTPUT_ENABLED
|
||||||
@ -12055,7 +12054,6 @@ xmlCleanupParser(void) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
xmlCleanupCharEncodingHandlers();
|
xmlCleanupCharEncodingHandlers();
|
||||||
xmlCleanupPredefinedEntities();
|
|
||||||
#ifdef LIBXML_CATALOG_ENABLED
|
#ifdef LIBXML_CATALOG_ENABLED
|
||||||
xmlCatalogCleanup();
|
xmlCatalogCleanup();
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user