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

Function tcsetattr

crates/stdlib/src/termios.rs:198–237  ·  view source on GitHub ↗
(fd: i32, when: i32, attributes: PyListRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

196
197 #[pyfunction]
198 fn tcsetattr(fd: i32, when: i32, attributes: PyListRef, vm: &VirtualMachine) -> PyResult<()> {
199 let [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] =
200 <&[PyObjectRef; 7]>::try_from(&*attributes.borrow_vec())
201 .map_err(|_| vm.new_type_error("tcsetattr, arg 3: must be 7 element list"))?
202 .clone();
203 let mut termios = Termios::from_fd(fd).map_err(|e| termios_error(e, vm))?;
204 termios.c_iflag = iflag.try_into_value(vm)?;
205 termios.c_oflag = oflag.try_into_value(vm)?;
206 termios.c_cflag = cflag.try_into_value(vm)?;
207 termios.c_lflag = lflag.try_into_value(vm)?;
208 termios::cfsetispeed(&mut termios, ispeed.try_into_value(vm)?)
209 .map_err(|e| termios_error(e, vm))?;
210 termios::cfsetospeed(&mut termios, ospeed.try_into_value(vm)?)
211 .map_err(|e| termios_error(e, vm))?;
212 let cc = PyListRef::try_from_object(vm, cc)?;
213 let cc = cc.borrow_vec();
214 let cc = <&[PyObjectRef; NCCS]>::try_from(&*cc).map_err(|_| {
215 vm.new_type_error(format!(
216 "tcsetattr: attributes[6] must be {NCCS} element list"
217 ))
218 })?;
219 for (cc, x) in termios.c_cc.iter_mut().zip(cc.iter()) {
220 *cc = if let Some(c) = x
221 .downcast_ref::<PyBytes>()
222 .filter(|b| b.as_bytes().len() == 1)
223 {
224 c.as_bytes()[0] as _
225 } else if let Some(i) = x.downcast_ref::<PyInt>() {
226 i.try_to_primitive(vm)?
227 } else {
228 return Err(vm.new_type_error(
229 "tcsetattr: elements of attributes must be characters or integers",
230 ));
231 };
232 }
233
234 termios::tcsetattr(fd, when, &termios).map_err(|e| termios_error(e, vm))?;
235
236 Ok(())
237 }
238
239 #[pyfunction]
240 fn tcsendbreak(fd: i32, duration: i32, vm: &VirtualMachine) -> PyResult<()> {

Callers

nothing calls this directly

Calls 11

termios_errorFunction · 0.85
borrow_vecMethod · 0.80
try_into_valueMethod · 0.80
try_to_primitiveMethod · 0.80
ErrClass · 0.50
cloneMethod · 0.45
iter_mutMethod · 0.45
iterMethod · 0.45
filterMethod · 0.45
lenMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected