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-111506: Implement Py_SET_REFCNT() as inline function by vstinner · Pull Request #112798 · python/cpython

gh-111506: Implement Py_SET_REFCNT() as inline function #112798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
vstinner wants to merge 1 commit into python:main from vstinner:set_refcnt_inline

Uh oh!

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

Closed

gh-111506: Implement Py_SET_REFCNT() as inline function #112798

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
49d6671
gh-111506: Implement Py_SET_REFCNT() as inline function
vstinner Dec 6, 2023
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view

There are no files selected for viewing

1 change: 1 addition & 0 deletions 1 Doc/data/stable_abi.dat
Show comments
View file
Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Oops, something went wrong.

Uh oh!

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

22 changes: 11 additions & 11 deletions 22 Include/object.h
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ PyAPI_FUNC(int) Py_Is(PyObject *x, PyObject *y);
#define Py_Is(x, y) ((x) == (y))

#if defined(Py_GIL_DISABLED) && !defined(Py_LIMITED_API)
static inline uintptr_t
inline PyAPI_FUNC(uintptr_t)
_Py_ThreadId(void)
{
uintptr_t tid;
Expand Down Expand Up @@ -285,7 +285,7 @@ _Py_ThreadId(void)
return tid;
}

static inline Py_ALWAYS_INLINE int
inline Py_ALWAYS_INLINE PyAPI_FUNC(int)
_Py_IsOwnedByCurrentThread(PyObject *ob)
{
return ob->ob_tid == _Py_ThreadId();
Expand Down Expand Up @@ -332,7 +332,8 @@ static inline Py_ssize_t Py_SIZE(PyObject *ob) {
# define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
#endif

static inline Py_ALWAYS_INLINE int _Py_IsImmortal(PyObject *op)
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030d0000
Comment thread
pitrou marked this conversation as resolved.
Resolved

Uh oh!

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

inline Py_ALWAYS_INLINE PyAPI_FUNC(int) _Py_IsImmortal(PyObject *op)
{
#if defined(Py_GIL_DISABLED)
return (op->ob_ref_local == _Py_IMMORTAL_REFCNT_LOCAL);
Expand All @@ -343,6 +344,8 @@ static inline Py_ALWAYS_INLINE int _Py_IsImmortal(PyObject *op)
#endif
}
#define _Py_IsImmortal(op) _Py_IsImmortal(_PyObject_CAST(op))
#endif // !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030d0000


static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
return Py_TYPE(ob) == type;
Expand All @@ -352,15 +355,12 @@ static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
#endif


// Py_SET_REFCNT() implementation for stable ABI
PyAPI_FUNC(void) _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt);

static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
// Stable ABI implements Py_SET_REFCNT() as an opaque function call in the
// limited C API version 3.13 and newer.
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030d0000
// Stable ABI implements Py_SET_REFCNT() as a function call
// on limited C API version 3.13 and newer.
_Py_SetRefcnt(ob, refcnt);
PyAPI_FUNC(void) Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt);
#else
inline PyAPI_FUNC(void) Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
// This immortal check is for code that is unaware of immortal objects.
// The runtime tracks these objects and we should avoid as much
// as possible having extensions inadvertently change the refcnt
Expand Down Expand Up @@ -394,11 +394,11 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
ob->ob_ref_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED);
}
#endif // Py_GIL_DISABLED
#endif // Py_LIMITED_API+0 < 0x030d0000
}
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
Comment thread
pitrou marked this conversation as resolved.
Resolved

Uh oh!

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

# define Py_SET_REFCNT(ob, refcnt) Py_SET_REFCNT(_PyObject_CAST(ob), (refcnt))
#endif
#endif // !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030d0000


static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
Expand Down
2 changes: 1 addition & 1 deletion 2 Lib/test/test_stable_abi_ctypes.py
Show comments
View file
Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Oops, something went wrong.

Uh oh!

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

3 changes: 1 addition & 2 deletions 3 Misc/stable_abi.toml
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,5 @@
added = '3.13'
[function.PySys_AuditTuple]
added = '3.13'
[function._Py_SetRefcnt]
[function.Py_SET_REFCNT]
added = '3.13'
abi_only = true
11 changes: 11 additions & 0 deletions 11 Objects/object.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2938,3 +2938,14 @@ _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)
{
Py_SET_REFCNT(ob, refcnt);
}


// Export inline functions as a regular functions
#ifdef Py_GIL_DISABLED
extern inline uintptr_t _Py_ThreadId(void);
extern inline int _Py_IsOwnedByCurrentThread(PyObject *ob);
#endif
#undef _Py_IsImmortal
extern inline PyAPI_FUNC(int) _Py_IsImmortal(PyObject *op);
#undef Py_SET_REFCNT
extern inline PyAPI_FUNC(void) Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt);
2 changes: 1 addition & 1 deletion 2 PC/python3dll.c
Show comments
View file
Open in desktop

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Oops, something went wrong.

Uh oh!

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

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.