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 — Unsafe DECREFs of borrowed references in the interpreter. · Issue #125323 · python/cpython

Unsafe DECREFs of borrowed references in the interpreter. #125323

New issue
Copy link
New issue
Copy link
Closed
Closed
Unsafe DECREFs of borrowed references in the interpreter.#125323
Copy link
Assignees
Fidget-Spinner
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

@markshannon
markshannon
opened on Oct 11, 2024
Issue body actions

Bug report

Bug description:

It is unsafe to borrow a PyObject * reference from a _PyStackRef and Py_DECREF the PyObject * reference and not close the _PyStackRef. This is quite a common pattern in bytecodes.c, and prevents any optimizations based on reference lifetimes as the inferred lifetime is incorrect.

The fix for this is to change the incorrect pattern:

PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
use(left_o);
Py_DECREF(left_o);

to the correct pattern:

PyObject *left_o = PyStackRef_AsPyObjectBorrow(left);
use(left_o);
PyStackRef_CLOSE(left);

This is causing problems, as optimizations to exploit stack refs don't work: https://github.com/python/cpython/compare/main...faster-cpython:cpython:use-stackrefs-opt-experiment?expand=1

CPython versions tested on:

CPython main branch

Operating systems tested on:

Other

Linked PRs

  • gh-125323: Remove some unsafe stackref decrefs #125324
  • GH-125323: Convert DECREF_INPUTS_AND_REUSE_FLOAT into a function that takes PyStackRefs. #125439
Reacted by Tomas R. and Sam Gross

Activity

  1. markshannon
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 11, 2024
  2. markshannon
    assigned
    Fidget-Spinner
    on Oct 11, 2024
  3. Fidget-Spinner commented on Oct 11, 2024

    @Fidget-Spinner
    Fidget-Spinner
    on Oct 11, 2024
    Member
    More actions

    Main culprits are Py_DECREF_SPECIALIZED. But removing that will get a slight perf hit. Should I do it?

  4. picnixz
    added
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    on Oct 11, 2024
  5. markshannon
    added 2 commits that reference this issue on Oct 14, 2024

    gh-125323: Remove some unsafe Py_DECREFs in bytecodes.c, replacing th…

    4b358ee

    GH-125323: Convert DECREF_INPUTS_AND_REUSE_FLOAT into a function that…

    06ca330
  6. markshannon
    closed this as completedon Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @Fidget-Spinner
    Fidget-Spinner

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.