[PATCH v2 0/2] Adapt to latest libxml2

I noticed a couple deprecation errors when trying to build libvirt with the latest libxml2 version from the master branch. These patches fix the deprecated fields. Both functions used are available in the oldest libxml2 version required by libvirt, so there is no need to bump it. Changes in v2: - Save return value of xmlCtxtGetLastError for later use - Check that xmlCtxtGetLastError doesn't return NULL Jakub Palacky (2): util/virxml: use xmlCtxtGetLastError when applicable vmx: use xmlBufferDetach() when applicable src/util/virxml.c | 19 ++++++++++--------- src/vmx/vmx.c | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) -- 2.46.0

xmlParserCtxt->lastError was deprecated in libxml2 v2.13.0-103-g1228b4e0 xmlCtxtGetLastError(xmlParserCtxt) should be used instead Signed-off-by: Jakub Palacky <jpalacky@redhat.com> --- src/util/virxml.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index a7b75fd7b3..51173303fe 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1029,14 +1029,15 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...) g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_autofree char *contextstr = NULL; g_autofree char *pointerstr = NULL; - + const xmlError *lastError = xmlCtxtGetLastError(ctxt); /* conditions for error printing */ if (!ctxt || (virGetLastErrorCode()) || ctxt->input == NULL || - ctxt->lastError.level != XML_ERR_FATAL || - ctxt->lastError.message == NULL) + lastError == NULL || + lastError->level != XML_ERR_FATAL || + lastError->message == NULL) return; if (ctxt->_private) @@ -1078,19 +1079,19 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...) pointerstr = virBufferContentAndReset(&buf); - if (ctxt->lastError.file) { + if (lastError->file) { virGenericReportError(domcode, VIR_ERR_XML_DETAIL, _("%1$s:%2$d: %3$s%4$s\n%5$s"), - ctxt->lastError.file, - ctxt->lastError.line, - ctxt->lastError.message, + lastError->file, + lastError->line, + lastError->message, contextstr, pointerstr); } else { virGenericReportError(domcode, VIR_ERR_XML_DETAIL, _("at line %1$d: %2$s%3$s\n%4$s"), - ctxt->lastError.line, - ctxt->lastError.message, + lastError->line, + lastError->message, contextstr, pointerstr); } -- 2.46.0

xmlBuffer->content was deprecated in libxml2 v2.13.0-33-gb34dc1e4 xmlBufferDetach(xmlBuffer) should be used instead Signed-off-by: Jakub Palacky <jpalacky@redhat.com> --- src/vmx/vmx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 227744d062..de16c1f634 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -794,7 +794,7 @@ virVMXConvertToUTF8(const char *encoding, const char *string) goto cleanup; } - result = (char *)g_steal_pointer(&utf8->content); + result = (char *)xmlBufferDetach(utf8); cleanup: xmlCharEncCloseFunc(handler); -- 2.46.0

On a Thursday in 2024, Jakub Palacky wrote:
I noticed a couple deprecation errors when trying to build libvirt with the latest libxml2 version from the master branch. These patches fix the deprecated fields.
Both functions used are available in the oldest libxml2 version required by libvirt, so there is no need to bump it.
Changes in v2: - Save return value of xmlCtxtGetLastError for later use - Check that xmlCtxtGetLastError doesn't return NULL
Jakub Palacky (2): util/virxml: use xmlCtxtGetLastError when applicable vmx: use xmlBufferDetach() when applicable
src/util/virxml.c | 19 ++++++++++--------- src/vmx/vmx.c | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> I will push it after the pipeline suceeds: https://gitlab.com/janotomko/libvirt/-/pipelines/1450732527 Jano
participants (2)
-
Jakub Palacky
-
Ján Tomko