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:
@ -4527,7 +4527,6 @@ htmlInitParserCtxt(htmlParserCtxtPtr ctxt, const htmlSAXHandler *sax,
|
|||||||
ctxt->myDoc = NULL;
|
ctxt->myDoc = NULL;
|
||||||
ctxt->wellFormed = 1;
|
ctxt->wellFormed = 1;
|
||||||
ctxt->replaceEntities = 0;
|
ctxt->replaceEntities = 0;
|
||||||
ctxt->linenumbers = xmlLineNumbersDefaultValue;
|
|
||||||
ctxt->keepBlanks = xmlKeepBlanksDefaultValue;
|
ctxt->keepBlanks = xmlKeepBlanksDefaultValue;
|
||||||
ctxt->html = INSERT_INITIAL;
|
ctxt->html = INSERT_INITIAL;
|
||||||
ctxt->vctxt.flags = XML_VCTXT_USE_PCTXT;
|
ctxt->vctxt.flags = XML_VCTXT_USE_PCTXT;
|
||||||
@ -5601,8 +5600,6 @@ htmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask)
|
|||||||
*/
|
*/
|
||||||
ctxt->dictNames = 0;
|
ctxt->dictNames = 0;
|
||||||
|
|
||||||
ctxt->linenumbers = 1;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allow XML_PARSE_NOENT which many users set on the HTML parser.
|
* Allow XML_PARSE_NOENT which many users set on the HTML parser.
|
||||||
*/
|
*/
|
||||||
|
2
SAX2.c
2
SAX2.c
@ -903,7 +903,6 @@ xmlSAX2AppendChild(xmlParserCtxtPtr ctxt, xmlNodePtr node) {
|
|||||||
node->parent = parent;
|
node->parent = parent;
|
||||||
|
|
||||||
if ((node->type != XML_TEXT_NODE) &&
|
if ((node->type != XML_TEXT_NODE) &&
|
||||||
(ctxt->linenumbers) &&
|
|
||||||
(ctxt->input != NULL)) {
|
(ctxt->input != NULL)) {
|
||||||
if ((unsigned) ctxt->input->line < (unsigned) USHRT_MAX)
|
if ((unsigned) ctxt->input->line < (unsigned) USHRT_MAX)
|
||||||
node->line = ctxt->input->line;
|
node->line = ctxt->input->line;
|
||||||
@ -2537,7 +2536,6 @@ xmlSAX2Text(xmlParserCtxtPtr ctxt, const xmlChar *ch, int len,
|
|||||||
|
|
||||||
if ((lastChild != NULL) &&
|
if ((lastChild != NULL) &&
|
||||||
(type == XML_TEXT_NODE) &&
|
(type == XML_TEXT_NODE) &&
|
||||||
(ctxt->linenumbers) &&
|
|
||||||
(ctxt->input != NULL)) {
|
(ctxt->input != NULL)) {
|
||||||
if ((unsigned) ctxt->input->line < (unsigned) USHRT_MAX)
|
if ((unsigned) ctxt->input->line < (unsigned) USHRT_MAX)
|
||||||
lastChild->line = ctxt->input->line;
|
lastChild->line = ctxt->input->line;
|
||||||
|
16
globals.c
16
globals.c
@ -214,7 +214,6 @@ static int xmlDoValidityCheckingDefaultValueThrDef = 0;
|
|||||||
static int xmlGetWarningsDefaultValueThrDef = 1;
|
static int xmlGetWarningsDefaultValueThrDef = 1;
|
||||||
static int xmlLoadExtDtdDefaultValueThrDef = 0;
|
static int xmlLoadExtDtdDefaultValueThrDef = 0;
|
||||||
static int xmlPedanticParserDefaultValueThrDef = 0;
|
static int xmlPedanticParserDefaultValueThrDef = 0;
|
||||||
static int xmlLineNumbersDefaultValueThrDef = 0;
|
|
||||||
static int xmlKeepBlanksDefaultValueThrDef = 1;
|
static int xmlKeepBlanksDefaultValueThrDef = 1;
|
||||||
static int xmlSubstituteEntitiesDefaultValueThrDef = 0;
|
static int xmlSubstituteEntitiesDefaultValueThrDef = 0;
|
||||||
|
|
||||||
@ -554,7 +553,6 @@ xmlInitGlobalState(xmlGlobalStatePtr gs) {
|
|||||||
xmlDoValidityCheckingDefaultValueThrDef;
|
xmlDoValidityCheckingDefaultValueThrDef;
|
||||||
gs->getWarningsDefaultValue = xmlGetWarningsDefaultValueThrDef;
|
gs->getWarningsDefaultValue = xmlGetWarningsDefaultValueThrDef;
|
||||||
gs->keepBlanksDefaultValue = xmlKeepBlanksDefaultValueThrDef;
|
gs->keepBlanksDefaultValue = xmlKeepBlanksDefaultValueThrDef;
|
||||||
gs->lineNumbersDefaultValue = xmlLineNumbersDefaultValueThrDef;
|
|
||||||
gs->loadExtDtdDefaultValue = xmlLoadExtDtdDefaultValueThrDef;
|
gs->loadExtDtdDefaultValue = xmlLoadExtDtdDefaultValueThrDef;
|
||||||
gs->pedanticParserDefaultValue = xmlPedanticParserDefaultValueThrDef;
|
gs->pedanticParserDefaultValue = xmlPedanticParserDefaultValueThrDef;
|
||||||
gs->substituteEntitiesDefaultValue =
|
gs->substituteEntitiesDefaultValue =
|
||||||
@ -900,13 +898,13 @@ int xmlThrDefKeepBlanksDefaultValue(int v) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xmlThrDefLineNumbersDefaultValue(int v) {
|
/**
|
||||||
int ret;
|
* Set per-thread default value.
|
||||||
xmlMutexLock(&xmlThrDefMutex);
|
*
|
||||||
ret = xmlLineNumbersDefaultValueThrDef;
|
* @deprecated Has no effect.
|
||||||
xmlLineNumbersDefaultValueThrDef = v;
|
*/
|
||||||
xmlMutexUnlock(&xmlThrDefMutex);
|
int xmlThrDefLineNumbersDefaultValue(int v ATTRIBUTE_UNUSED) {
|
||||||
return ret;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int xmlThrDefLoadExtDtdDefaultValue(int v) {
|
int xmlThrDefLoadExtDtdDefaultValue(int v) {
|
||||||
|
@ -436,7 +436,7 @@ struct _xmlParserCtxt {
|
|||||||
* should the external subset be loaded
|
* should the external subset be loaded
|
||||||
*/
|
*/
|
||||||
int loadsubset;
|
int loadsubset;
|
||||||
/* set line number in element content */
|
/* unused */
|
||||||
int linenumbers XML_DEPRECATED_MEMBER;
|
int linenumbers XML_DEPRECATED_MEMBER;
|
||||||
/**
|
/**
|
||||||
* @deprecated Use xmlCtxtGetCatalogs() and xmlCtxtSetCatalogs()
|
* @deprecated Use xmlCtxtGetCatalogs() and xmlCtxtSetCatalogs()
|
||||||
|
3
parser.c
3
parser.c
@ -12449,7 +12449,6 @@ xmlCreateURLParserCtxt(const char *filename, int options)
|
|||||||
options |= XML_PARSE_UNZIP;
|
options |= XML_PARSE_UNZIP;
|
||||||
|
|
||||||
xmlCtxtUseOptions(ctxt, options);
|
xmlCtxtUseOptions(ctxt, options);
|
||||||
ctxt->linenumbers = 1;
|
|
||||||
|
|
||||||
input = xmlLoadResource(ctxt, filename, NULL, XML_RESOURCE_MAIN_DOCUMENT);
|
input = xmlLoadResource(ctxt, filename, NULL, XML_RESOURCE_MAIN_DOCUMENT);
|
||||||
if (input == NULL) {
|
if (input == NULL) {
|
||||||
@ -13185,8 +13184,6 @@ xmlCtxtSetOptionsInternal(xmlParserCtxtPtr ctxt, int options, int keepMask)
|
|||||||
xmlDictSetLimit(ctxt->dict, 0);
|
xmlDictSetLimit(ctxt->dict, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctxt->linenumbers = 1;
|
|
||||||
|
|
||||||
return(options & ~allMask);
|
return(options & ~allMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2749,7 +2749,6 @@ xmlInitSAXParserCtxt(xmlParserCtxtPtr ctxt, const xmlSAXHandler *sax,
|
|||||||
if (ctxt->pedantic) {
|
if (ctxt->pedantic) {
|
||||||
ctxt->options |= XML_PARSE_PEDANTIC;
|
ctxt->options |= XML_PARSE_PEDANTIC;
|
||||||
}
|
}
|
||||||
ctxt->linenumbers = xmlLineNumbersDefaultValue;
|
|
||||||
ctxt->keepBlanks = xmlKeepBlanksDefaultValue;
|
ctxt->keepBlanks = xmlKeepBlanksDefaultValue;
|
||||||
if (ctxt->keepBlanks == 0) {
|
if (ctxt->keepBlanks == 0) {
|
||||||
ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
|
ctxt->sax->ignorableWhitespace = xmlSAX2IgnorableWhitespace;
|
||||||
@ -3353,21 +3352,17 @@ xmlPedanticParserDefault(int val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set and return the previous value for enabling line numbers in elements
|
* Has no effect.
|
||||||
* contents. This may break on old application and is turned off by default.
|
|
||||||
*
|
*
|
||||||
* @deprecated The modern options API always enables line numbers.
|
* @deprecated Line numbers are always enabled.
|
||||||
*
|
*
|
||||||
* @param val int 0 or 1
|
* @param val int 0 or 1
|
||||||
* @returns the last value for 0 for no substitution, 1 for substitution.
|
* @returns 1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int
|
int
|
||||||
xmlLineNumbersDefault(int val) {
|
xmlLineNumbersDefault(int val ATTRIBUTE_UNUSED) {
|
||||||
int old = xmlLineNumbersDefaultValue;
|
return(1);
|
||||||
|
|
||||||
xmlLineNumbersDefaultValue = val;
|
|
||||||
return(old);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,7 +92,7 @@ functions = {
|
|||||||
'xmlParserSetLineNumbers': (
|
'xmlParserSetLineNumbers': (
|
||||||
'Switch on the generation of line number for elements nodes.',
|
'Switch on the generation of line number for elements nodes.',
|
||||||
['void', None, None],
|
['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),
|
'python_accessor', None),
|
||||||
'xmlDebugMemory': (
|
'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.',
|
'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.',
|
||||||
|
@ -27,19 +27,19 @@ class ErrorHandler:
|
|||||||
self.errors.append(str)
|
self.errors.append(str)
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
def getLineNumbersDefault():
|
def getPedanticParserDefault():
|
||||||
old = libxml2.lineNumbersDefault(0)
|
old = libxml2.pedanticParserDefault(0)
|
||||||
libxml2.lineNumbersDefault(old)
|
libxml2.pedanticParserDefault(old)
|
||||||
return old
|
return old
|
||||||
|
|
||||||
def test(expectedLineNumbersDefault):
|
def test(expectedPedanticParserDefault):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
global failed
|
global failed
|
||||||
# check a per thread-global
|
# check a per thread-global
|
||||||
if expectedLineNumbersDefault != getLineNumbersDefault():
|
if expectedPedanticParserDefault != getPedanticParserDefault():
|
||||||
failed = 1
|
failed = 1
|
||||||
print("FAILED to obtain correct value for " \
|
print("FAILED to obtain correct value for " \
|
||||||
"lineNumbersDefault in thread %d" % get_ident())
|
"pedanticParserDefault in thread %d" % get_ident())
|
||||||
# check the global error handler
|
# check the global error handler
|
||||||
# (which is NOT per-thread in the python bindings)
|
# (which is NOT per-thread in the python bindings)
|
||||||
try:
|
try:
|
||||||
@ -54,7 +54,7 @@ eh = ErrorHandler()
|
|||||||
libxml2.registerErrorHandler(eh.handler,"")
|
libxml2.registerErrorHandler(eh.handler,"")
|
||||||
|
|
||||||
# set on the main thread only
|
# set on the main thread only
|
||||||
libxml2.lineNumbersDefault(1)
|
libxml2.pedanticParserDefault(1)
|
||||||
test(1)
|
test(1)
|
||||||
ec = len(eh.errors)
|
ec = len(eh.errors)
|
||||||
if ec == 0:
|
if ec == 0:
|
||||||
@ -63,7 +63,7 @@ if ec == 0:
|
|||||||
|
|
||||||
ts = []
|
ts = []
|
||||||
for i in range(THREADS_COUNT):
|
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
|
# the new value has been set on the main thread only
|
||||||
ts.append(Thread(target=test,args=(0,)))
|
ts.append(Thread(target=test,args=(0,)))
|
||||||
for t in ts:
|
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")
|
print("FAILED: did not obtain the correct number of errors")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# set lineNumbersDefault for future new threads
|
# set pedanticParserDefault for future new threads
|
||||||
libxml2.thrDefLineNumbersDefaultValue(1)
|
libxml2.thrDefPedanticParserDefaultValue(1)
|
||||||
ts = []
|
ts = []
|
||||||
for i in range(THREADS_COUNT):
|
for i in range(THREADS_COUNT):
|
||||||
# expect 1 for lineNumbersDefault
|
# expect 1 for pedanticParserDefault
|
||||||
ts.append(Thread(target=test,args=(1,)))
|
ts.append(Thread(target=test,args=(1,)))
|
||||||
for t in ts:
|
for t in ts:
|
||||||
t.start()
|
t.start()
|
||||||
|
@ -2060,7 +2060,6 @@ xmlNewTextReader(xmlParserInputBuffer *input, const char *URI) {
|
|||||||
}
|
}
|
||||||
ret->ctxt->parseMode = XML_PARSE_READER;
|
ret->ctxt->parseMode = XML_PARSE_READER;
|
||||||
ret->ctxt->_private = ret;
|
ret->ctxt->_private = ret;
|
||||||
ret->ctxt->linenumbers = 1;
|
|
||||||
ret->ctxt->dictNames = 1;
|
ret->ctxt->dictNames = 1;
|
||||||
ret->allocs = XML_TEXTREADER_CTXT;
|
ret->allocs = XML_TEXTREADER_CTXT;
|
||||||
/*
|
/*
|
||||||
@ -4838,7 +4837,6 @@ xmlTextReaderSetup(xmlTextReader *reader,
|
|||||||
reader->dict = reader->ctxt->dict;
|
reader->dict = reader->ctxt->dict;
|
||||||
}
|
}
|
||||||
reader->ctxt->_private = reader;
|
reader->ctxt->_private = reader;
|
||||||
reader->ctxt->linenumbers = 1;
|
|
||||||
reader->ctxt->dictNames = 1;
|
reader->ctxt->dictNames = 1;
|
||||||
/*
|
/*
|
||||||
* use the parser dictionary to allocate all elements and attributes names
|
* use the parser dictionary to allocate all elements and attributes names
|
||||||
|
@ -28328,7 +28328,6 @@ xmlSchemaValidateStreamInternal(xmlSchemaValidCtxtPtr ctxt,
|
|||||||
xmlSchemaSAXPlugPtr plug = NULL;
|
xmlSchemaSAXPlugPtr plug = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
pctxt->linenumbers = 1;
|
|
||||||
xmlSchemaValidateSetLocator(ctxt, xmlSchemaValidateStreamLocator, pctxt);
|
xmlSchemaValidateSetLocator(ctxt, xmlSchemaValidateStreamLocator, pctxt);
|
||||||
|
|
||||||
ctxt->parserCtxt = pctxt;
|
ctxt->parserCtxt = pctxt;
|
||||||
|
Reference in New Issue
Block a user