1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-05 19:01:18 +03:00

parser: Stop using 'directory' struct member

This was only used as a pointless fallback for URI resolution.
This commit is contained in:
Nick Wellnhofer
2023-12-23 00:58:36 +01:00
parent 60841beba6
commit 955c177f69
9 changed files with 4 additions and 82 deletions

View File

@ -2265,7 +2265,6 @@ htmlNewInputStream(htmlParserCtxtPtr ctxt) {
} }
memset(input, 0, sizeof(htmlParserInput)); memset(input, 0, sizeof(htmlParserInput));
input->filename = NULL; input->filename = NULL;
input->directory = NULL;
input->base = NULL; input->base = NULL;
input->cur = NULL; input->cur = NULL;
input->buf = NULL; input->buf = NULL;
@ -5861,12 +5860,6 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data,
xmlFreeParserInputBuffer(buf); xmlFreeParserInputBuffer(buf);
return(NULL); return(NULL);
} }
if (filename == NULL) {
ctxt->directory = NULL;
} else {
ctxt->directory = xmlParserGetDirectory(filename);
}
inputStream = htmlNewInputStream(ctxt); inputStream = htmlNewInputStream(ctxt);
if (inputStream == NULL) { if (inputStream == NULL) {
xmlFreeParserCtxt(ctxt); xmlFreeParserCtxt(ctxt);
@ -6272,8 +6265,6 @@ htmlCtxtReset(htmlParserCtxtPtr ctxt)
ctxt->version = NULL; ctxt->version = NULL;
DICT_FREE(ctxt->encoding); DICT_FREE(ctxt->encoding);
ctxt->encoding = NULL; ctxt->encoding = NULL;
DICT_FREE(ctxt->directory);
ctxt->directory = NULL;
DICT_FREE(ctxt->extSubURI); DICT_FREE(ctxt->extSubURI);
ctxt->extSubURI = NULL; ctxt->extSubURI = NULL;
DICT_FREE(ctxt->extSubSystem); DICT_FREE(ctxt->extSubSystem);

4
SAX2.c
View File

@ -412,8 +412,6 @@ xmlSAX2ResolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId
if (ctx == NULL) return(NULL); if (ctx == NULL) return(NULL);
if (ctxt->input != NULL) if (ctxt->input != NULL)
base = ctxt->input->filename; base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
if (xmlBuildURISafe(systemId, (const xmlChar *) base, &URI) < 0) if (xmlBuildURISafe(systemId, (const xmlChar *) base, &URI) < 0)
xmlSAX2ErrMemory(ctxt); xmlSAX2ErrMemory(ctxt);
@ -556,8 +554,6 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type,
if (ctxt->input != NULL) if (ctxt->input != NULL)
base = ctxt->input->filename; base = ctxt->input->filename;
if (base == NULL)
base = ctxt->directory;
if (base != NULL) { if (base != NULL) {
if (xmlBuildURISafe(systemId, (const xmlChar *) base, &URI) < 0) if (xmlBuildURISafe(systemId, (const xmlChar *) base, &URI) < 0)

View File

@ -871,7 +871,6 @@ xmlDocPtr
xmlParseCatalogFile(const char *filename) { xmlParseCatalogFile(const char *filename) {
xmlDocPtr ret; xmlDocPtr ret;
xmlParserCtxtPtr ctxt; xmlParserCtxtPtr ctxt;
char *directory = NULL;
xmlParserInputPtr inputStream; xmlParserInputPtr inputStream;
xmlParserInputBufferPtr buf; xmlParserInputBufferPtr buf;
@ -899,10 +898,7 @@ xmlParseCatalogFile(const char *filename) {
xmlBufResetInput(buf->buffer, inputStream); xmlBufResetInput(buf->buffer, inputStream);
inputPush(ctxt, inputStream); inputPush(ctxt, inputStream);
if (ctxt->directory == NULL)
directory = xmlParserGetDirectory(filename);
if ((ctxt->directory == NULL) && (directory != NULL))
ctxt->directory = directory;
ctxt->valid = 0; ctxt->valid = 0;
ctxt->validate = 0; ctxt->validate = 0;
ctxt->loadsubset = 0; ctxt->loadsubset = 0;

View File

@ -60,7 +60,7 @@ struct _xmlParserInput {
xmlParserInputBufferPtr buf; /* UTF-8 encoded buffer */ xmlParserInputBufferPtr buf; /* UTF-8 encoded buffer */
const char *filename; /* The file analyzed, if any */ const char *filename; /* The file analyzed, if any */
const char *directory; /* the directory/base of the file */ const char *directory; /* unused */
const xmlChar *base; /* Base of the array to parse */ const xmlChar *base; /* Base of the array to parse */
const xmlChar *cur; /* Current char being parsed */ const xmlChar *cur; /* Current char being parsed */
const xmlChar *end; /* end of the array to parse */ const xmlChar *end; /* end of the array to parse */
@ -229,7 +229,7 @@ struct _xmlParserCtxt {
xmlParserInputState instate; /* current type of input */ xmlParserInputState instate; /* current type of input */
int token; /* next char look-ahead */ int token; /* next char look-ahead */
char *directory; /* the data directory */ char *directory; /* unused */
/* Node name stack */ /* Node name stack */
const xmlChar *name; /* Current parsed Node */ const xmlChar *name; /* Current parsed Node */

View File

@ -12042,16 +12042,6 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data,
return(NULL); return(NULL);
} }
ctxt->dictNames = 1; ctxt->dictNames = 1;
if (filename == NULL) {
ctxt->directory = NULL;
} else {
ctxt->directory = xmlParserGetDirectory(filename);
if (ctxt->directory == NULL) {
xmlFreeParserCtxt(ctxt);
xmlFreeParserInputBuffer(buf);
return(NULL);
}
}
inputStream = xmlNewInputStream(ctxt); inputStream = xmlNewInputStream(ctxt);
if (inputStream == NULL) { if (inputStream == NULL) {
@ -13452,14 +13442,6 @@ xmlCreateEntityParserCtxtInternal(xmlSAXHandlerPtr sax, void *userData,
inputPush(ctxt, inputStream); inputPush(ctxt, inputStream);
if (ctxt->directory == NULL) {
ctxt->directory = xmlParserGetDirectory((char *)URL);
if (ctxt->directory == NULL) {
xmlErrMemory(ctxt);
goto error;
}
}
xmlFree(uri); xmlFree(uri);
return(ctxt); return(ctxt);
@ -13522,7 +13504,6 @@ xmlCreateURLParserCtxt(const char *filename, int options)
{ {
xmlParserCtxtPtr ctxt; xmlParserCtxtPtr ctxt;
xmlParserInputPtr inputStream; xmlParserInputPtr inputStream;
char *directory = NULL;
ctxt = xmlNewParserCtxt(); ctxt = xmlNewParserCtxt();
if (ctxt == NULL) if (ctxt == NULL)
@ -13539,10 +13520,6 @@ xmlCreateURLParserCtxt(const char *filename, int options)
} }
inputPush(ctxt, inputStream); inputPush(ctxt, inputStream);
if ((ctxt->directory == NULL) && (directory == NULL))
directory = xmlParserGetDirectory(filename);
if ((ctxt->directory == NULL) && (directory != NULL))
ctxt->directory = directory;
return(ctxt); return(ctxt);
} }
@ -13607,9 +13584,6 @@ xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const char *filename,
ctxt->_private = data; ctxt->_private = data;
} }
if (ctxt->directory == NULL)
ctxt->directory = xmlParserGetDirectory(filename);
ctxt->recovery = recovery; ctxt->recovery = recovery;
xmlParseDocument(ctxt); xmlParseDocument(ctxt);
@ -14227,8 +14201,6 @@ xmlCtxtReset(xmlParserCtxtPtr ctxt)
ctxt->version = NULL; ctxt->version = NULL;
DICT_FREE(ctxt->encoding); DICT_FREE(ctxt->encoding);
ctxt->encoding = NULL; ctxt->encoding = NULL;
DICT_FREE(ctxt->directory);
ctxt->directory = NULL;
DICT_FREE(ctxt->extSubURI); DICT_FREE(ctxt->extSubURI);
ctxt->extSubURI = NULL; ctxt->extSubURI = NULL;
DICT_FREE(ctxt->extSubSystem); DICT_FREE(ctxt->extSubSystem);
@ -14317,12 +14289,6 @@ xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk,
xmlCtxtReset(ctxt); xmlCtxtReset(ctxt);
if (filename == NULL) {
ctxt->directory = NULL;
} else {
ctxt->directory = xmlParserGetDirectory(filename);
}
inputStream = xmlNewInputStream(ctxt); inputStream = xmlNewInputStream(ctxt);
if (inputStream == NULL) { if (inputStream == NULL) {
xmlFreeParserInputBuffer(buf); xmlFreeParserInputBuffer(buf);

View File

@ -1420,7 +1420,6 @@ xmlFreeInputStream(xmlParserInputPtr input) {
if (input == NULL) return; if (input == NULL) return;
if (input->filename != NULL) xmlFree((char *) input->filename); if (input->filename != NULL) xmlFree((char *) input->filename);
if (input->directory != NULL) xmlFree((char *) input->directory);
if (input->version != NULL) xmlFree((char *) input->version); if (input->version != NULL) xmlFree((char *) input->version);
if ((input->free != NULL) && (input->base != NULL)) if ((input->free != NULL) && (input->base != NULL))
input->free((xmlChar *) input->base); input->free((xmlChar *) input->base);
@ -1736,10 +1735,6 @@ xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret) {
if (redir != NULL) { if (redir != NULL) {
if (ret->filename != NULL) if (ret->filename != NULL)
xmlFree((xmlChar *) ret->filename); xmlFree((xmlChar *) ret->filename);
if (ret->directory != NULL) {
xmlFree((xmlChar *) ret->directory);
ret->directory = NULL;
}
ret->filename = ret->filename =
(char *) xmlStrdup((const xmlChar *) redir); (char *) xmlStrdup((const xmlChar *) redir);
} }
@ -1762,7 +1757,6 @@ xmlParserInputPtr
xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) {
xmlParserInputBufferPtr buf; xmlParserInputBufferPtr buf;
xmlParserInputPtr inputStream; xmlParserInputPtr inputStream;
char *directory = NULL;
xmlChar *URI = NULL; xmlChar *URI = NULL;
int code; int code;
@ -1791,15 +1785,12 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) {
URI = xmlStrdup((xmlChar *) filename); URI = xmlStrdup((xmlChar *) filename);
else else
URI = xmlStrdup((xmlChar *) inputStream->filename); URI = xmlStrdup((xmlChar *) inputStream->filename);
directory = xmlParserGetDirectory((const char *) URI);
if (inputStream->filename != NULL) xmlFree((char *)inputStream->filename); if (inputStream->filename != NULL) xmlFree((char *)inputStream->filename);
inputStream->filename = (char *) xmlCanonicPath((const xmlChar *) URI); inputStream->filename = (char *) xmlCanonicPath((const xmlChar *) URI);
if (URI != NULL) xmlFree((char *) URI); if (URI != NULL) xmlFree((char *) URI);
inputStream->directory = directory;
xmlBufResetInput(inputStream->buf->buffer, inputStream); xmlBufResetInput(inputStream->buf->buffer, inputStream);
if ((ctxt->directory == NULL) && (directory != NULL))
ctxt->directory = (char *) xmlStrdup((const xmlChar *) directory);
return(inputStream); return(inputStream);
} }
@ -2035,7 +2026,6 @@ xmlInitSAXParserCtxt(xmlParserCtxtPtr ctxt, const xmlSAXHandler *sax,
ctxt->external = 0; ctxt->external = 0;
ctxt->instate = XML_PARSER_START; ctxt->instate = XML_PARSER_START;
ctxt->token = 0; ctxt->token = 0;
ctxt->directory = NULL;
/* Allocate the Node stack */ /* Allocate the Node stack */
if (ctxt->nodeTab == NULL) { if (ctxt->nodeTab == NULL) {
@ -2179,7 +2169,6 @@ xmlFreeParserCtxt(xmlParserCtxtPtr ctxt)
if (ctxt->sax != NULL) if (ctxt->sax != NULL)
#endif /* LIBXML_SAX1_ENABLED */ #endif /* LIBXML_SAX1_ENABLED */
xmlFree(ctxt->sax); xmlFree(ctxt->sax);
if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory);
if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab); if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab);
if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts); if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts);
if (ctxt->dict != NULL) xmlDictFree(ctxt->dict); if (ctxt->dict != NULL) xmlDictFree(ctxt->dict);

View File

@ -692,7 +692,6 @@ pythonExternalEntityLoader(const char *URL, const char *ID,
Py_DECREF(ret); Py_DECREF(ret);
} else if (URL != NULL) { } else if (URL != NULL) {
result->filename = (char *) xmlStrdup((const xmlChar *)URL); result->filename = (char *) xmlStrdup((const xmlChar *)URL);
result->directory = xmlParserGetDirectory((const char *) URL);
} }
} }
} }

