Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/python-wasm
Path: blob/main/core/dylink/test/wasi/dynamic-library.c
1393 views
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <string.h>
4
//#include <assert.h>
5
#include "app.h"
6
7
static int x = 388;
8
int y = 1;
9
10
EXPORTED_SYMBOL
11
PyObject* pynone_b() { return PyNone; }
12
13
EXPORTED_SYMBOL
14
int add10(const int a) { return a + 10; }
15
16
EXPORTED_SYMBOL
17
FUN_PTR pointer_to_add10() { return &add10; }
18
19
EXPORTED_SYMBOL
20
int add389(const int a) { return a + x + y; }
21
22
// This illustrates calling a function that is
23
// defined in the main app.c.
24
extern int add5077(int a);
25
26
EXPORTED_SYMBOL
27
int add5077_using_func_from_main(int a) {
28
// This uses WASI!
29
printf("Print from dynamic-library! add5077_using_func_from_main a=%d\n", a);
30
void* mem = malloc(32);
31
printf("I got some memory here: %p\n", mem);
32
free(mem);
33
int n = add5077(a - strlen("four") + 4);
34
// doesn't work due to issue with __assert_fail not being defined:
35
// assert(n == a + 5077);
36
return n;
37
}
38