Add bool support to c-api (#7938)

This commit is contained in:
Bas Schoenmaeckers authored and GitHub committed 2026-05-21 09:59:40 +09:00
1 parent ae8a7c117c
commit faabbbc5de
2 files changed
+29

No files matched your search

+28
View File
@@ -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
View File
@@ -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;