[Bugfix] Embedded interpreter's filesystem encoding is ASCII: open() cannot read a UTF-8 file #378
Labels
No labels
Alpha Release Requirement
Bugfix
Demo Target
Documentation
Major Feature
Minor Feature
priority:tier1-active
priority:tier2-foundation
priority:tier3-future
priority:tier4-deferred
Refactoring & Cleanup
system:animation
system:documentation
system:grid
system:input
system:performance
system:procgen
system:python-binding
system:rendering
system:ui-hierarchy
Tiny Feature
workflow:blocked
workflow:needs-benchmark
workflow:needs-documentation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
john/McRogueFace#378
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
init_python_with_config()— the init pathmain.cppactually uses — does nopre-initialization at all. It never calls
Py_PreInitialize, soPyPreConfig.utf8_modeis never enabled and the filesystem encoding falls back toASCII:
The correct block already exists in the other init path,
init_python()(
McRFPy_API.cpp:969), which does setpreconfig.utf8_mode = 1. Only the live pathis missing it.
Impact — scoped precisely
open()with no explicitencoding=defaults to the filesystem encoding, so itcannot read a UTF-8 file:
Any script that reads a data file, a save file, or its own source with a non-ASCII
character in it fails. This is a real, user-facing defect: in any normal CPython 3,
open()defaults to UTF-8.What is NOT affected (verified, and this corrects the original text of this issue):
--execon a source file containing non-ASCII characters works fine. The C++ sidereads the file and hands the bytes to Python, which parses them as UTF-8 per PEP 3120.
A
°in a comment does not break--exec.The long-standing folklore that "
--execscripts must be ASCII-only" is thereforewrong on the mechanism, but it was pointing at something real — this.
How it was found
Running the 130 documentation snippets from mcrogueface.github.io as a candidate test
corpus. 126 passed outright. Three failures (
101_grid_camera_rotation.py,105_scenes_dict.py,124_sprite_rotation.py) turned out to be the harness trippingover this bug — it used
open(path).read()— not the snippets, which are fine. Betweenthem the offending characters are two
°and one•.Fix
Pre-initialize with
utf8_mode = 1ininit_python_with_config(), matching whatinit_python()already does.Acceptance
sys.getfilesystemencoding()reportsutf-8open()with noencoding=reads a UTF-8 file[Bugfix] Embedded interpreter's filesystem encoding is ASCII: a non-ASCII character in a script kills --execto [Bugfix] Embedded interpreter's filesystem encoding is ASCII: open() cannot read a UTF-8 file