Skip to content

_Py_RefcntAdd doesn't increment ref count stats #127599

Closed

Description

@EdNutting

Bug report

Bug description:

Hi,

I am unsure if this intentional or not so apologies if this turns out not to be a bug.

The code for _Py_RefcntAdd does not include _Py_INCREF_STAT_INC. This appears to mean the statistics do not track these additions to the reference count, which are increments (although not increments by 1, they are increasing the ref count in a single operation).

static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)

I believe this may be an oversight because this stat should be tracked, and also because the corresponding decrement ref count code does call _Py_DECREF_STAT_INC (e.g.

_Py_DECREF_STAT_INC();
)

I have checked the callers of _Py_RefcntAdd (in listobject.c and tupleobject.c) and they do not separately perform the stats tracking.

Is this an issue or is there a reason this ref count increment is excluded?

Thanks,
Ed

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Linux, macOS

Linked PRs

Activity

  1. ZeroIntensity commented on Dec 4, 2024

    @ZeroIntensity
    Member

    Looks like a bug. We're missing _Py_INCREF_IMMORTAL_STAT_INC for immortal objects as well.

  2. EdNutting commented on Dec 4, 2024

    @EdNutting
    ContributorAuthor

    Thank you for such a quick reply! I'll try to clone CPython separately to create a PR to fix these over the next few days.

  3. added a commit that references this issue on Dec 15, 2024
  4. added a commit that references this issue on Dec 15, 2024
  5. added a commit that references this issue on Jan 8, 2025
  6. added 3 commits that reference this issue on Jan 10, 2025
  7. added 2 commits that reference this issue on Jan 18, 2025
  8. Eclips4 commented on Jan 18, 2025

    @Eclips4
    Member

    Thank you @EdNutting!

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)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions