From cca684b24728312f5a8029e244e062f0ad027cec Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 26 Jul 2001 21:30:29 +0000 Subject: [PATCH] applied changes from Tom Moog #58002 Some cleanup, there is still a memory * 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 | 7 +++++++ libexslt/functions.c | 2 ++ libxslt/documents.c | 4 ++-- libxslt/extensions.c | 12 +++++++----- libxslt/transform.c | 50 ++++++++++++++++++++++++++++++++++++++++++-------- libxslt/transform.h | 14 ++++++++++++++ 6 files changed, 74 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 289018e..a2c8217 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Fri Jul 27 10:50:39 EDT 2001 Daniel Veillard + + * 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 * libxslt/extensions.[ch] libxslt/functions.[ch] libxslt/preproc.c diff --git a/libexslt/functions.c b/libexslt/functions.c index c5910ea..56c293d 100644 --- a/libexslt/functions.c +++ b/libexslt/functions.c @@ -1,3 +1,5 @@ +#include + #include #include #include diff --git a/libxslt/documents.c b/libxslt/documents.c index c9d4314..9b2e8aa 100644 --- a/libxslt/documents.c +++ b/libxslt/documents.c @@ -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); } diff --git a/libxslt/extensions.c b/libxslt/extensions.c index 39f70b3..0fd72b0 100644 --- a/libxslt/extensions.c +++ b/libxslt/extensions.c @@ -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, diff --git a/libxslt/transform.c b/libxslt/transform.c index 1498d6a..a21e9f3 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -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, diff --git a/libxslt/transform.h b/libxslt/transform.h index a676545..d8ab3a2 100644 --- a/libxslt/transform.h +++ b/libxslt/transform.h @@ -24,6 +24,20 @@ 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 */ xsltTransformFunction -- 2.7.4