-
Notifications
You must be signed in to change notification settings - Fork 962
Add Py_SET_SIZE and Py_RETURN_NOTIMPLEMENTED functions #6003
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.
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
Open
clin1234
wants to merge
11
commits into
PyO3:main
Choose a base branch
from
clin1234:patch-10
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
74e87d1
Add Py_SET_SIZE and Py_RETURN_NOTIMPLEMENTED functions
clin1234 6133810
news
clin1234 da7723f
Update object.rs
clin1234 8c8a8bd
Fix return statements in Py_RETURN_NONE and Py_RETURN_NOTIMPLEMENTED
clin1234 eedc818
Update object.rs
clin1234 379db59
Import pyo3_ffi in object.rs
clin1234 6ad8034
Refactor conditional compilation for Py_RETURN_* functions
clin1234 091ddfd
Update object.rs
clin1234 f5a89ff
Update conditional compilation for Py_RETURN macros
clin1234 e82ab66
Refactor Py_RETURN_NONE and Py_RETURN_NOTIMPLEMENTED
clin1234 5a0134e
Refactor Py_RETURN_NONE and Py_RETURN_NOTIMPLEMENTED
clin1234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Add `Py_SET_SIZE` and `Py_RETURN_NOTIMPLEMENTED` functions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,8 @@ use crate::pyport::{Py_hash_t, Py_ssize_t}; | |
| use crate::refcount; | ||
| #[cfg(Py_GIL_DISABLED)] | ||
| use crate::PyMutex; | ||
| #[cfg(all(not(Py_3_13), Py_3_10, Py_LIMITED_API, not(PyPy)))] | ||
| use crate::Py_NewRef; | ||
| use std::ffi::{c_char, c_int, c_uint, c_ulong, c_void}; | ||
| use std::mem; | ||
| #[cfg(Py_GIL_DISABLED)] | ||
|
|
@@ -233,6 +235,8 @@ pub unsafe fn Py_SIZE(ob: *mut PyObject) -> Py_ssize_t { | |
| #[cfg(all(Py_LIMITED_API, Py_3_15))] | ||
| extern_libpython! { | ||
| pub fn Py_IS_TYPE(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_int; | ||
| pub fn Py_SET_SIZE(ob: *mut PyVarObject, size: Py_ssize_t); | ||
| pub fn Py_SET_TYPE(ob: *mut PyObject, tp: *mut PyTypeObject); | ||
| } | ||
|
|
||
| #[inline] | ||
|
|
@@ -241,9 +245,11 @@ pub unsafe fn Py_IS_TYPE(ob: *mut PyObject, tp: *mut PyTypeObject) -> c_int { | |
| (Py_TYPE(ob) == tp) as c_int | ||
| } | ||
|
|
||
| // skipped Py_SET_TYPE | ||
|
|
||
| // skipped Py_SET_SIZE | ||
| #[inline] | ||
| #[cfg(not(all(Py_LIMITED_API, Py_3_15)))] | ||
| pub unsafe fn Py_SET_SIZE(ob: *mut PyVarObject, size: Py_ssize_t) { | ||
| (*ob).ob_size = size | ||
| } | ||
|
|
||
| pub type unaryfunc = unsafe extern "C" fn(*mut PyObject) -> *mut PyObject; | ||
| pub type binaryfunc = unsafe extern "C" fn(*mut PyObject, *mut PyObject) -> *mut PyObject; | ||
|
|
@@ -643,7 +649,19 @@ pub unsafe fn Py_IsNone(x: *mut PyObject) -> c_int { | |
| Py_Is(x, Py_None()) | ||
| } | ||
|
|
||
| // skipped Py_RETURN_NONE | ||
| #[inline] | ||
| pub unsafe fn Py_RETURN_NONE() -> *mut PyObject { | ||
|
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. This is a macro which doesn't make sense to expose for the same reason #5976 was closed. |
||
| #[cfg(all(not(Py_3_13), Py_3_10, Py_LIMITED_API, not(PyPy)))] | ||
| { | ||
| let obj = Py_None(); | ||
| Py_NewRef(obj) | ||
| } | ||
|
|
||
| #[cfg(Py_3_10)] | ||
| { | ||
| Py_None() | ||
| } | ||
| } | ||
|
|
||
| extern_libpython! { | ||
| #[cfg(all(not(GraalPy), not(all(Py_3_13, Py_LIMITED_API))))] | ||
|
|
@@ -666,7 +684,19 @@ pub unsafe fn Py_NotImplemented() -> *mut PyObject { | |
| return _Py_NotImplementedStructReference; | ||
| } | ||
|
|
||
| // skipped Py_RETURN_NOTIMPLEMENTED | ||
| #[inline] | ||
| pub unsafe fn Py_RETURN_NOTIMPLEMENTED() -> *mut PyObject { | ||
|
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. Same comment that this doesn't work like the C macro. |
||
| #[cfg(all(not(Py_3_13), Py_3_10, Py_LIMITED_API, not(PyPy)))] | ||
| { | ||
| let obj = Py_NotImplemented(); | ||
| Py_NewRef(obj) | ||
| } | ||
|
|
||
| #[cfg(Py_3_10)] | ||
| { | ||
| Py_NotImplemented() | ||
| } | ||
| } | ||
|
|
||
| /* Rich comparison opcodes */ | ||
| pub const Py_LT: c_int = 0; | ||
|
|
||
Oops, something went wrong.
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.
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.
Should include
Py_SET_TYPEfor non-limited API operations?