FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add object protocol methods to c-api by bschoenmaeckers · Pull Request #7882 · RustPython/RustPython · GitHub

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

Filter by extension

Filter by extension .rs  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
52 changes: 52 additions & 0 deletions crates/capi/src/abstract_.rs
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,52 @@
use crate::{PyObject, pystate::with_vm};
use core::ffi::c_int;

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyObject_GetItem(obj: *mut PyObject, key: *mut PyObject) -> *mut PyObject {
with_vm(|vm| {
let obj = unsafe { &*obj };
let key = unsafe { &*key };
obj.get_item(key, vm)
})
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyObject_SetItem(
obj: *mut PyObject,
key: *mut PyObject,
value: *mut PyObject,
) -> c_int {
with_vm(|vm| {
let obj = unsafe { &*obj };
let key = unsafe { &*key };
let value = unsafe { &*value }.to_owned();
obj.set_item(key, value, vm)
})
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyObject_DelItem(obj: *mut PyObject, key: *mut PyObject) -> c_int {
with_vm(|vm| {
let obj = unsafe { &*obj };
let key = unsafe { &*key };
obj.del_item(key, vm)
})
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyObject_IsSubclass(derived: *mut PyObject, cls: *mut PyObject) -> c_int {
with_vm(|vm| {
let derived = unsafe { &*derived };
let cls = unsafe { &*cls };
derived.is_subclass(cls, vm)
})
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn PyObject_IsInstance(inst: *mut PyObject, cls: *mut PyObject) -> c_int {
with_vm(|vm| {
let inst = unsafe { &*inst };
let cls = unsafe { &*cls };
inst.is_instance(cls, vm)
})
}
1 change: 1 addition & 0 deletions crates/capi/src/lib.rs
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
Expand Up @@ -8,6 +8,7 @@ use std::sync::MutexGuard;

extern crate alloc;

pub mod abstract_;
pub mod import;
pub mod object;
pub mod pyerrors;
Expand Down
Loading

Back | FazBrowse Home | New Git URL