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 — gh-124074: Add _Py_NewImmortalRef() function by vstinner · Pull Request #124076 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Sep 13, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: [C API] Add _Py_NewImmortalRef() function to the internal C API #124074

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@vstinner
pythongh-124074: Add _Py_NewImmortalRef() function
6eb358c
@vstinner vstinner added the skip news label Sep 13, 2024
@bedevere-app bedevere-app Bot added the awaiting core review label Sep 13, 2024
@bedevere-app bedevere-app Bot mentioned this pull request Sep 13, 2024
[C API] Add _Py_NewImmortalRef() function to the internal C API #124074
Closed
@vstinner

vstinner commented Sep 13, 2024

Copy link
Copy Markdown
Member Author

cc @encukou

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ZeroIntensity
ZeroIntensity reviewed Sep 13, 2024
View reviewed changes
Comment thread Include/internal/pycore_object.h
Comment on lines +878 to +880
// Similar to Py_NewRef() but for immortal objects.
// obj must be immortal.
static inline PyObject* _Py_NewImmortalRef(PyObject *obj)

@ZeroIntensity ZeroIntensity Sep 13, 2024

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 7:

Suggested change
// Similar to Py_NewRef() but for immortal objects.
// obj must be immortal.
static inline PyObject* _Py_NewImmortalRef(PyObject *obj)
// Similar to Py_NewRef() but for immortal objects.
// obj must be immortal.
static inline PyObject *
_Py_NewImmortalRef(PyObject *obj)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@encukou

encukou commented Sep 16, 2024

Copy link
Copy Markdown
Member

cc @encukou

If you ask me: I don't think this is useful without

  • broad agreement among the core devs that it should be used;
  • a checker (e.g. including these in the refcount total -- until all the calls are fixed it would need to be optional);
  • documentation (in Devguide or InternalDocs);
  • a DECREF equivalent.
colesbury reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

a checker (e.g. including these in the refcount total -- until all the calls are fixed it would need to be optional);

Do you mean a tool which would fail if _Py_NewImmortalRef() is used to "INCREF" but Py_DECREF() (or _Py_DecRefImmortal()) would be omitted by mistake? It seems non trivial to implement checker in an efficient way.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity

ZeroIntensity commented Sep 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

For clarification: would _Py_NewImmortalRef only get used for immortal constants (things like Py_None, Py_True, Py_False), or try and retrofit it for other things that we happen to know are immortal (e.g., some interned strings)? If it's the former, then it should be relatively easy to write a checker for that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 16, 2024

Copy link
Copy Markdown
Member Author

It works on any immortal object: https://docs.python.org/dev/glossary.html#term-immortal

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Sep 17, 2024

Copy link
Copy Markdown
Member

Do you mean a tool which would fail if _Py_NewImmortalRef() is used to "INCREF" but Py_DECREF() (or _Py_DecRefImmortal()) would be omitted by mistake? It seems non trivial to implement checker in an efficient way.

AFAIK, it would only need the existing _Py_IncRefTotal and _Py_DecRefTotal.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 17, 2024

Copy link
Copy Markdown
Member Author

AFAIK, it would only need the existing _Py_IncRefTotal and _Py_DecRefTotal.

It's more complicated than that since Python/ceval.c now converts immortal objects to "stack ref" objects and it doesn't call DECREF on them on purpose. Maybe it's a lost battle and we should give up on doing Py_NewRef(Py_None), but just write Py_None.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou

encukou commented Sep 17, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

It's more complicated than that since Python/ceval.c now converts immortal objects to "stack ref" objects and it doesn't call DECREF on them on purpose.

Yeah, it would need to start doing that DECREF, in debug builds. Otherwise, _Py_NewImmortalRef is no better than a comment.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Sep 17, 2024

Copy link
Copy Markdown
Member Author

I prefer to abandon this function at this point. I failed to update Py_INCREF(), Py_DECREF() and _Py_NewImmortalRef() to keep a consistent "total ref count" using _Py_INCREF_IncRefTotal(); and _Py_DECREF_DecRefTotal();.

ZeroIntensity reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner closed this Sep 17, 2024
@vstinner
vstinner deleted the new_immortal_ref branch September 17, 2024 12:49
@vstinner vstinner mentioned this pull request Oct 15, 2024
Use _PyLong_GetOne() and _PyLong_GetZero() in long_invmod() #125044
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ZeroIntensity ZeroIntensity ZeroIntensity left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@vstinner @encukou @ZeroIntensity
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — 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.