Re: [xslt] Thread Safety Changes
- From: Peter Jones <mlists pmade org>
- To: xslt gnome org
- Subject: Re: [xslt] Thread Safety Changes
- Date: Wed, 29 Jan 2003 21:11:12 -0800
Hey, remember back when Daniel Veillard said:
> Exactly ! Providing a patch would speed up the process ;-)
I have attached the patch. Here is how you get thread safe StyleSheet
processing:
style = xsltNewStylesheet();
xsltSetStylesheetErrorFunc(style, ctx, func);
xsltProcessStylesheetFromDoc(style, doc);
xsltFreeStylesheet(style);
I did not know what to call the new function, so I just called it
xsltProcessStylesheetFromDoc which you will probably change since you
know the naming scheme better than I.
Let me know if anything is not right or needs to be changed.
--
Peter Jones <unix;c++;crypto;xml;vi;4wd;geek> [ http://pmade.org ]
PGP Fingerprint: 27AD 7922 D3BC 46A3 3627 D7B4 4240 46C3 A41E 844A
--- xslt.h.orig Wed Jan 29 16:25:24 2003
+++ xslt.h Wed Jan 29 16:27:00 2003
@@ -85,6 +85,11 @@
LIBXSLT_PUBLIC extern const int xsltLibxmlVersion;
/*
+ * Global setup function
+ */
+void xsltInit (void);
+
+/*
* Global cleanup function.
*/
void xsltCleanupGlobals (void);
--- xslt.c.orig Wed Jan 29 16:25:15 2003
+++ xslt.c Wed Jan 29 21:51:13 2003
@@ -142,7 +142,7 @@
* Initializes the processor (e.g. registers built-in extensions,
* etc.)
*/
-static void
+void
xsltInit (void) {
static int initialized = 0;
@@ -2001,6 +2001,42 @@
xsltResolveStylesheetAttributeSet(ret);
return(ret);
+}
+
+/**
+ * xsltProcessStylesheetFromDoc:
+ * @style a new StyleSheet
+ * @doc: and xmlDoc parsed XML
+ *
+ * parse an XSLT stylesheet building the associated structures
+ *
+ * Returns the given stylesheet or NULL if error. If this function returns
+ * NULL, both the xmlDocPtr and the xsltStylesheetPtr will need to be
+ * freed. If this function returns the given xsltStylesheetPtr, you should
+ * not free the xmlDocPtr, when you free the xsltStylesheetPtr the doc will
+ * be freed with it.
+ */
+
+xsltStylesheetPtr
+xsltProcessStylesheetFromDoc(xsltStylesheetPtr style, xmlDocPtr doc) {
+ if (style->doc != NULL) {
+ xsltTransformError(NULL, style, (xmlNodePtr) doc,
+ "xsltProcessStylesheetFromDoc: stylesheet already has a xmlDoc\n");
+ return NULL;
+ }
+
+ style->doc = doc;
+
+ xsltGatherNamespaces(style);
+
+ if (xsltParseStylesheetProcess(style, doc) == NULL) {
+ style->doc = NULL;
+ return NULL;
+ }
+
+ xsltResolveStylesheetAttributeSet(style);
+
+ return(style);
}
/**
--- xsltInternals.h.orig Wed Jan 29 16:28:26 2003
+++ xsltInternals.h Wed Jan 29 21:55:20 2003
@@ -413,6 +413,12 @@
*/
xmlHashTablePtr extInfos; /* the extension data */
int extrasNr; /* the number of extras required */
+
+ /*
+ * Error handling
+ */
+ xmlGenericErrorFunc error; /* a specific error handler */
+ void * errctx; /* context for the error handler */
};
/*
@@ -542,6 +548,8 @@
void xsltParseStylesheetOutput(xsltStylesheetPtr style,
xmlNodePtr cur);
xsltStylesheetPtr xsltParseStylesheetDoc (xmlDocPtr doc);
+xsltStylesheetPtr xsltProcessStylesheetFromDoc (xsltStylesheetPtr style,
+ xmlDocPtr doc);
xsltStylesheetPtr xsltParseStylesheetImportedDoc(xmlDocPtr doc);
xsltStylesheetPtr xsltLoadStylesheetPI (xmlDocPtr doc);
void xsltNumberFormat (xsltTransformContextPtr ctxt,
--- xsltutils.h.orig Wed Jan 29 21:39:26 2003
+++ xsltutils.h Wed Jan 29 21:40:44 2003
@@ -114,6 +114,9 @@
void xsltSetTransformErrorFunc (xsltTransformContextPtr ctxt,
void *ctx,
xmlGenericErrorFunc handler);
+void xsltSetStylesheetErrorFunc (xsltStylesheetPtr style,
+ void *ctx,
+ xmlGenericErrorFunc handler);
void xsltTransformError (xsltTransformContextPtr ctxt,
xsltStylesheetPtr style,
xmlNodePtr node,
--- xsltutils.c.orig Wed Jan 29 16:31:28 2003
+++ xsltutils.c Wed Jan 29 22:05:40 2003
@@ -406,6 +406,9 @@
error = ctxt->error;
errctx = ctxt->errctx;
}
+ } else if (style != NULL && style->error != NULL) {
+ error = style->error;
+ errctx = style->errctx;
}
if ((node == NULL) && (ctxt != NULL))
node = ctxt->inst;
@@ -477,6 +480,26 @@
}
/**
+ * xsltSetStylesheetErrorFunc:
+ * @style: the Stylesheet
+ * @ctx: the new error handling context
+ * @handler: the new handler function
+ *
+ * Function to reset the handler and the error context for out of
+ * context error messages specific to a given XSLT Stylesheet.
+ *
+ * This simply means that @handler will be called for subsequent
+ * error messages while processing the Stylesheet.
+ */
+void
+xsltSetStylesheetErrorFunc(xsltStylesheetPtr style,
+ void *ctx, xmlGenericErrorFunc handler)
+{
+ style->error = handler;
+ style->errctx = ctx;
+}
+
+/**
* xsltTransformError:
* @ctxt: an XSLT transformation context
* @style: the XSLT stylesheet used
@@ -502,6 +525,9 @@
error = ctxt->error;
errctx = ctxt->errctx;
}
+ } else if (style != NULL && style->error != NULL) {
+ error = style->error;
+ errctx = style->errctx;
}
if ((node == NULL) && (ctxt != NULL))
node = ctxt->inst;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]