Skip to content
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

Unclear whether __Pyx_PyDict_GetItemStr should clear exceptions #3091

Closed
jdemeyer opened this issue Aug 22, 2019 · 5 comments
Closed

Unclear whether __Pyx_PyDict_GetItemStr should clear exceptions #3091

jdemeyer opened this issue Aug 22, 2019 · 5 comments

Comments

@jdemeyer
Copy link
Contributor

We have

#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && CYTHON_USE_UNICODE_INTERNALS
#define __Pyx_PyDict_GetItemStr(dict, name)  _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash)
#else
#define __Pyx_PyDict_GetItemStr(dict, name)  PyDict_GetItem(dict, name)
#endif

The problem is that the two variants have different semantics when an exceptions occurs during __eq__: the first variant sets an exception while the second clears it. So there are probably subtle bugs possible because of this difference.

So far, I'm just noting this issue, not fixing it. I do plan to add a new function __Pyx_PyDict_GetItemStrWithError which always keeps the exception.

@scoder
Copy link
Contributor

scoder commented Aug 22, 2019 via email

@jdemeyer
Copy link
Contributor Author

Some code is certainly written with the assumption that __Pyx_PyDict_GetItemStr won't raise an exception. For example, the old kwargs-parsing code (that's how I noticed the problem).

@scoder
Copy link
Contributor

scoder commented Aug 23, 2019

Hmm, right, I guess the usage follows the behaviour of PyDict_GetItem(). We should propagate the exception where we can, preferably without too much overhead for the "normal" cases (found or not, maybe also for KeyError).

@jdemeyer
Copy link
Contributor Author

If you agree with the newly added function __Pyx_PyDict_GetItemStrWithError in #3021, this can be closed. Eventually, we should probably use __Pyx_PyDict_GetItemStrWithError everywhere (but that's certainly out of scope for #3021).

@scoder
Copy link
Contributor

scoder commented May 9, 2020

A reference leak due to calling PyObject_GetItem() was resolved in #3593.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants