mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
Warn when using deprecated functions from Python bindings
This requires Python code to be run with -Wd.
This commit is contained in:
@ -295,8 +295,6 @@ deprecated_funcs = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def skip_function(name):
|
def skip_function(name):
|
||||||
if name in deprecated_funcs:
|
|
||||||
return 1
|
|
||||||
if name[0:12] == "xmlXPathWrap":
|
if name[0:12] == "xmlXPathWrap":
|
||||||
return 1
|
return 1
|
||||||
if name == "xmlFreeParserCtxt":
|
if name == "xmlFreeParserCtxt":
|
||||||
@ -371,6 +369,8 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
# Don't delete the function entry in the caller.
|
# Don't delete the function entry in the caller.
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
is_deprecated = name in deprecated_funcs
|
||||||
|
|
||||||
c_call = ""
|
c_call = ""
|
||||||
format=""
|
format=""
|
||||||
format_args=""
|
format_args=""
|
||||||
@ -484,6 +484,8 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
output.write("#endif\n")
|
output.write("#endif\n")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
if is_deprecated:
|
||||||
|
output.write("XML_IGNORE_DEPRECATION_WARNINGS\n")
|
||||||
output.write("PyObject *\n")
|
output.write("PyObject *\n")
|
||||||
output.write("libxml_%s(PyObject *self ATTRIBUTE_UNUSED," % (name))
|
output.write("libxml_%s(PyObject *self ATTRIBUTE_UNUSED," % (name))
|
||||||
output.write(" PyObject *args")
|
output.write(" PyObject *args")
|
||||||
@ -496,6 +498,10 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
output.write(c_return)
|
output.write(c_return)
|
||||||
if c_args != "":
|
if c_args != "":
|
||||||
output.write(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 != "":
|
if format != "":
|
||||||
output.write("\n if (!PyArg_ParseTuple(args, (char *)\"%s\"%s))\n" %
|
output.write("\n if (!PyArg_ParseTuple(args, (char *)\"%s\"%s))\n" %
|
||||||
(format, format_args))
|
(format, format_args))
|
||||||
@ -507,7 +513,11 @@ def print_function_wrapper(name, output, export, include):
|
|||||||
if c_release != "":
|
if c_release != "":
|
||||||
output.write(c_release)
|
output.write(c_release)
|
||||||
output.write(ret_convert)
|
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 != "":
|
if cond != None and cond != "":
|
||||||
include.write("#endif /* %s */\n" % cond)
|
include.write("#endif /* %s */\n" % cond)
|
||||||
export.write("#endif /* %s */\n" % cond)
|
export.write("#endif /* %s */\n" % cond)
|
||||||
|
@ -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 *
|
* The registration stuff *
|
||||||
|
@ -60,6 +60,21 @@
|
|||||||
#define ATTRIBUTE_UNUSED
|
#define ATTRIBUTE_UNUSED
|
||||||
#endif
|
#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 : \
|
#define PyxmlNode_Get(v) (((v) == Py_None) ? NULL : \
|
||||||
(((PyxmlNode_Object *)(v))->obj))
|
(((PyxmlNode_Object *)(v))->obj))
|
||||||
|
|
||||||
@ -277,3 +292,5 @@ PyObject * libxml_xmlSchemaSetValidErrors(PyObject * self, PyObject * args);
|
|||||||
PyObject * libxml_xmlRegisterInputCallback(PyObject *self, PyObject *args);
|
PyObject * libxml_xmlRegisterInputCallback(PyObject *self, PyObject *args);
|
||||||
PyObject * libxml_xmlUnregisterInputCallback(PyObject *self, PyObject *args);
|
PyObject * libxml_xmlUnregisterInputCallback(PyObject *self, PyObject *args);
|
||||||
PyObject * libxml_xmlNodeRemoveNsDef(PyObject * self, PyObject * args);
|
PyObject * libxml_xmlNodeRemoveNsDef(PyObject * self, PyObject * args);
|
||||||
|
|
||||||
|
int libxml_deprecationWarning(const char *func);
|
||||||
|
Reference in New Issue
Block a user