summaryrefslogtreecommitdiff
path: root/contrib/xml2/xslt_proc.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2010-03-03 19:10:29 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2010-03-03 19:10:29 +0000
commit40c5457e60432696508a63135030936f61f54d1d (patch)
tree3f6d314f39dfae8a38cc1678f4b2e3141f26b2b2 /contrib/xml2/xslt_proc.c
parent3c93c3ab9535e88e47d1f357e5a77a0905dfcc01 (diff)
Make contrib/xml2 use core xml.c's error handler, when available (that is,
in versions >= 8.3). The core code is more robust and efficient than what was there before, and this also reduces risks involved in swapping different libxml error handler settings. Before 8.3, there is still some risk of problems if add-on modules such as Perl invoke libxml without setting their own error handler. Given the lack of reports I'm not sure there's a risk in practice, so I didn't take the step of actually duplicating the core code into older contrib/xml2 branches. Instead I just tweaked the existing code to ensure it didn't leave a dangling pointer to short-lived memory when throwing an error.
Diffstat (limited to 'contrib/xml2/xslt_proc.c')
-rw-r--r--contrib/xml2/xslt_proc.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/contrib/xml2/xslt_proc.c b/contrib/xml2/xslt_proc.c
index 5276ce9b0ce..a51b8c1516a 100644
--- a/contrib/xml2/xslt_proc.c
+++ b/contrib/xml2/xslt_proc.c
@@ -1,5 +1,5 @@
/*
- * $PostgreSQL: pgsql/contrib/xml2/xslt_proc.c,v 1.15.2.4 2010/03/01 18:08:07 tgl Exp $
+ * $PostgreSQL: pgsql/contrib/xml2/xslt_proc.c,v 1.15.2.5 2010/03/03 19:10:29 tgl Exp $
*
* XSLT processing functions (requiring libxslt)
*
@@ -12,6 +12,7 @@
#include "funcapi.h"
#include "miscadmin.h"
#include "utils/builtins.h"
+#include "utils/xml.h"
#ifdef USE_LIBXSLT
@@ -38,7 +39,6 @@ Datum xslt_process(PG_FUNCTION_ARGS);
#ifdef USE_LIBXSLT
/* declarations to come from xpath.c */
-extern void elog_error(const char *explain, bool force);
extern void pgxml_parser_init(void);
/* local defs */
@@ -88,11 +88,8 @@ xslt_process(PG_FUNCTION_ARGS)
doctree = xmlParseFile(text_to_cstring(doct));
if (doctree == NULL)
- {
- elog_error("error parsing XML document", false);
-
- PG_RETURN_NULL();
- }
+ xml_ereport(ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
+ "error parsing XML document");
/* Same for stylesheet */
if (VARDATA(ssheet)[0] == '<')
@@ -102,8 +99,8 @@ xslt_process(PG_FUNCTION_ARGS)
if (ssdoc == NULL)
{
xmlFreeDoc(doctree);
- elog_error("error parsing stylesheet as XML document", false);
- PG_RETURN_NULL();
+ xml_ereport(ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
+ "error parsing stylesheet as XML document");
}
stylesheet = xsltParseStylesheetDoc(ssdoc);
@@ -116,8 +113,8 @@ xslt_process(PG_FUNCTION_ARGS)
{
xmlFreeDoc(doctree);
xsltCleanupGlobals();
- elog_error("failed to parse stylesheet", false);
- PG_RETURN_NULL();
+ xml_ereport(ERROR, ERRCODE_EXTERNAL_ROUTINE_EXCEPTION,
+ "failed to parse stylesheet");
}
restree = xsltApplyStylesheet(stylesheet, doctree, params);