MCPcopy Index your code
hub / github.com/RustPython/RustPython / dlsym

Function dlsym

crates/vm/src/stdlib/_ctypes.rs:628–659  ·  view source on GitHub ↗
(
        handle: usize,
        name: crate::builtins::PyUtf8StrRef,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

626 #[cfg(not(windows))]
627 #[pyfunction]
628 fn dlsym(
629 handle: usize,
630 name: crate::builtins::PyUtf8StrRef,
631 vm: &VirtualMachine,
632 ) -> PyResult<usize> {
633 let symbol_name = alloc::ffi::CString::new(name.as_str())
634 .map_err(|_| vm.new_value_error("symbol name contains null byte"))?;
635
636 // Clear previous error
637 unsafe { libc::dlerror() };
638
639 let ptr = unsafe { libc::dlsym(handle as *mut libc::c_void, symbol_name.as_ptr()) };
640
641 // Check for error via dlerror first
642 let err = unsafe { libc::dlerror() };
643 if !err.is_null() {
644 let msg = unsafe {
645 core::ffi::CStr::from_ptr(err)
646 .to_string_lossy()
647 .into_owned()
648 };
649 return Err(vm.new_os_error(msg));
650 }
651
652 // Treat NULL symbol address as error
653 // This handles cases like GNU IFUNCs that resolve to NULL
654 if ptr.is_null() {
655 return Err(vm.new_os_error(format!("symbol '{}' not found", name.as_str())));
656 }
657
658 Ok(ptr as usize)
659 }
660
661 #[pyfunction(name = "POINTER")]
662 fn create_pointer_type(cls: PyObjectRef, vm: &VirtualMachine) -> PyResult {

Callers 1

test_null_dlsymMethod · 0.85

Calls 7

newFunction · 0.85
into_ownedMethod · 0.80
new_os_errorMethod · 0.80
ErrClass · 0.50
as_strMethod · 0.45
as_ptrMethod · 0.45
to_string_lossyMethod · 0.45

Tested by 1

test_null_dlsymMethod · 0.68