From 4ca8cab70f712428f56ade81876ac2c07a3bbcb0 Mon Sep 17 00:00:00 2001 From: "William M. Brack" Date: Thu, 25 Nov 2004 14:32:45 +0000 Subject: [PATCH] backed out the last change and re-did it the "right way" (bug 158372). * libxslt/variables.c, libxslt/xsltInternals.h: backed out the last change and re-did it the "right way" (bug 158372). * tests/general/bug-158.*, tests/general/Makefile.am, tests/docs/bug-158.*, tests/general/Makefile.am: added test case for this bug --- ChangeLog | 8 ++++++++ libxslt/variables.c | 19 +++++++++---------- libxslt/xsltInternals.h | 6 +++++- libxslt/xsltwin32config.h | 2 +- tests/docs/Makefile.am | 1 + tests/docs/bug-158.doc | 3 +++ tests/docs/bug-158.xml | 2 ++ tests/general/Makefile.am | 1 + tests/general/bug-158.out | 4 ++++ tests/general/bug-158.xsl | 19 +++++++++++++++++++ 10 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 tests/docs/bug-158.doc create mode 100644 tests/docs/bug-158.xml create mode 100644 tests/general/bug-158.out create mode 100644 tests/general/bug-158.xsl diff --git a/ChangeLog b/ChangeLog index a104683..48024f1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Nov 25 22:24:03 HKT 2004 William Brack + + * libxslt/variables.c, libxslt/xsltInternals.h: backed out the + last change and re-did it the "right way" (bug 158372). + * tests/general/bug-158.*, tests/general/Makefile.am, + tests/docs/bug-158.*, tests/general/Makefile.am: added test + case for this bug + Wed Nov 24 10:51:51 HKT 2004 William Brack * libxslt/variables.c, libxslt/xsltInternals.h: enhanced the diff --git a/libxslt/variables.c b/libxslt/variables.c index bcbcc32..e2d7fd4 100644 --- a/libxslt/variables.c +++ b/libxslt/variables.c @@ -563,6 +563,7 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) { xmlXPathObjectPtr result = NULL; xsltStylePreCompPtr precomp; int oldProximityPosition, oldContextSize; + xmlDocPtr oldDoc; xmlNodePtr oldInst; int oldNsNr; xmlNsPtr *oldNamespaces; @@ -570,8 +571,7 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) { if ((ctxt == NULL) || (elem == NULL)) return(NULL); - /* For pre-computation, need to correlate with the current document */ - if ((elem->computed) && (elem->doc == ctxt->xpathCtxt->doc)) + if (elem->computed) return(elem->value); @@ -580,12 +580,6 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) { "Evaluating global variable %s\n", elem->name)); #endif - /* If document has changed, destroy the old value */ - if (elem->value != NULL) { - xmlXPathFreeObject(elem->value); - elem->value = NULL; - } - #ifdef WITH_DEBUGGER if ((ctxt->debugStatus != XSLT_DEBUG_NONE) && elem->comp && elem->comp->inst) @@ -608,11 +602,13 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) { elem->name = name; return(NULL); } + oldDoc = ctxt->xpathCtxt->doc; oldProximityPosition = ctxt->xpathCtxt->proximityPosition; oldContextSize = ctxt->xpathCtxt->contextSize; oldInst = ctxt->inst; oldNsNr = ctxt->xpathCtxt->nsNr; oldNamespaces = ctxt->xpathCtxt->namespaces; + if (precomp != NULL) { ctxt->inst = precomp->inst; ctxt->xpathCtxt->namespaces = precomp->nsList; @@ -622,8 +618,11 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) { ctxt->xpathCtxt->namespaces = NULL; ctxt->xpathCtxt->nsNr = 0; } - ctxt->xpathCtxt->node = (xmlNodePtr) ctxt->node; + ctxt->xpathCtxt->doc = ctxt->tmpDoc; + ctxt->xpathCtxt->node = (xmlNodePtr) ctxt->tmpDoc; result = xmlXPathCompiledEval(comp, ctxt->xpathCtxt); + + ctxt->xpathCtxt->doc = oldDoc; ctxt->xpathCtxt->contextSize = oldContextSize; ctxt->xpathCtxt->proximityPosition = oldProximityPosition; ctxt->inst = oldInst; @@ -694,7 +693,6 @@ xsltEvalGlobalVariable(xsltStackElemPtr elem, xsltTransformContextPtr ctxt) { if (result != NULL) { elem->value = result; elem->computed = 1; - elem->doc = ctxt->xpathCtxt->doc; } elem->name = name; return(result); @@ -722,6 +720,7 @@ xsltEvalGlobalVariables(xsltTransformContextPtr ctxt) { "Registering global variables\n")); #endif + ctxt->tmpDoc = ctxt->document->doc; ctxt->node = (xmlNodePtr) ctxt->document->doc; ctxt->xpathCtxt->contextSize = 1; ctxt->xpathCtxt->proximityPosition = 1; diff --git a/libxslt/xsltInternals.h b/libxslt/xsltInternals.h index 7b6f99a..1378c73 100644 --- a/libxslt/xsltInternals.h +++ b/libxslt/xsltInternals.h @@ -311,7 +311,6 @@ struct _xsltStackElem { const xmlChar *select; /* the eval string */ xmlNodePtr tree; /* the tree if no eval string or the location */ xmlXPathObjectPtr value; /* The value if computed */ - xmlDocPtr doc; /* The document used to compute the value */ }; /* @@ -552,6 +551,11 @@ struct _xsltTransformContext { * dictionnary: shared between stylesheet, context and documents. */ xmlDictPtr dict; + /* + * temporary storage for doc ptr, currently only used for + * global var evaluation + */ + xmlDocPtr tmpDoc; }; /** diff --git a/libxslt/xsltwin32config.h b/libxslt/xsltwin32config.h index f9a0558..b542c1b 100644 --- a/libxslt/xsltwin32config.h +++ b/libxslt/xsltwin32config.h @@ -44,7 +44,7 @@ extern "C" { * * extra version information, used to show a CVS compilation */ -#define LIBXML_VERSION_EXTRA "-CVS966" +#define LIBXML_VERSION_EXTRA "-CVS967" /** * WITH_XSLT_DEBUG: diff --git a/tests/docs/Makefile.am b/tests/docs/Makefile.am index cc00c88..b0a1b08 100644 --- a/tests/docs/Makefile.am +++ b/tests/docs/Makefile.am @@ -157,6 +157,7 @@ EXTRA_DIST = \ bug-155.xml \ bug-156.xml \ bug-157.xml \ + bug-158.xml bug-158.doc \ character.xml \ array.xml \ items.xml diff --git a/tests/docs/bug-158.doc b/tests/docs/bug-158.doc new file mode 100644 index 0000000..80b3f01 --- /dev/null +++ b/tests/docs/bug-158.doc @@ -0,0 +1,3 @@ + + + diff --git a/tests/docs/bug-158.xml b/tests/docs/bug-158.xml new file mode 100644 index 0000000..1983741 --- /dev/null +++ b/tests/docs/bug-158.xml @@ -0,0 +1,2 @@ + + diff --git a/tests/general/Makefile.am b/tests/general/Makefile.am index 98059ca..25747fb 100644 --- a/tests/general/Makefile.am +++ b/tests/general/Makefile.am @@ -166,6 +166,7 @@ EXTRA_DIST = \ bug-156.err bug-156.out bug-156.xsl \ bug-156.imp1.imp bug-156.imp2.imp \ bug-157.err bug-157.out bug-157.xsl \ + bug-158.out bug-158.xsl \ character.out character.xsl \ character2.out character2.xsl \ itemschoose.out itemschoose.xsl \ diff --git a/tests/general/bug-158.out b/tests/general/bug-158.out new file mode 100644 index 0000000..663816c --- /dev/null +++ b/tests/general/bug-158.out @@ -0,0 +1,4 @@ + + +myPath is path +root is diff --git a/tests/general/bug-158.xsl b/tests/general/bug-158.xsl new file mode 100644 index 0000000..0e77175 --- /dev/null +++ b/tests/general/bug-158.xsl @@ -0,0 +1,19 @@ + + + + + + + + + + +myPath is +root is + + + -- 2.7.4