执行 AGENTS align-linuxcnc 加速规则
结论:补强 WASM Python C API 可执行探针,依据 LinuxCNC src/emc/rs274ngc/gcodemodule.cc、interpmodule.cc 和 py*.cc 对 PyObject_New、Py_TYPE、Py_None、PyList_Type 等 Python C API 的绑定用法。验证通过:./test-linuxcnc-wasm-python-c-api-symbols.sh、./test-native.sh、./test-linuxcnc-source-link.sh。
This commit is contained in:
73
core/wasm_shims/python_c_api_probe_main.cc
Normal file
73
core/wasm_shims/python_c_api_probe_main.cc
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "boost/python/object.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
// LinuxCNC source basis: src/emc/rs274ngc/gcodemodule.cc,
|
||||
// interpmodule.cc, and py*.cc use these Python C API entry points while
|
||||
// defining RS274 Python binding objects. The WASM shim keeps the API inert
|
||||
// and link-safe while browser Python execution remains disabled.
|
||||
namespace {
|
||||
|
||||
struct ProbeObject {
|
||||
PyObject_HEAD
|
||||
int value;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int main() {
|
||||
if (Py_IsInitialized() != 1) {
|
||||
return 1;
|
||||
}
|
||||
if (PyErr_Occurred() != nullptr) {
|
||||
return 2;
|
||||
}
|
||||
PyObject *exc = reinterpret_cast<PyObject *>(1);
|
||||
PyObject *val = reinterpret_cast<PyObject *>(1);
|
||||
PyObject *tb = reinterpret_cast<PyObject *>(1);
|
||||
PyErr_Fetch(&exc, &val, &tb);
|
||||
if (exc || val || tb) {
|
||||
return 3;
|
||||
}
|
||||
if (!Py_None || !Py_TYPE(Py_None) || std::strcmp(Py_TYPE(Py_None)->tp_name, "NoneType") != 0) {
|
||||
return 4;
|
||||
}
|
||||
if (PyUnicode_FromString("linuxcnc") != Py_None) {
|
||||
return 5;
|
||||
}
|
||||
if (std::strcmp(PyUnicode_AsUTF8(Py_None), "") != 0) {
|
||||
return 6;
|
||||
}
|
||||
if (PyLong_FromLong(7) != Py_None || PyLong_AsLong(Py_None) != 0) {
|
||||
return 7;
|
||||
}
|
||||
if (PyFloat_AsDouble(Py_None) != 0.0) {
|
||||
return 8;
|
||||
}
|
||||
if (PyTuple_New(2) != Py_None || PyTuple_SetItem(Py_None, 0, Py_None) != 0 || PyTuple_Size(Py_None) != 0) {
|
||||
return 9;
|
||||
}
|
||||
if (PyList_New(2) != Py_None || PyList_SetItem(Py_None, 0, Py_None) != 0 || PyList_Size(Py_None) != 0) {
|
||||
return 10;
|
||||
}
|
||||
if (PyObject_IsTrue(Py_None) != 0 || PyCallable_Check(Py_None) != 0 || PyObject_IsInstance(Py_None, Py_None) != 0) {
|
||||
return 11;
|
||||
}
|
||||
ProbeObject *probe = PyObject_New(ProbeObject, &PyList_Type);
|
||||
if (!probe || Py_TYPE(reinterpret_cast<PyObject *>(probe)) != &PyList_Type) {
|
||||
std::free(probe);
|
||||
return 12;
|
||||
}
|
||||
std::free(probe);
|
||||
if (PyModule_Create(nullptr) != Py_None || PyModule_AddObject(Py_None, "value", Py_None) != 0) {
|
||||
return 13;
|
||||
}
|
||||
if (PyType_Ready(&PyList_Type) != 0 || PyType_GenericNew(&PyList_Type, Py_None, Py_None) != Py_None) {
|
||||
return 14;
|
||||
}
|
||||
if (PyErr_Format(PyExc_TypeError, "linuxcnc") != nullptr) {
|
||||
return 15;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user