applied changes from Tom Moog #58002 Some cleanup, there is still a memory
authorDaniel Veillard <veillard@src.gnome.org>
Thu, 26 Jul 2001 21:30:29 +0000 (21:30 +0000)
committerDaniel Veillard <veillard@src.gnome.org>
Thu, 26 Jul 2001 21:30:29 +0000 (21:30 +0000)
* libxslt/transform.[ch]: applied changes from Tom Moog #58002
* libexslt/functions.c libxslt/documents.c libxslt/extensions.c:
  Some cleanup, there is still a memory leak left and some warnings
  in libexslt.
Daniel

ChangeLog
libexslt/functions.c
libxslt/documents.c
libxslt/extensions.c
libxslt/transform.c
libxslt/transform.h

index 289018e9e20cfa75244bfdac76f8019d21977c65..a2c8217097703ff35672487c89ceeed299642d3f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Jul 27 10:50:39 EDT 2001 Daniel Veillard <daniel@veillard.com>
+
+       * libxslt/transform.[ch]: applied changes from Tom Moog #58002
+       * libexslt/functions.c libxslt/documents.c libxslt/extensions.c:
+         Some cleanup, there is still a memory leak left and some warnings
+         in libexslt.
+
 Thu Jul 26 19:05:48 CEST 2001 Thomas Broyer <tbroyer@ltgt.net>
 
        * libxslt/extensions.[ch] libxslt/functions.[ch] libxslt/preproc.c
index c5910eaf5a85384ba91b3417f4748f3b7caad3af..56c293d7b7c60bbf8a880ecadc2f13a5f365989c 100644 (file)
@@ -1,3 +1,5 @@
+#include <string.h>
+
 #include <libxml/tree.h>
 #include <libxml/xpath.h>
 #include <libxml/xpathInternals.h>
index c9d431489867fd1dd07d78aaeb107956d4d3f213..9b2e8aa65bba556fa0d3ee3426bf366d417f8220 100644 (file)
@@ -238,8 +238,8 @@ xsltFindDocument (xsltTransformContextPtr ctxt, xmlDocPtr doc) {
            return(ret);
        ret = ret->next;
     }
-    if (doc==ctxt->style->doc)
-       return ctxt->style;
+    if (doc == ctxt->style->doc)
+       return(ctxt->document);
     return(NULL);
 }
 
index 39f70b3fe67daf0eedb55811853d46d835971cae..0fd72b0830973b05062c6935e6b928a6b48e637e 100644 (file)
@@ -1113,7 +1113,8 @@ xsltExtModuleTopLevelLookup (const xmlChar *name, const xmlChar *URI) {
     if ((xsltTopLevelsHash == NULL) || (name == NULL) || (URI == NULL))
        return(NULL);
 
-    return xmlHashLookup2(xsltTopLevelsHash, name, URI);
+    return((xsltPreComputeFunction)
+           xmlHashLookup2(xsltTopLevelsHash, name, URI));
 }
 
 /**
@@ -1158,10 +1159,10 @@ static xmlChar *testStyleData = NULL;
  * function libxslt:test() for testing the extensions support.
  */
 static void
