From 955c177f69d53bcf3ca2aaf13767a3a63daeef5c Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Sat, 23 Dec 2023 00:58:36 +0100 Subject: [PATCH] parser: Stop using 'directory' struct member This was only used as a pointless fallback for URI resolution. --- HTMLparser.c | 9 --------- SAX2.c | 4 ---- catalog.c | 6 +----- include/libxml/parser.h | 4 ++-- parser.c | 34 ---------------------------------- parserInternals.c | 13 +------------ python/libxml.c | 1 - xinclude.c | 8 -------- xmlreader.c | 7 ------- 9 files changed, 4 insertions(+), 82 deletions(-) diff --git a/HTMLparser.c b/HTMLparser.c index c0b54e69..5b7016be 100644 --- a/HTMLparser.c +++ b/HTMLparser.c @@ -2265,7 +2265,6 @@ htmlNewInputStream(htmlParserCtxtPtr ctxt) { } memset(input, 0, sizeof(htmlParserInput)); input->filename = NULL; - input->directory = NULL; input->base = NULL; input->cur = NULL; input->buf = NULL; @@ -5861,12 +5860,6 @@ htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax, void *user_data, xmlFreeParserInputBuffer(buf); return(NULL); } - if (filename == NULL) { - ctxt->directory = NULL; - } else { - ctxt->directory = xmlParserGetDirectory(filename); - } - inputStream = htmlNewInputStream(ctxt); if (inputStream == NULL) { xmlFreeParserCtxt(ctxt); @@ -6272,8 +6265,6 @@ htmlCtxtReset(htmlParserCtxtPtr ctxt) ctxt->version = NULL; DICT_FREE(ctxt->encoding); ctxt->encoding = NULL; - DICT_FREE(ctxt->directory); - ctxt->directory = NULL; DICT_FREE(ctxt->extSubURI); ctxt->extSubURI = NULL; DICT_FREE(ctxt->extSubSystem); diff --git a/SAX2.c b/SAX2.c index 9ec306fe..dc428a24 100644 --- a/SAX2.c +++ b/SAX2.c @@ -412,8 +412,6 @@ xmlSAX2ResolveEntity(void *ctx, const xmlChar *publicId, const xmlChar *systemId if (ctx == NULL) return(NULL); if (ctxt->input != NULL) base = ctxt->input->filename; - if (base == NULL) - base = ctxt->directory; if (xmlBuildURISafe(systemId, (const xmlChar *) base, &URI) < 0) xmlSAX2ErrMemory(ctxt); @@ -556,8 +554,6 @@ xmlSAX2EntityDecl(void *ctx, const xmlChar *name, int type, if (ctxt->input != NULL) base = ctxt->input->filename; - if (base == NULL) - base = ctxt->directory; if (base != NULL) { if (xmlBuildURISafe(systemId, (const xmlChar *) base, &URI) < 0) diff --git a/catalog.c b/catalog.c index a79ff5ae..947ec182 100644 --- a/catalog.c +++ b/catalog.c @@ -871,7 +871,6 @@ xmlDocPtr xmlParseCatalogFile(const char *filename) { xmlDocPtr ret; xmlParserCtxtPtr ctxt; - char *directory = NULL; xmlParserInputPtr inputStream; xmlParserInputBufferPtr buf; @@ -899,10 +898,7 @@ xmlParseCatalogFile(const char *filename) { xmlBufResetInput(buf->buffer, inputStream); inputPush(ctxt, inputStream); - if (ctxt->directory == NULL) - directory = xmlParserGetDirectory(filename); - if ((ctxt->directory == NULL) && (directory != NULL)) - ctxt->directory = directory; + ctxt->valid = 0; ctxt->validate = 0; ctxt->loadsubset = 0; diff --git a/include/libxml/parser.h b/include/libxml/parser.h index ebf5fdeb..f5628268 100644 --- a/include/libxml/parser.h +++ b/include/libxml/parser.h @@ -60,7 +60,7 @@ struct _xmlParserInput { xmlParserInputBufferPtr buf; /* UTF-8 encoded buffer */ 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 *cur; /* Current char being parsed */ const xmlChar *end; /* end of the array to parse */ @@ -229,7 +229,7 @@ struct _xmlParserCtxt { xmlParserInputState instate; /* current type of input */ int token; /* next char look-ahead */ - char *directory; /* the data directory */ + char *directory; /* unused */ /* Node name stack */ const xmlChar *name; /* Current parsed Node */ diff --git a/parser.c b/parser.c index 8823bfcf..5eaaf47a 100644 --- a/parser.c +++ b/parser.c @@ -12042,16 +12042,6 @@ xmlCreatePushParserCtxt(xmlSAXHandlerPtr sax, void *user_data, return(NULL); } 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); if (inputStream == NULL) { @@ -13452,14 +13442,6 @@ xmlCreateEntityParserCtxtInternal(xmlSAXHandlerPtr sax, void *userData, inputPush(ctxt, inputStream); - if (ctxt->directory == NULL) { - ctxt->directory = xmlParserGetDirectory((char *)URL); - if (ctxt->directory == NULL) { - xmlErrMemory(ctxt); - goto error; - } - } - xmlFree(uri); return(ctxt); @@ -13522,7 +13504,6 @@ xmlCreateURLParserCtxt(const char *filename, int options) { xmlParserCtxtPtr ctxt; xmlParserInputPtr inputStream; - char *directory = NULL; ctxt = xmlNewParserCtxt(); if (ctxt == NULL) @@ -13539,10 +13520,6 @@ xmlCreateURLParserCtxt(const char *filename, int options) } inputPush(ctxt, inputStream); - if ((ctxt->directory == NULL) && (directory == NULL)) - directory = xmlParserGetDirectory(filename); - if ((ctxt->directory == NULL) && (directory != NULL)) - ctxt->directory = directory; return(ctxt); } @@ -13607,9 +13584,6 @@ xmlSAXParseFileWithData(xmlSAXHandlerPtr sax, const char *filename, ctxt->_private = data; } - if (ctxt->directory == NULL) - ctxt->directory = xmlParserGetDirectory(filename); - ctxt->recovery = recovery; xmlParseDocument(ctxt); @@ -14227,8 +14201,6 @@ xmlCtxtReset(xmlParserCtxtPtr ctxt) ctxt->version = NULL; DICT_FREE(ctxt->encoding); ctxt->encoding = NULL; - DICT_FREE(ctxt->directory); - ctxt->directory = NULL; DICT_FREE(ctxt->extSubURI); ctxt->extSubURI = NULL; DICT_FREE(ctxt->extSubSystem); @@ -14317,12 +14289,6 @@ xmlCtxtResetPush(xmlParserCtxtPtr ctxt, const char *chunk, xmlCtxtReset(ctxt); - if (filename == NULL) { - ctxt->directory = NULL; - } else { - ctxt->directory = xmlParserGetDirectory(filename); - } - inputStream = xmlNewInputStream(ctxt); if (inputStream == NULL) { xmlFreeParserInputBuffer(buf); diff --git a/parserInternals.c b/parserInternals.c index ee5b4b12..79708cf0 100644 --- a/parserInternals.c +++ b/parserInternals.c @@ -1420,7 +1420,6 @@ xmlFreeInputStream(xmlParserInputPtr input) { if (input == NULL) return; 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->free != NULL) && (input->base != NULL)) input->free((xmlChar *) input->base); @@ -1736,10 +1735,6 @@ xmlCheckHTTPInput(xmlParserCtxtPtr ctxt, xmlParserInputPtr ret) { if (redir != NULL) { if (ret->filename != NULL) xmlFree((xmlChar *) ret->filename); - if (ret->directory != NULL) { - xmlFree((xmlChar *) ret->directory); - ret->directory = NULL; - } ret->filename = (char *) xmlStrdup((const xmlChar *) redir); } @@ -1762,7 +1757,6 @@ xmlParserInputPtr xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { xmlParserInputBufferPtr buf; xmlParserInputPtr inputStream; - char *directory = NULL; xmlChar *URI = NULL; int code; @@ -1791,15 +1785,12 @@ xmlNewInputFromFile(xmlParserCtxtPtr ctxt, const char *filename) { URI = xmlStrdup((xmlChar *) filename); else URI = xmlStrdup((xmlChar *) inputStream->filename); - directory = xmlParserGetDirectory((const char *) URI); if (inputStream->filename != NULL) xmlFree((char *)inputStream->filename); inputStream->filename = (char *) xmlCanonicPath((const xmlChar *) URI); if (URI != NULL) xmlFree((char *) URI); - inputStream->directory = directory; xmlBufResetInput(inputStream->buf->buffer, inputStream); - if ((ctxt->directory == NULL) && (directory != NULL)) - ctxt->directory = (char *) xmlStrdup((const xmlChar *) directory); + return(inputStream); } @@ -2035,7 +2026,6 @@ xmlInitSAXParserCtxt(xmlParserCtxtPtr ctxt, const xmlSAXHandler *sax, ctxt->external = 0; ctxt->instate = XML_PARSER_START; ctxt->token = 0; - ctxt->directory = NULL; /* Allocate the Node stack */ if (ctxt->nodeTab == NULL) { @@ -2179,7 +2169,6 @@ xmlFreeParserCtxt(xmlParserCtxtPtr ctxt) if (ctxt->sax != NULL) #endif /* LIBXML_SAX1_ENABLED */ xmlFree(ctxt->sax); - if (ctxt->directory != NULL) xmlFree((char *) ctxt->directory); if (ctxt->vctxt.nodeTab != NULL) xmlFree(ctxt->vctxt.nodeTab); if (ctxt->atts != NULL) xmlFree((xmlChar * *)ctxt->atts); if (ctxt->dict != NULL) xmlDictFree(ctxt->dict); diff --git a/python/libxml.c b/python/libxml.c index 8e4d9982..6bf06d57 100644 --- a/python/libxml.c +++ b/python/libxml.c @@ -692,7 +692,6 @@ pythonExternalEntityLoader(const char *URL, const char *ID, Py_DECREF(ret); } else if (URL != NULL) { result->filename = (char *) xmlStrdup((const xmlChar *)URL); - result->directory = xmlParserGetDirectory((const char *) URL); } } } diff --git a/xinclude.c b/xinclude.c index 07c6db59..5793a3ec 100644 --- a/xinclude.c +++ b/xinclude.c @@ -339,14 +339,6 @@ xmlXIncludeParseFile(xmlXIncludeCtxtPtr ctxt, const char *URL) { inputPush(pctxt, inputStream); - if (pctxt->directory == NULL) { - pctxt->directory = xmlParserGetDirectory(URL); - if (pctxt->directory == NULL) { - xmlXIncludeErrMemory(ctxt); - goto error; - } - } - pctxt->loadsubset |= XML_DETECT_IDS; xmlParseDocument(pctxt); diff --git a/xmlreader.c b/xmlreader.c index 1ea89056..d96a2ebc 100644 --- a/xmlreader.c +++ b/xmlreader.c @@ -2102,7 +2102,6 @@ xmlTextReaderPtr xmlNewTextReaderFilename(const char *URI) { xmlParserInputBufferPtr input; xmlTextReaderPtr ret; - char *directory = NULL; input = xmlParserInputBufferCreateFilename(URI, XML_CHAR_ENCODING_NONE); if (input == NULL) @@ -2113,12 +2112,6 @@ xmlNewTextReaderFilename(const char *URI) { return(NULL); } 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); }