llgo/ssa: LoadPyModSyms

This commit is contained in:
xushiwei
2024-05-12 18:27:23 +08:00
parent aac5e7b3cd
commit 9ac0450255
10 changed files with 176 additions and 24 deletions

25
py/_pyg/module.c Normal file
View File

@@ -0,0 +1,25 @@
#include <stdlib.h>
#include <stdarg.h>
// example:
// llgoLoadPyModSyms(mod, "name1", &func1, "name2", &func2, NULL)
typedef struct PyObject PyObject;
PyObject* PyObject_GetAttrString(PyObject* mod, const char* attrName);
void llgoLoadPyModSyms(PyObject* mod, ...) {
va_list ap;
va_start(ap, mod);
for (;;) {
const char* name = va_arg(ap, const char*);
if (name == NULL) {
break;
}
PyObject** pfunc = va_arg(ap, PyObject**);
if (*pfunc == NULL) {
*pfunc = PyObject_GetAttrString(mod, name);
}
}
va_end(ap);
}