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

Method try_writable

crates/stdlib/src/mmap.rs:891–908  ·  view source on GitHub ↗
(
            &self,
            vm: &VirtualMachine,
            f: impl FnOnce(&mut [u8]) -> R,
        )

Source from the content-addressed store, hash-verified

889
890 #[inline]
891 fn try_writable<R>(
892 &self,
893 vm: &VirtualMachine,
894 f: impl FnOnce(&mut [u8]) -> R,
895 ) -> PyResult<R> {
896 if matches!(self.access, AccessMode::Read) {
897 return Err(vm.new_type_error("mmap can't modify a readonly memory map."));
898 }
899
900 match self.check_valid(vm)?.deref_mut().as_mut().unwrap() {
901 MmapObj::Write(mmap) => Ok(f(&mut mmap[..])),
902 #[cfg(windows)]
903 MmapObj::Named(named) => Ok(f(unsafe {
904 core::slice::from_raw_parts_mut(named.view_ptr, named.len)
905 })),
906 _ => unreachable!("already checked"),
907 }
908 }
909
910 fn check_valid(&self, vm: &VirtualMachine) -> PyResult<PyMutexGuard<'_, Option<MmapObj>>> {
911 let m = self.mmap.lock();

Callers 5

move_Method · 0.80
writeMethod · 0.80
write_byteMethod · 0.80
setitem_by_indexMethod · 0.80
setitem_by_sliceMethod · 0.80

Calls 6

check_validMethod · 0.80
ErrClass · 0.50
fFunction · 0.50
unwrapMethod · 0.45
as_mutMethod · 0.45
deref_mutMethod · 0.45

Tested by

no test coverage detected