1 From 1f1ee5d3776af7ef56ffa3f4dcd22532c2c86c74 Mon Sep 17 00:00:00 2001
2 From: Jan Tojnar <jtojnar@gmail.com>
3 Date: Sun, 7 Jan 2024 10:19:54 +0100
4 Subject: [PATCH] Fix build with libxml2 2.12
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 libxml2 2.12.0 made `xmlGetLastError()` return `const` pointer:
11 https://gitlab.gnome.org/GNOME/libxml2/-/commit/61034116d0a3c8b295c6137956adc3ae55720711
13 Clang 16 does not like this:
15 error: assigning to 'xmlErrorPtr' (aka '_xmlError *') from 'const xmlError *' (aka 'const _xmlError *') discards qualifiers
16 error: cannot initialize a variable of type 'xmlErrorPtr' (aka '_xmlError *') with an rvalue of type 'const xmlError *' (aka 'const _xmlError *')
18 Let’s update the variables to `const`.
19 For older versions, it will be automatically converted.
21 But then `xmlResetError(xmlError*)` will not like the `const` pointer:
23 error: no matching function for call to 'xmlResetError'
24 note: candidate function not viable: 1st argument ('const xmlError *' (aka 'const _xmlError *')) would lose const qualifier
26 Let’s replace it with `xmlResetLastError()`.
28 ALso remove `LIBXMLDOC::Xerr` protected member property.
29 It was introduced in 65b0e5455b547a3d574fa77b34cce23ae3bea0a0
30 along with the `xmlResetError` calls.
31 It does not appear to be used for anything.
33 storage/connect/libdoc.cpp | 39 +++++++++++++++++++-------------------
34 1 file changed, 19 insertions(+), 20 deletions(-)
36 diff --git a/storage/connect/libdoc.cpp b/storage/connect/libdoc.cpp
37 index e414aa88355..10edcbc3ffa 100644
38 --- a/storage/connect/libdoc.cpp
39 +++ b/storage/connect/libdoc.cpp
40 @@ -93,7 +93,6 @@ class LIBXMLDOC : public XMLDOCUMENT {
41 xmlXPathContextPtr Ctxp;
42 xmlXPathObjectPtr Xop;
43 xmlXPathObjectPtr NlXop;
45 char *Buf; // Temporary
47 }; // end of class LIBXMLDOC
48 @@ -327,7 +326,6 @@ LIBXMLDOC::LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp)
55 } // end of LIBXMLDOC constructor
56 @@ -365,8 +363,8 @@ bool LIBXMLDOC::ParseFile(PGLOBAL g, char *fn)
57 Encoding = (char*)Docp->encoding;
60 - } else if ((Xerr = xmlGetLastError()))
61 - xmlResetError(Xerr);
62 + } else if (xmlGetLastError())
63 + xmlResetLastError();
67 @@ -505,9 +503,9 @@ int LIBXMLDOC::DumpDoc(PGLOBAL g, char *ofn)
69 // This function does not crash (
70 if (xmlSaveFormatFileEnc((const char *)ofn, Docp, Encoding, 0) < 0) {
71 - xmlErrorPtr err = xmlGetLastError();
72 + const xmlError *err = xmlGetLastError();
73 strcpy(g->Message, (err) ? err->message : "Error saving XML doc");
74 - xmlResetError(Xerr);
75 + xmlResetLastError();
78 // rc = xmlDocDump(of, Docp);
79 @@ -546,8 +544,8 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
81 xmlXPathFreeNodeSet(Nlist);
83 - if ((Xerr = xmlGetLastError()))
84 - xmlResetError(Xerr);
85 + if (xmlGetLastError())
86 + xmlResetLastError();
90 @@ -555,8 +553,8 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
92 xmlXPathFreeObject(Xop);
94 - if ((Xerr = xmlGetLastError()))
95 - xmlResetError(Xerr);
96 + if (xmlGetLastError())
97 + xmlResetLastError();
101 @@ -564,8 +562,8 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
103 xmlXPathFreeObject(NlXop);
105 - if ((Xerr = xmlGetLastError()))
106 - xmlResetError(Xerr);
107 + if (xmlGetLastError())
108 + xmlResetLastError();
112 @@ -573,8 +571,8 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
114 xmlXPathFreeContext(Ctxp);
116 - if ((Xerr = xmlGetLastError()))
117 - xmlResetError(Xerr);
118 + if (xmlGetLastError())
119 + xmlResetLastError();
123 @@ -590,6 +588,7 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
124 /******************************************************************/
125 xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp)
127 + const xmlError *xerr;
131 @@ -649,11 +648,11 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp)
133 xmlXPathFreeObject(Xop); // Caused node not found
135 - if ((Xerr = xmlGetLastError())) {
136 - strcpy(g->Message, Xerr->message);
137 - xmlResetError(Xerr);
138 + if ((xerr = xmlGetLastError())) {
139 + strcpy(g->Message, xerr->message);
140 + xmlResetLastError();
147 @@ -1079,7 +1078,7 @@ void XML2NODE::AddText(PGLOBAL g, PCSZ txtp)
148 /******************************************************************/
149 void XML2NODE::DeleteChild(PGLOBAL g, PXNODE dnp)
152 + const xmlError *xerr;
155 htrc("DeleteChild: node=%p\n", dnp);
156 @@ -1122,7 +1121,7 @@ void XML2NODE::DeleteChild(PGLOBAL g, PXNODE dnp)
158 htrc("DeleteChild: errmsg=%-.256s\n", xerr->message);
160 - xmlResetError(xerr);
161 + xmlResetLastError();
162 } // end of DeleteChild
164 /* -------------------- class XML2NODELIST ---------------------- */