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
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions crates/capi/src/descrobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ pub struct PyGetSetDef {
}

impl PyGetSetDef {
pub(crate) fn iter<'a>(mut defs: *const Self) -> impl Iterator<Item = &'a Self> {
core::iter::from_fn(move || {
let def = unsafe { &*defs };
if def.name.is_null() {
None
} else {
defs = unsafe { defs.add(1) };
Some(def)
}
})
}
pub(crate) fn build(
&self,
ty: &'static Py<PyType>,
Expand Down Expand Up @@ -114,6 +125,18 @@ pub struct PyMemberDef {
}

impl PyMemberDef {
pub(crate) fn iter<'a>(mut defs: *const Self) -> impl Iterator<Item = &'a Self> {
core::iter::from_fn(move || {
let def = unsafe { &*defs };
if def.name.is_null() {
None
} else {
defs = unsafe { defs.add(1) };
Some(def)
}
})
}

pub(crate) fn build(
&self,
ty: &Py<PyType>,
Expand Down
1 change: 1 addition & 0 deletions crates/capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub mod pystrcmp;
pub mod refcount;
pub mod setobject;
pub mod sliceobject;
pub mod slots;
pub mod traceback;
pub mod tupleobject;
pub mod unicodeobject;
Expand Down
22 changes: 22 additions & 0 deletions crates/capi/src/methodobject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,36 @@ use crate::object::define_py_check;
use crate::pystate::with_vm;
use crate::util::{CStrExt, FfiPtrExt};
use core::ffi::{c_char, c_int};
use core::fmt::Debug;
use rustpython_vm::function::{FuncArgs, HeapMethodDef, ItemDoc, PosArgs, PyMethodFlags};
use rustpython_vm::{AsObject, PyObjectRef, PyRef, PyResult, VirtualMachine};

define_py_check!(fn PyCFunction_Check, types.builtin_function_or_method_type);
define_py_check!(exact fn PyCFunction_CheckExact, types.builtin_function_or_method_type);

#[repr(C)]
#[derive(Debug)]
pub struct PyMethodDef {
pub ml_name: *const c_char,
pub ml_meth: PyMethodPointer,
pub ml_flags: c_int,
pub ml_doc: *const c_char,
}

impl PyMethodDef {
pub(crate) fn iter<'a>(mut methods: *const Self) -> impl Iterator<Item = &'a Self> {
core::iter::from_fn(move || {
let def = unsafe { &*methods };
if def.ml_name.is_null() {
None
} else {
methods = unsafe { methods.add(1) };
Some(def)
}
})
}
}

#[repr(C)]
#[derive(Copy, Clone)]
#[allow(non_snake_case)]
Expand All @@ -41,6 +57,12 @@ pub union PyMethodPointer {
) -> *mut PyObject,
}

impl Debug for PyMethodPointer {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
unsafe { self.PyCFunction.fmt(f) }
}
}

pub(crate) fn build_method_def(
vm: &VirtualMachine,
ml: &PyMethodDef,
Expand Down
Loading
Loading