8000 _ctypes.addressof · RustPython/RustPython@2baeb3e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2baeb3e

Browse files
committed
_ctypes.addressof
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
1 parent b2abb1a commit 2baeb3e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

vm/src/stdlib/ctypes.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,16 @@ pub(crate) mod _ctypes {
214214
}
215215
}
216216

217+
#[pyfunction]
218+
fn addressof(obj: PyObjectRef, vm: &VirtualMachine) -> PyResult<usize> {
219+
if obj.is_instance(PyCSimple::static_type().as_ref(), vm)? {
220+
let simple = obj.downcast_ref::<PyCSimple>().unwrap();
221+
Ok(simple.value.as_ptr() as usize)
222+
} else {
223+
Err(vm.new_type_error("expected a ctypes instance".to_string()))
224+
}
225+
}
226+
217227
#[pyfunction]
218228
fn get_errno() -> i32 {
219229
errno::errno().0

0 commit comments

Comments
 (0)
0