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

Avoid raising a SystemError when clearing slots if setstate() failed. #62

Merged
merged 1 commit into from
Mar 20, 2017

Conversation

jamadden
Copy link
Member

@jamadden jamadden commented Mar 20, 2017

PR #52 introduced a code path to ghostify that calls PyErr_Clear() with the intent to avoid propagating AttributeErrors for slots.

However, if there is an error (like a POSKeyError) raised by jar.setstate(), then unghostify will call ghostify with an error pending. If the object had slots that weren't set and the AttributeError was cleared, so was the pending error from setstate. So when ghostify returned NULL that got propagated up to the interpreter which finds no exception and so raises SystemError: error return without exception set.

This commit makes unghostify save and restore the exception state around the call to PyErr_Clear so the real exception is raised, rather than the baffling and unhelpful SystemError.

@jamadden jamadden requested a review from tseaver March 20, 2017 12:44
Copy link
Member

@tseaver tseaver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, except for the exc=NotImplementedError bit noted.

@@ -68,7 +71,7 @@ def register(self, obj):
jar._cache = self._makeCache(jar)
return jar

def _makeBrokenJar(self):
def _makeBrokenJar(self, exc=NotImplementedError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra indirection seems like YAGNI.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I was imagining that NotImplementedError might be caught and handled specially somewhere so I wanted to be sure to have something that would definitely propagate. But that is hypothetical, I admit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

PR #52 introduced a code path to `ghostify` that calls PyErr_Clear()
with the intent to avoid propagating AttributeErrors for slots.

However, if there is an error (like a POSKeyError) raised by
jar.setstate(), then `unghostify` will call ghostify with an error
pending. If the object had slots that weren't set and the
AttributeError was cleared, so was the pending error from setstate. So
when `ghostify` returned NULL that got propagated up to the
interpreter which finds no exception and so raises `SystemError: error
return without exception set`.

This commit makes `unghostify` save and restore the exception state
around the call to PyErr_Clear.
@jamadden
Copy link
Member Author

@tseaver Could we get a merge and release please?

@tseaver tseaver merged commit afeb85b into master Mar 20, 2017
@tseaver tseaver deleted the jam-systemerror branch March 20, 2017 15:49
@tseaver
Copy link
Member

tseaver commented Mar 20, 2017

@jamadden
Copy link
Member Author

Thank you!

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

Successfully merging this pull request may close these issues.

None yet

2 participants