Skip to content

Commit 400928b

Browse files
committed
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 65c5864 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
1 parent 5de890e commit 400928b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

contrib/xml2/xpath.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ pgxml_parser_init(PgXmlStrictness strictness)
7474
/* Initialize libxml */
7575
xmlInitParser();
7676

77-
xmlLoadExtDtdDefaultValue = 1;
78-
7977
return xmlerrcxt;
8078
}
8179

src/backend/utils/adt/xml.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@
6767
#if LIBXML_VERSION >= 20704
6868
#define HAVE_XMLSTRUCTUREDERRORCONTEXT 1
6969
#endif
70+
71+
/*
72+
* libxml2 2.12 decided to insert "const" into the error handler API.
73+
*/
74+
#if LIBXML_VERSION >= 21200
75+
#define PgXmlErrorPtr const xmlError *
76+
#else
77+
#define PgXmlErrorPtr xmlErrorPtr
78+
#endif
79+
7080
#endif /* USE_LIBXML */
7181

7282
#include "access/htup_details.h"
@@ -124,7 +134,7 @@ static xmlParserInputPtr xmlPgEntityLoader(const char *URL, const char *ID,
124134
xmlParserCtxtPtr ctxt);
125135
static void xml_errsave(Node *escontext, PgXmlErrorContext *errcxt,
126136
int sqlcode, const char *msg);
127-
static void xml_errorHandler(void *data, xmlErrorPtr error);
137+
static void xml_errorHandler(void *data, PgXmlErrorPtr error);
128138
static int errdetail_for_xml_code(int code);
129139
static void chopStringInfoNewlines(StringInfo str);
130140
static void appendStringInfoLineSeparator(StringInfo str);
@@ -2024,7 +2034,7 @@ xml_errsave(Node *escontext, PgXmlErrorContext *errcxt,
20242034
* Error handler for libxml errors and warnings
20252035
*/
20262036
static void
2027-
xml_errorHandler(void *data, xmlErrorPtr error)
2037+
xml_errorHandler(void *data, PgXmlErrorPtr error)
20282038
{
20292039
PgXmlErrorContext *xmlerrcxt = (PgXmlErrorContext *) data;
20302040
xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) error->ctxt;

0 commit comments

Comments
 (0)