python / python/cpython

Missing Py_SetStackPointer call in LIST_APPEND

Open
#151,119 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

interpreter-core type-crash
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Linked PRs
  • gh-151538

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue is already linked to PR gh-151538, so review that work first rather than starting independently. To reproduce the failure, run the shown _testcapi.set_nomemory(2) list-comprehension example in a debug build, then inspect LIST_APPEND, _PyList_AppendTakeRef, and _PyList_AppendTakeRefListResize; completion means the object.c assertion no longer occurs when the resize fails.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.