Skip to content

Commit cae1863

Browse files
jtojnargrooverdan
authored andcommitted
MDEV-33439 Fix build with libxml2 2.12
libxml2 2.12.0 made `xmlGetLastError()` return `const` pointer: https://gitlab.gnome.org/GNOME/libxml2/-/commit/61034116d0a3c8b295c6137956adc3ae55720711 Clang 16 does not like this: error: assigning to 'xmlErrorPtr' (aka '_xmlError *') from 'const xmlError *' (aka 'const _xmlError *') discards qualifiers error: cannot initialize a variable of type 'xmlErrorPtr' (aka '_xmlError *') with an rvalue of type 'const xmlError *' (aka 'const _xmlError *') Let’s update the variables to `const`. For older versions, it will be automatically converted. But then `xmlResetError(xmlError*)` will not like the `const` pointer: error: no matching function for call to 'xmlResetError' note: candidate function not viable: 1st argument ('const xmlError *' (aka 'const _xmlError *')) would lose const qualifier Let’s replace it with `xmlResetLastError()`. ALso remove `LIBXMLDOC::Xerr` protected member property. It was introduced in 65b0e54 along with the `xmlResetError` calls. It does not appear to be used for anything.
1 parent 3281b6b commit cae1863

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

storage/connect/libdoc.cpp

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ class LIBXMLDOC : public XMLDOCUMENT {
9393
xmlXPathContextPtr Ctxp;
9494
xmlXPathObjectPtr Xop;
9595
xmlXPathObjectPtr NlXop;
96-
xmlErrorPtr Xerr;
9796
char *Buf; // Temporary
9897
bool Nofreelist;
9998
}; // end of class LIBXMLDOC
@@ -327,7 +326,6 @@ LIBXMLDOC::LIBXMLDOC(char *nsl, char *nsdf, char *enc, PFBLOCK fp)
327326
Ctxp = NULL;
328327
Xop = NULL;
329328
NlXop = NULL;
330-
Xerr = NULL;
331329
Buf = NULL;
332330
Nofreelist = false;
333331
} // end of LIBXMLDOC constructor
@@ -365,8 +363,8 @@ bool LIBXMLDOC::ParseFile(PGLOBAL g, char *fn)
365363
Encoding = (char*)Docp->encoding;
366364

367365
return false;
368-
} else if ((Xerr = xmlGetLastError()))
369-
xmlResetError(Xerr);
366+
} else if (xmlGetLastError())
367+
xmlResetLastError();
370368

371369
return true;
372370
} // end of ParseFile
@@ -505,9 +503,9 @@ int LIBXMLDOC::DumpDoc(PGLOBAL g, char *ofn)
505503
#if 1
506504
// This function does not crash (
507505
if (xmlSaveFormatFileEnc((const char *)ofn, Docp, Encoding, 0) < 0) {
508-
xmlErrorPtr err = xmlGetLastError();
506+
const xmlError *err = xmlGetLastError();
509507
strcpy(g->Message, (err) ? err->message : "Error saving XML doc");
510-
xmlResetError(Xerr);
508+
xmlResetLastError();
511509
rc = -1;
512510
} // endif Save
513511
// rc = xmlDocDump(of, Docp);
@@ -546,35 +544,35 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
546544
if (Nlist) {
547545
xmlXPathFreeNodeSet(Nlist);
548546

549-
if ((Xerr = xmlGetLastError()))
550-
xmlResetError(Xerr);
547+
if (xmlGetLastError())
548+
xmlResetLastError();
551549

552550
Nlist = NULL;
553551
} // endif Nlist
554552

555553
if (Xop) {
556554
xmlXPathFreeObject(Xop);
557555

558-
if ((Xerr = xmlGetLastError()))
559-
xmlResetError(Xerr);
556+
if (xmlGetLastError())
557+
xmlResetLastError();
560558

561559
Xop = NULL;
562560
} // endif Xop
563561

564562
if (NlXop) {
565563
xmlXPathFreeObject(NlXop);
566564

567-
if ((Xerr = xmlGetLastError()))
568-
xmlResetError(Xerr);
565+
if (xmlGetLastError())
566+
xmlResetLastError();
569567

570568
NlXop = NULL;
571569
} // endif NlXop
572570

573571
if (Ctxp) {
574572
xmlXPathFreeContext(Ctxp);
575573

576-
if ((Xerr = xmlGetLastError()))
577-
xmlResetError(Xerr);
574+
if (xmlGetLastError())
575+
xmlResetLastError();
578576

579577
Ctxp = NULL;
580578
} // endif Ctxp
@@ -590,6 +588,7 @@ void LIBXMLDOC::CloseDoc(PGLOBAL g, PFBLOCK xp)
590588
/******************************************************************/
591589
xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp)
592590
{
591+
const xmlError *xerr;
593592
xmlNodeSetPtr nl;
594593

595594
if (trace(1))
@@ -649,11 +648,11 @@ xmlNodeSetPtr LIBXMLDOC::GetNodeList(PGLOBAL g, xmlNodePtr np, char *xp)
649648
} else
650649
xmlXPathFreeObject(Xop); // Caused node not found
651650

652-
if ((Xerr = xmlGetLastError())) {
653-
strcpy(g->Message, Xerr->message);
654-
xmlResetError(Xerr);
651+
if ((xerr = xmlGetLastError())) {
652+
strcpy(g->Message, xerr->message);
653+
xmlResetLastError();
655654
return NULL;
656-
} // endif Xerr
655+
} // endif xerr
657656

658657
} // endif Xop
659658

@@ -1079,7 +1078,7 @@ void XML2NODE::AddText(PGLOBAL g, PCSZ txtp)
10791078
/******************************************************************/
10801079
void XML2NODE::DeleteChild(PGLOBAL g, PXNODE dnp)
10811080
{
1082-
xmlErrorPtr xerr;
1081+
const xmlError *xerr;
10831082

10841083
if (trace(1))
10851084
htrc("DeleteChild: node=%p\n", dnp);
@@ -1122,7 +1121,7 @@ void XML2NODE::DeleteChild(PGLOBAL g, PXNODE dnp)
11221121
if (trace(1))
11231122
htrc("DeleteChild: errmsg=%-.256s\n", xerr->message);
11241123

1125-
xmlResetError(xerr);
1124+
xmlResetLastError();
11261125
} // end of DeleteChild
11271126

11281127
/* -------------------- class XML2NODELIST ---------------------- */

0 commit comments

Comments
 (0)