Skip to content

Commit e3517a0

Browse files
committed
add ascii
1 parent d69583b commit e3517a0

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

.cspell.dict/python-more.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ PYTHONHASHSEED
178178
PYTHONHOME
179179
PYTHONINSPECT
180180
PYTHONINTMAXSTRDIGITS
181+
PYTHONIOENCODING
181182
PYTHONNODEBUGRANGES
182183
PYTHONNOUSERSITE
183184
PYTHONOPTIMIZE

crates/vm/src/vm/mod.rs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,28 @@ impl VirtualMachine {
261261
Ok(())
262262
}
263263

264-
fn import_utf8_encodings(&mut self) -> PyResult<()> {
264+
fn import_ascii_utf8_encodings(&mut self) -> PyResult<()> {
265265
import::import_frozen(self, "codecs")?;
266-
// FIXME: See corresponding part of `core_frozen_inits`
267-
// let encoding_module_name = if cfg!(feature = "freeze-stdlib") {
268-
// "encodings.utf_8"
269-
// } else {
270-
// "encodings_utf_8"
271-
// };
272-
let encoding_module_name = "encodings_utf_8";
273-
let encoding_module = import::import_frozen(self, encoding_module_name)?;
274-
let getregentry = encoding_module.get_attr("getregentry", self)?;
266+
267+
// Use dotted names when freeze-stdlib is enabled (modules come from Lib/encodings/),
268+
// otherwise use underscored names (modules come from core_modules/).
269+
let (ascii_module_name, utf8_module_name) = if cfg!(feature = "freeze-stdlib") {
270+
("encodings.ascii", "encodings.utf_8")
271+
} else {
272+
("encodings_ascii", "encodings_utf_8")
273+
};
274+
275+
// Register ascii encoding
276+
let ascii_module = import::import_frozen(self, ascii_module_name)?;
277+
let getregentry = ascii_module.get_attr("getregentry", self)?;
278+
let codec_info = getregentry.call((), self)?;
279+
self.state
280+
.codec_registry
281+
.register_manual("ascii", codec_info.try_into_value(self)?)?;
282+
283+
// Register utf-8 encoding
284+
let utf8_module = import::import_frozen(self, utf8_module_name)?;
285+
let getregentry = utf8_module.get_attr("getregentry", self)?;
275286
let codec_info = getregentry.call((), self)?;
276287
self.state
277288
.codec_registry
@@ -298,7 +309,7 @@ impl VirtualMachine {
298309
#[cfg(not(feature = "threading"))]
299310
import::import_frozen(self, "_thread")?;
300311
let importlib = import::init_importlib_base(self)?;
301-
self.import_utf8_encodings()?;
312+
self.import_ascii_utf8_encodings()?;
302313

303314
#[cfg(any(not(target_arch = "wasm32"), target_os = "wasi"))]
304315
{
@@ -1015,6 +1026,8 @@ pub fn resolve_frozen_alias(name: &str) -> &str {
10151026
match name {
10161027
"_frozen_importlib" => "importlib._bootstrap",
10171028
"_frozen_importlib_external" => "importlib._bootstrap_external",
1029+
"encodings_ascii" => "encodings.ascii",
1030+
"encodings_utf_8" => "encodings.utf_8",
10181031
_ => name,
10191032
}
10201033
}

0 commit comments

Comments
 (0)