GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Callable iterator can SystemError if call exhausts the iterator · Issue #101892 · python/cpython

Callable iterator can SystemError if call exhausts the iterator #101892

New issue
Copy link
New issue
Copy link
Closed
Closed
Callable iterator can SystemError if call exhausts the iterator#101892
Copy link
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@ionite34
ionite34
opened on Feb 13, 2023
Issue body actions

Bug report

If the callable of a callable iterator (with sentinel) exhausts the iterator itself during the call, a SystemError occurs.

Example discovered by @chilaxan

def bug():
    if bug.clear:
        return 1
    else:
        bug.clear = True
        list(bug.iterator)
        return 0

bug.iterator = iter(bug, 1)
bug.clear = False
next(bug.iterator)
SystemError: Objects\object.c:722: bad argument to internal function

Likely cause

iterobject.calliter_iternext does not check whether it->it_sentinel is NULL after the _PyObject_CallNoArgs call
https://github.com/python/cpython/blob/main/Objects/iterobject.c#L207-L237

static PyObject *
calliter_iternext(calliterobject *it)
{
    PyObject *result;

    if (it->it_callable == NULL) {
        return NULL;
    }

+   result = _PyObject_CallNoArgs(it->it_callable);
    if (result != NULL) {
        int ok;

+       ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
        if (ok == 0) {
            return result; /* Common case, fast path */
        }
(...)

Your environment

Appears to affect 3.7-3.12

Linked PRs

  • gh-101892: Fix SystemError when a callable iterator call exhausts the iterator #101896
  • [3.11] gh-101892: Fix SystemError when a callable iterator call exhausts the iterator (GH-101896) #102418
  • [3.10] gh-101892: Fix SystemError when a callable iterator call exhausts the iterator (GH-101896) #102422

Activity

  1. ionite34
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Feb 13, 2023
  2. arhadthedev
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Feb 14, 2023
  3. kumaraditya303
    added a commit that references this issue on Mar 4, 2023

    gh-101892: Fix `SystemError` when a callable iterator call exhausts t…

    705487c
  4. miss-islington
    added 2 commits that reference this issue on Mar 4, 2023

    pythongh-101892: Fix `SystemError` when a callable iterator call exha…

    1d07066

    gh-101892: Fix `SystemError` when a callable iterator call exhausts t…

    06a3bb8
  5. arhadthedev
    added a commit that references this issue on Mar 4, 2023

    pythongh-101892: Fix `SystemError` when a callable iterator call exha…

    5573d36
  6. kumaraditya303
    added a commit that references this issue on Mar 4, 2023

    [3.10] gh-101892: Fix `SystemError` when a callable iterator call exh…

    fe36778
  7. kumaraditya303
    closed this as completedon Mar 4, 2023
  8. hugovk
    added a commit that references this issue on Mar 6, 2023

    pythongh-101892: Fix `SystemError` when a callable iterator call exha…

    bf01a62
  9. carljm
    added 2 commits that reference this issue on Mar 6, 2023

    Merge branch 'main' into nodeaddict

    33dda2a

    Merge branch 'main' into inlinecomp2

    ecb313c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.