diff --git a/check-linuxcnc-wasm-shims-source-map.sh b/check-linuxcnc-wasm-shims-source-map.sh index fd38b42..b1f54c3 100755 --- a/check-linuxcnc-wasm-shims-source-map.sh +++ b/check-linuxcnc-wasm-shims-source-map.sh @@ -102,6 +102,28 @@ grep -F 'retval = bp::exec(cmd, main_namespace, main_namespace);' \ "$linuxcnc_root/src/emc/pythonplugin/python_plugin.cc" >/dev/null grep -F 'PyObject *rv = PyObject_Call(function.ptr(), tupleargs.ptr(), kwargs.ptr());' \ "$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 '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 @@ -313,11 +335,28 @@ for needle in [ if needle not in python_plugin_probe: raise SystemExit(f"PythonPlugin probe missing disabled-python status assertion: {needle}") for needle in [ - "Py_IsInitialized", - "PyObject_CallMethod", - "Py_BuildValue", - "PyModule_Create", - "PyType_Ready", + "static PyTypeObject none_type = {\"NoneType\"};", + "static PyObject none_object = {&none_type};", + "PyObject *_Py_NoneStructPtr = &none_object;", + "int Py_IsInitialized(void)", + "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: raise SystemExit(f"Python C API shim missing symbol boundary: {needle}") @@ -362,6 +401,8 @@ for phrase in [ "`wordfree()` cleanup", "must not become a shell expansion feature", "must not become Python execution", + "Python C API shim must return inert objects", + "must not call into CPython runtime", "keeping Python execution disabled", "must not execute `bp::exec`, `bp::exec_file`, or", "inactive-DB return values", diff --git a/docs/linuxcnc-wasm-shims-source-map.md b/docs/linuxcnc-wasm-shims-source-map.md index bab4b27..0ad52e4 100644 --- a/docs/linuxcnc-wasm-shims-source-map.md +++ b/docs/linuxcnc-wasm-shims-source-map.md @@ -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 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 `PythonPlugin` status edges for `PLUGIN_NO_SECTION`, `PLUGIN_BAD_INIFILE`, `PLUGIN_PYTHON_NOT_INITIALIZED`, `PLUGIN_NO_CALLABLE`, and