mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Add SeqIter and CallIter support to c-api (#8794)
This commit is contained in:
1 parent
05f1386fca
commit
43a595ed65
2 files changed
+30
No files matched your search
@@ -0,0 +1,29 @@
|
||||
use crate::object::define_py_check;
|
||||
use crate::{PyObject, pystate::with_vm};
|
||||
use rustpython_vm::PyPayload;
|
||||
use rustpython_vm::TryFromObject;
|
||||
use rustpython_vm::builtins::{PyCallableIterator, PySequenceIterator};
|
||||
use rustpython_vm::function::ArgCallable;
|
||||
|
||||
define_py_check!(exact fn PySeqIter_Check, types.iter_type);
|
||||
define_py_check!(exact fn PyCallIter_Check, types.callable_iterator);
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn PySeqIter_New(seq: *mut PyObject) -> *mut PyObject {
|
||||
with_vm(|vm| {
|
||||
let seq = unsafe { &*seq }.to_owned();
|
||||
Ok(PySequenceIterator::new(seq, vm)?.into_pyobject(vm))
|
||||
})
|
||||
}
|
||||
|
||||
#[unsafe(no_mangle)]
|
||||
pub unsafe extern "C" fn PyCallIter_New(
|
||||
callable: *mut PyObject,
|
||||
sentinel: *mut PyObject,
|
||||
) -> *mut PyObject {
|
||||
with_vm(|vm| {
|
||||
let callable = ArgCallable::try_from_object(vm, unsafe { &*callable }.to_owned())?;
|
||||
let sentinel = unsafe { &*sentinel }.to_owned();
|
||||
Ok(PyCallableIterator::new(callable, sentinel).into_pyobject(vm))
|
||||
})
|
||||
}
|
||||
@@ -22,6 +22,7 @@ pub mod dictobject;
|
||||
pub mod floatobject;
|
||||
pub mod genericaliasobject;
|
||||
pub mod import;
|
||||
pub mod iterobject;
|
||||
pub mod listobject;
|
||||
pub mod longobject;
|
||||
pub mod memoryobject;
|
||||
|
||||
Reference in new issue
Block a user