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

Function setrlimit

crates/stdlib/src/resource.rs:172–193  ·  view source on GitHub ↗
(resource: i32, limits: Limits, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

170
171 #[pyfunction]
172 fn setrlimit(resource: i32, limits: Limits, vm: &VirtualMachine) -> PyResult<()> {
173 #[allow(clippy::unnecessary_cast)]
174 if resource < 0 || resource >= RLIM_NLIMITS as i32 {
175 return Err(vm.new_value_error("invalid resource specified"));
176 }
177 let res = unsafe {
178 if libc::setrlimit(resource as _, &limits.0) == -1 {
179 Err(io::Error::last_os_error())
180 } else {
181 Ok(())
182 }
183 };
184 res.map_err(|e| match e.kind() {
185 io::ErrorKind::InvalidInput => {
186 vm.new_value_error("current limit exceeds maximum limit")
187 }
188 io::ErrorKind::PermissionDenied => {
189 vm.new_value_error("not allowed to raise maximum limit")
190 }
191 _ => e.to_pyexception(vm),
192 })
193 }
194}

Callers 2

suppress_crash_reportFunction · 0.85

Calls 3

ErrClass · 0.50
kindMethod · 0.45
to_pyexceptionMethod · 0.45

Tested by 1