Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
more tmp
  • Loading branch information
arihant2math committed Mar 24, 2025
commit b47bbc3e2d106f70c05697e2911b391ed6f315d0
1 change: 1 addition & 0 deletions extra_tests/snippets/builtins_ctypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def LoadLibrary(self, name):
cdll = LibraryLoader(CDLL)

test_byte_array = create_string_buffer(b"Hello, World!")
assert test_byte_array._length_ == 14

if _os.name == "posix" or _sys.platform == "darwin":
pass
Expand Down
17 changes: 15 additions & 2 deletions vm/src/stdlib/ctypes/function.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::builtins::{PyStr, PyTupleRef, PyTypeRef};
use crate::class::StaticType;
use crate::convert::ToPyObject;
use crate::function::FuncArgs;
use crate::stdlib::ctypes::PyCData;
Expand Down Expand Up @@ -38,13 +39,25 @@ impl Function {
let args = args
.iter()
.map(|arg| {
if let Some(data) = arg.downcast_ref::<PyCSimple>() {
Ok(ffi_type_from_str(&data._type_).unwrap())
dbg!();
if arg.obj_type().is_subclass(PyCSimple::static_type().into(), vm)? {
dbg!();
let typ = arg.get_attr("_type_", vm)?;
let typ = typ.downcast_ref::<PyStr>().unwrap();
let converted = ffi_type_from_str(typ.as_str());
match converted {
Some(t) => Ok(t),
None => Err(vm.new_type_error(format!(
"Invalid type: {}",
typ.as_str()
))),
}
} else {
Err(vm.new_type_error("Expected a ctypes simple type".to_string()))
}
})
.collect::<PyResult<Vec<Type>>>()?;
dbg!();
let terminated = format!("{}\0", function);
let pointer: Symbol<'_, FP> = unsafe {
library
Expand Down