Skip to content

Commit 6c318f2

Browse files
authored
Merge pull request RustPython#3305 from youknowone/less-pymodule
replace py_module! from errno and sysconfigdata
2 parents 718de8f + b9ffa93 commit 6c318f2

File tree

2 files changed

+30
-21
lines changed

2 files changed

+30
-21
lines changed

vm/src/stdlib/errno.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
use crate::VirtualMachine;
22
use crate::{ItemProtocol, PyObjectRef};
33

4+
#[pymodule]
5+
mod errno {}
6+
47
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
8+
let module = errno::make_module(vm);
59
let errorcode = vm.ctx.new_dict();
6-
let module = py_module!(vm, "errno", {
10+
extend_module!(vm, module, {
711
"errorcode" => errorcode.clone(),
812
});
913
for (name, code) in ERROR_CODES {

vm/src/stdlib/sysconfigdata.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
use super::sys::MULTIARCH;
2-
use crate::{function::IntoPyObject, ItemProtocol, PyObjectRef, VirtualMachine};
1+
pub(crate) use _sysconfigdata::make_module;
32

4-
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
5-
let vars = vm.ctx.new_dict();
6-
macro_rules! sysvars {
7-
($($key:literal => $value:expr),*$(,)?) => {{
8-
$(vars.set_item($key, $value.into_pyobject(vm), vm).unwrap();)*
9-
}};
10-
}
11-
sysvars! {
12-
// fake shared module extension
13-
"EXT_SUFFIX" => format!(".rustpython-{}", MULTIARCH),
14-
"MULTIARCH" => MULTIARCH,
15-
// enough for tests to stop expecting urandom() to fail after restricting file resources
16-
"HAVE_GETRANDOM" => 1,
17-
}
18-
include!(concat!(env!("OUT_DIR"), "/env_vars.rs"));
3+
#[pymodule]
4+
pub(crate) mod _sysconfigdata {
5+
use crate::{
6+
builtins::PyDictRef, function::IntoPyObject, stdlib::sys::MULTIARCH, ItemProtocol,
7+
VirtualMachine,
8+
};
199

20-
py_module!(vm, "_sysconfigdata", {
21-
"build_time_vars" => vars,
22-
})
10+
#[pyattr]
11+
fn build_time_vars(vm: &VirtualMachine) -> PyDictRef {
12+
let vars = vm.ctx.new_dict();
13+
macro_rules! sysvars {
14+
($($key:literal => $value:expr),*$(,)?) => {{
15+
$(vars.set_item($key, $value.into_pyobject(vm), vm).unwrap();)*
16+
}};
17+
}
18+
sysvars! {
19+
// fake shared module extension
20+
"EXT_SUFFIX" => format!(".rustpython-{}", MULTIARCH),
21+
"MULTIARCH" => MULTIARCH,
22+
// enough for tests to stop expecting urandom() to fail after restricting file resources
23+
"HAVE_GETRANDOM" => 1,
24+
}
25+
include!(concat!(env!("OUT_DIR"), "/env_vars.rs"));
26+
vars
27+
}
2328
}

0 commit comments

Comments
 (0)