projects/guix·blob python-team · refs

83 lines · 2.8 KiB

1From 0adf38535637ec668e658d43f04f60f11f51574f Mon Sep 17 00:00:00 2001
2From: Roman Bogorodskiy <[email protected]>
3Date: Thu, 10 Apr 2025 13:54:02 +0200
4Subject: [PATCH] loader: don't use libxml2 deprecated APIs
5
6Address the following items:
7
8 - Deprecated direct access to buf's content
9 - Mismatching error function signature
10 - Deprecated direct access to ctxt's lastError
11
12Signed-off-by: Roman Bogorodskiy <[email protected]>
13---
14 osinfo/osinfo_loader.c | 42 +++++++++++++++++++++++-------------------
15 1 file changed, 23 insertions(+), 19 deletions(-)
16
17diff --git a/osinfo/osinfo_loader.c b/osinfo/osinfo_loader.c
18index 0a9004af..b3fd4535 100644
19--- a/osinfo/osinfo_loader.c
20+++ b/osinfo/osinfo_loader.c
21@@ -354,7 +354,7 @@ osinfo_loader_doc(const char *xpath,
22 xmlXPathFreeObject(obj);
23 OSINFO_LOADER_SET_ERROR(err, "Cannot format stylesheet");
24 }
25- ret = g_strdup((char *)buf->content);
26+ ret = g_strdup((char *)xmlBufferContent(buf));
27
28 xmlBufferFree(buf);
29 xmlXPathFreeObject(obj);
30@@ -1902,28 +1902,32 @@ static void osinfo_loader_root(OsinfoLoader *loader,
31 }
32
33 static void
34-catchXMLError(void *ctx, const char *msg ATTRIBUTE_UNUSED, ...)
35+catchXMLError(void *ctx, const char *msg, ...)
36 {
37 xmlParserCtxtPtr ctxt = (xmlParserCtxtPtr) ctx;
38+ const xmlError *xmlErr = NULL;
39+ g_autofree gchar *xmlmsg = NULL;
40
41- if (ctxt && ctxt->_private) {
42- GError **err = ctxt->_private;
43- if (!error_is_set(err)) {
44- gchar *xmlmsg;
45- if (ctxt->lastError.file) {
46- xmlmsg = g_strdup_printf("%s:%d: %s",
47- ctxt->lastError.file,
48- ctxt->lastError.line,
49- ctxt->lastError.message);
50- } else {
51- xmlmsg = g_strdup_printf("at line %d: %s",
52- ctxt->lastError.line,
53- ctxt->lastError.message);
54- }
55- OSINFO_LOADER_SET_ERROR(ctxt->_private, xmlmsg);
56- g_free(xmlmsg);
57- }
58+ if (!ctxt || !ctxt->_private)
59+ return;
60+
61+ if (error_is_set(ctxt->_private))
62+ return;
63+
64+ if (!(xmlErr = xmlCtxtGetLastError(ctx)))
65+ return;
66+
67+ if (xmlErr->file) {
68+ xmlmsg = g_strdup_printf("%s:%d: %s",
69+ xmlErr->file,
70+ xmlErr->line,
71+ xmlErr->message);
72+ } else {
73+ xmlmsg = g_strdup_printf("at line %d: %s",
74+ xmlErr->line,
75+ xmlErr->message);
76 }
77+ OSINFO_LOADER_SET_ERROR(ctxt->_private, xmlmsg);
78 }
79
80 static void osinfo_loader_process_xml(OsinfoLoader *loader,
81--
82GitLab
83