| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -131,14 +131,14 @@ check by comparing the reference count field to the immortality reference count. | |
| #define PyObject_HEAD_INIT(type) \ | ||
| { \ | ||
| _PyObject_EXTRA_INIT \ | ||
| { _Py_IMMORTAL_REFCNT }, \ | ||
| _Py_IMMORTAL_REFCNT, \ | ||
| (type) \ | ||
| }, | ||
| #else | ||
| #define PyObject_HEAD_INIT(type) \ | ||
| { \ | ||
| _PyObject_EXTRA_INIT \ | ||
| { 1 }, \ | ||
| 1, \ | ||
| (type) \ | ||
| }, | ||
| #endif /* Py_BUILD_CORE */ | ||
| Expand All | @@ -165,12 +165,7 @@ check by comparing the reference count field to the immortality reference count. | |
| */ | ||
| struct _object { | ||
| _PyObject_HEAD_EXTRA | ||
| union { | ||
| Py_ssize_t ob_refcnt; | ||
| #if SIZEOF_VOID_P > 4 | ||
| PY_UINT32_T ob_refcnt_split[2]; | ||
| #endif | ||
| }; | ||
| Py_ssize_t ob_refcnt; | ||
| PyTypeObject *ob_type; | ||
| }; | ||
|
|
||
| Expand Down Expand Up | @@ -624,12 +619,12 @@ static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op) | |
| // directly PyObject.ob_refcnt. | ||
| #if SIZEOF_VOID_P > 4 | ||
| // Portable saturated add, branching on the carry flag and set low bits | ||
| PY_UINT32_T cur_refcnt = op->ob_refcnt_split[PY_BIG_ENDIAN]; | ||
| PY_UINT32_T cur_refcnt = _Py_CAST(PY_UINT32_T, op->ob_refcnt); | ||
| PY_UINT32_T new_refcnt = cur_refcnt + 1; | ||
| if (new_refcnt == 0) { | ||
| return; | ||
| } | ||
| op->ob_refcnt_split[PY_BIG_ENDIAN] = new_refcnt; | ||
| memcpy(&op->ob_refcnt, &new_refcnt, sizeof(new_refcnt)); | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIsn't this require the little-endian?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityMaybe move the union here, use memcpy() and only use the bits that you need in the union?
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThe problem of the current implementation (without this change) is the usage of anonymous union in PyObject: it is not compatible with (strict) C99. A named union is fine with C89 and C99. It's more about finding the right syntax to get the most efficient code.
Sorry, something went wrong.
All reactions
|
||
| #else | ||
| // Explicitly check immortality against the immortal value | ||
| if (_Py_IsImmortal(op)) { | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIt makes me sad to use memcpy() in the limited C API which should attempt to hide as many implementation details as possible. I don't get how the immortal object change interacts with the stable ABI. I would prefer to convert Py_INCREF/Py_DECREF to opaque function calls. It would avoid any C and C++ compatibility issue. At least, it would make the ABI a little bit more "forward compatible".
But that can be done later, since the priority is to unblock the next Python 3.12 beta release.
By the way, the nogil fork has also a completely different implementation which is also ABI incompatible unless these functions are implemented as opaque function calls.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.