bpo-33012: Add _Py_CAST_FUNC() to cast function ptr by vstinner · Pull Request #10744 · python/cpython (original) (raw)
The problem is not in warnings, but in incorrect function signatures.
What do you mean by "incorrect function signature"? Example:
static PyObject *
method_get_doc(PyMethodDescrObject *descr, void *closure)
{
return _PyType_GetDocFromInternalDoc(descr->d_method->ml_name, descr->d_method->ml_doc);
}
static PyGetSetDef method_getset[] = {
{"__doc__", (getter)method_get_doc},
...
};
Here the warning is that PyGetSetDef expects PyObject* as the first argument of the getter, whereas method_getset uses PyMethodDescrObject*. Is it an invalid signature? Would you prefer to write:
static PyObject *
method_get_doc(PyObject *descr_obj, void *closure)
{
PyMethodDescrObject *descr = (PyMethodDescrObject *)descr_obj;
return _PyType_GetDocFromInternalDoc(descr->d_method->ml_name, descr->d_method->ml_doc);
}
which is the "correct" signature? The additional "PyMethodDescrObject *descr = (PyMethodDescrObject *)descr_obj;" doesn't seem to provide any value to the compiler nor to the developer who read/maintain the code.
The problem is not in warnings, but in incorrect function signatures. This PR just silences valid compiler warnings. See #10746.
Right, that's a good fix, but I was too lazy to check each function pointer.