New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PyModule_GetDict() claims it can never fail, but it can #57155
Comments
As is obvious from the code, PyModule_GetDict() can fail if being passed a non-module object, and when the (unlikely) dict creation at the end fails. The documentation of the C-API function should be fixed to reflect that, i.e. it should state that NULL is returned in the case of an error. PyObject *
PyModule_GetDict(PyObject *m)
{
PyObject *d;
if (!PyModule_Check(m)) {
PyErr_BadInternalCall();
return NULL;
}
d = ((PyModuleObject *)m) -> md_dict;
if (d == NULL)
((PyModuleObject *)m) -> md_dict = d = PyDict_New();
return d;
} |
The path with PyDict_New() is never taken, because PyModule_New already fills md_dict. |
So, can we close this issue? |
I gave two reasons why this function can fail, and one turns out to be assumed-to-be-dead code. So, no, there are two issues now, one with the documentation, one with the code. |
If the call to PyDict_New() is never called, the test can be replaced with an assertion. |
I've changed the dead code to
and added the following sentence to PyModule_GetDict documentation:
|
you can merge the patch. |
New changeset bd2a4c138b76 by Berker Peksag in branch '3.5': New changeset c2e74b88947d by Berker Peksag in branch 'default': |
New changeset 4b64a049f451 by Berker Peksag in branch 'default': |
Thanks for the report, Stefan! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: