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

parser: Stop using ctxt->linenumbers

I think this was used to avoid setting the `line` member before it was
added (20+ years ago).
This commit is contained in:
Nick Wellnhofer
2025-05-15 23:43:32 +02:00
parent 5ce48ec131
commit 6f4b452742
10 changed files with 25 additions and 43 deletions

View File

@ -4527,7 +4527,6 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt, const htmlSAXHandler *sax,
ctxt->myDoc = NULL;
ctxt->wellFormed = 1;
ctxt->replaceEntities = 0;
ctxt->linenumbers = xmlLineNumbersDefaultValue;
ctxt->keepBlanks = xmlKeepBlanksDefaultValue;
ctxt->html = INSERT_INITIAL;
ctxt->vctxt.flags = XML_VCTXT_USE_PCTXT;
@ -5601,8 +5600,6 @@ htmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask)
*/
ctxt->dictNames = 0;
ctxt->linenumbers = 1;
/*
* Allow XML_PARSE_NOENT which many users set on the HTML parser.
*/

2
SAX2.c
View File

@ -903,7 +903,6 @@ xmlSAX2AppendChild(xmlParserCtxtPtr ctxt, xmlNodePtr node) {
node->parent = parent;
if ((node->type != XML_TEXT_NODE) &&
(ctxt->linenumbers) &&
(ctxt->input != NULL)) {
if ((unsigned) ctxt->input->line < (unsigned) USHRT_MAX)
node->line = ctxt->input->line;
@ -2537,7 +2536,6 @@ xmlSAX2Text(xmlParserCtxtPtr ctxt, const xmlChar *ch, int len,
if ((lastChild != NULL) &&
(type == XML_TEXT_NODE) &&
(ctxt->linenumbers) &&
(ctxt->input != NULL)) {
if ((unsigned) ctxt->input->line < (unsigned) USHRT_MAX)
lastChild->line = ctxt->input->line;

View File

@ -214,7 +214,6 @@ static int xmlDoValidityCheckingDefaultValueThrDef = 0;
static int xmlGetWarningsDefaultValueThrDef = 1;
static int xmlLoadExtDtdDefaultValueThrDef = 0;
static int xmlPedanticParserDefaultValueThrDef = 0;
static int xmlLineNumbersDefaultValueThrDef = 0;
static int xmlKeepBlanksDefaultValueThrDef = 1;
static int xmlSubstituteEntitiesDefaultValueThrDef = 0;
@ -554,7 +553,6 @@ xmlInitGlobalState(xmlGlobalStatePtr gs) {
xmlDoValidityCheckingDefaultValueThrDef;
gs->getWarningsDefaultValue = xmlGetWarningsDefaultValueThrDef;
gs->keepBlanksDefaultValue = xmlKeepBlanksDefaultValueThrDef;
gs->lineNumbersDefaultValue = xmlLineNumbersDefaultValueThrDef;
gs->loadExtDtdDefaultValue = xmlLoadExtDtdDefaultValueThrDef;
gs->pedanticParserDefaultValue = xmlPedanticParserDefaultValueThrDef;
gs->substituteEntitiesDefaultValue =
@ -900,13 +898,13 @@ int xmlThrDefKeepBlanksDefaultValue(int v) {
return ret;
}
int xmlThrDefLineNumbersDefaultValue(int v) {
int ret;
xmlMutexLock(&xmlThrDefMutex);
ret = xmlLineNumbersDefaultValueThrDef;
xmlLineNumbersDefaultValueThrDef = v;
xmlMutexUnlock(&xmlThrDefMutex);
return ret;
/**
* Set per-thread default value.
*
* @deprecated Has no effect.
*/
int xmlThrDefLineNumbersDefaultValue(int v ATTRIBUTE_UNUSED) {
return 1;
}
int xmlThrDefLoadExtDtdDefaultValue(int v) {

View File

@ -436,7 +436,7 @@ struct _xmlParserCtxt {
* should the external subset be loaded
*/
int loadsubset;
/* set line number in element content */
/* unused */
int linenumbers XML_DEPRECATED_MEMBER;
/**
* @deprecated Use xmlCtxtGetCatalogs() and xmlCtxtSetCatalogs()

View File

@ -12449,7 +12449,6 @@ xmlCreateURLParserCtxt(const char *filename, int options)
options |= XML_PARSE_UNZIP;
xmlCtxtUseOptions(ctxt, options);
ctxt->linenumbers = 1;
input = xmlLoadResource(ctxt, filename, NULL, XML_RESOURCE_MAIN_DOCUMENT);
if (input == NULL) {
@ -13185,8 +13184,6 @@ xmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask)
xmlDictSetLimit(ctxt->dict, 0);
}
ctxt->linenumbers = 1;
return(options & ~allMask);
}

View File

@ -2749,7 +2749,6 @@ xmlInitSAXParserCtxt(xmlParserCtxtPtr ctxt, const xmlSAXHandler *sax,
if (ctxt->pedantic) {
ctxt->options |= XML_PARSE_PEDANTIC;
}
ctxt->linenumbers = xmlLineNumbersDefaultValue;
ctxt->keepBlanks = xmlKeepBlanksDefaultValue;
if (ctxt->keepBlanks == 0) {
ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
@ -3353,21 +3352,17 @@ xmlPedanticParserDefault(int val) {
}
/**
* Set and return the previous value for enabling line numbers in elements
* contents. This may break on old application and is turned off by default.
* Has no effect.
*
* @deprecated The modern options API always enables line numbers.
* @deprecated Line numbers are always enabled.
*
* @param val int 0 or 1
* @returns the last value for 0 for no substitution, 1 for substitution.
* @returns 1
*/
int
xmlLineNumbersDefault(int val) {
int old = xmlLineNumbersDefaultValue;
xmlLineNumbersDefaultValue = val;
return(old);
xmlLineNumbersDefault(int val ATTRIBUTE_UNUSED) {
return(1);
}
/**

View File

@ -92,7 +92,7 @@ functions = {
'xmlParserSetLineNumbers': (
'Switch on the generation of line number for elements nodes.',
['void', None, None],
[['ctxt', 'xmlParserCtxt *', 'the parser context'], ['linenumbers', 'int', '1 to save line numbers']],
[['ctxt', 'xmlParserCtxt *', 'the parser context'], ['linenumbers', 'int', 'unused']],
'python_accessor', None),
'xmlDebugMemory': (
'Switch on the generation of line number for elements nodes. Also returns the number of bytes allocated and not freed by libxml2 since memory debugging was switched on.',

View File

@ -27,19 +27,19 @@ class ErrorHandler:
self.errors.append(str)
self.lock.release()
def getLineNumbersDefault():
old = libxml2.lineNumbersDefault(0)
libxml2.lineNumbersDefault(old)
def getPedanticParserDefault():
old = libxml2.pedanticParserDefault(0)
libxml2.pedanticParserDefault(old)
return old
def test(expectedLineNumbersDefault):
def test(expectedPedanticParserDefault):
time.sleep(1)
global failed
# check a per thread-global
if expectedLineNumbersDefault != getLineNumbersDefault():
if expectedPedanticParserDefault != getPedanticParserDefault():
failed = 1
print("FAILED to obtain correct value for " \
"lineNumbersDefault in thread %d" % get_ident())
"pedanticParserDefault in thread %d" % get_ident())
# check the global error handler
# (which is NOT per-thread in the python bindings)
try:
@ -54,7 +54,7 @@ eh = ErrorHandler()
libxml2.registerErrorHandler(eh.handler,"")
# set on the main thread only
libxml2.lineNumbersDefault(1)
libxml2.pedanticParserDefault(1)
test(1)
ec = len(eh.errors)
if ec == 0:
@ -63,7 +63,7 @@ if ec == 0:
ts = []
for i in range(THREADS_COUNT):
# expect 0 for lineNumbersDefault because
# expect 0 for pedanticParserDefault because
# the new value has been set on the main thread only
ts.append(Thread(target=test,args=(0,)))
for t in ts:
@ -75,11 +75,11 @@ if len(eh.errors) != ec+THREADS_COUNT*ec:
print("FAILED: did not obtain the correct number of errors")
sys.exit(1)
# set lineNumbersDefault for future new threads
libxml2.thrDefLineNumbersDefaultValue(1)
# set pedanticParserDefault for future new threads
libxml2.thrDefPedanticParserDefaultValue(1)
ts = []
for i in range(THREADS_COUNT):
# expect 1 for lineNumbersDefault
# expect 1 for pedanticParserDefault
ts.append(Thread(target=test,args=(1,)))
for t in ts:
t.start()

View File

@ -2060,7 +2060,6 @@ xmlNewTextReader(xmlParserInputBuffer *input, const char *URI) {
}
ret->ctxt->parseMode = XML_PARSE_READER;
ret->ctxt->_private = ret;
ret->ctxt->linenumbers = 1;
ret->ctxt->dictNames = 1;
ret->allocs = XML_TEXTREADER_CTXT;
/*
@ -4838,7 +4837,6 @@ xmlTextReaderSetup(xmlTextReader *reader,
reader->dict = reader->ctxt->dict;
}
reader->ctxt->_private = reader;
reader->ctxt->linenumbers = 1;
reader->ctxt->dictNames = 1;
/*
* use the parser dictionary to allocate all elements and attributes names

View File

@ -28328,7 +28328,6 @@ xmlSchemaValidateStreamInternal(xmlSchemaValidCtxtPtr ctxt,
xmlSchemaSAXPlugPtr plug = NULL;
int ret;
pctxt->linenumbers = 1;
xmlSchemaValidateSetLocator(ctxt, xmlSchemaValidateStreamLocator, pctxt);
ctxt->parserCtxt = pctxt;