From 6d99ca67a966918dd8065bcc175cc2f5ddf24fc3 Mon Sep 17 00:00:00 2001 From: cnc Date: Fri, 5 Jun 2026 07:50:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=BD=E5=BF=AB=E6=8E=A8=E8=BF=9B=EF=BC=9A?= =?UTF-8?q?=E6=94=B6=E7=B4=A7PythonPlugin=E7=A6=81=E7=94=A8=E8=BE=B9?= =?UTF-8?q?=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 initialize() 负状态语义,WASM安全shim在Python不可用时返回PLUGIN_PYTHON_NOT_INITIALIZED并保持负状态短路;未实现Python/remap执行,未扩展smoke parser。 --- core/wasm_shims/pythonplugin/python_plugin.cc | 9 ++++--- .../pythonplugin/python_plugin_probe_main.cc | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/core/wasm_shims/pythonplugin/python_plugin.cc b/core/wasm_shims/pythonplugin/python_plugin.cc index 65c559c..72b9ddc 100644 --- a/core/wasm_shims/pythonplugin/python_plugin.cc +++ b/core/wasm_shims/pythonplugin/python_plugin.cc @@ -42,8 +42,7 @@ int PythonPlugin::configure(const char *iniFilename, const char *section) { } std::fclose(file); - status = PLUGIN_OK; - return status; + return initialize(); } bool PythonPlugin::is_callable(const char *, const char *) { @@ -86,6 +85,10 @@ int PythonPlugin::call_method(boost::python::object, boost::python::object &retv } int PythonPlugin::initialize() { - status = PLUGIN_OK; + // LinuxCNC source basis: src/emc/pythonplugin/python_plugin.cc sets + // PLUGIN_PYTHON_NOT_INITIALIZED when initialize() runs without an active + // Python runtime. Browser-safe probes keep Python execution disabled. + error_msg = "python disabled in wasm-safe probe"; + status = PLUGIN_PYTHON_NOT_INITIALIZED; return status; } diff --git a/core/wasm_shims/pythonplugin/python_plugin_probe_main.cc b/core/wasm_shims/pythonplugin/python_plugin_probe_main.cc index 72fb00c..119f99e 100644 --- a/core/wasm_shims/pythonplugin/python_plugin_probe_main.cc +++ b/core/wasm_shims/pythonplugin/python_plugin_probe_main.cc @@ -1,5 +1,7 @@ #include "pythonplugin/python_plugin.hh" +#include + // LinuxCNC source basis: src/emc/pythonplugin/python_plugin.cc and // python_plugin.hh define the PythonPlugin API exercised by this link probe. int main() { @@ -26,6 +28,29 @@ int main() { if (plugin->run_string("noop", retval, false) != PLUGIN_OK) { return 3; } + const char *ini = "/tmp/cnc_sim_python_plugin_probe.ini"; + { + FILE *file = std::fopen(ini, "w"); + if (!file) { + return 16; + } + std::fputs("[PYTHON]\n", file); + std::fclose(file); + } + if (plugin->configure(ini, "PYTHON") != PLUGIN_PYTHON_NOT_INITIALIZED) { + std::remove(ini); + return 17; + } + std::remove(ini); + if (plugin->call(nullptr, "noop", boost::python::object(), boost::python::object(), retval) != PLUGIN_PYTHON_NOT_INITIALIZED) { + return 18; + } + if (plugin->call_method(boost::python::object(), retval) != PLUGIN_PYTHON_NOT_INITIALIZED) { + return 19; + } + if (plugin->run_string("noop", retval, false) != PLUGIN_OK) { + return 20; + } if (plugin->call(nullptr, nullptr, boost::python::object(), boost::python::object(), retval) != PLUGIN_NO_CALLABLE) { return 8; }