Skip to content

Commit 2c97a50

Browse files
committed
sys - use py_module.
1 parent d420c7f commit 2c97a50

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

vm/src/sysmodule.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ pub fn mk_module(ctx: &PyContext) -> PyObjectRef {
4949
};
5050
let path = ctx.new_list(path_list);
5151

52-
let modules = ctx.new_dict();
53-
54-
let sys_name = "sys";
5552
let sys_doc = "This module provides access to some objects used or maintained by the
5653
interpreter and to functions that interact strongly with the interpreter.
5754
@@ -121,20 +118,22 @@ setprofile() -- set the global profiling function
121118
setrecursionlimit() -- set the max recursion depth for the interpreter
122119
settrace() -- set the global debug tracing function
123120
";
124-
let sys_mod = ctx.new_module(&sys_name, ctx.new_scope(None));
121+
let modules = ctx.new_dict();
122+
let sys_name = "sys";
123+
let sys_mod = py_module!(ctx, sys_name, {
124+
"argv" => argv(ctx),
125+
"getrefcount" => ctx.new_rustfunc(sys_getrefcount),
126+
"getsizeof" => ctx.new_rustfunc(sys_getsizeof),
127+
"maxsize" => ctx.new_int(std::usize::MAX),
128+
"path" => path,
129+
"ps1" => ctx.new_str(">>>>> ".to_string()),
130+
"ps2" => ctx.new_str("..... ".to_string()),
131+
"__doc__" => ctx.new_str(sys_doc.to_string()),
132+
"_getframe" => ctx.new_rustfunc(getframe),
133+
});
125134

126135
ctx.set_item(&modules, sys_name, sys_mod.clone());
127-
128136
ctx.set_attr(&sys_mod, "modules", modules);
129-
ctx.set_attr(&sys_mod, "argv", argv(ctx));
130-
ctx.set_attr(&sys_mod, "getrefcount", ctx.new_rustfunc(sys_getrefcount));
131-
ctx.set_attr(&sys_mod, "getsizeof", ctx.new_rustfunc(sys_getsizeof));
132-
ctx.set_attr(&sys_mod, "maxsize", ctx.new_int(std::usize::MAX));
133-
ctx.set_attr(&sys_mod, "path", path);
134-
ctx.set_attr(&sys_mod, "ps1", ctx.new_str(">>>>> ".to_string()));
135-
ctx.set_attr(&sys_mod, "ps2", ctx.new_str("..... ".to_string()));
136-
ctx.set_attr(&sys_mod, "__doc__", ctx.new_str(sys_doc.to_string()));
137-
ctx.set_attr(&sys_mod, "_getframe", ctx.new_rustfunc(getframe));
138137

139138
sys_mod
140139
}

0 commit comments

Comments
 (0)