From 42e5b0784def554447e9fb7014f19d03cdadc29f Mon Sep 17 00:00:00 2001 From: cnc Date: Sat, 6 Jun 2026 12:53:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E6=BA=90=E9=AA=8C=E8=AF=81Python?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E8=B7=AF=E5=BE=84=E8=8A=82=E8=BE=B9=E7=95=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 源依据:LinuxCNC src/emc/pythonplugin/python_plugin.cc 的 configure() 按调用方 section 查找 TOPLEVEL,但 PATH_APPEND 固定从 PYTHON section 逐项读取并在 tilde expansion 失败时返回 PLUGIN_EXCEPTION_DURING_PATH_APPEND。 结论:wasm-safe python_plugin standalone probe 增加 REMAP/PYTHON section 分离边界,确认禁用 Python 时仍保留 LinuxCNC 的 INI 查找顺序和失败状态,不引入浏览器端 Python 执行。 检查:./test-linuxcnc-wasm-python-plugin-link.sh;./test-native.sh;./test-linuxcnc-source-link.sh。 --- .../pythonplugin/python_plugin_probe_main.cc | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/core/wasm_shims/pythonplugin/python_plugin_probe_main.cc b/core/wasm_shims/pythonplugin/python_plugin_probe_main.cc index 34ea018..4afa074 100644 --- a/core/wasm_shims/pythonplugin/python_plugin_probe_main.cc +++ b/core/wasm_shims/pythonplugin/python_plugin_probe_main.cc @@ -198,6 +198,44 @@ int main() { setenv("HOME", saved_home_value.c_str(), 1); } std::remove(path_append_ini); + const char *section_path_append_ini = "/tmp/cnc_sim_python_plugin_probe_section_path_append.ini"; + { + FILE *file = std::fopen(section_path_append_ini, "w"); + if (!file) { + std::remove(ini); + return 50; + } + std::fputs("[REMAP]\n" + "[PYTHON]\nTOPLEVEL = /tmp/cnc_sim_missing_python_section_toplevel.py\n" + "PATH_APPEND = ~/linuxcnc-python\n", + file); + std::fclose(file); + } + unsetenv("HOME"); + // LinuxCNC source basis: python_plugin.cc configure() looks up TOPLEVEL in + // the caller-provided section, but PATH_APPEND entries are read from the + // fixed PYTHON section before initialize(); a PYTHON TOPLEVEL is ignored + // when the caller configures a different section. + if (plugin->configure(section_path_append_ini, "REMAP") != PLUGIN_EXCEPTION_DURING_PATH_APPEND) { + if (saved_home) { + setenv("HOME", saved_home_value.c_str(), 1); + } + std::remove(ini); + std::remove(section_path_append_ini); + return 51; + } + if (plugin->last_errmsg() != "bad path append") { + if (saved_home) { + setenv("HOME", saved_home_value.c_str(), 1); + } + std::remove(ini); + std::remove(section_path_append_ini); + return 52; + } + if (saved_home) { + setenv("HOME", saved_home_value.c_str(), 1); + } + std::remove(section_path_append_ini); const char *plain_path_ini = "/tmp/cnc_sim_python_plugin_probe_plain_path.ini"; { FILE *file = std::fopen(plain_path_ini, "w");