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

Method seek

crates/stdlib/src/mmap.rs:1285–1321  ·  view source on GitHub ↗
(
            &self,
            dist: isize,
            whence: OptionalArg<libc::c_int>,
            vm: &VirtualMachine,
        )

Source from the content-addressed store, hash-verified

1283
1284 #[pymethod]
1285 fn seek(
1286 &self,
1287 dist: isize,
1288 whence: OptionalArg<libc::c_int>,
1289 vm: &VirtualMachine,
1290 ) -> PyResult<()> {
1291 let how = whence.unwrap_or(0);
1292 let size = self.__len__();
1293
1294 let new_pos = match how {
1295 0 => dist, // relative to start
1296 1 => {
1297 // relative to current position
1298 let pos = self.pos();
1299 if (((isize::MAX as usize) - pos) as isize) < dist {
1300 return Err(vm.new_value_error("seek out of range"));
1301 }
1302 pos as isize + dist
1303 }
1304 2 => {
1305 // relative to end
1306 if (((isize::MAX as usize) - size) as isize) < dist {
1307 return Err(vm.new_value_error("seek out of range"));
1308 }
1309 size as isize + dist
1310 }
1311 _ => return Err(vm.new_value_error("unknown seek type")),
1312 };
1313
1314 if new_pos < 0 || (new_pos as usize) > size {
1315 return Err(vm.new_value_error("seek out of range"));
1316 }
1317
1318 self.pos.store(new_pos as usize);
1319
1320 Ok(())
1321 }
1322
1323 #[cfg(unix)]
1324 #[pymethod]

Callers

nothing calls this directly

Calls 4

ErrClass · 0.50
__len__Method · 0.45
posMethod · 0.45
storeMethod · 0.45

Tested by

no test coverage detected