GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||
GeezerVison is showing github.com — _ctypes pt. 3 by arihant2math · Pull Request #5530 · RustPython/RustPython Conversation
|
|
Some updates: I've gotten arbitrary function argument passing to work on a test, I still am figuring out return type inference however. use std::ffi::c_void; use std::path::Path; use libffi::middle as libffi; use libloading::Symbol; type FP = unsafe extern "C" fn (); fn main() { let path = "C:\\Windows\\System32\\kernel32.dll"; let path = Path::new(path); let lib = unsafe { libloading::Library::new(path) }.unwrap(); let function_bytes = b"Sleep\0"; let function: Symbol<FP> = unsafe { lib.get(function_bytes) }.unwrap(); let function = *function; let args = vec![libffi::Type::u32()]; let cif = libffi::Cif::new(args.into_iter(), libffi::Type::void()); let ms_wait: u32 = 5000; println!("Calling function"); let now = std::time::Instant::now(); let _res: *const c_void = unsafe { cif.call(libffi::CodePtr(function as *mut _), &[libffi::arg(&ms_wait)]) }; println!("Function returned in {}ms", now.elapsed().as_millis()); println!("Function called"); } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Nevermind, it seems like return type needs to be manually specified and the default is cint |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Ready for review. (this is from the extra test) libc = cdll.msvcrt print("rand", libc.rand()) /cc @youknowone |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
3115d8a to
06dbae4
Compare
Signed-off-by: Ashwin Naren <[email protected]>
Signed-off-by: Ashwin Naren <[email protected]>
Signed-off-by: Ashwin Naren <[email protected]>
Signed-off-by: Ashwin Naren <[email protected]>
Signed-off-by: Ashwin Naren <[email protected]>
Signed-off-by: Ashwin Naren <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you so much!
Please check if the extra indent is intended or not.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Done. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
👍
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Jeong, YunWon <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.