8000 Fix os.unsetenv · RustPython/RustPython@142d333 · GitHub
[go: up one dir, main page]

Skip to content

Commit 142d333

Browse files
committed
Fix os.unsetenv
1 parent 13c4917 commit 142d333

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

vm/src/stdlib/nt.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ pub(crate) mod module {
1616
builtins::{PyDictRef, PyStrRef, PyTupleRef},
1717
common::{crt_fd::Fd, os::last_os_error, suppress_iph},
1818
convert::ToPyException,
19-
function::Either,
20-
function::OptionalArg,
19+
function::{Either, OptionalArg},
2120
ospath::OsPath,
2221
stdlib::os::{errno_err, DirFd, FollowSymlinks, SupportFunc, TargetIsDirectory, _os},
2322
PyResult, TryFromObject, VirtualMachine,

vm/src/stdlib/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ pub(super) mod _os {
407407
return Err(vm.new_value_error("embedded null byte".to_string()));
408408
}
409409
if key.is_empty() || key.contains('=') {
410-
return Err(vm.new_value_error("illegal environment variable name".to_string()));
410+
return Err(vm.new_errno_error(22, "Invalid argument".to_owned()));
411411
}
412412
env::remove_var(key);
413413
Ok(())

vm/src/vm/vm_new.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ impl VirtualMachine {
189189
self.new_exception_msg(os_error, msg)
190190
}
191191

192+
pub fn new_errno_error(&self, errno: i32, msg: String) -> PyBaseExceptionRef {
193+
let vm = self;
194+
let exc_type =
195+
crate::exceptions::errno_to_exc_type(errno, vm).unwrap_or(vm.ctx.exceptions.os_error);
196+
197+
let errno_obj = vm.new_pyobj(errno);
198+
vm.new_exception(exc_type.to_owned(), vec![errno_obj, vm.new_pyobj(msg)])
199+
}
200+
192201
pub fn new_system_error(&self, msg: String) -> PyBaseExceptionRef {
193202
let sys_error = self.ctx.exceptions.system_error.to_owned();
194203
self.new_exception_msg(sys_error, msg)

0 commit comments

Comments
 (0)
0