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

Method madvise

crates/stdlib/src/mmap.rs:1037–1057  ·  view source on GitHub ↗
(&self, options: AdviseOptions, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1035 #[cfg(all(unix, not(target_os = "redox")))]
1036 #[pymethod]
1037 fn madvise(&self, options: AdviseOptions, vm: &VirtualMachine) -> PyResult<()> {
1038 let (option, start, length) = options.values(self.__len__(), vm)?;
1039 let advice = validate_advice(vm, option)?;
1040
1041 let guard = self.check_valid(vm)?;
1042 let mmap = guard.deref().as_ref().unwrap();
1043 let ptr = match mmap {
1044 MmapObj::Read(m) => m.as_ptr(),
1045 MmapObj::Write(m) => m.as_ptr(),
1046 };
1047
1048 // Apply madvise to the specified range (start, length)
1049 let ptr_with_offset = unsafe { ptr.add(start) };
1050 let result =
1051 unsafe { libc::madvise(ptr_with_offset as *mut libc::c_void, length, advice) };
1052 if result != 0 {
1053 return Err(io::Error::last_os_error().to_pyexception(vm));
1054 }
1055
1056 Ok(())
1057 }
1058
1059 #[pymethod(name = "move")]
1060 fn move_(

Callers 1

test_madviseMethod · 0.80

Calls 11

validate_adviceFunction · 0.85
check_validMethod · 0.80
ErrClass · 0.50
valuesMethod · 0.45
__len__Method · 0.45
unwrapMethod · 0.45
as_refMethod · 0.45
derefMethod · 0.45
as_ptrMethod · 0.45
addMethod · 0.45
to_pyexceptionMethod · 0.45

Tested by 1

test_madviseMethod · 0.64