lol
1From 1f1ee5d3776af7ef56ffa3f4dcd22532c2c86c74 Mon Sep 17 00:00:00 2001
2From: Jan Tojnar <jtojnar@gmail.com>
3Date: Sun, 7 Jan 2024 10:19:54 +0100
4Subject: [PATCH] Fix build with libxml2 2.12
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9libxml2 2.12.0 made `xmlGetLastError()` return `const` pointer:
10
11https://gitlab.gnome.org/GNOME/libxml2/-/commit/61034116d0a3c8b295c6137956adc3ae55720711
12
13Clang 16 does not like this:
14
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 *')
17
18Let’s update the variables to `const`.
19For older versions, it will be automatically converted.
20
21But then `xmlResetError(xmlError*)` will not like the `const` pointer:
22
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
25
26Let’s replace it with `xmlResetLastError()`.
27
28ALso remove `LIBXMLDOC::Xerr` protected member property.
29It was introduced in 65b0e5455b547a3d574fa77b34cce23ae3bea0a0
30along with the `xmlResetError` calls.
31It does not appear to be used for anything.
32---
33 storage/connect/libdoc.cpp | 39 +++++++++++++++++++-------------------
34 1 file changed, 19 insertions(+), 20 deletions(-)
35
36diff --git a/storage/connect/libdoc.cpp b/storage/connect/libdoc.cpp
37index 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;
44- xmlErrorPtr Xerr;
45 char *Buf; // Temporary
46 bool Nofreelist;
47 }; // end of class LIBXMLDOC
48@@ -327,7 +326,6 @@ LIBXMLDOC::LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp)
49 Ctxp = NULL;
50 Xop = NULL;
51 NlXop = NULL;
52- Xerr = NULL;
53 Buf = NULL;
54 Nofreelist = false;
55 } // end of LIBXMLDOC constructor
56@@ -365,8 +363,8 @@ bool LIBXMLDOC::ParseFile(PGLOBAL g, char *fn)
57 Encoding = (char*)Docp->encoding;
58
59 return false;
60- } else if ((Xerr = xmlGetLastError()))
61- xmlResetError(Xerr);
62+ } else if (xmlGetLastError())
63+ xmlResetLastError();
64
65 return true;
66 } // end of ParseFile
67@@ -505,9 +503,9 @@ int LIBXMLDOC::DumpDoc(PGLOBAL g, char *ofn)
68 #if 1
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();
76 rc = -1;
77 } // endif Save
78 // rc = xmlDocDump(of, Docp);
79@@ -546,8 +544,8 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
80 if (Nlist) {
81 xmlXPathFreeNodeSet(Nlist);
82
83- if ((Xerr = xmlGetLastError()))
84- xmlResetError(Xerr);
85+ if (xmlGetLastError())
86+ xmlResetLastError();
87
88 Nlist = NULL;
89 } // endif Nlist
90@@ -555,8 +553,8 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
91 if (Xop) {
92 xmlXPathFreeObject(Xop);
93
94- if ((Xerr = xmlGetLastError()))
95- xmlResetError(Xerr);
96+ if (xmlGetLastError())
97+ xmlResetLastError();
98
99 Xop = NULL;
100 } // endif Xop
101@@ -564,8 +562,8 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
102 if (NlXop) {
103 xmlXPathFreeObject(NlXop);
104
105- if ((Xerr = xmlGetLastError()))
106- xmlResetError(Xerr);
107+ if (xmlGetLastError())
108+ xmlResetLastError();
109
110 NlXop = NULL;
111 } // endif NlXop
112@@ -573,8 +571,8 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
113 if (Ctxp) {
114 xmlXPathFreeContext(Ctxp);
115
116- if ((Xerr = xmlGetLastError()))
117- xmlResetError(Xerr);
118+ if (xmlGetLastError())
119+ xmlResetLastError();
120
121 Ctxp = NULL;
122 } // endif Ctxp
123@@ -590,6 +588,7 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
124 /******************************************************************/
125 xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp)
126 {
127+ const xmlError *xerr;
128 xmlNodeSetPtr nl;
129
130 if (trace(1))
131@@ -649,11 +648,11 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp)
132 } else
133 xmlXPathFreeObject(Xop); // Caused node not found
134
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();
141 return NULL;
142- } // endif Xerr
143+ } // endif xerr
144
145 } // endif Xop
146
147@@ -1079,7 +1078,7 @@ void XML2NODE::AddText(PGLOBAL g, PCSZ txtp)
148 /******************************************************************/
149 void XML2NODE::DeleteChild(PGLOBAL g, PXNODE dnp)
150 {
151- xmlErrorPtr xerr;
152+ const xmlError *xerr;
153
154 if (trace(1))
155 htrc("DeleteChild: node=%p\n", dnp);
156@@ -1122,7 +1121,7 @@ void XML2NODE::DeleteChild(PGLOBAL g, PXNODE dnp)
157 if (trace(1))
158 htrc("DeleteChild: errmsg=%-.256s\n", xerr->message);
159
160- xmlResetError(xerr);
161+ xmlResetLastError();
162 } // end of DeleteChild
163
164 /* -------------------- class XML2NODELIST ---------------------- */
165--
1662.42.0
167