port(2P step 2): ScriptLib/PythonLauncher on the embedded interpreter

Link mtpython into port_logic and copy 40250's ScriptLib launcher across:
PythonLauncher, PythonUtils and PythonMarshal, plus the 12 forwarding headers
that make its `#include <Python-2.7/*>` lines compile unchanged. symtable.h
forward-declares mod_ty rather than including Python-ast.h, whose one-word
macros (Delete, Module, Set, Print) collide with EterLib/Pool.h — the same
clash 40250 sidestepped by commenting out PySymtable_Build.

Two `// PORT:` edits: `unsigned char(val)` is an MSVC extension (PythonUtils.cpp,
twice), and PyObject_AsCharBuffer wants a Py_ssize_t* (TraceFunc).

port_python_launcher_test drives the launcher in the order UserInterface.cpp
does (:241-434): Create(), __DEBUG__/__COMMAND_LINE__, TRUE/FALSE, a CRLF script
through RunMemoryTextFile, a .pyc through RunCompiledFile, then RunFile reading
system.py out of the real pack. It stops at `ImportError: No module named app`,
i.e. the first C++ module RunMainScript registers — that is the 2V0 slice, and
the stdlib behind it is step 3. The host flags (Py_NoSiteFlag and friends) sit
in the test for now; step 3 moves them into the platform layer.

port-map statuses are set only for what the test actually executes: 10 of 12
launcher functions and 4 of 11 marshal ones (the small-.pyc path delegates to
CPython's own reader, so the ported r_object stays unreached). PythonUtils
compiles but nothing calls it until the binding modules arrive, so it stays TODO.

Windows has no mtpython yet, so port_logic drops ScriptLib and the shims there.

Tests: macOS ctest 27/27 incl. port.python_launcher; port_logic (with ScriptLib)
also compiles for android arm64 (NDK API 24) and ios arm64.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-23 08:54:48 +09:00
co-authored by Claude Opus 5
parent 5fad769ee8
commit 43bb561551
28 changed files with 1879 additions and 8 deletions
@@ -0,0 +1,84 @@
{
"reference": "ScriptLib/PythonLauncher.cpp",
"reference_sha256": "3dbaccfb21153cbbf201c2fe7252063455f6b9a9c79c1c55f9d03e8573bf65c8",
"priority": "P4",
"contracts": [],
"functions": {
"CPythonLauncher::CPythonLauncher": {
"impl": [
"extension/src/port/ScriptLib/PythonLauncher.cpp:CPythonLauncher::CPythonLauncher"
],
"status": "PORTED",
"test": "extension/tests/port_python_launcher_test.cpp (port.python_launcher)"
},
"CPythonLauncher::~CPythonLauncher": {
"impl": [
"extension/src/port/ScriptLib/PythonLauncher.cpp:CPythonLauncher::~CPythonLauncher"
],
"status": "PORTED",
"test": "extension/tests/port_python_launcher_test.cpp (port.python_launcher)"
},
"CPythonLauncher::Clear": {
"impl": [
"extension/src/port/ScriptLib/PythonLauncher.cpp:CPythonLauncher::Clear"
],
"status": "PORTED",
"test": "extension/tests/port_python_launcher_test.cpp (port.python_launcher)"
},
"Traceback": {
"impl": [
"extension/src/port/ScriptLib/PythonLauncher.cpp:Traceback"
],
"status": "PORTED",
"test": "extension/tests/port_python_launcher_test.cpp (port.python_launcher)"
},
"TraceFunc": {
"status": "TODO"
},
"CPythonLauncher::SetTraceFunc": {
"status": "TODO"
},
"CPythonLauncher::Create": {
"impl": [
"extension/src/port/ScriptLib/PythonLauncher.cpp:CPythonLauncher::Create"
],
"status": "PORTED",
"test": "extension/tests/port_python_launcher_test.cpp (port.python_launcher)"
},
"CPythonLauncher::RunCompiledFile": {
"impl": [
"extension/src/port/ScriptLib/PythonLauncher.cpp:CPythonLauncher::RunCompiledFile"
],
"status": "PORTED",
"test": "extension/tests/port_python_launcher_test.cpp (port.python_launcher)"
},
"CPythonLauncher::RunMemoryTextFile": {
"impl": [
"extension/src/port/ScriptLib/PythonLauncher.cpp:CPythonLauncher::RunMemoryTextFile"
],
"status": "PORTED",
"test": "extension/tests/port_python_launcher_test.cpp (port.python_launcher)"
},
"CPythonLauncher::RunFile": {
"impl": [
"extension/src/port/ScriptLib/PythonLauncher.cpp:CPythonLauncher::RunFile"
],
"status": "PORTED",
"test": "extension/tests/port_python_launcher_test.cpp (port.python_launcher)"
},
"CPythonLauncher::RunLine": {
"impl": [
"extension/src/port/ScriptLib/PythonLauncher.cpp:CPythonLauncher::RunLine"
],
"status": "PORTED",
"test": "extension/tests/port_python_launcher_test.cpp (port.python_launcher)"
},
"CPythonLauncher::GetError": {
"impl": [
"extension/src/port/ScriptLib/PythonLauncher.cpp:CPythonLauncher::GetError"
],
"status": "PORTED",
"test": "extension/tests/port_python_launcher_test.cpp (port.python_launcher)"
}
}
}