mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Add type name c-api functions (#7925)
This commit is contained in:
1 parent
1e20975838
commit
720791c58e
1 file changed
+27
@@ -66,6 +66,33 @@ pub unsafe extern "C" fn PyType_IsSubtype(a: *const PyTypeObject, b: *const PyTy
|
||||
})
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn PyType_GetName(ptr: *const PyTypeObject) -> *mut PyObject {
|
||||
with_vm(|vm| unsafe { &*ptr }.__name__(vm))
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn PyType_GetQualName(ptr: *const PyTypeObject) -> *mut PyObject {
|
||||
with_vm(|vm| unsafe { &*ptr }.__qualname__(vm))
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn PyType_GetFullyQualifiedName(ptr: *const PyTypeObject) -> *mut PyObject {
|
||||
with_vm(|vm| {
|
||||
let ty = unsafe { &*ptr };
|
||||
let qualname = ty.__qualname__(vm).try_downcast::<PyStr>(vm)?;
|
||||
let module = ty.__module__(vm);
|
||||
|
||||
if let Some(module) = module.downcast_ref::<PyStr>()
|
||||
&& module.as_wtf8() != "builtins"
|
||||
{
|
||||
Ok(vm.ctx.new_str(format!("{module}.{qualname}")))
|
||||
} else {
|
||||
Ok(qualname)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub extern "C" fn Py_GetConstantBorrowed(constant_id: c_uint) -> *mut PyObject {
|
||||
with_vm(|vm| {
|
||||
|
||||
Reference in new issue
Block a user