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
28 changes: 28 additions & 0 deletions crates/capi/src/boolobject.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use crate::object::define_py_check;
use crate::{PyObject, pystate::with_vm};
use core::ffi::{c_int, c_long};
use rustpython_vm::AsObject;

define_py_check!(fn PyBool_Check, types.bool_type);

#[unsafe(no_mangle)]
pub unsafe extern "C" fn Py_IsTrue(obj: *mut PyObject) -> c_int {
with_vm(|vm| unsafe { obj.as_ref().is_some_and(|obj| obj.is(&vm.ctx.true_value)) })
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn Py_IsFalse(obj: *mut PyObject) -> c_int {
with_vm(|vm| unsafe { obj.as_ref().is_some_and(|obj| obj.is(&vm.ctx.false_value)) })
}

#[unsafe(no_mangle)]
pub extern "C" fn PyBool_FromLong(value: c_long) -> *mut PyObject {
with_vm(|vm| {
if value == 0 {
&vm.ctx.false_value
} else {
&vm.ctx.true_value
}
.to_owned()
})
}
1 change: 1 addition & 0 deletions crates/capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::sync::MutexGuard;
extern crate alloc;

pub mod abstract_;
pub mod boolobject;
pub mod bytesobject;
pub mod ceval;
pub mod import;
Expand Down
Loading