mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Add bool support to c-api (#7938)
This commit is contained in:
1 parent
ae8a7c117c
commit
faabbbc5de
2 files changed
+29
No files matched your search
@@ -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()
|
||||
})
|
||||
}
|
||||
@@ -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 dictobject;
|
||||
|
||||
Reference in new issue
Block a user