Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.dict/cpython.txt
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pyerrors
Pyfunc
pylifecycle
pymain
pymem
pyrepl
pystate
PYTHONTRACEMALLOC
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/capi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
bitflags = { workspace = true }
itertools = { workspace = true }
libc = { workspace = true }
num-complex = { workspace = true }
rustpython-vm = { workspace = true, features = ["threading", "compiler", "importlib", "host_env"] }
rustpython-stdlib = {workspace = true, features = ["threading"] }
Expand Down
1 change: 1 addition & 0 deletions crates/capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mod object;
pub mod pycapsule;
pub mod pyerrors;
pub mod pylifecycle;
pub mod pymem;
pub mod pystate;
pub mod refcount;
pub mod setobject;
Expand Down
46 changes: 46 additions & 0 deletions crates/capi/src/pymem.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use core::ffi::c_void;

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyMem_Malloc(n: usize) -> *mut c_void {
unsafe { libc::malloc(if n == 0 { 1 } else { n }) }
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyMem_Calloc(nelem: usize, elsize: usize) -> *mut c_void {
unsafe {
libc::calloc(
if nelem == 0 || elsize == 0 { 1 } else { nelem },
if nelem == 0 || elsize == 0 { 1 } else { elsize },
)
}
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyMem_Realloc(ptr: *mut c_void, new_size: usize) -> *mut c_void {
unsafe { libc::realloc(ptr, if new_size == 0 { 1 } else { new_size }) }
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyMem_Free(ptr: *mut c_void) {
unsafe { libc::free(ptr) }
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyMem_RawMalloc(n: usize) -> *mut c_void {
unsafe { libc::malloc(n) }
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyMem_RawCalloc(nelem: usize, elsize: usize) -> *mut c_void {
unsafe { libc::calloc(nelem, elsize) }
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyMem_RawRealloc(ptr: *mut c_void, new_size: usize) -> *mut c_void {
unsafe { libc::realloc(ptr, new_size) }
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyMem_RawFree(ptr: *mut c_void) {
unsafe { libc::free(ptr) }
}
Loading