From 400928b83bd254d20f0790d467f221bb52707e6e Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 29 Jan 2024 12:06:07 -0500 Subject: [PATCH] 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/1389505.1706382262@sss.pgh.pa.us --- contrib/xml2/xpath.c | 2 -- src/backend/utils/adt/xml.c | 14 ++++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c index a967257546..b999b1f706 100644 --- a/contrib/xml2/xpath.c +++ b/contrib/xml2/xpath.c @@ -74,8 +74,6 @@ pgxml_parser_init(PgXmlStrictness strictness) /* Initialize libxml */ xmlInitParser(); - xmlLoadExtDtdDefaultValue = 1; - return xmlerrcxt; } diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index f869c680af..3e24aba546 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -67,6 +67,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" @@ -124,7 +134,7 @@ static xmlParserInputPtr xmlPgEntityLoader(const char *URL, const char *ID, xmlParserCtxtPtr ctxt); static void xml_errsave(Node *escontext, PgXmlErrorContext *errcxt, int sqlcode, const char *msg); -static void xml_errorHandler(void *data, xmlErrorPtr error); +static void xml_errorHandler(void *data, PgXmlErrorPtr error); static int errdetail_for_xml_code(int code); static void chopStringInfoNewlines(StringInfo str); static void appendStringInfoLineSeparator(StringInfo str); @@ -2024,7 +2034,7 @@ xml_errsave(Node *escontext, PgXmlErrorContext *errcxt, * 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;