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

Function initialize_main_vm

crates/vm/src/vm/interpreter.rs:40–154  ·  view source on GitHub ↗

Private helper to initialize a VM with settings, context, and custom initialization.

(
    settings: Settings,
    ctx: PyRc<Context>,
    module_defs: Vec<&'static builtins::PyModuleDef>,
    frozen_modules: Vec<(&'static str, FrozenModule)>,
    init_hooks: Vec<InitFunc>,
    init: 

Source from the content-addressed store, hash-verified

38
39/// Private helper to initialize a VM with settings, context, and custom initialization.
40fn initialize_main_vm<F>(
41 settings: Settings,
42 ctx: PyRc<Context>,
43 module_defs: Vec<&'static builtins::PyModuleDef>,
44 frozen_modules: Vec<(&'static str, FrozenModule)>,
45 init_hooks: Vec<InitFunc>,
46 init: F,
47) -> (VirtualMachine, PyRc<PyGlobalState>)
48where
49 F: FnOnce(&mut VirtualMachine),
50{
51 use crate::codecs::CodecsRegistry;
52 use crate::common::hash::HashSecret;
53 use crate::common::lock::PyMutex;
54 use crate::warn::WarningsState;
55 use core::sync::atomic::{AtomicBool, AtomicU64};
56 use crossbeam_utils::atomic::AtomicCell;
57
58 let paths = getpath::init_path_config(&settings);
59 let config = PyConfig::new(settings, paths);
60
61 // Build module_defs map from builtin modules + additional modules
62 let mut all_module_defs: BTreeMap<&'static str, &'static builtins::PyModuleDef> =
63 crate::stdlib::builtin_module_defs(&ctx)
64 .into_iter()
65 .chain(module_defs)
66 .map(|def| (def.name.as_str(), def))
67 .collect();
68
69 // Register sysconfigdata under platform-specific name as well
70 if let Some(&sysconfigdata_def) = all_module_defs.get("_sysconfigdata") {
71 use std::sync::OnceLock;
72 static SYSCONFIGDATA_NAME: OnceLock<&'static str> = OnceLock::new();
73 let leaked_name = *SYSCONFIGDATA_NAME.get_or_init(|| {
74 let name = crate::stdlib::sys::sysconfigdata_name();
75 Box::leak(name.into_boxed_str())
76 });
77 all_module_defs.insert(leaked_name, sysconfigdata_def);
78 }
79
80 // Create hash secret
81 let seed = match config.settings.hash_seed {
82 Some(seed) => seed,
83 None => super::process_hash_secret_seed(),
84 };
85 let hash_secret = HashSecret::new(seed);
86
87 // Create codec registry and warnings state
88 let codec_registry = CodecsRegistry::new(&ctx);
89 let warnings = WarningsState::init_state(&ctx);
90
91 // Create int_max_str_digits
92 let int_max_str_digits = AtomicCell::new(match config.settings.int_max_str_digits {
93 -1 => 4300,
94 other => other,
95 } as usize);
96
97 // Initialize frozen modules (core + user-provided)

Callers 2

buildMethod · 0.85
with_initMethod · 0.85

Calls 15

init_path_configFunction · 0.85
newFunction · 0.85
builtin_module_defsFunction · 0.85
sysconfigdata_nameFunction · 0.85
leakFunction · 0.85
process_hash_secret_seedFunction · 0.85
core_frozen_initsFunction · 0.85
hookFunction · 0.85
collectMethod · 0.80
chainMethod · 0.80
initFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected