#include <math.h>
#include <stdio.h>
#include <assert.h>
#include "app.h"
extern void* dlopen(const char* filename, int flags);
extern void* dlsym(void* handle, const char* symbol);
#ifndef WASM_EXPORT
#define WASM_EXPORT(x) __attribute__((visibility("default"))) void* __WASM_EXPORT__##x() { return &(x);}
#endif
EXPORTED_SYMBOL
PyObject _Py_NoneStruct = {.thingy = 1};
WASM_EXPORT(_Py_NoneStruct)
EXPORTED_SYMBOL
int vecsum(int* v, int n) {
int s = 0;
for (int i = 0; i < n; i++) {
s += v[i];
}
return s;
}
EXPORTED_SYMBOL
int PyModuleDef_Init(struct PyModuleDef* module) {
printf("PyModuleDef_Init, module = %p \n", module);
PyCFunction f = (module->m_methods)[0].f;
printf("PyModuleDef_Init, hello = %p \n", f);
(*f)(NULL, NULL);
return 0;
}
typedef int (*INIT_FUNCTION)();
int main() {
printf("stdout=%d, &stdout=%p\n", stdout, &stdout);
printf("Running Tests...\n");
void* handle = dlopen("./hello.so", 2);
printf("Got handle=%p\n", handle);
assert(handle != NULL);
INIT_FUNCTION init = (INIT_FUNCTION)dlsym(handle, "PyInit_hello");
assert(init != NULL);
printf("Got init=%p\n", init);
printf("PyInit_hello() = %d\n", (*init)());
printf("All tests passed!\n");
}