View File

@ -339,14 +339,6 @@ xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) {
inputPush(pctxt, inputStream); inputPush(pctxt, inputStream);
if (pctxt->directory == NULL) {
pctxt->directory = xmlParserGetDirectory(URL);
if (pctxt->directory == NULL) {
xmlXIncludeErrMemory(ctxt);
goto error;
}
}
pctxt->loadsubset |= XML_DETECT_IDS; pctxt->loadsubset |= XML_DETECT_IDS;
xmlParseDocument(pctxt); xmlParseDocument(pctxt);

View File

@ -2102,7 +2102,6 @@ xmlTextReaderPtr
xmlNewTextReaderFilename(const char *URI) { xmlNewTextReaderFilename(const char *URI) {
xmlParserInputBufferPtr input; xmlParserInputBufferPtr input;
xmlTextReaderPtr ret; xmlTextReaderPtr ret;
char *directory = NULL;
input = xmlParserInputBufferCreateFilename(URI, XML_CHAR_ENCODING_NONE); input = xmlParserInputBufferCreateFilename(URI, XML_CHAR_ENCODING_NONE);
if (input == NULL) if (input == NULL)
@ -2113,12 +2112,6 @@ xmlNewTextReaderFilename(const char *URI) {
return(NULL); return(NULL);
} }
ret->allocs |= XML_TEXTREADER_INPUT; ret->allocs |= XML_TEXTREADER_INPUT;
if (ret->ctxt->directory == NULL)
directory = xmlParserGetDirectory(URI);
if ((ret->ctxt->directory == NULL) && (directory != NULL))
ret->ctxt->directory = (char *) xmlStrdup((xmlChar *) directory);
if (directory != NULL)
xmlFree(directory);
return(ret); return(ret);
} }