Skip to content

Commit 09823a0

Browse files
Merge pull request RustPython#1078 from corona10/sys.byteorder
sys.byteorder: Implement sys.byteorder
2 parents 18a49d1 + 1035591 commit 09823a0

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

tests/snippets/sysmod.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
assert sys.getfilesystemencoding() == 'utf-8'
1515
assert sys.getfilesystemencodeerrors().startswith('surrogate')
1616

17+
assert sys.byteorder == "little" or sys.byteorder == "big"
18+
1719
assert isinstance(sys.flags, tuple)
1820
assert type(sys.flags).__name__ == "flags"
1921
assert type(sys.flags.optimize) is int

vm/src/sysmodule.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ pub fn make_module(vm: &VirtualMachine, module: PyObjectRef, builtins: PyObjectR
151151
"unknown".to_string()
152152
};
153153

154+
// https://doc.rust-lang.org/reference/conditional-compilation.html#target_endian
155+
let bytorder = if cfg!(target_endian = "little") {
156+
"little".to_string()
157+
} else if cfg!(target_endian = "big") {
158+
"big".to_string()
159+
} else {
160+
"unknown".to_string()
161+
};
162+
154163
let sys_doc = "This module provides access to some objects used or maintained by the
155164
interpreter and to functions that interact strongly with the interpreter.
156165
@@ -229,6 +238,7 @@ settrace() -- set the global debug tracing function
229238
"__name__" => ctx.new_str(String::from("sys")),
230239
"argv" => argv(ctx),
231240
"builtin_module_names" => ctx.new_tuple(module_names.iter().map(|v| v.into_pyobject(vm).unwrap()).collect()),
241+
"byteorder" => ctx.new_str(bytorder),
232242
"flags" => flags,
233243
"getrefcount" => ctx.new_rustfunc(sys_getrefcount),
234244
"getsizeof" => ctx.new_rustfunc(sys_getsizeof),

0 commit comments

Comments
 (0)