Version 2.12.0 of libxml2 changes a few functions to return (const
xmlError *) where previously they returned only (xmlError *).
Compilers generally are not happy with this. For example,

  bindings/xml/libxml_xmlparser.c: In function 'xml_parser_start_document':
  bindings/xml/libxml_xmlparser.c:327:16: error: assignment discards 'const'
  qualifier from pointer target type [-Werror=discarded-qualifiers]
  327 |         xmlerr = xmlCtxtGetLastError(parser->xml_ctx);

This commit adds a few #ifdefs to handle both versions of the API
cleanly. It's probably not the sexiest fix, but it's simple and gets
the job done.
---
 bindings/xml/libxml_xmlparser.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/bindings/xml/libxml_xmlparser.c b/bindings/xml/libxml_xmlparser.c
index 28aadf1..cd7f8ad 100644
--- a/bindings/xml/libxml_xmlparser.c
+++ b/bindings/xml/libxml_xmlparser.c
@@ -317,7 +317,11 @@ dom_xml_error dom_xml_parser_completed(dom_xml_parser 
*parser)
 void xml_parser_start_document(void *ctx)
 {
        dom_xml_parser *parser = (dom_xml_parser *) ctx;
+#if LIBXML_VERSION >= 21200
+       const xmlError *xmlerr;
+#else
        xmlErrorPtr xmlerr;
+#endif
 
        if (parser->err != DOM_NO_ERR)
                return;
@@ -349,7 +353,11 @@ void xml_parser_end_document(void *ctx)
        dom_xml_parser *parser = (dom_xml_parser *) ctx;
        xmlNodePtr node;
        xmlNodePtr n;
+#if LIBXML_VERSION >= 21200
+       const xmlError *xmlerr;
+#else
        xmlErrorPtr xmlerr;
+#endif
 
        if (parser->err != DOM_NO_ERR)
                return;
@@ -431,7 +439,11 @@ void xml_parser_start_element_ns(void *ctx, const xmlChar 
*localname,
 {
        dom_xml_parser *parser = (dom_xml_parser *) ctx;
        xmlNodePtr parent = parser->xml_ctx->node;
+#if LIBXML_VERSION >= 21200
+       const xmlError *xmlerr;
+#else
        xmlErrorPtr xmlerr;
+#endif
 
        if (parser->err != DOM_NO_ERR)
                return;
@@ -510,7 +522,11 @@ void xml_parser_end_element_ns(void *ctx, const xmlChar 
*localname,
        dom_xml_parser *parser = (dom_xml_parser *) ctx;
        xmlNodePtr node = parser->xml_ctx->node;
        xmlNodePtr n;
+#if LIBXML_VERSION >= 21200
+       const xmlError *xmlerr;
+#else
        xmlErrorPtr xmlerr;
+#endif
 
        if (parser->err != DOM_NO_ERR)
                return;
-- 
2.43.0


Reply via email to