-xsltExtFunctionTest(xmlXPathParserContextPtr ctxt, int nargs)
+xsltExtFunctionTest(xmlXPathParserContextPtr ctxt, int nargs ATTRIBUTE_UNUSED)
 {
     xsltTransformContextPtr tctxt;
-    void *data;
+    void *data = NULL;
 
     tctxt = xsltXPathGetTransformContext(ctxt);
 
@@ -1370,7 +1371,8 @@ xsltExtShutdownTest(xsltTransformContextPtr ctxt,
  * Returns a pointer to the module specific data for this transformation
  */
 static void *
-xsltExtStyleInitTest(xsltStylesheetPtr style, const xmlChar * URI)
+xsltExtStyleInitTest(xsltStylesheetPtr style ATTRIBUTE_UNUSED,
+                    const xmlChar * URI)
 {
     if (testStyleData != NULL) {
        xsltPrintErrorContext(NULL, NULL, NULL);
@@ -1394,7 +1396,7 @@ xsltExtStyleInitTest(xsltStylesheetPtr style, const xmlChar * URI)
  * A function called at shutdown time of an XSLT extension module
  */
 static void
-xsltExtStyleShutdownTest(xsltStylesheetPtr style,
+xsltExtStyleShutdownTest(xsltStylesheetPtr style ATTRIBUTE_UNUSED,
                         const xmlChar * URI, void *data) {
     if (testStyleData == NULL) {
         xsltGenericError(xsltGenericErrorContext,
index 1498d6ae399b191f492ffd56c63e22083d7c46b4..a21e9f318c2f716c5857b16534957ba84a21e740 100644 (file)
@@ -164,7 +164,7 @@ xsltGetXIncludeDefault(void) {
  *
  * Returns the newly allocated xsltTransformContextPtr or NULL in case of error
  */
-static xsltTransformContextPtr
+xsltTransformContextPtr
 xsltNewTransformContext(xsltStylesheetPtr style, xmlDocPtr doc) {
     xsltTransformContextPtr cur;
     xsltDocumentPtr docu;
@@ -259,7 +259,7 @@ xsltNewTransformContext(xsltStylesheetPtr style, xmlDocPtr doc) {
  *
  * Free up the memory allocated by @ctxt
  */
-static void
+void
 xsltFreeTransformContext(xsltTransformContextPtr ctxt) {
     if (ctxt == NULL)
        return;
@@ -3117,6 +3117,7 @@ xsltGetHTMLIDs(const xmlChar *version, const xmlChar **public,
  * @params:  a NULL terminated arry of parameters names/values tuples
  * @output:  the targetted output
  * @profile:  profile FILE * output or NULL
+ * @user:  user provided parameter
  *
  * Apply the stylesheet to the document
  * NOTE: This may lead to a non-wellformed output XML wise !
@@ -3126,7 +3127,7 @@ xsltGetHTMLIDs(const xmlChar *version, const xmlChar **public,
 static xmlDocPtr
 xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc,
                             const char **params, const char *output,
-                            FILE * profile)
+                            FILE * profile, xsltTransformContextPtr userCtxt)
 {
     xmlDocPtr res = NULL;
     xsltTransformContextPtr ctxt = NULL;
@@ -3140,7 +3141,12 @@ xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc,
 
     if ((style == NULL) || (doc == NULL))
         return (NULL);
-    ctxt = xsltNewTransformContext(style, doc);
+
+    if (userCtxt != NULL)
+       ctxt = userCtxt;
+    else
+       ctxt = xsltNewTransformContext(style, doc);
+
     if (ctxt == NULL)
         return (NULL);
 
@@ -3311,7 +3317,9 @@ xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc,
     if (profile != NULL) {
         xsltSaveProfiling(ctxt, profile);
     }
-    xsltFreeTransformContext(ctxt);
+    if (userCtxt == NULL)
+       xsltFreeTransformContext(ctxt);
+
     return (res);
 
 error:
@@ -3337,7 +3345,7 @@ xmlDocPtr
 xsltApplyStylesheet(xsltStylesheetPtr style, xmlDocPtr doc,
                     const char **params)
 {
-    return (xsltApplyStylesheetInternal(style, doc, params, NULL, NULL));
+    return (xsltApplyStylesheetInternal(style, doc, params, NULL, NULL, NULL));
 }
 
 /**
@@ -3358,7 +3366,33 @@ xsltProfileStylesheet(xsltStylesheetPtr style, xmlDocPtr doc,
 {
     xmlDocPtr res;
 
-    res = xsltApplyStylesheetInternal(style, doc, params, NULL, output);
+    res = xsltApplyStylesheetInternal(style, doc, params, NULL, output, NULL);
+    return (res);
+}
+
+/**
+ * xsltApplyStylesheetUser:
+ * @style:  a parsed XSLT stylesheet
+ * @doc:  a parsed XML document
+ * @params:  a NULL terminated arry of parameters names/values tuples
+ * @output:  the targetted output
+ * @profile:  profile FILE * output or NULL
+ * @userCtxt:  user provided transform context
+ *
+ * Apply the stylesheet to the document and allow the user to provide
+ * its own transformation context.
+ *
+ * Returns the result document or NULL in case of error
+ */
+xmlDocPtr
+xsltApplyStylesheetUser(xsltStylesheetPtr style, xmlDocPtr doc,
+                            const char **params, const char *output,
+                            FILE * profile, xsltTransformContextPtr userCtxt)
+{
+    xmlDocPtr res;
+
+    res = xsltApplyStylesheetInternal(style, doc, params, output,
+                                     profile, userCtxt);
     return (res);
 }
 
@@ -3405,7 +3439,7 @@ xsltRunStylesheet(xsltStylesheetPtr style, xmlDocPtr doc,
             return (-1);
     }
 
-    tmp = xsltApplyStylesheetInternal(style, doc, params, output, NULL);
+    tmp = xsltApplyStylesheetInternal(style, doc, params, output, NULL, NULL);
     if (tmp == NULL) {
        xsltPrintErrorContext(NULL, NULL, (xmlNodePtr) doc);
         xsltGenericError(xsltGenericErrorContext,
index a6765451680794a66221dae15de38428e5114471..d8ab3a232adef689ddd9a75a33b9b752e7d59f75 100644 (file)
@@ -23,6 +23,20 @@ extern "C" {
 void           xsltSetXIncludeDefault  (int xinclude);
 int            xsltGetXIncludeDefault  (void);
 
+/**
+ * Export context to users.
+ */
+xsltTransformContextPtr xsltNewTransformContext        (xsltStylesheetPtr style,
+                                                xmlDocPtr doc);
+
+void                   xsltFreeTransformContext(xsltTransformContextPtr ctxt);
+
+xmlDocPtr              xsltApplyStylesheetUser (xsltStylesheetPtr style,
+                                                xmlDocPtr doc,
+                                                const char **params,
+                                                const char *output,
+                                                FILE * profile,
+                                            xsltTransformContextPtr userCtxt);
 /**
  * Private Interfaces
  */