1
0
mirror of https://gitlab.gnome.org/GNOME/libxslt synced 2025-08-08 21:42:07 +03:00

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
This commit is contained in:
Daniel Veillard
2001-07-26 21:30:29 +00:00
parent ef9ed9d048
commit cca684b247
6 changed files with 74 additions and 15 deletions

View File

@@ -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> Thu Jul 26 19:05:48 CEST 2001 Thomas Broyer <tbroyer@ltgt.net>
* libxslt/extensions.[ch] libxslt/functions.[ch] libxslt/preproc.c * libxslt/extensions.[ch] libxslt/functions.[ch] libxslt/preproc.c

View File

@@ -1,3 +1,5 @@
#include <string.h>
#include <libxml/tree.h> #include <libxml/tree.h>
#include <libxml/xpath.h> #include <libxml/xpath.h>
#include <libxml/xpathInternals.h> #include <libxml/xpathInternals.h>

View File

@@ -238,8 +238,8 @@ xsltFindDocument (xsltTransformContextPtr ctxt, xmlDocPtr doc) {
return(ret); return(ret);
ret = ret->next; ret = ret->next;
} }
if (doc==ctxt->style->doc) if (doc == ctxt->style->doc)
return ctxt->style; return(ctxt->document);
return(NULL); return(NULL);
} }

View File

@@ -1113,7 +1113,8 @@ xsltExtModuleTopLevelLookup (const xmlChar *name, const xmlChar *URI) {
if ((xsltTopLevelsHash == NULL) || (name == NULL) || (URI == NULL)) if ((xsltTopLevelsHash == NULL) || (name == NULL) || (URI == NULL))
return(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. * function libxslt:test() for testing the extensions support.
*/ */
static void static void
xsltExtFunctionTest(xmlXPathParserContextPtr ctxt, int nargs) xsltExtFunctionTest(xmlXPathParserContextPtr ctxt, int nargs ATTRIBUTE_UNUSED)
{ {
xsltTransformContextPtr tctxt; xsltTransformContextPtr tctxt;
void *data; void *data = NULL;
tctxt = xsltXPathGetTransformContext(ctxt); tctxt = xsltXPathGetTransformContext(ctxt);
@@ -1370,7 +1371,8 @@ xsltExtShutdownTest(xsltTransformContextPtr ctxt,
* Returns a pointer to the module specific data for this transformation * Returns a pointer to the module specific data for this transformation
*/ */
static void * static void *
xsltExtStyleInitTest(xsltStylesheetPtr style, const xmlChar * URI) xsltExtStyleInitTest(xsltStylesheetPtr style ATTRIBUTE_UNUSED,
const xmlChar * URI)
{ {
if (testStyleData != NULL) { if (testStyleData != NULL) {
xsltPrintErrorContext(NULL, NULL, 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 * A function called at shutdown time of an XSLT extension module
*/ */
static void static void
xsltExtStyleShutdownTest(xsltStylesheetPtr style, xsltExtStyleShutdownTest(xsltStylesheetPtr style ATTRIBUTE_UNUSED,
const xmlChar * URI, void *data) { const xmlChar * URI, void *data) {
if (testStyleData == NULL) { if (testStyleData == NULL) {
xsltGenericError(xsltGenericErrorContext, xsltGenericError(xsltGenericErrorContext,

View File

@@ -164,7 +164,7 @@ xsltGetXIncludeDefault(void) {
* *
* Returns the newly allocated xsltTransformContextPtr or NULL in case of error * Returns the newly allocated xsltTransformContextPtr or NULL in case of error
*/ */
static xsltTransformContextPtr xsltTransformContextPtr
xsltNewTransformContext(xsltStylesheetPtr style, xmlDocPtr doc) { xsltNewTransformContext(xsltStylesheetPtr style, xmlDocPtr doc) {
xsltTransformContextPtr cur; xsltTransformContextPtr cur;
xsltDocumentPtr docu; xsltDocumentPtr docu;
@@ -259,7 +259,7 @@ xsltNewTransformContext(xsltStylesheetPtr style, xmlDocPtr doc) {
* *
* Free up the memory allocated by @ctxt * Free up the memory allocated by @ctxt
*/ */
static void void
xsltFreeTransformContext(xsltTransformContextPtr ctxt) { xsltFreeTransformContext(xsltTransformContextPtr ctxt) {
if (ctxt == NULL) if (ctxt == NULL)
return; return;
@@ -3117,6 +3117,7 @@ xsltGetHTMLIDs(const xmlChar *version, const xmlChar **public,
* @params: a NULL terminated arry of parameters names/values tuples * @params: a NULL terminated arry of parameters names/values tuples
* @output: the targetted output * @output: the targetted output
* @profile: profile FILE * output or NULL * @profile: profile FILE * output or NULL
* @user: user provided parameter
* *
* Apply the stylesheet to the document * Apply the stylesheet to the document
* NOTE: This may lead to a non-wellformed output XML wise ! * NOTE: This may lead to a non-wellformed output XML wise !
@@ -3126,7 +3127,7 @@ xsltGetHTMLIDs(const xmlChar *version, const xmlChar **public,
static xmlDocPtr static xmlDocPtr
xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc, xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc,
const char **params, const char *output, const char **params, const char *output,
FILE * profile) FILE * profile, xsltTransformContextPtr userCtxt)
{ {
xmlDocPtr res = NULL; xmlDocPtr res = NULL;
xsltTransformContextPtr ctxt = NULL; xsltTransformContextPtr ctxt = NULL;
@@ -3140,7 +3141,12 @@ xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc,
if ((style == NULL) || (doc == NULL)) if ((style == NULL) || (doc == NULL))
return (NULL); return (NULL);
if (userCtxt != NULL)
ctxt = userCtxt;
else
ctxt = xsltNewTransformContext(style, doc); ctxt = xsltNewTransformContext(style, doc);
if (ctxt == NULL) if (ctxt == NULL)
return (NULL); return (NULL);
@@ -3311,7 +3317,9 @@ xsltApplyStylesheetInternal(xsltStylesheetPtr style, xmlDocPtr doc,
if (profile != NULL) { if (profile != NULL) {
xsltSaveProfiling(ctxt, profile); xsltSaveProfiling(ctxt, profile);
} }
if (userCtxt == NULL)
xsltFreeTransformContext(ctxt); xsltFreeTransformContext(ctxt);
return (res); return (res);
error: error:
@@ -3337,7 +3345,7 @@ xmlDocPtr
xsltApplyStylesheet(xsltStylesheetPtr style, xmlDocPtr doc, xsltApplyStylesheet(xsltStylesheetPtr style, xmlDocPtr doc,
const char **params) 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; 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); return (res);
} }
@@ -3405,7 +3439,7 @@ xsltRunStylesheet(xsltStylesheetPtr style, xmlDocPtr doc,
return (-1); return (-1);
} }
tmp = xsltApplyStylesheetInternal(style, doc, params, output, NULL); tmp = xsltApplyStylesheetInternal(style, doc, params, output, NULL, NULL);
if (tmp == NULL) { if (tmp == NULL) {
xsltPrintErrorContext(NULL, NULL, (xmlNodePtr) doc); xsltPrintErrorContext(NULL, NULL, (xmlNodePtr) doc);
xsltGenericError(xsltGenericErrorContext, xsltGenericError(xsltGenericErrorContext,

View File

@@ -23,6 +23,20 @@ extern "C" {
void xsltSetXIncludeDefault (int xinclude); void xsltSetXIncludeDefault (int xinclude);
int xsltGetXIncludeDefault (void); 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 * Private Interfaces
*/ */