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

Function read

crates/vm/src/stdlib/os.rs:286–301  ·  view source on GitHub ↗
(fd: crt_fd::Borrowed<'_>, n: usize, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

284
285 #[pyfunction]
286 fn read(fd: crt_fd::Borrowed<'_>, n: usize, vm: &VirtualMachine) -> PyResult<PyBytesRef> {
287 let mut buffer = vec![0u8; n];
288 loop {
289 match vm.allow_threads(|| crt_fd::read(fd, &mut buffer)) {
290 Ok(n) => {
291 buffer.truncate(n);
292 return Ok(vm.ctx.new_bytes(buffer));
293 }
294 Err(e) if e.raw_os_error() == Some(libc::EINTR) => {
295 vm.check_signals()?;
296 continue;
297 }
298 Err(e) => return Err(e.into_pyexception(vm)),
299 }
300 }
301 }
302
303 #[pyfunction]
304 fn readinto(

Callers 4

readMethod · 0.70
readintoMethod · 0.70
readintoFunction · 0.70
from_pyc_pathMethod · 0.50

Calls 7

allow_threadsMethod · 0.80
check_signalsMethod · 0.80
SomeClass · 0.50
ErrClass · 0.50
truncateMethod · 0.45
new_bytesMethod · 0.45
into_pyexceptionMethod · 0.45

Tested by

no test coverage detected