1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-02-06 05:57:39 +03:00

Warn when using deprecated functions from Python bindings

This requires Python code to be run with -Wd.
This commit is contained in:
Nick Wellnhofer 2022-03-01 13:57:16 +01:00
parent b66ce0bba8
commit ebc5009793
3 changed files with 47 additions and 3 deletions

View File

@ -295,8 +295,6 @@ deprecated_funcs = {
}
def skip_function(name):
if name in deprecated_funcs:
return 1
if name[0:12] == "xmlXPathWrap":
return 1
if name == "xmlFreeParserCtxt":
@ -371,6 +369,8 @@ def print_function_wrapper(name, output, export, include):
# Don't delete the function entry in the caller.
return 1
is_deprecated = name in deprecated_funcs
c_call = ""
format=""
format_args=""
@ -484,6 +484,8 @@ def print_function_wrapper(name, output, export, include):
output.write("#endif\n")
return 1
if is_deprecated:
output.write("XML_IGNORE_DEPRECATION_WARNINGS\n")
output.write("PyObject *\n")
output.write("libxml_%s(PyObject *self ATTRIBUTE_UNUSED," % (name))
output.write(" PyObject *args")
@ -496,6 +498,10 @@ def print_function_wrapper(name, output, export, include):
output.write(c_return)
if c_args != "":
output.write(c_args)
if is_deprecated:
output.write("\n if (libxml_deprecationWarning(\"%s\") == -1)\n" %
name)
output.write(" return(NULL);\n")
if format != "":
output.write("\n if (!PyArg_ParseTuple(args, (char *)\"%s\"%s))\n" %
(format, format_args))
@ -507,7 +513,11 @@ def print_function_wrapper(name, output, export, include):
if c_release != "":
output.write(c_release)
output.write(ret_convert)
output.write("}\n\n")
output.write("}\n")
if is_deprecated:
output.write("XML_POP_WARNINGS\n")
output.write("\n")
if cond != None and cond != "":
include.write("#endif /* %s */\n" % cond)
export.write("#endif /* %s */\n" % cond)

View File

@ -3822,6 +3822,23 @@ libxml_nodeHash(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
}
/************************************************************************
* *
* Deprecation warnings *
* *
************************************************************************/
int
libxml_deprecationWarning(const char *func) {
#if PY_VERSION_HEX >= 0x03020000
return PyErr_WarnFormat(PyExc_PendingDeprecationWarning, 1,
"libxml2mod.%s is deprecated and will be removed "
"in future versions", func);
#else
return PyErr_WarnEx(PyExc_PendingDeprecationWarning, func, 1);
#endif
}
/************************************************************************
* *
* The registration stuff *

View File

@ -60,6 +60,21 @@
#define ATTRIBUTE_UNUSED
#endif
/*
* Macros to ignore deprecation warnings
*/
#if defined(__clang__) || \
(defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 406))
#define XML_IGNORE_DEPRECATION_WARNINGS \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
#define XML_POP_WARNINGS \
_Pragma("GCC diagnostic pop")
#else
#define XML_IGNORE_PEDANTIC_WARNINGS
#define XML_POP_WARNINGS
#endif
#define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
(((PyxmlNode_Object *)(v))->obj))
@ -277,3 +292,5 @@ PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args);
PyObject * libxml_xmlRegisterInputCallback(PyObject *self, PyObject *args);
PyObject * libxml_xmlUnregisterInputCallback(PyObject *self, PyObject *args);
PyObject * libxml_xmlNodeRemoveNsDef(PyObject * self, PyObject * args);
int libxml_deprecationWarning(const char *func);