-
Notifications
You must be signed in to change notification settings - Fork 1k
add PyMemRawAllocator
#6279
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
chirizxc
wants to merge
39
commits into
PyO3:main
Choose a base branch
from
chirizxc:pymem-raw-alloc
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.
+427
−16
Open
add PyMemRawAllocator
#6279
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
56ff758
add `PyMemRawAllocator`
chirizxc 27eab03
docs
chirizxc 6c554a0
docs (x2)
chirizxc 781b2c3
add newsfragments
chirizxc eadec33
update MAX_ALIGN
chirizxc 707c873
update newsfragments
chirizxc 0ae37cc
fix comment
chirizxc c430046
update doc
chirizxc d5dc676
refactor
chirizxc 56dce48
remove unnecessary `unsafe` block
chirizxc 2f1bdba
refactoring
chirizxc 8a1777c
fmt
chirizxc 583d780
rumdl fmt guide/src/features.md
chirizxc 61f76db
fix newsfragments
chirizxc e3806cb
fix
chirizxc 7ec0df4
try fix
chirizxc bcc71cb
add tests
chirizxc e388cec
remove whitespaces
chirizxc d53be71
more test
chirizxc 24e5953
fix cfg
chirizxc ddf34d8
GLOBAL -> GLOBAL_ALLOCATOR
chirizxc 81ed81c
remove feature
chirizxc 0aa7a07
fix
chirizxc 429bb8a
add safety comments
chirizxc 1c9b8a3
update safety comments
chirizxc e416c10
update safety comments, add cpython docs links
chirizxc 6624118
sync `pymem.h` with 3.15 branch
chirizxc 4cc1242
fix clippy
chirizxc 4c5106e
fix `cargo doc`
chirizxc 89b135c
fix
chirizxc 16e9763
fix clippy
chirizxc cffcdf7
fix test
chirizxc d9f21b8
fmt
chirizxc f8dd183
fix clippy
chirizxc ea4c350
fix MSRV
chirizxc e56c4a1
fix MSRV (x2)
chirizxc db5e086
fix MSRV (x3)
chirizxc 5068b35
fix clippy
chirizxc eec4e73
Merge branch 'main' into pymem-raw-alloc
chirizxc 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 @@ | ||
| Added `pyo3::pymem_alloc::PyMemRawAllocator`, a `GlobalAlloc` implementation backed by CPython's `PyMem_Raw*` (`PYMEM_DOMAIN_RAW`) allocator functions. Not registered as the global allocator automatically. |
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
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
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 |
|---|---|---|
|
|
@@ -4,10 +4,59 @@ use libc::size_t; | |
| extern_libpython! { | ||
| #[cfg_attr(PyPy, link_name = "PyPyMem_Malloc")] | ||
| pub fn PyMem_Malloc(size: size_t) -> *mut c_void; | ||
|
|
||
| #[cfg_attr(PyPy, link_name = "PyPyMem_Calloc")] | ||
| pub fn PyMem_Calloc(nelem: size_t, elsize: size_t) -> *mut c_void; | ||
|
|
||
| #[cfg_attr(PyPy, link_name = "PyPyMem_Realloc")] | ||
| pub fn PyMem_Realloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; | ||
|
|
||
| #[cfg_attr(PyPy, link_name = "PyPyMem_Free")] | ||
| pub fn PyMem_Free(ptr: *mut c_void); | ||
| } | ||
|
|
||
| #[inline] | ||
| pub unsafe fn PyMem_New<T>(n: size_t) -> *mut T { | ||
| if n > isize::MAX as size_t / size_of::<T>() as size_t { | ||
| core::ptr::null_mut() | ||
| } else { | ||
| PyMem_Malloc(n * size_of::<T>() as size_t).cast() | ||
| } | ||
| } | ||
|
|
||
| #[inline] | ||
| pub unsafe fn PyMem_Resize<T>(p: &mut *mut T, n: size_t) { | ||
| *p = if n > isize::MAX as size_t / size_of::<T>() as size_t { | ||
| core::ptr::null_mut() | ||
| } else { | ||
| PyMem_Realloc(p.cast(), n * size_of::<T>() as size_t).cast() | ||
| }; | ||
| } | ||
|
|
||
| extern_libpython! { | ||
| // Deprecated aliases: | ||
| // | ||
| // skipped PyMem_MALLOC | ||
| // skipped PyMem_NEW | ||
| // skipped PyMem_REALLOC | ||
| // skipped PyMem_RESIZE | ||
| // skipped PyMem_FREE | ||
| // skipped PyMem_Del | ||
| // skipped PyMem_DEL | ||
|
|
||
| #[cfg_attr(PyPy, link_name = "PyPyMem_RawMalloc")] | ||
|
Contributor
Author
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. |
||
| #[cfg(any(Py_3_13, not(Py_LIMITED_API)))] | ||
| pub fn PyMem_RawMalloc(size: size_t) -> *mut c_void; | ||
|
|
||
| #[cfg_attr(PyPy, link_name = "PyPyMem_RawCalloc")] | ||
| #[cfg(any(Py_3_13, not(Py_LIMITED_API)))] | ||
| pub fn PyMem_RawCalloc(nelem: size_t, elsize: size_t) -> *mut c_void; | ||
|
|
||
| #[cfg_attr(PyPy, link_name = "PyPyMem_RawRealloc")] | ||
| #[cfg(any(Py_3_13, not(Py_LIMITED_API)))] | ||
| pub fn PyMem_RawRealloc(ptr: *mut c_void, new_size: size_t) -> *mut c_void; | ||
|
|
||
| #[cfg_attr(PyPy, link_name = "PyPyMem_RawFree")] | ||
| #[cfg(any(Py_3_13, not(Py_LIMITED_API)))] | ||
| pub fn PyMem_RawFree(ptr: *mut c_void); | ||
| } | ||
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
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.
https://github.com/python/cpython/blob/3.15/Include/cpython/pymem.h