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

bpo-39091: Fix segfault when Exception constructor returns non-exception for gen.throw #17658

Open
wants to merge 7 commits into
base: master
from

Conversation

@coolreader18
Copy link

coolreader18 commented Dec 19, 2019

I added a type check in _PyErr_CreateException as @serhiy-storchaka suggested.

I'm not sure if I should replace the check in do_raise in ceval.c with a call to _PyErr_CreateException somehow, as it's effectively the same functionality?

https://bugs.python.org/issue39091

@the-knights-who-say-ni

This comment has been minimized.

Copy link

the-knights-who-say-ni commented Dec 19, 2019

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@coolreader18

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

@coolreader18 coolreader18 changed the title bpo-39091: Fix segfault when Exception constructor returns non-exception for gen.throw (and probably some other places) bpo-39091: Fix segfault when Exception constructor returns non-exception for gen.throw Dec 19, 2019
@coolreader18 coolreader18 force-pushed the coolreader18:gen-throw-bpo-39091 branch 2 times, most recently from ad65177 to 08e42d6 Dec 19, 2019
'should have returned an instance of BaseException'):
gen.throw(E)

self.assertRaises(StopIteration, next, gen)

This comment has been minimized.

Copy link
@eric-wieser

eric-wieser Dec 20, 2019

Contributor

Now that we know the generator is exhausted, the next question might be "does the generator receive the TypeError"?

So perhaps:

def boring_generator():
    with self.assertRaisesRegex(
            TypeError,
            'should have returned an instance of BaseException'):
        yield

gen = boring_generator()
next(gen)  # advance to the yield in the with statement
gen.throw(E)
self.assertRaises(StopIteration, next, gen)
Python/errors.c Outdated Show resolved Hide resolved
Python/errors.c Outdated Show resolved Hide resolved
Python/errors.c Outdated Show resolved Hide resolved
@@ -0,0 +1,2 @@
Type check the result of constructing the new exception instance in
:c:func:`_PyErr_CreateException`

This comment has been minimized.

Copy link
@serhiy-storchaka

serhiy-storchaka Dec 21, 2019

Member

Since it is your first contribution, please add your name in Misc/ACKS.

You can also add "Patch by yourname." here. Don't forget about the ending period.

@serhiy-storchaka

This comment has been minimized.

Copy link
Member

serhiy-storchaka commented Dec 21, 2019

do_raise has a complex code. Unless it contains similar bug I suggest to left refactoring to other issue.

coolreader18 and others added 5 commits Dec 19, 2019
@coolreader18 coolreader18 force-pushed the coolreader18:gen-throw-bpo-39091 branch from 3cb4685 to a2a7e43 Dec 23, 2019
@coolreader18 coolreader18 force-pushed the coolreader18:gen-throw-bpo-39091 branch from a2a7e43 to bfa9b85 Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.