Skip to content

Missing Py_SetStackPointer call in LIST_APPEND #151119

@stestagg

Description

@stestagg

Bug report

Bug description:

In a debug build:

import _testcapi
_testcapi.set_nomemory(2)
result = [f'1{x}' for x in range(1)]
Assertion failed: (tstate->current_frame == NULL || tstate->current_frame->stackpointer != NULL), function _Py_Dealloc, file object.c, line 3298.
fish: Job 1, './python.exe test.py' terminated by signal SIGABRT (Abort)

LIST_APPEND op calls _PyList_AppendTakeRef without setting the stack frame, _PyList_AppendTakeRef calls _PyList_AppendTakeRefListResize with a stolen ref to newitem. If the list resize fails, then newitem is decref'd, which can cause a dealloc, which triggers the above assert on a debug build.

Unless there is a performance impact, then I'm assuming this is just a case of calling Py_SetStackPointer at the appropriate point?

Python 3.16.0a0 (heads/main-dirty:29a920e, Jun 9 2026, 00:36:55) [Clang 22.1.6 ]

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions