GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-101892: Fix SystemError when a callable iterator call exhausts the iterator by workingpayload · Pull Request #101896 · python/cpython Conversation
|
|
It's good to coverage this case in tests. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Added a test copied from the issue with readability changes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| result = _PyObject_CallNoArgs(it->it_callable); | ||
| if (result != NULL) { | ||
| if (result != NULL && it->it_callable != NULL) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but this won't fix it. Notice the first if statement in the function. If it->it_callable == NULL is true, NULL is returned. So it->it_callable != NULL is already guaranteed at this point.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What if we check it->it_sentinel != NULL ?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It looks like NULL is being passed to PyObject_RichCompareBool() through it->it_sentinel when it expects an object?
If we add the check
if (result != NULL && it->it_sentinel != NULL) {
and get rid of that Py_DECREF(result) and place a new
Py_XDECREF(result);
just before return NULL;
Then the code in the issue will raise a StopIteration (no longer SystemError) and tests pass.
I'm not entirely sure if this is correct, TBH, but this is my guess.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return NO_MORE | ||
| spam.need_reentrance = True | ||
| spam.iterator = iter(spam, NO_MORE) | ||
| next(spam.iterator) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
What's the expected behaviour here? StopIteration?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thank you for noticing the oversight! Fixed.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@workingpayload What do you think? Worth a try? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yeah! Why not? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| def spam(): | ||
| if spam.need_reentrance: | ||
| spam.need_reentrance = False | ||
| list(spam.iterator) # Implicitly call ourselves |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This evening (after getting access to my dev machine) I'll check whether the inner list() is required to throw StopIteration to trigger the bug. If no, I will simplify the test:
| list(spam.iterator) # Implicitly call ourselves | |
| try: | |
| list(spam.iterator) # Implicitly call ourselves. | |
| except StopIteration: | |
| pass |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I got it wrong. list() cannot throw an exception because it returns a ready-to-use list (possibly empty) processing StopIteration by itself.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
LGTM. By the way PR title can be more meaningful. Ex: Fix SystemError when a callable iterator call exhausts the iterator. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@kumaraditya303 Thank you, addressed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @workingpayload for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Sorry, @workingpayload and @kumaraditya303, I could not cleanly backport this to |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-102418 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…usts the iterator (pythonGH-101896) (cherry picked from commit 705487c) Co-authored-by: Raj <[email protected]> Co-authored-by: Oleg Iarygin <[email protected]>
…he iterator (GH-101896) (cherry picked from commit 705487c) Co-authored-by: Raj <[email protected]> Co-authored-by: Oleg Iarygin <[email protected]>
…usts the iterator (python#101896) Co-authored-by: Oleg Iarygin <[email protected]> (cherry picked from commit 705487c)
|
GH-102422 is a backport of this pull request to the 3.10 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…austs the iterator (GH-101896) (#102422) gh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (#101896) Co-authored-by: Oleg Iarygin <[email protected]> (cherry picked from commit 705487c) Co-authored-by: Raj <[email protected]>
|
@arhadthedev Thanks for the continued work on this! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…usts the iterator (python#101896) Co-authored-by: Oleg Iarygin <[email protected]>
* main: (21 commits) pythongh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives in sub interpreters module (python#102472) pythongh-95672: Fix versionadded indentation of get_pagesize in test.rst (pythongh-102455) pythongh-102416: Do not memoize incorrectly loop rules in the parser (python#102467) pythonGH-101362: Optimise PurePath(PurePath(...)) (pythonGH-101667) pythonGH-101362: Check pathlib.Path flavour compatibility at import time (pythonGH-101664) pythonGH-101362: Call join() only when >1 argument supplied to pathlib.PurePath() (python#101665) pythongh-102444: Fix minor bugs in `test_typing` highlighted by pyflakes (python#102445) pythonGH-102341: Improve the test function for pow (python#102342) Fix unused classes in a typing test (pythonGH-102437) pythongh-101979: argparse: fix a bug where parentheses in metavar argument of add_argument() were dropped (python#102318) pythongh-102356: Add thrashcan macros to filter object dealloc (python#102426) Move around example in to_bytes() to avoid confusion (python#101595) pythonGH-97546: fix flaky asyncio `test_wait_for_race_condition` test (python#102421) pythongh-96821: Add config option `--with-strict-overflow` (python#96823) pythongh-101992: update pstlib module documentation (python#102133) pythongh-63301: Set exit code when tabnanny CLI exits on error (python#7699) pythongh-101863: Fix wrong comments in EUC-KR codec (pythongh-102417) pythongh-102302 Micro-optimize `inspect.Parameter.__hash__` (python#102303) pythongh-102179: Fix `os.dup2` error reporting for negative fds (python#102180) pythongh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (python#101896) ...
* main: (37 commits) pythongh-102192: Replace PyErr_Fetch/Restore etc by more efficient alternatives in sub interpreters module (python#102472) pythongh-95672: Fix versionadded indentation of get_pagesize in test.rst (pythongh-102455) pythongh-102416: Do not memoize incorrectly loop rules in the parser (python#102467) pythonGH-101362: Optimise PurePath(PurePath(...)) (pythonGH-101667) pythonGH-101362: Check pathlib.Path flavour compatibility at import time (pythonGH-101664) pythonGH-101362: Call join() only when >1 argument supplied to pathlib.PurePath() (python#101665) pythongh-102444: Fix minor bugs in `test_typing` highlighted by pyflakes (python#102445) pythonGH-102341: Improve the test function for pow (python#102342) Fix unused classes in a typing test (pythonGH-102437) pythongh-101979: argparse: fix a bug where parentheses in metavar argument of add_argument() were dropped (python#102318) pythongh-102356: Add thrashcan macros to filter object dealloc (python#102426) Move around example in to_bytes() to avoid confusion (python#101595) pythonGH-97546: fix flaky asyncio `test_wait_for_race_condition` test (python#102421) pythongh-96821: Add config option `--with-strict-overflow` (python#96823) pythongh-101992: update pstlib module documentation (python#102133) pythongh-63301: Set exit code when tabnanny CLI exits on error (python#7699) pythongh-101863: Fix wrong comments in EUC-KR codec (pythongh-102417) pythongh-102302 Micro-optimize `inspect.Parameter.__hash__` (python#102303) pythongh-102179: Fix `os.dup2` error reporting for negative fds (python#102180) pythongh-101892: Fix `SystemError` when a callable iterator call exhausts the iterator (python#101896) ...
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.