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 — bpo-40170: PyType_HasFeature() no longer acccess directly tp_flags by vstinner · Pull Request #19378 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Apr 4, 2020 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

PyType_HasFeature() now always calls PyType_GetFlags() to hide
implementation details. Previously, it accessed directly the
PyTypeObject.tp_flags member when the limited C API was not used.

Add fast inlined version _PyType_HasFeature() and _PyType_IS_GC()
for object.c and typeobject.c.

https://bugs.python.org/issue40170

Sorry, something went wrong.

Uh oh!

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

All reactions
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Apr 4, 2020
@bedevere-bot bedevere-bot added the awaiting core review label Apr 4, 2020
@vstinner

vstinner commented Apr 4, 2020

Copy link
Copy Markdown
Member Author

I expect no significant performance difference or a very low overhead for macros and functions using PyType_HasFeature().

PyType_HasFeature() is used by the following code in header files:

  • PyVectorcall_Function()
  • PyType_IS_GC()
  • PyType_FastSubclass()

PyType_FastSubclass() is used by many PyXXX_Check() macros:

  • PyLong_Check()
  • PyBytes_Check(), PyUnicode_Check()
  • PyTuple_Check(op), PyList_Check()
  • PyDict_Check()
  • PyExceptionClass_Check(), PyExceptionInstance_Check()
All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Apr 5, 2020

Copy link
Copy Markdown
Member Author

@serhiy-storchaka @methane: Do you expect such change to have an impact on performance? What do you think of the change?

All reactions

Sorry, something went wrong.

Uh oh!

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

@methane

methane commented Apr 5, 2020

Copy link
Copy Markdown
Member

Some PyType_HasFeature(cls, Py_TPFLAGS_HAVE_VERSION_TAG) are in Object/typeobject.c.
They are performance critical.
Can we have private inline function?

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Apr 5, 2020

Copy link
Copy Markdown
Member Author

Can we have private inline function?

Yes, that's possible but I would prefer to add new functions to the internal C API for that. For example, add a fast _PyLong_Check() function.


In the past, I tried to reuse the same name for two implementation of the same function: one "slow" using a function call, one "fast" using a macro or static inline function.

I'm thinking at PyThreadState_GET(). The internal C API uses:

/* Redefine PyThreadState_GET() as an alias to _PyThreadState_GET() */
#undef PyThreadState_GET
#define PyThreadState_GET() _PyThreadState_GET()

The problem is that depending if the internal C API is included or not, you may get the slow or the fast function.

I changed my approach: use a different name for the fast function. _PyThreadState_GET() is guaranteed to be fast, but it's only provided by the internal C API. In short, using it ensures that you get the fast implementation, but also that the internal C API is included.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
bpo-40170: PyType_HasFeature() no longer acccess directly tp_flags
c2ccff8
PyType_HasFeature() now always calls PyType_GetFlags() to hide
implementation details. Previously, it accessed directly the
PyTypeObject.tp_flags member when the limited C API was not used.

Add fast inlined version _PyType_HasFeature() and _PyType_IS_GC()
for object.c and typeobject.c.
@vstinner

vstinner commented Apr 7, 2020

Copy link
Copy Markdown
Member Author

@methane: I added fast inlined version _PyType_HasFeature() and _PyType_IS_GC() for object.c and typeobject.c.

All reactions

Sorry, something went wrong.

Uh oh!

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

methane
methane approved these changes Apr 7, 2020
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Apr 7, 2020
@vstinner
vstinner merged commit 45ec5b9 into python:master Apr 7, 2020
@bedevere-bot bedevere-bot removed the awaiting merge label Apr 7, 2020
@vstinner
vstinner deleted the type_has_feature branch April 7, 2020 23:42
vstinner added a commit that referenced this pull request Jul 8, 2020
@vstinner
Revert "bpo-40170: PyType_HasFeature() now always calls PyType_GetFla…
b26a0db
…gs() (GH-19378)" (GH-21390)

This partially reverts commit 45ec5b9.
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 8, 2020
@vstinner @miss-islington
Revert "bpo-40170: PyType_HasFeature() now always calls PyType_GetFla…
30fd8fc
…gs() (pythonGH-19378)" (pythonGH-21390)

This partially reverts commit 45ec5b9.
(cherry picked from commit b26a0db)

Co-authored-by: Victor Stinner <[email protected]>
miss-islington added a commit that referenced this pull request Jul 8, 2020
@miss-islington @vstinner
Revert "bpo-40170: PyType_HasFeature() now always calls PyType_GetFla…
a0a6f11
…gs() (GH-19378)" (GH-21390)

This partially reverts commit 45ec5b9.
(cherry picked from commit b26a0db)

Co-authored-by: Victor Stinner <[email protected]>
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Jul 12, 2020
@vstinner @shihai1991
Revert "bpo-40170: PyType_HasFeature() now always calls PyType_GetFla…
cb4bfdc
…gs() (pythonGH-19378)" (pythonGH-21390)

This partially reverts commit 45ec5b9.
shihai1991 pushed a commit to shihai1991/cpython that referenced this pull request Aug 20, 2020
@vstinner @shihai1991
Revert "bpo-40170: PyType_HasFeature() now always calls PyType_GetFla…
e4512c0
…gs() (pythonGH-19378)" (pythonGH-21390)

This partially reverts commit 45ec5b9.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@methane methane methane approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

None yet

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.

4 participants

@vstinner @methane @the-knights-who-say-ni @bedevere-bot
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 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.