summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2024-01-29 17:06:07 +0000
committerTom Lane2024-01-29 17:06:07 +0000
commit3f8ac13b19764e3a485772d3cbb3ae6c4047eef2 (patch)
tree5e8715de829116f28b115bc9dd3a024f626e2bfb
parente43425f481542e4d5ef9c8fbdfe1759159b9f183 (diff)
Fix incompatibilities with libxml2 >= 2.12.0.
libxml2 changed the required signature of error handler callbacks to make the passed xmlError struct "const". This is causing build failures on buildfarm member caiman, and no doubt will start showing up in the field quite soon. Add a version check to adjust the declaration of xml_errorHandler() according to LIBXML_VERSION. 2.12.x also produces deprecation warnings for contrib/xml2/xpath.c's assignment to xmlLoadExtDtdDefaultValue. I see no good reason for that to still be there, seeing that we disabled external DTDs (at a lower level) years ago for security reasons. Let's just remove it. Back-patch to all supported branches, since they might all get built with newer libxml2 once it gets a bit more popular. (The back branches produce another deprecation warning about xpath.c's use of xmlSubstituteEntitiesDefault(). We ought to consider whether to back-patch all or part of commit 65c5864d7 to silence that. It's less urgent though, since it won't break the buildfarm.) Discussion: https://postgr.es/m/[email protected]
-rw-r--r--contrib/xml2/xpath.c1
-rw-r--r--src/backend/utils/adt/xml.c14
2 files changed, 12 insertions, 3 deletions
diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c
index a692dc6be86..94641930f7b 100644
--- a/contrib/xml2/xpath.c
+++ b/contrib/xml2/xpath.c
@@ -75,7 +75,6 @@ pgxml_parser_init(PgXmlStrictness strictness)
xmlInitParser();
xmlSubstituteEntitiesDefault(1);
- xmlLoadExtDtdDefaultValue = 1;
return xmlerrcxt;
}
diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c
index 6411f56b998..aae06925865 100644
--- a/src/backend/utils/adt/xml.c
+++ b/src/backend/utils/adt/xml.c
@@ -65,6 +65,16 @@
#if LIBXML_VERSION >= 20704
#define HAVE_XMLSTRUCTUREDERRORCONTEXT 1
#endif
+
+/*
+ * libxml2 2.12 decided to insert "const" into the error handler API.
+ */
+#if LIBXML_VERSION >= 21200
+#define PgXmlErrorPtr const xmlError *
+#else
+#define PgXmlErrorPtr xmlErrorPtr
+#endif
+
#endif /* USE_LIBXML */
#include "access/htup_details.h"
@@ -119,7 +129,7 @@ struct PgXmlErrorContext
static xmlParserInputPtr xmlPgEntityLoader(const char *URL, const char *ID,
xmlParserCtxtPtr ctxt);
-static void xml_errorHandler(void *data, xmlErrorPtr error);
+static void xml_errorHandler(void *data, PgXmlErrorPtr error);
static void xml_ereport_by_code(int level, int sqlcode,
const char *msg, int errcode);
static void chopStringInfoNewlines(StringInfo str);
@@ -1749,7 +1759,7 @@ xml_ereport(PgXmlErrorContext *errcxt, int level, int sqlcode, const char *msg)
* Error handler for libxml errors and warnings
*/
static void
-xml_errorHandler(void *data, xmlErrorPtr error)
+xml_errorHandler(void *data, PgXmlErrorPtr error)
{
PgXmlErrorContext *xmlerrcxt = (PgXmlErrorContext *) data;
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) error->ctxt;