尽快推进:收紧Python C API shim源码锚点

This commit is contained in:
cnc
2026-06-05 09:38:13 +08:00
parent 9b9e942dd6
commit 440a61be32
2 changed files with 50 additions and 5 deletions

View File

@@ -102,6 +102,28 @@ grep -F 'retval = bp::exec(cmd, main_namespace, main_namespace);' \
"$linuxcnc_root/src/emc/pythonplugin/python_plugin.cc" >/dev/null "$linuxcnc_root/src/emc/pythonplugin/python_plugin.cc" >/dev/null
grep -F 'PyObject *rv = PyObject_Call(function.ptr(), tupleargs.ptr(), kwargs.ptr());' \ grep -F 'PyObject *rv = PyObject_Call(function.ptr(), tupleargs.ptr(), kwargs.ptr());' \
"$linuxcnc_root/src/emc/pythonplugin/python_plugin.cc" >/dev/null "$linuxcnc_root/src/emc/pythonplugin/python_plugin.cc" >/dev/null
grep -F 'PyErr_Fetch(&exc,&val,&tb);' \
"$linuxcnc_root/src/emc/rs274ngc/interp_python.cc" >/dev/null
grep -F 'PyErr_NormalizeException(&exc,&val,&tb);' \
"$linuxcnc_root/src/emc/rs274ngc/interp_python.cc" >/dev/null
grep -F 'if (Py_IsInitialized()) {' \
"$linuxcnc_root/src/emc/pythonplugin/python_plugin.cc" >/dev/null
grep -F '#define callmethod(o, m, f, ...) PyObject_CallMethod((o), (char*)(m), (char*)(f), ## __VA_ARGS__)' \
"$linuxcnc_root/src/emc/rs274ngc/gcodemodule.cc" >/dev/null
grep -F 'PyObject *result = PyObject_GetAttrString(callback, "parameter_file");' \
"$linuxcnc_root/src/emc/rs274ngc/gcodemodule.cc" >/dev/null
grep -F 'PyErr_Format(PyExc_TypeError,' \
"$linuxcnc_root/src/emc/rs274ngc/gcodemodule.cc" >/dev/null
grep -F 'return Py_BuildValue("[ddd][ddd][ddd][ddd]",' \
"$linuxcnc_root/src/emc/rs274ngc/gcodemodule.cc" >/dev/null
grep -F 'PyObject *m = PyModule_Create(&gcode_moduledef);' \
"$linuxcnc_root/src/emc/rs274ngc/gcodemodule.cc" >/dev/null
grep -F 'PyType_Ready(&LineCodeType);' \
"$linuxcnc_root/src/emc/rs274ngc/gcodemodule.cc" >/dev/null
grep -F 'PyModule_AddObject(m, "linecode", (PyObject*)&LineCodeType);' \
"$linuxcnc_root/src/emc/rs274ngc/gcodemodule.cc" >/dev/null
grep -F 'PyObject_SetAttrString(m, "MAX_ERROR", PyLong_FromLong(maxerror));' \
"$linuxcnc_root/src/emc/rs274ngc/gcodemodule.cc" >/dev/null
grep -F '#define TOOL_MMAP_FILENAME ".tool.mmap"' "$linuxcnc_root/src/emc/tooldata/tooldata_mmap.cc" >/dev/null grep -F '#define TOOL_MMAP_FILENAME ".tool.mmap"' "$linuxcnc_root/src/emc/tooldata/tooldata_mmap.cc" >/dev/null
grep -F 'int tool_nml_register(CANON_TOOL_TABLE *tblptr)' "$linuxcnc_root/src/emc/tooldata/tooldata_nml.cc" >/dev/null grep -F 'int tool_nml_register(CANON_TOOL_TABLE *tblptr)' "$linuxcnc_root/src/emc/tooldata/tooldata_nml.cc" >/dev/null
grep -F 'int tooldata_db_init(char progname_plus_args[]' "$linuxcnc_root/src/emc/tooldata/tooldata_db.cc" >/dev/null grep -F 'int tooldata_db_init(char progname_plus_args[]' "$linuxcnc_root/src/emc/tooldata/tooldata_db.cc" >/dev/null
@@ -313,11 +335,28 @@ for needle in [
if needle not in python_plugin_probe: if needle not in python_plugin_probe:
raise SystemExit(f"PythonPlugin probe missing disabled-python status assertion: {needle}") raise SystemExit(f"PythonPlugin probe missing disabled-python status assertion: {needle}")
for needle in [ for needle in [
"Py_IsInitialized", "static PyTypeObject none_type = {\"NoneType\"};",
"PyObject_CallMethod", "static PyObject none_object = {&none_type};",
"Py_BuildValue", "PyObject *_Py_NoneStructPtr = &none_object;",
"PyModule_Create", "int Py_IsInitialized(void)",
"PyType_Ready", "return 1;",
"PyObject *PyErr_Occurred(void)",
"return nullptr;",
"void PyErr_Fetch(PyObject **exc, PyObject **val, PyObject **tb)",
"*exc = nullptr;",
"*val = nullptr;",
"*tb = nullptr;",
"int PyCallable_Check(PyObject *)",
"return 0;",
"PyObject *PyObject_CallMethod(PyObject *, char *, char *, ...)",
"PyObject *PyObject_GetAttrString(PyObject *, const char *)",
"return &none_object;",
"PyObject *Py_BuildValue(const char *, ...)",
"PyObject *PyModule_Create(PyModuleDef *)",
"int PyModule_AddObject(PyObject *, const char *, PyObject *)",
"int PyType_Ready(PyTypeObject *)",
"void *PyObject_NewShim(std::size_t size, PyTypeObject *type)",
"std::calloc(1, size)",
]: ]:
if needle not in python_c_api_shim: if needle not in python_c_api_shim:
raise SystemExit(f"Python C API shim missing symbol boundary: {needle}") raise SystemExit(f"Python C API shim missing symbol boundary: {needle}")
@@ -362,6 +401,8 @@ for phrase in [
"`wordfree()` cleanup", "`wordfree()` cleanup",
"must not become a shell expansion feature", "must not become a shell expansion feature",
"must not become Python execution", "must not become Python execution",
"Python C API shim must return inert objects",
"must not call into CPython runtime",
"keeping Python execution disabled", "keeping Python execution disabled",
"must not execute `bp::exec`, `bp::exec_file`, or", "must not execute `bp::exec`, `bp::exec_file`, or",
"inactive-DB return values", "inactive-DB return values",

View File

@@ -55,6 +55,10 @@ only; it must not add CNC behavior and must not expand the temporary smoke parse
- `core/wasm_shims/python_c_api_shim.cc` satisfies Python C API symbols used by - `core/wasm_shims/python_c_api_shim.cc` satisfies Python C API symbols used by
LinuxCNC RS274/remap sources; it must not become Python execution. LinuxCNC RS274/remap sources; it must not become Python execution.
- The Python C API shim must return inert objects, null exceptions, false
callable/type checks, and successful module/type registration statuses only
to satisfy LinuxCNC `interp_python.cc`, `gcodemodule.cc`, and
`python_plugin.cc` link expectations; it must not call into CPython runtime.
- `core/wasm_shims/pythonplugin/python_plugin.cc` must preserve LinuxCNC - `core/wasm_shims/pythonplugin/python_plugin.cc` must preserve LinuxCNC
`PythonPlugin` status edges for `PLUGIN_NO_SECTION`, `PLUGIN_BAD_INIFILE`, `PythonPlugin` status edges for `PLUGIN_NO_SECTION`, `PLUGIN_BAD_INIFILE`,
`PLUGIN_PYTHON_NOT_INITIALIZED`, `PLUGIN_NO_CALLABLE`, and `PLUGIN_PYTHON_NOT_INITIALIZED`, `PLUGIN_NO_CALLABLE`, and