summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 11:19:16 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-07-24 09:53:24 +0000
commitb5f8ee61a7f7e9bd291dd26b0585d03eb686c941 (patch)
treed4d31289c39fc00da064a825df13a0b98ce95b10 /fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api
parentAdding upstream version 1.44.3. (diff)
downloadnetdata-b5f8ee61a7f7e9bd291dd26b0585d03eb686c941.tar.xz
netdata-b5f8ee61a7f7e9bd291dd26b0585d03eb686c941.zip
Adding upstream version 1.46.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api')
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/README.md7
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/design.md708
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/images/python_package_life_cycle.pngbin76811 -> 0 bytes
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/setup_dev_env.md12
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/requirements.txt5
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello.wat4
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_oop.py41
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_procedural.py93
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/__init__.py7
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/context.py13
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_advanced.py525
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_basic.py1590
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/utils/bindgen.py386
13 files changed, 0 insertions, 3391 deletions
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/README.md b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/README.md
deleted file mode 100644
index 1684afa5c..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
-# WASM-C-API
-
-## Examples
-
-There is a [simple example](./samples/hello_procedural.py) to show how to use bindings. Actually, the python binding follows C-APIs. There it should be easy if be familiar with _programming with wasm-c-api_.
-
-Unit test cases under _./tests_ could be another but more complete references.
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/design.md b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/design.md
deleted file mode 100644
index 6c3bc9168..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/design.md
+++ /dev/null
@@ -1,708 +0,0 @@
-# how to implement a python binding of WAMR
-
-A python language binding of Wasm runtime allows its users to call a set of APIs of
-the runtime from the python world. Those APIs maybe implemented in C, C++, or Rust.
-
-In the WAMR case, a python binding allows APIs in `core/iwasm/include/wasm_c_api.h`
-to be used in the python scripts. To achieve that, we will create two kinds
-of stuff: wrappers of structured data types and wrappers of functions under the
-help of _ctypes_.
-
-Cyptes is a tool in the standard library for creating Python bindings. It
-provides a low-level toolset for loading shared libraries and marshaling
-data between Python and C. Other options include _cffi_, _pybind11_,
-_cpython_ and so on. Because we tend to make the binding depending on least
-items. The built-in module, _ctypes_, is a good choice.
-
-## General rules to marshal
-
-The core of the idea of a language binding is how to translate different
-representations of types in different language.
-
-### load libraries
-
-The `ctypes` supports locating a dynamic link library in a way similar to the
-compiler does.
-
-Currently, `ctypes.LoadLibrary` supports:
-
-- `CDLL`. Those libraries use the standard C calling conversion.
-- `OleDLL` and `WinDLL`. Those libraries use the `stdcall` calling conversion on
- Windows only
-
-### fundamental datatypes
-
-_ctypes_ provides [primitive C compatiable data types](https://docs.python.org/3/library/ctypes.html#fundamental-data-types).
-Like `c_bool`, `c_byte`, `c_int`, `c_long` and so on.
-
-> `c_int` represents the _C_ `signed int` datatype. On platforms where
-> `sizeof(int) == sizeof(long)` it is an alias to `c_long`.
-
-| c datatypes | ctypes |
-| ------------------- | ----------------------- |
-| bool | c_bool |
-| byte_t | c_ubyte |
-| char | c_char |
-| float32_t | c_float |
-| float64_t | c_double |
-| int32_t | c_int32 |
-| int64_t | c_int64 |
-| intptr_t | c_void_p |
-| size_t | c_size_t |
-| uint8_t | c_uint8 |
-| uint32_t | c_uint32 |
-| void | None |
-| wasm_byte_t | c_ubyte |
-| wasm_externkind_t | c_uint8 |
-| wasm_memory_pages_t | c_uint32 |
-| wasm_mutability_t | c_bool |
-| wasm_table_size_t | c_uint32 |
-| wasm_valkind_t | c_uint8 |
-| wasm_data_type\* | POINTER(wasm_data_type) |
-
-- `c_void_p` only represents `void *` only
-- `None` represents `void` in function parameter lists and return lists
-
-### structured datatypes
-
-Create a corresponding concept for every native structured data type includes
-`enum`, `struct` and `union`, in the python world.
-
-#### Enum types
-
-For example, if there is a `enum wams_mutability_enum` in native.
-
-```c
-typedef uint8_t wams_mutability_t;
-enum wams_mutability_enum {
- WASM_CONST,
- WASM_VAR
-};
-```
-
-Use `ctypes.int`(or any integer types in ctypes) to represents its value directly.
-
-```python
-# represents enum wams_mutability_enum
-wasm_mutability_t = c_uint8
-
-WASM_CONST = 0
-WASM_VAR = 1
-```
-
-> C standard only requires "Each enumerated type shall be compatible with char,
-> a signed integer type, or an unsigned integer type. The choice of the integer
-> type is implementation-defined, but shall be capable of representing the
-> values of all the members of the enumeration.
-
-#### Struct types
-
-If there is a `struct wasm_byte_vec_t` in native(in C).
-
-```c
-typedef struct wasm_byte_vec_t {
- size_t size;
- wasm_byte_t *data;
- size_t num_elems;
- size_t size_of_elem;
-} wasm_byte_vec_t;
-```
-
-Use `ctypes.Structure` to create its corresponding data type in python.
-
-```python
-class wasm_byte_vec_t(ctypes.Structure):
- _fileds_ = [
- ("size", ctypes.c_size_t),
- ("data", ctypes.POINTER(c_ubyte)),
- ("num_elems", ctypes.c_size_t),
- ("size_of_elem", ctypes.c_size_t),
- ]
-```
-
-a list of `Structures`
-
-| name |
-| ----------------- |
-| wasm_engine_t |
-| wasm_store_t |
-| wasm_limits_t |
-| wasm_valtype_t |
-| wasm_functype_t |
-| wasm_globaltype_t |
-| wasm_tabletype_t |
-| wasm_memorytype_t |
-| wasm_externtype_t |
-| wasm_importtype_t |
-| wasm_exporttype_t |
-| wasm_ref_t |
-| wasm_ref_t |
-| wasm_frame_t |
-| wasm_trap_t |
-| wasm_foreign_t |
-| WASMModuleCommon |
-| WASMModuleCommon |
-| wasm_func_t |
-| wasm_global_t |
-| wasm_table_t |
-| wasm_memory_t |
-| wasm_extern_t |
-| wasm_instance_t |
-
-not supported `struct`
-
-- wasm_config_t
-
-If there is an anonymous `union` in native.
-
-```c
-typedef struct wasm_val_t {
- wasm_valkind_t kind;
- union {
- int32_t i32;
- int64_t i64;
- float32_t f32;
- float64_t f64;
- } of;
-} wasm_val_t;
-```
-
-Use `ctypes.Union` to create its corresponding data type in python.
-
-```python
-class _OF(ctypes.Union):
- _fields_ = [
- ("i32", ctypes.c_int32),
- ("i64", ctypes.c_int64),
- ("f32", ctypes.c_float),
- ("f64", ctypes.c_double),
- ]
-
-class wasm_val_t(ctypes.Structure):
- _anonymous_ = ("of",)
- _fields_ = [
- ("kind", ctypes.c_uint8)
- ("of", _OF)
- ]
-```
-
-### wrappers of functions
-
-Foreign functions (C functions) can be accessed as attributes of loaded shared
-libraries or an instance of function prototypes. Callback functions(python
-functions) can only be accessed by instantiating function prototypes.
-
-For example,
-
-```c
-void wasm_name_new(wasm_name_t* out, size_t len, wasm_byte_t [] data);
-```
-
-Assume there are:
-
-- `class wasm_name_t` of python represents `wasm_name_t` of C
-- `libiwasm` represents loaded _libiwasm.so_
-
-If to access a c function like an attribute,
-
-```python
-def wasm_name_new(out, len, data):
- _wasm_name_new = libiwasm.wasm_name_new
- _wasm_name_new.argtypes = (ctypes.POINTER(wasm_name_t), ctypes.c_size_t, ctypes.POINTER(ctypes.c_ubyte))
- _wasm_name_new.restype = None
- return _wasm_name_new(out, len, data)
-```
-
-Or to instantiate a function prototype,
-
-```python
-def wasm_name_new(out, len, data):
- return ctypes.CFUNCTYPE(None, (ctypes.POINTER(wasm_name_t), ctypes.c_size_t, ctypes.POINTER(ctypes.c_ubyte)))(
- ("wasm_name_new", libiwasm), out, len, data)
-```
-
-Now it is able to create a `wasm_name_t` with `wasm_name_new()` in python.
-
-Sometimes, need to create a python function as a callback of c.
-
-```c
-wasm_trap_t* (*wasm_func_callback_t)(wasm_val_vec_t* args, wasm_val_vec_t *results);
-```
-
-Use `cyptes.CFUNCTYPE` to create a _pointer of function_
-
-```python
-def hello(args, results):
- print("hello from a callback")
-
-wasm_func_callback_t = ctypes.CFUNCTYPE(c_size_t, POINTER(wasm_val_vec_t), POINTER(wasm_val_vec_t))
-hello_callback = wasm_func_callback_t(hello)
-```
-
-or with a decorator
-
-```python
-def wasm_func_cb_decl(func):
- return @ctypes.CFUNCTYPE(ctypes.POINTER(wasm_trap_t), (ctypes.POINTER(wasm_val_vec_t), ctypes.POINTER(wasm_val_vec_t)))(func)
-
-@wasm_func_cb_decl
-def hello(args, results):
- print("hello from a callback")
-```
-
-### programming tips
-
-#### `struct` and `ctypes.Structure`
-
-There are two kinds of `cytes.Structure` in `binding.py`.
-
-- has `__field__` definition. like `class wasm_byte_vec_t(Structure)`
-- doesn't have `__field__` definition. like `class wasm_config_t(Structure)`
-
-Since, `ctypes` will create its C world _mirror_ variable according to `__field__`
-information, `wasm_config_t()` will only create a python instance without binding
-to any C variable. `wasm_byte_vec_t()` will return a python instance with an internal
-C variable.
-
-That is why `pointer(wasm_config_t())` is a NULL pointer which can not be dereferenced.
-
-#### deal with pointers
-
-`byref()` and `pointer()` are two functions can return a pointer.
-
-```python
-x = ctypes.c_int(2)
-
-# use pointer() to creates a new pointer instance which would later be used in Python
-x_ptr = ctypes.pointer(x)
-...
-struct_use_pointer = Mystruct()
-struct_use_pointer.ptr = x_ptr
-
-# use byref() pass a pointer to an object to a foreign function call
-func(ctypes.byref(x))
-```
-
-The main difference is that `pointer()` does a lot more work since it
-constructs a real pointer object. It is faster to use `byref(`) if don't need
-the pointer object in Python itself(e.g. only use it as an argument to pass
-to a function).
-
-There is no doubt that `wasm_xxx_new()` which return type is `ctypes.POINTER`
-can return a pointer. Plus, the return value of `wasm_xxx_t()` can also be
-used as a pointer without casting by `byref` or `pointer`.
-
-#### array
-
-In [ctypes document](https://docs.python.org/3/library/ctypes.html#arrays),
-it states that "The recommended way to create array types is by multiplying a
-data type with a positive integer". So _multiplying a data type_ should be a
-better way to create arrays
-
-```python
-from ctypes import *
-
-class POINT(Structure):
- _fields_ = ("x", c_int), ("y", c_int)
-
-# multiplying a data type
-# type(TenPointsArrayType) is <class '_ctypes.PyCArrayType'>
-TenPointsArrayType = POINT * 10
-
-# Instances are created in the usual way, by calling the class:
-arr = TenPointsArrayType()
-arr[0] = POINT(3,2)
-for pt in arr:
- print(pt.x, pt.y)
-```
-
-On both sides, it is OK to assign an array to a pointer.
-
-```c
-char buf[128] = {0};
-char *ptr = buf;
-```
-
-```python
-binary = wasm_byte_vec_t()
-binary.data = (ctypes.c_ubyte * len(wasm)).from_buffer_copy(wasm)
-```
-
-#### exceptions and traps
-
-Interfaces of _wasm-c-api_ have their return values to represent failures.
-The python binding should just keep and transfer them to callers instead of
-raising any additional exception.
-
-The python binding should raise exceptions when the python partial is failed.
-
-#### readonly buffer
-
-```python
-with open("hello.wasm", "rb") as f:
- wasm = f.read()
- binary = wasm_byte_vec_t()
- wasm_byte_vec_new_uninitialized(byref(binary), len(wasm))
- # create a ctypes instance (byte[] in c) and copy the content
- # from wasm(bytearray in python)
- binary.data = (ctypes.c_ubyte * len(wasm)).from_buffer_copy(wasm)
-```
-
-in the above example, `wasm` is a python-created readable buffer. It is not
-writable and needs to be copied into a ctype array.
-
-#### variable arguments
-
-A function with _variable arugments_ makes it hard to specify the required
-argument types for the function prototype. It leaves us one way to call it
-directly without any arguments type checking.
-
-```python
-libc.printf(b"Hello, an int %d, a float %f, a string %s\n", c_int(1), c_doulbe(3.14), "World!")
-```
-
-#### Use `c_bool` to represent `wasm_mutability_t `
-
-- `True` for `WASM_CONST`
-- `False` for `WASM_VALUE`
-
-#### customize class builtins
-
-- `__eq__` for comparation.
-- `__repr__` for printing.
-
-### bindgen.py
-
-`bindge.py` is a tool to create WAMR python binding automatically. `binding.py`
-is generated. We should avoid modification on it. Additional helpers should go
-to `ffi.py`.
-
-`bindgen.py` uses _pycparser_. Visit the AST of `core/iwasm/include/wasm_c_api.h`
-created by _gcc_ and generate necessary wrappers.
-
-```python
-from pycparser import c_ast
-
-class Visitor(c_ast.NodeVisitor):
- def visit_Struct(self, node):
- pass
-
- def visit_Union(self, node):
- pass
-
- def visit_TypeDef(self, node):
- pass
-
- def visit_FuncDecl(self, node):
- pass
-
-ast = parse_file(...)
-v = Visitor()
-v.visit(ast)
-```
-
-Before running _bindgen.py_, the shared library _libiwasm.so_ should be generated.
-
-```bash
-$ cd /path/to/wamr/repo
-$ # if it is in linux
-$ pushd product-mini/platforms/linux/
-$ cmake -S . -B build ..
-$ cmake --build build --target iwasm
-$ popd
-$ cd binding/python
-$ python utils/bindgen.py
-```
-
-`wasm_frame_xxx` and `wasm_trap_xxx` only work well when enabling `WAMR_BUILD_DUMP_CALL_STACK`.
-
-```bash
-$ cmake -S . -B build -DWAMR_BUILD_DUMP_CALL_STACK=1 ..
-```
-
-## OOP wrappers
-
-Based on the above general rules, there will be corresponding python
-APIs for every C API in `wasm_c_api.h` with same name. Users can do procedural
-programming with those.
-
-In next phase, we will create OOP APIs. Almost follow the
-[C++ version of wasm_c_api](https://github.com/WebAssembly/wasm-c-api/blob/master/include/wasm.hh)
-
-## A big list
-
-| WASM Concept | Procedural APIs | OOP APIs | OOP APIs methods |
-| ------------ | ------------------------------ | ---------- | ---------------- |
-| XXX_vec | wasm_xxx_vec_new | | list |
-| | wasm_xxx_vec_new_uninitialized | | |
-| | wasm_xxx_vec_new_empty | | |
-| | wasm_xxx_vec_copy | | |
-| | wasm_xxx_vec_delete | | |
-| valtype | wasm_valtype_new | valtype | \_\_init\_\_ |
-| | wasm_valtype_delete | | \_\_del\_\_ |
-| | wasm_valtype_kind | | \_\_eq\_\_ |
-| | wasm_valtype_copy | | |
-| | _vector methods_ | | |
-| functype | wasm_functype_new | functype | |
-| | wasm_functype_delete | | |
-| | wasm_functype_params | | |
-| | wasm_functype_results | | |
-| | wasm_functype_copy | | |
-| | _vector methods_ | | |
-| globaltype | wasm_globaltype_new | globaltype | \_\_init\_\_ |
-| | wasm_globaltype_delete | | \_\_del\_\_ |
-| | wasm_globaltype_content | | \_\_eq\_\_ |
-| | wasm_globaltype_mutability | | |
-| | wasm_globaltype_copy | | |
-| | _vector methods_ | | |
-| tabletype | wasm_tabletype_new | tabletype | \_\_init\_\_ |
-| | wasm_tabletype_delete | | \_\_del\_\_ |
-| | wasm_tabletype_element | | \_\_eq\_\_ |
-| | wasm_tabletype_limits | | |
-| | wasm_tabletype_copy | | |
-| | _vector methods_ | | |
-| memorytype | wasm_memorytype_new | memorytype | \_\_init\_\_ |
-| | wasm_memorytype_delete | | \_\_del\_\_ |
-| | wasm_memorytype_limits | | \_\_eq\_\_ |
-| | wasm_memorytype_copy | | |
-| | _vector methods_ | | |
-| externtype | wasm_externtype_as_XXX | externtype | |
-| | wasm_XXX_as_externtype | | |
-| | wasm_externtype_copy | | |
-| | wasm_externtype_delete | | |
-| | wasm_externtype_kind | | |
-| | _vector methods_ | | |
-| importtype | wasm_importtype_new | importtype | |
-| | wasm_importtype_delete | | |
-| | wasm_importtype_module | | |
-| | wasm_importtype_name | | |
-| | wasm_importtype_type | | |
-| | wasm_importtype_copy | | |
-| | _vector methods_ | | |
-| exportype | wasm_exporttype_new | exporttype | |
-| | wasm_exporttype_delete | | |
-| | wasm_exporttype_name | | |
-| | wasm_exporttype_type | | |
-| | wasm_exporttype_copy | | |
-| | _vector methods_ | | |
-| val | wasm_val_delete | val | |
-| | wasm_val_copy | | |
-| | _vector methods_ | | |
-| frame | wasm_frame_delete | frame | |
-| | wasm_frame_instance | | |
-| | wasm_frame_func_index | | |
-| | wasm_frame_func_offset | | |
-| | wasm_frame_module_offset | | |
-| | wasm_frame_copy | | |
-| | _vector methods_ | | |
-| trap | wasm_trap_new | trap | |
-| | wasm_trap_delete | | |
-| | wasm_trap_message | | |
-| | wasm_trap_origin | | |
-| | wasm_trap_trace | | |
-| | _vector methods_ | | |
-| foreign | wasm_foreign_new | foreign | |
-| | wasm_foreign_delete | | |
-| | _vector methods_ | | |
-| engine | wasm_engine_new | engine | |
-| | wasm_engine_new_with_args\* | | |
-| | wasm_engine_new_with_config | | |
-| | wasm_engine_delete | | |
-| store | wasm_store_new | store | |
-| | wasm_store_delete | | |
-| | _vector methods_ | | |
-| module | wasm_module_new | module | |
-| | wasm_module_delete | | |
-| | wasm_module_validate | | |
-| | wasm_module_imports | | |
-| | wasm_module_exports | | |
-| instance | wasm_instance_new | instance | |
-| | wasm_instance_delete | | |
-| | wasm_instance_new_with_args\* | | |
-| | wasm_instance_exports | | |
-| | _vector methods_ | | |
-| func | wasm_func_new | func | |
-| | wasm_func_new_with_env | | |
-| | wasm_func_delete | | |
-| | wasm_func_type | | |
-| | wasm_func_call | | |
-| | wasm_func_param_arity | | |
-| | wasm_func_result_arity | | |
-| | _vector methods_ | | |
-| global | wasm_global_new | global | |
-| | wasm_global_delete | | |
-| | wasm_global_type | | |
-| | wasm_global_get | | |
-| | wasm_global_set | | |
-| | _vector methods_ | | |
-| table | wasm_table_new | table | |
-| | wasm_table_delete | | |
-| | wasm_table_type | | |
-| | wasm_table_get | | |
-| | wasm_table_set | | |
-| | wasm_table_size | | |
-| | _vector methods_ | | |
-| memory | wasm_memory_new | memory | |
-| | wasm_memory_delete | | |
-| | wasm_memory_type | | |
-| | wasm_memory_data | | |
-| | wasm_memory_data_size | | |
-| | wasm_memory_size | | |
-| | _vector methods_ | | |
-| extern | wasm_extern_delete | extern | |
-| | wasm_extern_as_XXX | | |
-| | wasm_XXX_as_extern | | |
-| | wasm_extern_kind | | |
-| | wasm_extern_type | | |
-| | _vector methods_ | | |
-
-not supported _functions_
-
-- wasm_config_XXX
-- wasm_module_deserialize
-- wasm_module_serialize
-- wasm_ref_XXX
-- wasm_XXX_as_ref
-- wasm_XXX_as_ref_const
-- wasm_XXX_copy
-- wasm_XXX_get_host_info
-- wasm_XXX_set_host_info
-
-## test
-
-there will be two kinds of tests in the project
-
-- unit test. located in `./tests`. driven by _unittest_. run by
- `$ python -m unittest` or `$ make test`.
-- integration test. located in `./samples`.
-
-The whole project is under test-driven development. Every wrapper function will
-have two kinds of test cases. The first kind is a positive case. It checks a
-wrapper function with expected and safe arguments combinations. Its goal is the
-function should work well with expected inputs. Another kind is a negative
-case. It feeds unexpected arguments combinations into a wrapper function. Arguments
-should include but not be limited to `None`. It ensures that the function will
-gracefully handle invalid input or unexpected behaviors.
-
-## distribution
-
-### package
-
-Create a python package named `wamr`. Users should import it after installation
-just like any other python module.
-
-```python
-from wamr import *
-```
-
-### PyPI
-
-Refer to [tutorial provided by PyPA](https://packaging.python.org/en/latest/tutorials/packaging-projects/).
-Steps to publish WAMR Python library:
-
-1. Creating `pyproject.toml` tells build tools (like pip and build) what is
- required to build a project. An example .toml file uses _setuptools_
-
- ```toml
- [build-system]
- requires = [
- "setuptools>=42",
- "wheel"
- ]
- build-backend = "setuptools.build_meta"
- ```
-
-2. Configuring metadata tells build tools about a package (such as the name
- and the version), as well as which code files to include
-
- - Static metadata (`setup.cfg`): guaranteed to be the same every time.
- It is simpler, easier to read, and avoids many common errors, like
- encoding errors.
-
- - Dynamic metadata (`setup.py`): possibly non-deterministic. Any items that
- are dynamic or determined at install-time, as well as extension modules
- or extensions to setuptools, need to go into setup.py.
-
- **_Static metadata should be preferred_**. Dynamic metadata should be used
- only as an escape hatch when necessary. setup.py used to be
- required, but can be omitted with newer versions of setuptools and pip.
-
-3. Including other files in the distribution
-
- - For [source distribution](https://packaging.python.org/en/latest/glossary/#term-Source-Distribution-or-sdist):
-
- It's usually generated using `python setup.py sdist`, providing metadata
- and the essential source files needed for installing by a tool like pip,
- or for generating a Built Distribution.
-
- It includes our Python modules, pyproject.toml, metadata, README.md,
- LICENSE. If you want to control what goes in this explicitly,
- see [Including files in source distributions with MANIFEST.in](https://packaging.python.org/en/latest/guides/using-manifest-in/#using-manifest-in).
-
- - For [final built distribution](https://packaging.python.org/en/latest/glossary/#term-Built-Distribution)
-
- A Distribution format containing files and metadata that only need to be
- moved to the correct location on the target system, to be installed.
- e.g. `Wheel`
-
- It will have the Python files in the discovered or listed Python packages.
- If you want to control what goes here, such as to add data files,
- see [Including Data Files](https://setuptools.pypa.io/en/latest/userguide/datafiles.html) from the [setuptools docs](https://setuptools.pypa.io/en/latest/index.html).
-
-4. Generating distribution archives. These are archives that are uploaded to
- the Python Package Index and can be installed by pip.
-
- example using `setuptools`
-
- ```shell
- python3 -m pip install --upgrade build
- python3 -m build
- ```
-
- generated files:
-
- ```shell
- dist/
- WAMR-package-0.0.1-py3-none-any.whl
- WAMR-package-0.0.1.tar.gz
- ```
-
- The `tar.gz` file is a _source archive_ whereas the `.whl file` is a
- _built distribution_. Newer pip versions preferentially install built
- distributions but will fall back to source archives if needed. You should
- always upload a source archive and provide built archives for compatibility
- reasons.
-
-5. Uploading the distribution archives
-
- - Register an account on https://pypi.org.
- - To securely upload your project, you’ll need a
- [PyPI API token](https://pypi.org/help/#apitoken). It can create at
- [here](https://pypi.org/manage/account/#api-tokens), and the “Scope”
- the setting needs to be “Entire account”.
- - After registration, now twine can be used to upload the distribution packages.
-
- ```shell
- # install twine
- python3 -m pip install --upgrade twine
- # --repository is https://pypi.org/ by default.
- # You will be prompted for a username and password. For the username, use __token__. For the password, use the token value, including the pypi- prefix.
- twine upload dist/*
- ```
-
-after all, the python binding will be installed with
-
-```shell
-$ pip install wamr
-```
-
-PS: A example lifecycle of a python package
-![python-package-lifecycle](images/python_package_life_cycle.png)
-
-## CI
-
-There are several parts:
-
-- code format check.
-- test. include running all unit test cases and examples.
-- publish built distribution.
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/images/python_package_life_cycle.png b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/images/python_package_life_cycle.png
deleted file mode 100644
index 90856e181..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/images/python_package_life_cycle.png
+++ /dev/null
Binary files differ
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/setup_dev_env.md b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/setup_dev_env.md
deleted file mode 100644
index 6612748f6..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/docs/setup_dev_env.md
+++ /dev/null
@@ -1,12 +0,0 @@
-Use a python virtual environment tool to create an environment for development. All necessary packages are in _../requirements.txt_.
-
-python code formatter is provided by _black_.
-
-python code linter is provided by _pylint_ and default configuration.
-
-Unit tests are driven by _unittest_.
-
-```bash
-$ python -m unittest -v tests/test_basics.py
-$ python -m unittest -v tests/test_advanced.py
-```
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/requirements.txt b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/requirements.txt
deleted file mode 100644
index 7bb68ba6c..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/requirements.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-black
-nose
-pycparser
-pylint
-
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello.wat b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello.wat
deleted file mode 100644
index 1c56c5582..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello.wat
+++ /dev/null
@@ -1,4 +0,0 @@
-(module
- (func $hello (import "" "hello"))
- (func (export "run") (call $hello))
-)
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_oop.py b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_oop.py
deleted file mode 100644
index 666f63cd8..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_oop.py
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/usr/bin/env python3
-#
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-import ctypes
-from wamr import *
-
-
-def hello_callback():
- print("Calling back...")
- print("> Hello World!")
-
-
-def main():
- print("Initializing...")
- engine = Engine()
- store = Store(engine)
-
- print("Loading binary...")
- print("Compiling module...")
- module = Module.from_file(engine, "./hello.wasm")
-
- print("Creating callback...")
- hello = Func(store, FuncType([], []), hello_callback)
-
- print("Instantiating module...")
- instance = Instance(store, module, [hello])
-
- print("Extracting export...")
- run = instance.exports(store)["run"]
-
- print("Calling export...")
- run(store)
-
- print("Shutting down...")
- print("Done.")
-
-
-if __name__ == "__main__":
- main()
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_procedural.py b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_procedural.py
deleted file mode 100644
index 5924423bd..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/samples/hello_procedural.py
+++ /dev/null
@@ -1,93 +0,0 @@
-# -*- coding: utf-8 -*-
-#!/usr/bin/env python3
-#
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-import ctypes
-import wamr.wasmcapi.ffi as ffi
-
-WAMS_BINARY_CONTENT = (
- b"\x00asm\x01\x00\x00\x00\x01\x84\x80\x80\x80\x00\x01`\x00\x00\x02\x8a\x80"
- b"\x80\x80\x00\x01\x00\x05hello\x00\x00\x03\x82\x80\x80\x80\x00\x01\x00"
- b"\x07\x87\x80\x80\x80\x00\x01\x03run\x00\x01\n\x8a\x80\x80\x80\x00\x01"
- b"\x84\x80\x80\x80\x00\x00\x10\x00\x0b"
-)
-
-
-@ffi.wasm_func_cb_decl
-def hello_callback(args, results):
- print("Calling back...")
- print("> Hello World!")
-
-
-def main():
- print("Initializing...")
- engine = ffi.wasm_engine_new()
- store = ffi.wasm_store_new(engine)
-
- print("Loading binary...")
-
- # for convenience, use binary content instead of open file
- # with open("./hello.wasm", "rb") as f:
- # wasm = f.read()
- wasm = WAMS_BINARY_CONTENT
- binary = ffi.wasm_byte_vec_t()
- ffi.wasm_byte_vec_new_uninitialized(binary, len(wasm))
- # underlying buffer is not writable
- binary.data = (ctypes.c_ubyte * len(wasm)).from_buffer_copy(wasm)
-
- print("Compiling module...")
- module = ffi.wasm_module_new(store, binary)
- if not module:
- raise RuntimeError("Compiling module failed")
-
- binary.data = None
- ffi.wasm_byte_vec_delete(binary)
-
- print("Creating callback...")
- hello_type = ffi.wasm_functype_new_0_0()
- hello_func = ffi.wasm_func_new(
- store,
- hello_type,
- hello_callback,
- )
-
- ffi.wasm_functype_delete(hello_type)
-
- print("Instantiating module...")
-
- imports = ffi.wasm_extern_vec_t()
- ffi.wasm_extern_vec_new((imports), 1, ffi.wasm_func_as_extern(hello_func))
- instance = ffi.wasm_instance_new(store, module, imports, None)
-
- ffi.wasm_func_delete(hello_func)
-
- print("Extracting export...")
- exports = ffi.wasm_extern_vec_t()
- ffi.wasm_instance_exports(instance, exports)
-
- run_func = ffi.wasm_extern_as_func(exports.data[0])
- if not run_func:
- raise RuntimeError("can not extract exported function")
-
- ffi.wasm_instance_delete(instance)
- ffi.wasm_module_delete(module)
-
- print("Calling export...")
- args = ffi.wasm_val_vec_t()
- results = ffi.wasm_val_vec_t()
-
- ffi.wasm_val_vec_new_empty(args)
- ffi.wasm_val_vec_new_empty(results)
- ffi.wasm_func_call(run_func, args, results)
-
- print("Shutting down...")
- ffi.wasm_store_delete(store)
- ffi.wasm_engine_delete(engine)
-
- print("Done.")
-
-
-if __name__ == "__main__":
- main()
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/__init__.py b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/__init__.py
deleted file mode 100644
index fd913c63c..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/__init__.py
+++ /dev/null
@@ -1,7 +0,0 @@
-# -*- coding: utf-8 -*-
-#!/usr/bin/env python3
-#
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-__all__ = ["test_basic", "test_advanced"]
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/context.py b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/context.py
deleted file mode 100644
index 15c30087c..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/context.py
+++ /dev/null
@@ -1,13 +0,0 @@
-# -*- coding: utf-8 -*-
-#!/usr/bin/env python3
-#
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-
-import sys
-import os
-
-sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
-
-import wamr
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_advanced.py b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_advanced.py
deleted file mode 100644
index 2e1c285ea..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_advanced.py
+++ /dev/null
@@ -1,525 +0,0 @@
-# -*- coding: utf-8 -*-
-#!/usr/bin/env python3
-#
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-# pylint: disable=missing-class-docstring
-# pylint: disable=missing-function-docstring
-# pylint: disable=missing-module-docstring
-
-import ctypes as c
-import math
-import unittest
-
-import wamr.wasmcapi.ffi as ffi
-
-
-# It is a module likes:
-# (module
-# (import "mod" "g0" (global i32))
-# (import "mod" "f0" (func (param f32) (result f64)))
-#
-# (func (export "f1") (param i32 i64))
-# (global (export "g1") (mut f32) (f32.const 3.14))
-# (memory (export "m1") 1 2)
-# (table (export "t1") 1 funcref)
-#
-# (func (export "f2") (unreachable))
-# )
-MODULE_BINARY = (
- b"\x00asm\x01\x00\x00\x00\x01\x0e\x03`\x01}\x01|`\x02\x7f~\x00`\x00"
- b"\x00\x02\x14\x02\x03mod\x02g0\x03\x7f\x00\x03mod\x02f0\x00\x00\x03\x03"
- b"\x02\x01\x02\x04\x04\x01p\x00\x01\x05\x04\x01\x01\x01\x02\x06\t\x01}\x01C"
- b"\xc3\xf5H@\x0b\x07\x1a\x05\x02f1\x00\x01\x02g1\x03\x01\x02m1\x02\x00\x02t1"
- b"\x01\x00\x02f2\x00\x02\n\x08\x02\x02\x00\x0b\x03\x00\x00\x0b"
-)
-
-# False -> True when testing with a library enabling WAMR_BUILD_DUMP_CALL_STACK flag
-TEST_WITH_WAMR_BUILD_DUMP_CALL_STACK = False
-
-
-@ffi.wasm_func_cb_decl
-def callback(args, results):
- args = ffi.dereference(args)
- results = ffi.dereference(results)
-
- arg_v = args.data[0]
-
- result_v = ffi.wasm_f64_val(arg_v.of.f32 * 2.0)
- ffi.wasm_val_copy(results.data[0], result_v)
- results.num_elems = 1
-
- print(f"\nIn callback: {arg_v} --> {result_v}\n")
-
-
-@ffi.wasm_func_with_env_cb_decl
-def callback_with_env(env, args, results):
- # pylint: disable=unused-argument
- print("summer")
-
-
-class AdvancedTestSuite(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- print("Initializing...")
- cls._wasm_engine = ffi.wasm_engine_new()
- cls._wasm_store = ffi.wasm_store_new(cls._wasm_engine)
-
- def assertIsNullPointer(self, pointer):
- # pylint: disable=invalid-name
- if not ffi.is_null_pointer(pointer):
- self.fail("not a non-null pointer")
-
- def assertIsNotNullPointer(self, pointer):
- # pylint: disable=invalid-name
- if ffi.is_null_pointer(pointer):
- self.fail("not a non-null pointer")
-
- def load_binary(self, binary_string):
- print("Load binary...")
- binary = ffi.load_module_file(binary_string)
- binary = c.pointer(binary)
- self.assertIsNotNullPointer(binary)
- return binary
-
- def compile(self, binary):
- print("Compile...")
- module = ffi.wasm_module_new(self._wasm_store, binary)
- self.assertIsNotNullPointer(module)
- return module
-
- def prepare_imports_local(self):
- print("Prepare imports...")
- func_type = ffi.wasm_functype_new_1_1(
- ffi.wasm_valtype_new(ffi.WASM_F32),
- ffi.wasm_valtype_new(ffi.WASM_F64),
- )
- func = ffi.wasm_func_new(self._wasm_store, func_type, callback)
- self.assertIsNotNullPointer(func)
- ffi.wasm_functype_delete(func_type)
-
- glbl_type = ffi.wasm_globaltype_new(ffi.wasm_valtype_new(ffi.WASM_I32), True)
- init = ffi.wasm_i32_val(1024)
- glbl = ffi.wasm_global_new(self._wasm_store, glbl_type, init)
- self.assertIsNotNullPointer(glbl)
- ffi.wasm_globaltype_delete(glbl_type)
-
- imports = ffi.wasm_extern_vec_t()
- data = ffi.list_to_carray(
- c.POINTER(ffi.wasm_extern_t),
- ffi.wasm_func_as_extern(func),
- ffi.wasm_global_as_extern(glbl),
- )
- ffi.wasm_extern_vec_new(imports, 2, data)
- imports = c.pointer(imports)
- self.assertIsNotNullPointer(imports)
- return imports
-
- def instantiate(self, module, imports):
- print("Instantiate module...")
- instance = ffi.wasm_instance_new(
- self._wasm_store, module, imports, ffi.create_null_pointer(ffi.wasm_trap_t)
- )
- self.assertIsNotNone(instance)
- self.assertIsNotNullPointer(instance)
- return instance
-
- def extract_exports(self, instance):
- print("Extracting exports...")
- exports = ffi.wasm_extern_vec_t()
- ffi.wasm_instance_exports(instance, exports)
- exports = c.pointer(exports)
- self.assertIsNotNullPointer(exports)
- return exports
-
- def setUp(self):
- binary = self.load_binary(MODULE_BINARY)
- self.module = self.compile(binary)
- self.imports = self.prepare_imports_local()
- self.instance = self.instantiate(self.module, self.imports)
- self.exports = self.extract_exports(self.instance)
-
- ffi.wasm_byte_vec_delete(binary)
-
- def tearDown(self):
- if self.imports:
- ffi.wasm_extern_vec_delete(self.imports)
-
- if self.exports:
- ffi.wasm_extern_vec_delete(self.exports)
-
- ffi.wasm_instance_delete(self.instance)
- ffi.wasm_module_delete(self.module)
-
- def test_wasm_func_call_wasm(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- print(export_list)
-
- func = ffi.wasm_extern_as_func(export_list[0])
- self.assertIsNotNullPointer(func)
-
- # make a call
- params = ffi.wasm_val_vec_t()
- data = ffi.list_to_carray(
- ffi.wasm_val_t,
- ffi.wasm_i32_val(1024),
- ffi.wasm_i64_val(1024 * 1024),
- )
- ffi.wasm_val_vec_new(params, 2, data)
-
- results = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new_empty(results)
-
- ffi.wasm_func_call(func, params, results)
-
- def test_wasm_func_call_native(self):
- import_list = ffi.wasm_vec_to_list(self.imports)
-
- func = ffi.wasm_extern_as_func(import_list[0])
- self.assertIsNotNullPointer(func)
-
- params = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new(
- params, 1, ffi.list_to_carray(ffi.wasm_val_t, ffi.wasm_f32_val(3.14))
- )
- results = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new_uninitialized(results, 1)
- ffi.wasm_func_call(func, params, results)
- self.assertEqual(params.data[0].of.f32 * 2, results.data[0].of.f64)
-
- def test_wasm_func_call_wrong_params(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- func = ffi.wasm_extern_as_func(export_list[0])
- # make a call
- params = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new_empty(params)
- results = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new_empty(results)
- trap = ffi.wasm_func_call(func, params, results)
-
- self.assertIsNotNullPointer(trap)
-
- def test_wasm_func_call_unlinked(self):
- ft = ffi.wasm_functype_new_0_0()
- func = ffi.wasm_func_new(self._wasm_store, ft, callback)
- params = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new_empty(params)
- results = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new_empty(results)
- trap = ffi.wasm_func_call(func, params, results)
- ffi.wasm_func_delete(func)
-
- def test_wasm_global_get_wasm(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- glb = ffi.wasm_extern_as_global(export_list[1])
- self.assertIsNotNullPointer(glb)
-
- # access the global
- val = ffi.wasm_val_t()
- ffi.wasm_global_get(glb, val)
- self.assertAlmostEqual(val.of.f32, 3.14, places=3)
-
- def test_wasm_global_get_native(self):
- import_list = ffi.wasm_vec_to_list(self.imports)
-
- glb = ffi.wasm_extern_as_global(import_list[1])
- self.assertIsNotNullPointer(glb)
-
- val = ffi.wasm_val_t()
- ffi.wasm_global_get(glb, val)
- self.assertEqual(val.of.i32, 1024)
-
- def test_wasm_global_get_unlinked(self):
- gt = ffi.wasm_globaltype_new(ffi.wasm_valtype_new(ffi.WASM_I32), True)
- init = ffi.wasm_i32_val(32)
- glbl = ffi.wasm_global_new(self._wasm_store, gt, init)
- val_ret = ffi.wasm_f32_val(3.14)
- ffi.wasm_global_get(glbl, val_ret)
- ffi.wasm_global_delete(glbl)
-
- # val_ret wasn't touched, keep the original value
- self.assertAlmostEqual(val_ret.of.f32, 3.14, 3)
-
- def test_wasm_global_get_null_val(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- glb = ffi.wasm_extern_as_global(export_list[1])
- ffi.wasm_global_get(glb, ffi.create_null_pointer(ffi.wasm_val_t))
-
- def test_wasm_global_get_null_global(self):
- val = ffi.wasm_val_t()
- ffi.wasm_global_get(ffi.create_null_pointer(ffi.wasm_global_t), val)
-
- def test_wasm_global_set_wasm(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- glb = ffi.wasm_extern_as_global(export_list[1])
- self.assertIsNotNullPointer(glb)
-
- # access the global
- new_val = ffi.wasm_f32_val(math.e)
- ffi.wasm_global_set(glb, new_val)
-
- val = ffi.wasm_val_t()
- ffi.wasm_global_get(glb, val)
- self.assertNotEqual(val.of.f32, 3.14)
-
- def test_wasm_global_set_native(self):
- import_list = ffi.wasm_vec_to_list(self.imports)
-
- glb = ffi.wasm_extern_as_global(import_list[1])
- self.assertIsNotNullPointer(glb)
-
- new_val = ffi.wasm_i32_val(2048)
- ffi.wasm_global_set(glb, new_val)
-
- val = ffi.wasm_val_t()
- ffi.wasm_global_get(glb, val)
- self.assertEqual(val, new_val)
-
- def test_wasm_global_set_unlinked(self):
- gt = ffi.wasm_globaltype_new(ffi.wasm_valtype_new(ffi.WASM_I32), True)
- init = ffi.wasm_i32_val(32)
- glbl = ffi.wasm_global_new(self._wasm_store, gt, init)
- val_ret = ffi.wasm_f32_val(3.14)
- ffi.wasm_global_set(glbl, val_ret)
- ffi.wasm_global_delete(glbl)
-
- def test_wasm_global_set_null_v(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- glb = ffi.wasm_extern_as_global(export_list[1])
- # access the global
- ffi.wasm_global_set(glb, ffi.create_null_pointer(ffi.wasm_val_t))
-
- def test_wasm_global_set_null_global(self):
- # access the global
- new_val = ffi.wasm_f32_val(math.e)
- ffi.wasm_global_set(ffi.create_null_pointer(ffi.wasm_global_t), new_val)
-
- def test_wasm_table_size(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- tbl = ffi.wasm_extern_as_table(export_list[3])
- self.assertIsNotNullPointer(tbl)
-
- tbl_sz = ffi.wasm_table_size(tbl)
- self.assertEqual(tbl_sz, 1)
-
- def test_wasm_table_size_unlink(self):
- vt = ffi.wasm_valtype_new(ffi.WASM_FUNCREF)
- limits = ffi.wasm_limits_new(10, 15)
- tt = ffi.wasm_tabletype_new(vt, limits)
- tbl = ffi.wasm_table_new(
- self._wasm_store, tt, ffi.create_null_pointer(ffi.wasm_ref_t)
- )
- tbl_sz = ffi.wasm_table_size(tbl)
- ffi.wasm_table_delete(tbl)
-
- def test_wasm_table_size_null_table(self):
- ffi.wasm_table_size(ffi.create_null_pointer(ffi.wasm_table_t))
-
- def test_wasm_table_get(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- tbl = ffi.wasm_extern_as_table(export_list[3])
- self.assertIsNotNullPointer(tbl)
-
- ref = ffi.wasm_table_get(tbl, 0)
- self.assertIsNullPointer(ref)
-
- ref = ffi.wasm_table_get(tbl, 4096)
- self.assertIsNullPointer(ref)
-
- def test_wasm_table_get_unlinked(self):
- vt = ffi.wasm_valtype_new(ffi.WASM_FUNCREF)
- limits = ffi.wasm_limits_new(10, 15)
- tt = ffi.wasm_tabletype_new(vt, limits)
- tbl = ffi.wasm_table_new(
- self._wasm_store, tt, ffi.create_null_pointer(ffi.wasm_ref_t)
- )
- ffi.wasm_table_get(tbl, 0)
- ffi.wasm_table_delete(tbl)
-
- def test_wasm_table_get_null_table(self):
- ffi.wasm_table_get(ffi.create_null_pointer(ffi.wasm_table_t), 0)
-
- def test_wasm_table_get_out_of_bounds(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- tbl = ffi.wasm_extern_as_table(export_list[3])
- ffi.wasm_table_get(tbl, 1_000_000_000)
-
- def test_wasm_ref(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- func = ffi.wasm_extern_as_func(export_list[0])
- self.assertIsNotNullPointer(func)
-
- ref = ffi.wasm_func_as_ref(func)
- self.assertIsNotNullPointer(ref)
-
- func_from_ref = ffi.wasm_ref_as_func(ref)
- self.assertEqual(
- ffi.dereference(ffi.wasm_func_type(func)),
- ffi.dereference(ffi.wasm_func_type(func_from_ref)),
- )
-
- def test_wasm_table_set(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- tbl = ffi.wasm_extern_as_table(export_list[3])
- self.assertIsNotNullPointer(tbl)
-
- func = ffi.wasm_extern_as_func(export_list[0])
- ref = ffi.wasm_func_as_ref(func)
-
- ffi.wasm_table_set(tbl, 0, ref)
-
- ref_ret = ffi.wasm_table_get(tbl, 0)
- self.assertIsNotNullPointer(ref_ret)
- func_ret = ffi.wasm_ref_as_func(ref_ret)
- self.assertEqual(
- ffi.dereference(ffi.wasm_func_type(func)),
- ffi.dereference(ffi.wasm_func_type(func_ret)),
- )
-
- def test_wasm_table_set_unlinked(self):
- vt = ffi.wasm_valtype_new(ffi.WASM_FUNCREF)
- limits = ffi.wasm_limits_new(10, 15)
- tt = ffi.wasm_tabletype_new(vt, limits)
- tbl = ffi.wasm_table_new(
- self._wasm_store, tt, ffi.create_null_pointer(ffi.wasm_ref_t)
- )
- export_list = ffi.wasm_vec_to_list(self.exports)
- func = ffi.wasm_extern_as_func(export_list[0])
- ref = ffi.wasm_func_as_ref(func)
- ffi.wasm_table_set(tbl, 0, ref)
- ffi.wasm_table_delete(tbl)
-
- def test_wasm_table_set_null_table(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- func = ffi.wasm_extern_as_func(export_list[0])
- ref = ffi.wasm_func_as_ref(func)
- ffi.wasm_table_set(ffi.create_null_pointer(ffi.wasm_table_t), 0, ref)
-
- def test_wasm_table_set_null_ref(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- tbl = ffi.wasm_extern_as_table(export_list[3])
- ffi.wasm_table_set(tbl, 0, ffi.create_null_pointer(ffi.wasm_ref_t))
-
- def test_wasm_table_set_out_of_bounds(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- tbl = ffi.wasm_extern_as_table(export_list[3])
- func = ffi.wasm_extern_as_func(export_list[0])
- ref = ffi.wasm_func_as_ref(func)
- ffi.wasm_table_set(tbl, 1_000_000_000, ref)
-
- def test_wasm_memory_size(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- mem = ffi.wasm_extern_as_memory(export_list[2])
- self.assertIsNotNullPointer(mem)
-
- pg_sz = ffi.wasm_memory_size(mem)
- self.assertEqual(pg_sz, 1)
-
- def test_wasm_memory_size_unlinked(self):
- limits = ffi.wasm_limits_new(10, 12)
- mt = ffi.wasm_memorytype_new(limits)
- mem = ffi.wasm_memory_new(self._wasm_store, mt)
- ffi.wasm_memory_size(mem)
- ffi.wasm_memory_delete(mem)
-
- def test_wasm_memory_data(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- mem = ffi.wasm_extern_as_memory(export_list[2])
- self.assertIsNotNullPointer(mem)
-
- data_base = ffi.wasm_memory_data(mem)
- self.assertIsNotNone(data_base)
-
- def test_wasm_memory_data_unlinked(self):
- limits = ffi.wasm_limits_new(10, 12)
- mt = ffi.wasm_memorytype_new(limits)
- mem = ffi.wasm_memory_new(self._wasm_store, mt)
- ffi.wasm_memory_data(mem)
- ffi.wasm_memory_delete(mem)
-
- def test_wasm_memory_data_size(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- mem = ffi.wasm_extern_as_memory(export_list[2])
- self.assertIsNotNullPointer(mem)
-
- mem_sz = ffi.wasm_memory_data_size(mem)
- self.assertGreater(mem_sz, 0)
-
- def test_wasm_memory_data_size_unlinked(self):
- limits = ffi.wasm_limits_new(10, 12)
- mt = ffi.wasm_memorytype_new(limits)
- mem = ffi.wasm_memory_new(self._wasm_store, mt)
- ffi.wasm_memory_data_size(mem)
- ffi.wasm_memory_delete(mem)
-
- def test_wasm_trap(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- func = ffi.wasm_extern_as_func(export_list[0])
- # make a call
- params = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new_empty(params)
- results = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new_empty(results)
-
- trap = ffi.wasm_func_call(func, params, results)
- self.assertIsNotNullPointer(trap)
-
- message = ffi.wasm_message_t()
- ffi.wasm_trap_message(trap, message)
- self.assertIsNotNullPointer(c.pointer(message))
-
- # not a function internal exception
- frame = ffi.wasm_trap_origin(trap)
- self.assertIsNullPointer(frame)
-
- @unittest.skipUnless(
- TEST_WITH_WAMR_BUILD_DUMP_CALL_STACK,
- "need to enable WAMR_BUILD_DUMP_CALL_STACK",
- )
- # assertions only works if enabling WAMR_BUILD_DUMP_CALL_STACK
- def test_wasm_frame(self):
- export_list = ffi.wasm_vec_to_list(self.exports)
- func = ffi.wasm_extern_as_func(export_list[4])
- # make a call
- params = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new_empty(params)
- results = ffi.wasm_val_vec_t()
- ffi.wasm_val_vec_new_empty(results)
-
- print("Making a call...")
- trap = ffi.wasm_func_call(func, params, results)
-
- message = ffi.wasm_message_t()
- ffi.wasm_trap_message(trap, message)
- self.assertIsNotNullPointer(c.pointer(message))
- print(message)
-
- frame = ffi.wasm_trap_origin(trap)
- self.assertIsNotNullPointer(frame)
- print(ffi.dereference(frame))
-
- traces = ffi.wasm_frame_vec_t()
- ffi.wasm_trap_trace(trap, traces)
- self.assertIsNotNullPointer(c.pointer(frame))
-
- instance = ffi.wasm_frame_instance(frame)
- self.assertIsNotNullPointer(instance)
-
- module_offset = ffi.wasm_frame_module_offset(frame)
-
- func_index = ffi.wasm_frame_func_index(frame)
- self.assertEqual(func_index, 2)
-
- func_offset = ffi.wasm_frame_func_offset(frame)
- self.assertGreater(func_offset, 0)
-
- @classmethod
- def tearDownClass(cls):
- print("Shutting down...")
- ffi.wasm_store_delete(cls._wasm_store)
- ffi.wasm_engine_delete(cls._wasm_engine)
-
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_basic.py b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_basic.py
deleted file mode 100644
index a2d3f2850..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/tests/test_basic.py
+++ /dev/null
@@ -1,1590 +0,0 @@
-# -*- coding: utf-8 -*-
-#!/usr/bin/env python3
-#
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-# pylint: disable=missing-class-docstring
-# pylint: disable=missing-function-docstring
-# pylint: disable=missing-module-docstring
-
-import ctypes as c
-import unittest
-from venv import create
-
-from wamr.wasmcapi.ffi import *
-
-# It is a module likes:
-# (module
-# (import "mod" "g0" (global i32))
-# (import "mod" "f0" (func (param f32) (result f64)))
-#
-# (func (export "f1") (param i32 i64))
-# (global (export "g1") (mut f32) (f32.const 3.14))
-# (memory 1 2)
-# (table 1 funcref)
-# )
-MODULE_BINARY = (
- b"\x00asm\x01\x00\x00\x00\x01\x0b\x02`\x01}\x01|`\x02\x7f~\x00"
- b"\x02\x14\x02\x03mod\x02g0\x03\x7f\x00\x03mod\x02f0\x00\x00\x03"
- b"\x02\x01\x01\x04\x04\x01p\x00\x01\x05\x04\x01\x01\x01\x02\x06\t"
- b"\x01}\x01C\xc3\xf5H@\x0b\x07\x0b\x02\x02f1\x00\x01\x02g1\x03\x01\n"
- b"\x04\x01\x02\x00\x0b"
-)
-
-
-@wasm_func_cb_decl
-def callback(args, results):
- # pylint: disable=unused-argument
- print("summer")
-
-
-@wasm_func_with_env_cb_decl
-def callback_with_env(env, args, results):
- # pylint: disable=unused-argument
- print("summer")
-
-
-class BasicTestSuite(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- cls._wasm_engine = wasm_engine_new()
- cls._wasm_store = wasm_store_new(cls._wasm_engine)
-
- def assertIsNullPointer(self, c_pointer):
- if not is_null_pointer(c_pointer):
- self.fail("not a null pointer")
-
- def assertIsNotNullPointer(self, c_pointer):
- if is_null_pointer(c_pointer):
- self.fail("not a non-null pointer")
-
- def test_wasm_valkind(self):
- self.assertEqual(
- [WASM_I32, WASM_I64, WASM_F32, WASM_F64, WASM_ANYREF, WASM_FUNCREF],
- [0, 1, 2, 3, 128, 129],
- )
-
- def test_wasm_valtype_new_pos(self):
- vt = wasm_valtype_new(WASM_I32)
- self.assertIsNotNullPointer(vt)
- wasm_valtype_delete(vt)
-
- def test_wasm_valtype_new_neg(self):
- vt = wasm_valtype_new(37)
- self.assertIsNullPointer(vt)
- wasm_valtype_delete(vt)
-
- def test_wasm_valtype_kind_pos(self):
- vt = wasm_valtype_new(WASM_I64)
- self.assertEqual(wasm_valtype_kind(vt), WASM_I64)
- wasm_valtype_delete(vt)
-
- def test_wasm_valtype_kind_neg(self):
- wasm_valtype_kind(create_null_pointer(wasm_valtype_t))
-
- def test_wasm_valtype_delete_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- wasm_valtype_delete(vt)
-
- def test_wasm_valtype_delete_neg(self):
- wasm_valtype_delete(create_null_pointer(wasm_valtype_t))
-
- def test_wasm_valtype_copy_pos(self):
- vt1 = wasm_valtype_new(WASM_FUNCREF)
- vt2 = wasm_valtype_copy(vt1)
-
- self.assertIsNotNone(vt1)
- self.assertIsNotNullPointer(vt1)
- self.assertEqual(dereference(vt1), dereference(vt2))
-
- wasm_valtype_delete(vt1)
- wasm_valtype_delete(vt2)
-
- def test_wasm_valtype_copy_neg(self):
- vt = wasm_valtype_copy(create_null_pointer(wasm_valtype_t))
- self.assertIsNotNone(vt)
- self.assertIsNullPointer(vt)
-
- def test_list_to_carray(self):
- v1 = wasm_valtype_new(WASM_I64)
- v2 = wasm_valtype_new(WASM_F32)
- v3 = wasm_valtype_new(WASM_FUNCREF)
- data = list_to_carray(c.POINTER(wasm_valtype_t), v1, v2, v3)
-
- self.assertIsNotNone(data)
- self.assertTrue(isinstance(data, c.Array))
- self.assertEqual(data._length_, 3)
- self.assertEqual(dereference(data[0]), dereference(v1))
- self.assertEqual(dereference(data[1]), dereference(v2))
- self.assertEqual(dereference(data[2]), dereference(v3))
-
- wasm_valtype_delete(v1)
- wasm_valtype_delete(v2)
- wasm_valtype_delete(v3)
-
- def test_wasm_valtype_vec_new_pos(self):
- def_vt_list = [
- wasm_valtype_new(WASM_I32),
- wasm_valtype_new(WASM_F64),
- wasm_valtype_new(WASM_FUNCREF),
- ]
- data = list_to_carray(c.POINTER(wasm_valtype_t), *def_vt_list)
- vt_vec = wasm_valtype_vec_t()
- wasm_valtype_vec_new(vt_vec, 3, data)
-
- self.assertEqual(vt_vec.size, 3)
- self.assertEqual(vt_vec.num_elems, 3)
- self.assertIsNotNullPointer(vt_vec.data)
-
- ret_vt_list = wasm_vec_to_list(vt_vec)
- ret_vt_list = [dereference(vt) for vt in ret_vt_list]
- def_vt_list = [dereference(vt) for vt in def_vt_list]
- self.assertEqual(ret_vt_list, def_vt_list)
-
- wasm_valtype_vec_delete(vt_vec)
-
- def test_wasm_valtype_vec_new_neg(self):
- data = list_to_carray(
- c.POINTER(wasm_valtype_t),
- wasm_valtype_new(WASM_I32),
- wasm_valtype_new(WASM_F64),
- wasm_valtype_new(WASM_FUNCREF),
- )
- vt_vec = wasm_valtype_vec_t()
- wasm_valtype_vec_new(vt_vec, 1_000_000_000, data)
-
- self.assertEqual(vt_vec.size, 0)
- self.assertIsNullPointer(vt_vec.data)
-
- wasm_valtype_vec_delete(vt_vec)
-
- def test_wasm_valtype_vec_new_null_out(self):
- data = list_to_carray(
- c.POINTER(wasm_valtype_t),
- wasm_valtype_new(WASM_I32),
- wasm_valtype_new(WASM_F64),
- wasm_valtype_new(WASM_FUNCREF),
- )
- wasm_valtype_vec_new(create_null_pointer(wasm_valtype_vec_t), 10, data)
-
- def test_wasm_valtype_vec_new_null_data(self):
- vt_vec = wasm_valtype_vec_t()
- wasm_valtype_vec_new(vt_vec, 3, create_null_pointer(wasm_valtype_t))
- self.assertIsNotNone(vt_vec)
- self.assertIsNotNullPointer(c.pointer(vt_vec))
-
- def test_wasm_valtype_vec_new_uninitialized_pos(self):
- vt_vec = wasm_valtype_vec_t()
- wasm_valtype_vec_new_uninitialized((vt_vec), 2)
- self.assertEqual(2, vt_vec.size)
- wasm_valtype_vec_delete(vt_vec)
-
- def test_wasm_valtype_vec_new_uninitialized_neg(self):
- vt_vec = wasm_valtype_vec_t()
- wasm_valtype_vec_new_uninitialized(vt_vec, 1_000_000_000)
- self.assertEqual(vt_vec.size, 0)
- self.assertIsNullPointer(vt_vec.data)
- wasm_valtype_vec_delete(vt_vec)
-
- def test_wasm_valtype_vec_new_uninitialized_null_out(self):
- wasm_valtype_vec_new_uninitialized(create_null_pointer(wasm_valtype_vec_t), 2)
-
- def test_wasm_valtype_vec_new_empty_pos(self):
- vt_vec = wasm_valtype_vec_t()
- wasm_valtype_vec_new_empty(vt_vec)
- self.assertEqual(0, vt_vec.size)
- self.assertIsNullPointer(vt_vec.data)
- wasm_valtype_vec_delete(vt_vec)
-
- def test_wasm_valtype_vec_new_empty_neg(self):
- wasm_valtype_vec_new_empty(create_null_pointer(wasm_valtype_vec_t))
-
- def test_wasm_valtype_vec_copy_pos(self):
- vt_vec1 = wasm_valtype_vec_t()
- vt1 = wasm_valtype_new(WASM_F32)
- vt2 = wasm_valtype_new(WASM_I32)
- data = list_to_carray(c.POINTER(wasm_valtype_t), vt1, vt2)
- wasm_valtype_vec_new(vt_vec1, 2, data)
-
- vt_vec2 = wasm_valtype_vec_t()
- wasm_valtype_vec_copy(vt_vec2, vt_vec1)
-
- print(f"{vt_vec1} --> {vt_vec2}")
-
- self.assertEqual(vt_vec2.size, 2)
- self.assertEqual(vt_vec2.num_elems, 2)
- self.assertEqual(dereference(vt_vec2.data[0]), dereference(vt1))
- self.assertEqual(dereference(vt_vec2.data[1]), dereference(vt2))
-
- wasm_valtype_vec_delete(vt_vec1)
- wasm_valtype_vec_delete(vt_vec2)
-
- def test_wasm_valtype_vec_copy_null_src(self):
- dst = wasm_valtype_vec_t()
- wasm_valtype_vec_copy(dst, create_null_pointer(wasm_valtype_vec_t))
- self.assertIsNotNullPointer(c.pointer(dst))
- self.assertIsNullPointer(dst.data)
-
- def test_wasm_valtype_vec_copy_null_dst(self):
- src = wasm_valtype_vec_t()
- wasm_valtype_vec_new_empty(src)
- wasm_valtype_vec_copy(create_null_pointer(wasm_valtype_vec_t), src)
- wasm_valtype_vec_delete(src)
-
- def test_wasm_valtype_vec_delete_pos(self):
- vt_vec = wasm_valtype_vec_t()
- wasm_valtype_vec_new_uninitialized(vt_vec, 10)
- wasm_valtype_vec_delete(vt_vec)
-
- vt_vec = wasm_valtype_vec_t()
- wasm_valtype_vec_new_empty(vt_vec)
- wasm_valtype_vec_delete(vt_vec)
-
- def test_wasm_valtype_vec_delete_neg(self):
- wasm_valtype_vec_delete(create_null_pointer(wasm_valtype_vec_t))
-
- def test_wasm_functype_new_0_0(self):
- ft = wasm_functype_new_0_0()
-
- self.assertIsNotNullPointer(ft)
- self.assertEqual(0, dereference(wasm_functype_params(ft)).size)
- self.assertEqual(0, dereference(wasm_functype_results(ft)).size)
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_new_1_0(self):
- vt = wasm_valtype_new(WASM_I64)
- ft = wasm_functype_new_1_0(vt)
-
- self.assertIsNotNullPointer(ft)
- params = wasm_vec_to_list(wasm_functype_params(ft))
- self.assertEqual([dereference(p) for p in params], [dereference(vt)])
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_new_2_0(self):
- vt1 = wasm_valtype_new(WASM_I64)
- vt2 = wasm_valtype_new(WASM_F64)
- ft = wasm_functype_new_2_0(vt1, vt2)
-
- self.assertIsNotNullPointer(ft)
- self.assertEqual(2, dereference(wasm_functype_params(ft)).size)
- self.assertEqual(0, dereference(wasm_functype_results(ft)).size)
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_new_3_0(self):
- vt_list = [
- wasm_valtype_new(WASM_I64),
- wasm_valtype_new(WASM_F64),
- wasm_valtype_new(WASM_I64),
- ]
- ft = wasm_functype_new_3_0(*vt_list)
-
- params = wasm_vec_to_list(wasm_functype_params(ft))
- self.assertEqual(
- [dereference(p) for p in params],
- [dereference(vt) for vt in vt_list],
- )
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_new_0_1(self):
- vt1 = wasm_valtype_new(WASM_I64)
- ft = wasm_functype_new_0_1(vt1)
-
- self.assertIsNotNullPointer(ft)
- self.assertEqual(0, dereference(wasm_functype_params(ft)).size)
- self.assertEqual(1, dereference(wasm_functype_results(ft)).size)
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_new_1_1(self):
- vt1 = wasm_valtype_new(WASM_I64)
- vt2 = wasm_valtype_new(WASM_F64)
- ft = wasm_functype_new_1_1(vt1, vt2)
-
- params = wasm_vec_to_list(wasm_functype_params(ft))
- self.assertEqual(dereference(params[0]), dereference(vt1))
-
- results = wasm_vec_to_list(wasm_functype_results(ft))
- self.assertEqual(dereference(results[0]), dereference(vt2))
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_new_2_1(self):
- vt_list = [
- wasm_valtype_new(WASM_I64),
- wasm_valtype_new(WASM_F64),
- wasm_valtype_new(WASM_I64),
- ]
- ft = wasm_functype_new_2_1(*vt_list)
-
- self.assertIsNotNullPointer(ft)
- self.assertEqual(2, dereference(wasm_functype_params(ft)).size)
- self.assertEqual(1, dereference(wasm_functype_results(ft)).size)
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_new_3_1(self):
- vt_list = [
- wasm_valtype_new(WASM_I64),
- wasm_valtype_new(WASM_F64),
- wasm_valtype_new(WASM_I64),
- wasm_valtype_new(WASM_I32),
- ]
- ft = wasm_functype_new_3_1(*vt_list)
-
- params = wasm_vec_to_list(wasm_functype_params(ft))
- self.assertEqual(
- [dereference(p) for p in params], [dereference(vt) for vt in vt_list[:3]]
- )
-
- results = wasm_vec_to_list(wasm_functype_results(ft))
- self.assertEqual(dereference(results[0]), dereference(vt_list[-1]))
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_new_neg(self):
- ft = wasm_functype_new(
- create_null_pointer(wasm_valtype_vec_t),
- create_null_pointer(wasm_valtype_vec_t),
- )
-
- self.assertIsNotNullPointer(ft)
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_delete_pos(self):
- ft = wasm_functype_new_0_0()
- wasm_functype_delete(ft)
-
- def test_wasm_functype_delete_neg(self):
- wasm_functype_delete(create_null_pointer(wasm_functype_t))
-
- def test_wasm_functype_params_pos(self):
- vt_list = [
- wasm_valtype_new(WASM_I64),
- wasm_valtype_new(WASM_F64),
- wasm_valtype_new(WASM_I64),
- ]
- ft = wasm_functype_new_3_0(*vt_list)
- params = wasm_vec_to_list(wasm_functype_params(ft))
-
- self.assertEqual(
- [dereference(p) for p in params],
- [dereference(vt) for vt in vt_list],
- )
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_params_neg(self):
- params = wasm_functype_params(create_null_pointer(wasm_functype_t))
- self.assertIsNullPointer(params)
-
- def test_wasm_functype_results_pos(self):
- vt1 = wasm_valtype_new(WASM_I64)
- ft = wasm_functype_new_0_1(vt1)
- results = wasm_vec_to_list(wasm_functype_results(ft))
-
- self.assertEqual(dereference(results[0]), dereference(vt1))
-
- wasm_functype_delete(ft)
-
- def test_wasm_functype_results_neg(self):
- results = wasm_functype_results(create_null_pointer(wasm_functype_t))
- self.assertIsNullPointer(results)
-
- def test_wasm_functype_copy_pos(self):
- ft1 = wasm_functype_new_2_1(
- wasm_valtype_new(WASM_I64),
- wasm_valtype_new(WASM_F64),
- wasm_valtype_new(WASM_I64),
- )
- ft2 = wasm_functype_copy(ft1)
-
- self.assertIsNotNullPointer(ft2)
- self.assertEqual(2, dereference(wasm_functype_params(ft1)).size)
- self.assertEqual(1, dereference(wasm_functype_results(ft2)).size)
-
- wasm_functype_delete(ft1)
- wasm_functype_delete(ft2)
-
- def test_wasm_functype_copy_neg(self):
- ft2 = wasm_functype_copy(create_null_pointer(wasm_functype_t))
- self.assertIsNullPointer(ft2)
- wasm_functype_delete(ft2)
-
- def test_wasm_globaltype_new_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- gt = wasm_globaltype_new(vt, True)
-
- self.assertIsNotNullPointer(gt)
-
- wasm_globaltype_delete(gt)
-
- def test_wasm_globaltype_new_neg(self):
- gt = wasm_globaltype_new(create_null_pointer(wasm_valtype_t), True)
- self.assertIsNullPointer(gt)
- wasm_globaltype_delete(gt)
-
- def test_wasm_globaltype_delete_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- gt = wasm_globaltype_new(vt, False)
- wasm_globaltype_delete(gt)
-
- def test_wasm_globaltype_delete_neg(self):
- wasm_globaltype_delete(create_null_pointer(wasm_globaltype_t))
-
- def test_wasm_globaltype_content_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- gt = wasm_globaltype_new(vt, True)
- gt_ret = wasm_globaltype_content(gt)
-
- self.assertEqual(dereference(vt), dereference(gt_ret))
-
- wasm_globaltype_delete(gt)
-
- def test_wasm_globaltype_content_neg(self):
- gt_ret = wasm_globaltype_content(create_null_pointer(wasm_globaltype_t))
- self.assertIsNullPointer(gt_ret)
-
- def test_wasm_globaltype_mutability_pos(self):
- vt1 = wasm_valtype_new(WASM_F32)
- gt1 = wasm_globaltype_new(vt1, False)
- vt2 = wasm_valtype_new(WASM_F32)
- gt2 = wasm_globaltype_new(vt2, True)
-
- self.assertFalse(wasm_globaltype_mutability(gt1))
- self.assertTrue(wasm_globaltype_mutability(gt2))
-
- wasm_globaltype_delete(gt1)
- wasm_globaltype_delete(gt2)
-
- def test_wasm_globaltype_mutability_neg(self):
- self.assertFalse(
- wasm_globaltype_mutability(create_null_pointer(wasm_globaltype_t))
- )
-
- def test_wasm_globaltype_copy_pos(self):
- vt = wasm_valtype_new(WASM_I32)
- gt1 = wasm_globaltype_new(vt, True)
- gt2 = wasm_globaltype_copy(gt1)
-
- self.assertEqual(dereference(gt1), dereference(gt2))
-
- wasm_globaltype_delete(gt1)
- wasm_globaltype_delete(gt2)
-
- def test_wasm_globaltype_copy_neg(self):
- gt2 = wasm_globaltype_copy(create_null_pointer(wasm_globaltype_t))
-
- self.assertIsNullPointer(gt2)
- wasm_globaltype_delete(gt2)
-
- def test_wasm_limit_new(self):
- limit = wasm_limits_new(10, 20)
- self.assertIsNotNullPointer(limit)
- self.assertEqual(dereference(limit).min, 10)
- self.assertEqual(dereference(limit).max, 20)
-
- def test_wasm_tabletype_new_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- limit = wasm_limits_new(0, 0xFF)
- tt = wasm_tabletype_new(vt, limit)
-
- self.assertIsNotNullPointer(tt)
- wasm_tabletype_delete(tt)
-
- def test_wasm_tabletype_new_null_val_type(self):
- limit = wasm_limits_new(0, 0xFFFFFFFF)
- tt = wasm_tabletype_new(create_null_pointer(wasm_valtype_t), limit)
-
- self.assertIsNullPointer(tt)
- wasm_tabletype_delete(tt)
-
- def test_wasm_tabletype_new_null_limits(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- tt = wasm_tabletype_new(vt, create_null_pointer(wasm_limits_t))
-
- self.assertIsNullPointer(tt)
- wasm_tabletype_delete(tt)
-
- def test_wasm_tabletype_delete_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- limit = wasm_limits_new(0, 0xFFFFFFFF)
- tt = wasm_tabletype_new(vt, limit)
- wasm_tabletype_delete(tt)
-
- def test_wasm_tabletype_delete_neg(self):
- wasm_tabletype_delete(create_null_pointer(wasm_tabletype_t))
-
- def test_wasm_tabletype_element_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- limit = wasm_limits_new(0, 0xFFFFFFFF)
- tt = wasm_tabletype_new(vt, limit)
- vt_ret = wasm_tabletype_element(tt)
-
- self.assertEqual(dereference(vt), dereference(vt_ret))
-
- wasm_tabletype_delete(tt)
-
- def test_wasm_tabletype_element_neg(self):
- vt_ret = wasm_tabletype_element(create_null_pointer(wasm_tabletype_t))
- self.assertIsNullPointer(vt_ret)
-
- def test_wasm_tabletype_limits_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- limit = wasm_limits_new(100, 256)
- tt = wasm_tabletype_new(vt, limit)
- limit_ret = wasm_tabletype_limits(tt)
-
- self.assertEqual(dereference(limit), dereference(limit_ret))
-
- wasm_tabletype_delete(tt)
-
- def test_wasm_tabletype_limits_neg(self):
- limit_ret = wasm_tabletype_limits(create_null_pointer(wasm_tabletype_t))
- self.assertIsNullPointer(limit_ret)
-
- def test_wasm_tabletype_copy_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- limit = wasm_limits_new(13, 19)
- tt1 = wasm_tabletype_new(vt, limit)
- tt2 = wasm_tabletype_copy(tt1)
-
- self.assertEqual(dereference(tt1), dereference(tt2))
-
- wasm_tabletype_delete(tt1)
- wasm_tabletype_delete(tt2)
-
- def test_wasm_tabletype_copy_neg(self):
- tt2 = wasm_tabletype_copy(create_null_pointer(wasm_tabletype_t))
- self.assertIsNullPointer(tt2)
- wasm_tabletype_delete(tt2)
-
- def test_wasm_memorytype_new_pos(self):
- limit = wasm_limits_new(0, 3)
- mt = wasm_memorytype_new(limit)
-
- self.assertIsNotNullPointer(mt)
-
- wasm_memorytype_delete(mt)
-
- def test_wasm_memorytype_new_neg(self):
- mt = wasm_memorytype_new(None)
-
- self.assertIsNullPointer(mt)
-
- wasm_memorytype_delete(mt)
-
- def test_wasm_memorytype_delete_pos(self):
- limit = wasm_limits_new(1, 2)
- mt = wasm_memorytype_new(limit)
- wasm_memorytype_delete(mt)
-
- def test_wasm_memorytype_delete_neg(self):
- wasm_memorytype_delete(create_null_pointer(wasm_memorytype_t))
-
- def test_wasm_memorytype_limits_pos(self):
- limit = wasm_limits_new(3, 8)
- mt = wasm_memorytype_new(limit)
- limit_ret = wasm_memorytype_limits(mt)
-
- self.assertEqual(dereference(limit), dereference(limit_ret))
-
- wasm_memorytype_delete(mt)
-
- def test_wasm_memorytype_limits_neg(self):
- wasm_memorytype_limits(create_null_pointer(wasm_memorytype_t))
-
- def test_wasm_memorytype_copy_pos(self):
- limit = wasm_limits_new(7, 13)
- mt1 = wasm_memorytype_new(limit)
- mt2 = wasm_memorytype_copy(mt1)
-
- self.assertEqual(
- dereference(mt1),
- dereference(mt2),
- )
-
- wasm_memorytype_delete(mt1)
- wasm_memorytype_delete(mt2)
-
- def test_wasm_memorytype_copy_neg(self):
- mt2 = wasm_memorytype_copy(create_null_pointer(wasm_memorytype_t))
-
- self.assertIsNullPointer(mt2)
-
- wasm_memorytype_delete(mt2)
-
- def test_wasm_externtype_kind_pos(self):
- ft = wasm_functype_new_0_0()
- gt = wasm_globaltype_new(wasm_valtype_new(WASM_FUNCREF), True)
- mt = wasm_memorytype_new(wasm_limits_new(1, 2))
- tt = wasm_tabletype_new(wasm_valtype_new(WASM_FUNCREF), wasm_limits_new(10, 20))
- ets = [
- wasm_functype_as_externtype(ft),
- wasm_globaltype_as_externtype(gt),
- wasm_memorytype_as_externtype(mt),
- wasm_tabletype_as_externtype(tt),
- ]
- type_kinds = [wasm_externtype_kind(et) for et in ets]
-
- self.assertEqual(
- type_kinds,
- [
- WASM_EXTERN_FUNC,
- WASM_EXTERN_GLOBAL,
- WASM_EXTERN_MEMORY,
- WASM_EXTERN_TABLE,
- ],
- )
-
- [wasm_externtype_delete(et) for et in ets]
-
- def test_wasm_externtype_kind_neg(self):
- et = wasm_memorytype_as_externtype(create_null_pointer(wasm_memorytype_t))
- self.assertIsNullPointer(et)
-
- def test_wasm_externtype_delete_pos(self):
- mt = wasm_memorytype_new(wasm_limits_new(10, 20))
- et = wasm_memorytype_as_externtype(mt)
- wasm_externtype_delete(et)
-
- def test_wasm_externtype_delete_neg(self):
- et = wasm_globaltype_as_externtype(create_null_pointer(wasm_globaltype_t))
- wasm_externtype_delete(et)
-
- def test_wasm_externtype_copy_pos(self):
- tt1 = wasm_tabletype_new(
- wasm_valtype_new(WASM_FUNCREF), wasm_limits_new(10, 20)
- )
- et1 = wasm_tabletype_as_externtype(tt1)
- et2 = wasm_externtype_copy(et1)
-
- tt2 = wasm_externtype_as_tabletype(et2)
- self.assertEqual(dereference(tt1), dereference(tt2))
-
- wasm_externtype_delete(et2)
- wasm_externtype_delete(et1)
-
- def test_wasm_externtype_copy_neg(self):
- et1 = create_null_pointer(wasm_externtype_t)
- et2 = wasm_externtype_copy(et1)
- wasm_externtype_delete(et2)
- wasm_externtype_delete(et1)
-
- def test_wasm_name_new_from_string(self):
- s = "let the stars shine upon you"
- name = wasm_name_new_from_string(s)
-
- name_data = c.cast(name.data, c.c_char_p)
- name_data = bytes.decode(name_data.value)
- self.assertEqual(name_data, s)
-
- def test_wasm_importtype_new_pos(self):
- module_name = "mA"
- field_name = "func#1"
- module_name = wasm_name_new_from_string(module_name)
- field_name = wasm_name_new_from_string(field_name)
- ft = wasm_functype_new_0_0()
- et = wasm_functype_as_externtype(ft)
- it = wasm_importtype_new(module_name, field_name, et)
-
- self.assertIsNotNullPointer(it)
- self.assertEqual(dereference(wasm_importtype_module(it)), module_name)
- self.assertEqual(dereference(wasm_importtype_name(it)), field_name)
- self.assertEqual(dereference(wasm_importtype_type(it)), dereference(et))
-
- wasm_importtype_delete(it)
-
- def test_wasm_importtype_new_null_ext_type(self):
- module_name = "mA"
- field_name = "func#1"
- module_name = wasm_name_new_from_string(module_name)
- field_name = wasm_name_new_from_string(field_name)
- it = wasm_importtype_new(
- module_name,
- field_name,
- create_null_pointer(wasm_externtype_t),
- )
-
- self.assertIsNullPointer(it)
-
- wasm_importtype_delete(it)
-
- def test_wasm_importtype_new_null_module(self):
- field_name = "func#1"
- field_name = wasm_name_new_from_string(field_name)
- ft = wasm_functype_new_0_0()
- et = wasm_functype_as_externtype(ft)
- it = wasm_importtype_new(create_null_pointer(wasm_name_t), field_name, et)
-
- self.assertIsNullPointer(it)
-
- wasm_importtype_delete(it)
-
- def test_wasm_importtype_new_null_field(self):
- module_name = "mA"
- module_name = wasm_name_new_from_string(module_name)
- ft = wasm_functype_new_0_0()
- et = wasm_functype_as_externtype(ft)
- it = wasm_importtype_new(module_name, create_null_pointer(wasm_name_t), et)
-
- self.assertIsNullPointer(it)
-
- wasm_importtype_delete(it)
-
- def test_wasm_importtype_copy_pos(self):
- module_name = "mA"
- field_name = "memory#1"
- module_name = wasm_name_new_from_string(module_name)
- field_name = wasm_name_new_from_string(field_name)
- mt = wasm_memorytype_new(wasm_limits_new(10, 20))
- et = wasm_memorytype_as_externtype(mt)
- it1 = wasm_importtype_new(module_name, field_name, et)
- it2 = wasm_importtype_copy(it1)
-
- self.assertEqual(dereference(it1), dereference(it2))
-
- wasm_importtype_delete(it1)
- wasm_importtype_delete(it2)
-
- def test_wasm_importtype_copy_neg(self):
- it1 = create_null_pointer(wasm_importtype_t)
- it2 = wasm_importtype_copy(it1)
- wasm_importtype_delete(it1)
- wasm_importtype_delete(it2)
-
- def test_wasm_importtype_delete_pos(self):
- module_name = "mA"
- field_name = "memory#1"
- module_name = wasm_name_new_from_string(module_name)
- field_name = wasm_name_new_from_string(field_name)
- tt = wasm_tabletype_new(wasm_valtype_new(WASM_FUNCREF), wasm_limits_new(10, 20))
- et = wasm_tabletype_as_externtype(tt)
- it = wasm_importtype_new(module_name, field_name, et)
- wasm_importtype_delete(it)
-
- def test_wasm_importtype_delete_neg(self):
- wasm_importtype_delete(create_null_pointer(wasm_importtype_t))
-
- def test_wasm_importtype_module_pos(self):
- module_name = "mA"
- field_name = "func#1"
- module_name = wasm_name_new_from_string(module_name)
- field_name = wasm_name_new_from_string(field_name)
- ft = wasm_functype_new_0_0()
- et = wasm_functype_as_externtype(ft)
- it = wasm_importtype_new(module_name, field_name, et)
- module_name_ret = wasm_importtype_module(it)
-
- self.assertEqual(dereference(module_name_ret), module_name)
-
- wasm_importtype_delete(it)
-
- def test_wasm_importtype_module_neg(self):
- it = create_null_pointer(wasm_importtype_t)
- wasm_importtype_module(it)
- wasm_importtype_delete(it)
-
- def test_wasm_importtype_name_pos(self):
- module_name = "mA"
- field_name = "func#1"
- module_name = wasm_name_new_from_string(module_name)
- field_name = wasm_name_new_from_string(field_name)
- ft = wasm_functype_new_0_0()
- et = wasm_functype_as_externtype(ft)
- it = wasm_importtype_new(module_name, field_name, et)
- field_name_ret = wasm_importtype_name(it)
-
- self.assertEqual(dereference(field_name_ret), field_name)
-
- wasm_importtype_delete(it)
-
- def test_wasm_importtype_name_neg(self):
- it = create_null_pointer(wasm_importtype_t)
- wasm_importtype_name(it)
- wasm_importtype_delete(it)
-
- def test_wasm_importtype_type_pos(self):
- module_name = "mA"
- field_name = "func#1"
- module_name = wasm_name_new_from_string(module_name)
- field_name = wasm_name_new_from_string(field_name)
- ft = wasm_functype_new_0_0()
- et = wasm_functype_as_externtype(ft)
- it = wasm_importtype_new(module_name, field_name, et)
- et_ret = wasm_importtype_type(it)
-
- self.assertEqual(dereference(et_ret), dereference(et))
-
- wasm_importtype_delete(it)
-
- def test_wasm_importtype_type_neg(self):
- it = create_null_pointer(wasm_importtype_t)
- wasm_importtype_type(it)
- wasm_importtype_delete(it)
-
- def test_wasm_exporttype_new_pos(self):
- name = "hello"
- name = wasm_name_new_from_string(name)
- ft = wasm_functype_new_0_0()
- ft = wasm_functype_as_externtype(ft)
- et = wasm_exporttype_new(name, ft)
-
- self.assertIsNotNullPointer(et)
-
- wasm_exporttype_delete(et)
-
- def test_wasm_exporttype_new_null_name(self):
- name = create_null_pointer(wasm_name_t)
- ft = wasm_functype_new_0_0()
- ft = wasm_functype_as_externtype(ft)
- et = wasm_exporttype_new(name, ft)
-
- self.assertIsNullPointer(et)
-
- wasm_exporttype_delete(et)
-
- def test_wasm_exporttype_new_null_ext_type(self):
- name = "hello"
- name = wasm_name_new_from_string(name)
- ext_type = create_null_pointer(wasm_externtype_t)
- et = wasm_exporttype_new(name, ext_type)
-
- self.assertIsNullPointer(et)
-
- wasm_exporttype_delete(et)
-
- def test_wasm_exporttype_copy_pos(self):
- name = "hello"
- name = wasm_name_new_from_string(name)
- gt = wasm_globaltype_new(wasm_valtype_new(WASM_F32), True)
- gt = wasm_globaltype_as_externtype(gt)
- et1 = wasm_exporttype_new(name, gt)
- et2 = wasm_exporttype_copy(et1)
-
- self.assertEqual(
- dereference(et1),
- dereference(et2),
- )
-
- wasm_exporttype_delete(et1)
- wasm_exporttype_delete(et2)
-
- def test_wasm_exporttype_copy_neg(self):
- et1 = create_null_pointer(wasm_exporttype_t)
- et2 = wasm_exporttype_copy(et1)
-
- wasm_exporttype_delete(et1)
- wasm_exporttype_delete(et2)
-
- def test_wasm_exporttype_delete_pos(self):
- name = "hello"
- name = wasm_name_new_from_string(name)
- mt = wasm_memorytype_new(wasm_limits_new(10, 20))
- mt = wasm_memorytype_as_externtype(mt)
- et = wasm_exporttype_new(name, mt)
-
- wasm_exporttype_delete(et)
-
- def test_wasm_exporttype_delete_neg(self):
- et = create_null_pointer(wasm_exporttype_t)
- wasm_exporttype_delete(et)
-
- def test_wasm_exporttype_name_pos(self):
- name = "hello"
- name = wasm_name_new_from_string(name)
- tt = wasm_tabletype_new(wasm_valtype_new(WASM_FUNCREF), wasm_limits_new(10, 20))
- tt = wasm_tabletype_as_externtype(tt)
- et = wasm_exporttype_new(name, tt)
- name_ret = wasm_exporttype_name(et)
-
- self.assertEqual(dereference(name_ret), name)
-
- wasm_exporttype_delete(et)
-
- def test_wasm_exporttype_name_neg(self):
- et = create_null_pointer(wasm_exporttype_t)
- wasm_exporttype_name(et)
- wasm_exporttype_delete(et)
-
- def test_wasm_exporttype_type_pos(self):
- name = "hello"
- name = wasm_name_new_from_string(name)
- tt = wasm_tabletype_new(wasm_valtype_new(WASM_FUNCREF), wasm_limits_new(10, 20))
- tt = wasm_tabletype_as_externtype(tt)
- et = wasm_exporttype_new(name, tt)
- tt_ret = wasm_exporttype_type(et)
-
- self.assertEqual(dereference(tt_ret), dereference(tt))
-
- wasm_exporttype_delete(et)
-
- def test_wasm_exporttype_type_neg(self):
- et = create_null_pointer(wasm_exporttype_t)
- wasm_exporttype_type(et)
- wasm_exporttype_delete(et)
-
- def test_wasm_i32_val(self):
- val = wasm_i32_val(100)
-
- self.assertEqual(val.kind, WASM_I32)
- self.assertEqual(val.of.i32, 100)
-
- # can not use wasm_val_delete() because it is not malloced
-
- def test_wasm_i64_val(self):
- val = wasm_i64_val(-100)
-
- self.assertEqual(val.kind, WASM_I64)
- self.assertEqual(val.of.i64, -100)
-
- # can not use wasm_val_delete() because it is not malloced
-
- def test_wasm_f32_val(self):
- val = wasm_f32_val(100)
-
- self.assertEqual(val.kind, WASM_F32)
- self.assertEqual(val.of.f32, 100.0)
-
- # can not use wasm_val_delete() because it is not malloced
-
- def test_wasm_f64_val(self):
- val = wasm_f64_val(-100)
-
- self.assertEqual(val.kind, WASM_F64)
- self.assertEqual(val.of.f64, -100.0)
-
- # can not use wasm_val_delete() because it is not malloced
-
- # there is no wasm_val_new() to malloc a wasm_val_t
- def test_wasm_val_delete(self):
- pass
-
- def test_wasm_val_copy(self):
- v1 = wasm_f32_val(3.14)
- v2 = wasm_val_t()
- wasm_val_copy(v1, v2)
-
- self.assertEqual(v1, v2)
- # can not use wasm_val_delete() because it is not malloced
-
- def test_wasm_ref_delete_neg(self):
- ref = create_null_pointer(wasm_ref_t)
- wasm_ref_delete(ref)
-
- ref = wasm_ref_t()
- wasm_ref_delete(ref)
-
- def test_wasm_trap_new_pos(self):
- # can't create a trap with traces(wasm_frame_vec_t)
- msg = wasm_name_new_from_string("a fake trap")
- trap = wasm_trap_new(self._wasm_store, msg)
-
- self.assertIsNotNone(trap)
-
- wasm_trap_delete(trap)
-
- def test_wasm_trap_new_null_msg(self):
- trap = wasm_trap_new(self._wasm_store, create_null_pointer(wasm_name_t))
-
- self.assertIsNotNone(trap)
- self.assertIsNotNullPointer(trap)
-
- wasm_trap_delete(trap)
-
- def test_wasm_trap_message_pos(self):
- msg = wasm_name_new_from_string("a fake trap")
- trap = wasm_trap_new(self._wasm_store, msg)
- msg_in_trap = wasm_message_t()
- wasm_trap_message(trap, msg_in_trap)
-
- self.assertEqual(
- msg,
- msg_in_trap,
- )
-
- wasm_trap_delete(trap)
-
- def test_wasm_trap_message_null_trap(self):
- msg = wasm_name_new_from_string("a fake trap")
- wasm_trap_message(create_null_pointer(wasm_trap_t), msg)
-
- def test_wasm_trap_message_null_out(self):
- msg = wasm_name_new_from_string("a fake trap")
- trap = wasm_trap_new(self._wasm_store, msg)
- wasm_trap_message(trap, create_null_pointer(wasm_message_t))
- wasm_trap_delete(trap)
-
- # test those APIs in advance:
- # wasm_trap_origin
- # wasm_trap_trace
- # wasm_frame_delete
- # wasm_frame_copy
- # wasm_frame_module_offset
- # wasm_frame_instance
- # wasm_frame_func_index
- # wasm_frame_func_offset
-
- def test_wasm_foreign_new_pos(self):
- foreign = wasm_foreign_new(self._wasm_store)
-
- self.assertIsNotNone(foreign)
- self.assertIsNotNullPointer(foreign)
-
- wasm_foreign_delete(foreign)
-
- def test_wasm_foreign_new_neg(self):
- foreign = wasm_foreign_new(create_null_pointer(wasm_store_t))
-
- self.assertIsNotNone(foreign)
- self.assertIsNullPointer(foreign)
-
- wasm_foreign_delete(foreign)
-
- def test_wasm_foreign_delete_pos(self):
- foreign = wasm_foreign_new(self._wasm_store)
- wasm_foreign_delete(foreign)
-
- def test_wasm_foreign_delete_neg(self):
- wasm_foreign_delete(create_null_pointer(wasm_foreign_t))
-
- # wasm_egnine_new()/wasm_engine_delete()
- # wasm_store_new()/wasm_store_delete()
- # used in setUpClass() and tearDownClass
-
- def test_wasm_module_new_pos(self):
- binary = load_module_file(MODULE_BINARY)
- module = wasm_module_new(self._wasm_store, binary)
-
- self.assertIsNotNone(module)
- self.assertIsNotNullPointer(module)
-
- wasm_byte_vec_delete(binary)
- wasm_module_delete(module)
-
- def test_wasm_module_new_neg(self):
- module = wasm_module_new(self._wasm_store, create_null_pointer(wasm_byte_vec_t))
-
- self.assertIsNotNone(module)
- self.assertIsNullPointer(module)
-
- wasm_module_delete(module)
-
- def test_wasm_module_delete_pos(self):
- binary = load_module_file(MODULE_BINARY)
- module = wasm_module_new(self._wasm_store, binary)
- wasm_byte_vec_delete(binary)
- wasm_module_delete(module)
-
- def test_wasm_module_delete_neg(self):
- module = wasm_module_new(self._wasm_store, create_null_pointer(wasm_byte_vec_t))
- wasm_module_delete(module)
-
- def test_wasm_module_validate_pos(self):
- binary = load_module_file(MODULE_BINARY)
- validation = wasm_module_validate(self._wasm_store, binary)
-
- self.assertTrue(validation)
-
- wasm_byte_vec_delete(binary)
-
- def test_wasm_module_validate_neg(self):
- tmp = (1024).to_bytes(2, byteorder="big")
- binary = load_module_file(tmp)
- validation = wasm_module_validate(self._wasm_store, binary)
-
- self.assertFalse(validation)
-
- wasm_byte_vec_delete(binary)
-
- def test_wasm_module_imports_pos(self):
- binary = load_module_file(MODULE_BINARY)
- module = wasm_module_new(self._wasm_store, binary)
- imports = wasm_importtype_vec_t()
- wasm_module_imports(module, imports)
-
- imports_list = wasm_vec_to_list(imports)
- self.assertEqual(len(imports_list), 2)
-
- func_type = wasm_functype_new_1_1(
- wasm_valtype_new(WASM_F32),
- wasm_valtype_new(WASM_F64),
- )
- ext_type = wasm_functype_as_externtype(func_type)
- self.assertEqual(
- dereference(wasm_importtype_type(imports_list[0])), dereference(ext_type)
- )
-
- wasm_externtype_delete(ext_type)
- wasm_importtype_vec_delete(imports)
- wasm_byte_vec_delete(binary)
- wasm_module_delete(module)
-
- def test_wasm_module_imports_null_module(self):
- imports = wasm_importtype_vec_t()
- wasm_module_imports(create_null_pointer(wasm_module_t), imports)
-
- self.assertEqual(imports.size, 0)
-
- wasm_importtype_vec_delete(imports)
-
- def test_wasm_module_imports_null_out(self):
- binary = load_module_file(MODULE_BINARY)
- module = wasm_module_new(self._wasm_store, binary)
- wasm_module_imports(module, create_null_pointer(wasm_importtype_vec_t))
- wasm_byte_vec_delete(binary)
- wasm_module_delete(module)
-
- def test_wasm_module_exports_pos(self):
- binary = load_module_file(MODULE_BINARY)
- module = wasm_module_new(self._wasm_store, binary)
- exports = wasm_exporttype_vec_t()
- wasm_module_exports(module, exports)
-
- exports_list = wasm_vec_to_list(exports)
- self.assertEqual(len(exports_list), 2)
-
- glbl_type = wasm_globaltype_new(wasm_valtype_new(WASM_F32), True)
- ext_type = wasm_globaltype_as_externtype(glbl_type)
- self.assertEqual(
- dereference(wasm_exporttype_type(exports_list[1])), dereference(ext_type)
- )
-
- wasm_exporttype_vec_delete(exports)
- wasm_byte_vec_delete(binary)
- wasm_module_delete(module)
-
- def test_wasm_module_exports_null_module(self):
- exports = wasm_exporttype_vec_t()
- wasm_module_exports(create_null_pointer(wasm_module_t), exports)
-
- self.assertEqual(exports.size, 0)
-
- wasm_exporttype_vec_delete(exports)
-
- def test_wasm_module_exports_null_out(self):
- binary = load_module_file(MODULE_BINARY)
- module = wasm_module_new(self._wasm_store, binary)
- wasm_module_exports(module, create_null_pointer(wasm_exporttype_vec_t))
- wasm_byte_vec_delete(binary)
- wasm_module_delete(module)
-
- def test_wasm_instance_new_pos_empty_imports(self):
- binary = load_module_file(MODULE_BINARY)
- module = wasm_module_new(self._wasm_store, binary)
- imports = wasm_extern_vec_t()
- wasm_extern_vec_new_empty(imports)
- instance = wasm_instance_new(
- self._wasm_store, module, imports, create_null_pointer(wasm_trap_t)
- )
-
- wasm_module_delete(module)
-
- self.assertIsNullPointer(instance)
-
- def test_wasm_instance_new_pos(self):
- binary = load_module_file(MODULE_BINARY)
- module = wasm_module_new(self._wasm_store, binary)
-
- ft = wasm_functype_new_1_1(
- wasm_valtype_new(WASM_F32),
- wasm_valtype_new(WASM_F64),
- )
- func = wasm_func_new(self._wasm_store, ft, callback)
-
- gt = wasm_globaltype_new(wasm_valtype_new(WASM_I32), True)
- init = wasm_i32_val(100)
- gb = wasm_global_new(self._wasm_store, gt, init)
-
- imports = wasm_extern_vec_t()
- data = list_to_carray(
- c.POINTER(wasm_extern_t),
- wasm_func_as_extern(func),
- wasm_global_as_extern(gb),
- )
- wasm_extern_vec_new(imports, 2, data)
-
- instance = wasm_instance_new(
- self._wasm_store, module, imports, create_null_pointer(wasm_trap_t)
- )
-
- self.assertIsNotNone(instance)
-
- wasm_instance_delete(instance)
- wasm_module_delete(module)
-
- def test_wasm_instance_new_neg_null_imports(self):
- binary = load_module_file(MODULE_BINARY)
- module = wasm_module_new(self._wasm_store, binary)
- instance = wasm_instance_new(
- self._wasm_store,
- module,
- create_null_pointer(wasm_extern_vec_t),
- create_null_pointer(wasm_trap_t),
- )
-
- wasm_module_delete(module)
-
- self.assertIsNullPointer(instance)
-
- # test those APIs in advanced:
- # wasm_instance_delete
- # wasm_instance_exports
-
- def test_wasm_func_new_pos(self):
- vt1 = wasm_valtype_new(WASM_F32)
- vt2 = wasm_valtype_new(WASM_FUNCREF)
- ft = wasm_functype_new_1_1(vt1, vt2)
- func = wasm_func_new(self._wasm_store, ft, callback)
-
- self.assertIsNotNone(func)
- self.assertIsNotNullPointer(func)
-
- wasm_func_delete(func)
-
- def test_wasm_func_new_null_type(self):
- func = wasm_func_new(
- self._wasm_store, create_null_pointer(wasm_functype_t), callback
- )
-
- self.assertIsNotNone(func)
- self.assertIsNullPointer(func)
-
- wasm_func_delete(func)
-
- def test_wasm_func_new_null_callback(self):
- vt1 = wasm_valtype_new(WASM_F32)
- vt2 = wasm_valtype_new(WASM_FUNCREF)
- ft = wasm_functype_new_1_1(vt1, vt2)
- func = wasm_func_new(self._wasm_store, ft, wasm_func_callback_t())
-
- self.assertIsNotNone(func)
- self.assertIsNullPointer(func)
-
- wasm_func_delete(func)
-
- def test_wasm_func_new_with_env_pos(self):
- ft = wasm_functype_new_3_1(
- wasm_valtype_new(WASM_I32),
- wasm_valtype_new(WASM_F32),
- wasm_valtype_new(WASM_I64),
- wasm_valtype_new(WASM_I64),
- )
- func = wasm_func_new_with_env(
- self._wasm_store,
- ft,
- callback_with_env,
- c.c_void_p(0),
- wasm_finalizer(0),
- )
-
- self.assertIsNotNone(func)
- self.assertIsNotNullPointer(func)
-
- wasm_func_delete(func)
-
- def test_wasm_func_new_with_env_null_type(self):
- func = wasm_func_new_with_env(
- self._wasm_store,
- create_null_pointer(wasm_functype_t),
- callback_with_env,
- c.c_void_p(0),
- wasm_finalizer(0),
- )
-
- self.assertIsNotNone(func)
- self.assertIsNullPointer(func)
-
- wasm_func_delete(func)
-
- def test_wasm_func_new_with_env_null_callback(self):
- ft = wasm_functype_new_3_1(
- wasm_valtype_new(WASM_I32),
- wasm_valtype_new(WASM_F32),
- wasm_valtype_new(WASM_I64),
- wasm_valtype_new(WASM_I64),
- )
- func = wasm_func_new_with_env(
- self._wasm_store,
- ft,
- wasm_func_callback_with_env_t(),
- c.c_void_p(0),
- wasm_finalizer(0),
- )
-
- self.assertIsNotNone(func)
- self.assertIsNullPointer(func)
-
- wasm_func_delete(func)
-
- def test_wasm_func_delete_pos(self):
- ft = wasm_functype_new_0_0()
- func = wasm_func_new(self._wasm_store, ft, callback)
- wasm_func_delete(func)
-
- def test_wasm_func_delete_neg(self):
- wasm_func_delete(create_null_pointer(wasm_func_t))
-
- def test_wasm_func_type_pos(self):
- ft = wasm_functype_new_2_0(
- wasm_valtype_new(WASM_F32),
- wasm_valtype_new(WASM_FUNCREF),
- )
- func = wasm_func_new(self._wasm_store, ft, callback)
- ft_ret = wasm_func_type(func)
-
- self.assertEqual(
- dereference(ft),
- dereference(ft_ret),
- )
-
- wasm_functype_delete(ft_ret)
- wasm_func_delete(func)
-
- def test_wasm_func_type_neg(self):
- ft_ret = wasm_func_type(create_null_pointer(wasm_func_t))
- wasm_functype_delete(ft_ret)
-
- def test_wasm_func_copy_pos(self):
- vt1 = wasm_valtype_new(WASM_F32)
- ft = wasm_functype_new_0_1(vt1)
- func1 = wasm_func_new(self._wasm_store, ft, callback)
- func2 = wasm_func_copy(func1)
-
- self.assertEqual(
- dereference(wasm_func_type(func1)), dereference(wasm_func_type(func2))
- )
-
- wasm_func_delete(func2)
- wasm_func_delete(func1)
-
- def test_wasm_func_copy_neg(self):
- func1 = wasm_func_new(
- self._wasm_store, create_null_pointer(wasm_functype_t), callback
- )
- func2 = wasm_func_copy(func1)
-
- wasm_func_delete(func2)
- wasm_func_delete(func1)
-
- # test wasm_func_call in advanced
-
- def test_wasm_global_new_pos(self):
- vt = wasm_valtype_new(WASM_F32)
- gt = wasm_globaltype_new(vt, False)
- v = wasm_f32_val(3.14)
- g = wasm_global_new(self._wasm_store, gt, v)
-
- self.assertIsNotNone(g)
- self.assertIsNotNullPointer(g)
-
- wasm_globaltype_delete(gt)
- wasm_global_delete(g)
-
- def test_wasm_global_new_null_type(self):
- v = wasm_f32_val(3.14)
- g = wasm_global_new(self._wasm_store, create_null_pointer(wasm_globaltype_t), v)
-
- self.assertIsNotNone(g)
- self.assertIsNullPointer(g)
-
- wasm_global_delete(g)
-
- def test_wasm_global_new_null_init(self):
- vt = wasm_valtype_new(WASM_F32)
- gt = wasm_globaltype_new(vt, False)
- g = wasm_global_new(self._wasm_store, gt, create_null_pointer(wasm_val_t))
-
- self.assertIsNotNone(g)
- self.assertIsNullPointer(g)
-
- wasm_globaltype_delete(gt)
- wasm_global_delete(g)
-
- def test_wasm_global_delete_pos(self):
- vt = wasm_valtype_new(WASM_I32)
- gt = wasm_globaltype_new(vt, True)
- v = wasm_i32_val(3)
- g = wasm_global_new(self._wasm_store, gt, v)
- wasm_globaltype_delete(gt)
- wasm_global_delete(g)
-
- def test_wasm_global_delete_neg(self):
- wasm_global_delete(create_null_pointer(wasm_global_t))
-
- def test_wasm_global_type_pos(self):
- vt = wasm_valtype_new(WASM_I64)
- gt = wasm_globaltype_new(vt, False)
- v = wasm_i32_val(3)
- g = wasm_global_new(self._wasm_store, gt, v)
- gt_ret = wasm_global_type(g)
-
- self.assertEqual(dereference(gt), dereference(gt_ret))
-
- wasm_globaltype_delete(gt)
- wasm_globaltype_delete(gt_ret)
- wasm_global_delete(g)
-
- def test_wasm_global_type_neg(self):
- gt = wasm_global_type(create_null_pointer(wasm_global_t))
- wasm_globaltype_delete(gt)
-
- # test wasm_global_get and wasm_global_set in advanced
-
- def test_wasm_table_new_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- limits = wasm_limits_new(10, 15)
- tt = wasm_tabletype_new(vt, limits)
- t = wasm_table_new(self._wasm_store, tt, create_null_pointer(wasm_ref_t))
-
- self.assertIsNotNone(t)
- self.assertIsNotNullPointer(t)
-
- wasm_table_delete(t)
-
- def test_wasm_table_new_null_type(self):
- t = wasm_table_new(
- self._wasm_store,
- create_null_pointer(wasm_tabletype_t),
- create_null_pointer(wasm_ref_t),
- )
-
- self.assertIsNotNone(t)
- self.assertIsNullPointer(t)
-
- wasm_table_delete(t)
-
- def test_wasm_table_delete_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- limits = wasm_limits_new(10, 15)
- tt = wasm_tabletype_new(vt, limits)
- t = wasm_table_new(self._wasm_store, tt, create_null_pointer(wasm_ref_t))
- wasm_table_delete(t)
-
- def test_wasm_table_delete_neg(self):
- wasm_table_delete(create_null_pointer(wasm_table_t))
-
- def test_wasm_table_type_pos(self):
- vt = wasm_valtype_new(WASM_FUNCREF)
- limits = wasm_limits_new(1, 2)
- tt = wasm_tabletype_new(vt, limits)
- t = wasm_table_new(self._wasm_store, tt, create_null_pointer(wasm_ref_t))
- tt_ret = wasm_table_type(t)
-
- self.assertEqual(
- dereference(tt),
- dereference(tt_ret),
- )
-
- wasm_table_delete(t)
-
- def test_wasm_table_type_neg(self):
- t = wasm_table_new(
- self._wasm_store,
- create_null_pointer(wasm_tabletype_t),
- create_null_pointer(wasm_ref_t),
- )
- tt_ret = wasm_table_type(t)
- wasm_table_delete(t)
-
- # test wasm_table_size, wasm_table_get, wasm_table_set in advanced
-
- def test_wasm_memory_new_pos(self):
- limits = wasm_limits_new(10, 12)
- mt = wasm_memorytype_new(limits)
- m = wasm_memory_new(self._wasm_store, mt)
-
- self.assertIsNotNullPointer(m)
-
- wasm_memory_delete(m)
-
- def test_wasm_memory_new_null_type(self):
- m = wasm_memory_new(self._wasm_store, create_null_pointer(wasm_memorytype_t))
-
- self.assertIsNullPointer(m)
-
- wasm_memory_delete(m)
-
- def test_wasm_memory_delete_pos(self):
- limits = wasm_limits_new(10, 21)
- mt = wasm_memorytype_new(limits)
- m = wasm_memory_new(self._wasm_store, mt)
- wasm_memory_delete(m)
-
- def test_wasm_memory_delete_neg(self):
- wasm_memory_delete(create_null_pointer(wasm_memory_t))
-
- def test_wasm_memory_type_pos(self):
- limits = wasm_limits_new(10, 21)
- mt = wasm_memorytype_new(limits)
- m = wasm_memory_new(self._wasm_store, mt)
- mt_ret = wasm_memory_type(m)
-
- self.assertEqual(dereference(mt), dereference(mt_ret))
-
- wasm_memory_delete(m)
-
- def test_wasm_memory_type_neg(self):
- mt = wasm_memory_type(create_null_pointer(wasm_memory_t))
-
- self.assertIsNullPointer(mt)
- wasm_memorytype_delete(mt)
-
- # test wasm_memory_size, wasm_memory_data, wasm_memory_data_size in advanced
-
- def test_wasm_extern_delete_pos(self):
- vt = wasm_valtype_new(WASM_I64)
- gt = wasm_globaltype_new(vt, False)
- v = wasm_i64_val(128)
- glb = wasm_global_new(self._wasm_store, gt, v)
- etrn = wasm_global_as_extern(glb)
- wasm_extern_delete(etrn)
-
- def test_wasm_extern_delete_neg(self):
- etrn = wasm_global_as_extern(create_null_pointer(wasm_global_t))
- wasm_extern_delete(etrn)
-
- def test_wasm_extern_type_pos(self):
- vt = wasm_valtype_new(WASM_I64)
- gt = wasm_globaltype_new(vt, False)
- v = wasm_i64_val(128)
- glb = wasm_global_new(self._wasm_store, gt, v)
- etrn = wasm_global_as_extern(glb)
-
- tp = wasm_extern_type(etrn)
- gt_ret = wasm_externtype_as_globaltype(tp)
- self.assertEqual(
- dereference(gt),
- dereference(gt_ret),
- )
- wasm_extern_delete(etrn)
-
- def test_wasm_extern_type_neg(self):
- wasm_extern_type(create_null_pointer(wasm_extern_t))
-
- def test_wasm_extern_kind_pos(self):
- ft = wasm_functype_new_0_0()
- func = wasm_func_new(self._wasm_store, ft, callback)
- etrn = wasm_func_as_extern(func)
- kind = wasm_extern_kind(etrn)
-
- self.assertEqual(WASM_EXTERN_FUNC, kind)
-
- wasm_extern_delete(etrn)
-
- def test_wasm_extern_kind_neg(self):
- wasm_extern_kind(create_null_pointer(wasm_extern_t))
-
- @classmethod
- def tearDownClass(cls):
- wasm_store_delete(cls._wasm_store)
- wasm_engine_delete(cls._wasm_engine)
-
-
-if __name__ == "__main__":
- unittest.main()
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/utils/bindgen.py b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/utils/bindgen.py
deleted file mode 100644
index a505404d5..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/language-bindings/python/wasm-c-api/utils/bindgen.py
+++ /dev/null
@@ -1,386 +0,0 @@
-# -*- coding: utf-8 -*-
-#!/usr/bin/env python3
-#
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-# pylint: disable=missing-class-docstring
-# pylint: disable=missing-function-docstring
-# pylint: disable=missing-module-docstring
-
-"""
-- Need to run *download_wamr.py* firstly.
-- Parse *./wasm-micro-runtime/core/iwasm/include/wasm_c_api.h* and generate
- *wamr/binding.py*
-"""
-import os
-import pathlib
-import shutil
-import sys
-
-from pycparser import c_ast, parse_file
-
-WASM_C_API_HEADER = "core/iwasm/include/wasm_c_api.h"
-BINDING_PATH = "language-bindings/python/wamr/wasmcapi/binding.py"
-# 4 spaces as default indent
-INDENT = " "
-
-IGNORE_SYMOLS = (
- "wasm_engine_new_with_args",
- "wasm_valkind_is_num",
- "wasm_valkind_is_ref",
- "wasm_valtype_is_num",
- "wasm_valtype_is_ref",
- "wasm_valtype_new_i32",
- "wasm_valtype_new_i64",
- "wasm_valtype_new_f32",
- "wasm_valtype_new_f64",
- "wasm_valtype_new_anyref",
- "wasm_valtype_new_funcref",
- "wasm_functype_new_0_0",
- "wasm_functype_new_0_0",
- "wasm_functype_new_1_0",
- "wasm_functype_new_2_0",
- "wasm_functype_new_3_0",
- "wasm_functype_new_0_1",
- "wasm_functype_new_1_1",
- "wasm_functype_new_2_1",
- "wasm_functype_new_3_1",
- "wasm_functype_new_0_2",
- "wasm_functype_new_1_2",
- "wasm_functype_new_2_2",
- "wasm_functype_new_3_2",
- "wasm_val_init_ptr",
- "wasm_val_ptr",
- "wasm_val_t",
- "wasm_ref_t",
- "wasm_name_new_from_string",
- "wasm_name_new_from_string_nt",
-)
-
-
-class Visitor(c_ast.NodeVisitor):
- def __init__(self):
- self.type_map = {
- "_Bool": "c_bool",
- "byte_t": "c_ubyte",
- "char": "c_char",
- "errno_t": "c_int",
- "int": "c_int",
- "long": "c_long",
- "size_t": "c_size_t",
- "uint32_t": "c_uint32",
- "uint8_t": "c_uint8",
- "void": "None",
- }
- self.ret = (
- "# -*- coding: utf-8 -*-\n"
- "#!/usr/bin/env python3\n"
- "#\n"
- "# Copyright (C) 2019 Intel Corporation. All rights reserved.\n"
- "# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception\n"
- "#\n"
- "#It is a generated file. DO NOT EDIT.\n"
- "#\n"
- "from ctypes import *\n"
- "\n"
- "from .ffi import dereference, libiwasm, wasm_ref_t, wasm_val_t\n"
- "\n"
- "\n"
- )
-
- def get_type_name(self, c_type):
- if isinstance(c_type, c_ast.TypeDecl):
- return self.get_type_name(c_type.type)
- elif isinstance(c_type, c_ast.PtrDecl):
- pointed_type = self.get_type_name(c_type.type)
-
- if isinstance(c_type.type, c_ast.FuncDecl):
- # CFUCNTYPE is a pointer of function
- return pointed_type
-
- if "None" == pointed_type:
- return "c_void_p"
-
- return f"POINTER({pointed_type})"
-
- elif isinstance(c_type, c_ast.ArrayDecl):
- return f"POINTER({self.get_type_name(c_type.type)})"
- elif isinstance(c_type, c_ast.IdentifierType):
- if len(c_type.names) > 1:
- raise RuntimeError(f"unexpected type with a long names: {c_type}")
-
- type_name = c_type.names[0]
-
- if type_name.startswith("wasm_"):
- return type_name
-
- if not type_name in self.type_map:
- raise RuntimeError(f"a new type should be in type_map: {type_name}")
-
- return self.type_map.get(type_name)
- elif isinstance(c_type, c_ast.Union):
- if not c_type.name:
- raise RuntimeError(f"found an anonymous union {c_type}")
-
- return c_type.name
- elif isinstance(c_type, c_ast.Struct):
- if not c_type.name:
- raise RuntimeError(f"found an anonymous union {c_type}")
-
- return c_type.name
- elif isinstance(c_type, c_ast.FuncDecl):
- content = "CFUNCTYPE("
- if isinstance(c_type.type, c_ast.PtrDecl):
- # there is a bug in CFUNCTYPE if the result type is a pointer
- content += "c_void_p"
- else:
- content += f"{self.get_type_name(c_type.type)}"
- content += f",{self.get_type_name(c_type.args)}" if c_type.args else ""
- content += ")"
- return content
- elif isinstance(c_type, c_ast.Decl):
- return self.get_type_name(c_type.type)
- elif isinstance(c_type, c_ast.ParamList):
- content = ",".join(
- [self.get_type_name(param.type) for param in c_type.params]
- )
- return content
- else:
- raise RuntimeError(f"unexpected type: {c_type.show()}")
-
- def visit_Struct(self, node):
- # pylint: disable=invalid-name
- def gen_fields(info, indent):
- content = ""
- for k, v in info.items():
- content += f'{indent}("{k}", {v}),\n'
- return content[:-1]
-
- def gen_equal(info, indent):
- content = f"{indent}return"
- for k, v in info.items():
- # not compare pointer value in __eq__
- if v.startswith("POINTER") or v.startswith("c_void_p"):
- continue
-
- content += f" self.{k} == other.{k} and"
- return content[:-4]
-
- def gen_repr(info, indent):
- content = f'{indent}return f"{{{{'
- for k, _ in info.items():
- content += f"{k}={{self.{k}}}, "
- content = content[:-2] + '}}"'
- return content
-
- def gen_vector_repr(info, indent):
- content = f'{indent}ret = ""\n'
- content += f"{indent}for i in range(self.num_elems):\n"
-
- if 1 == info["data"].count("POINTER"):
- # pointer
- content += f"{2*indent}ret += str(self.data[i])\n"
- else:
- # pointer of pointer
- content += f"{2*indent}ret += str(dereference(self.data[i]))\n"
-
- content += f'{2*indent}ret += " "\n'
- content += f"{indent}return ret\n"
- return content
-
- if not node.name or not node.name.lower().startswith("wasm"):
- return
-
- if node.name in IGNORE_SYMOLS:
- return
-
- name = node.name
-
- info = {}
- if node.decls:
- for decl in node.decls:
- info[decl.name] = self.get_type_name(decl.type)
-
- if info:
- self.ret += (
- f"class {name}(Structure):\n"
- f"{INDENT}_fields_ = [\n"
- f"{gen_fields(info, INDENT*2)}\n"
- f"{INDENT}]\n"
- f"\n"
- f"{INDENT}def __eq__(self, other):\n"
- f"{INDENT*2}if not isinstance(other, {name}):\n"
- f"{INDENT*3}return False\n"
- f"{gen_equal(info, INDENT*2)}\n"
- f"\n"
- f"{INDENT}def __repr__(self):\n"
- )
- self.ret += (
- f"{gen_vector_repr(info, INDENT*2)}\n"
- if name.endswith("_vec_t")
- else f"{gen_repr(info, INDENT*2)}\n"
- )
- self.ret += "\n"
-
- else:
- self.ret += f"class {name}(Structure):\n{INDENT}pass\n"
-
- self.ret += "\n"
-
- def visit_Union(self, node):
- # pylint: disable=invalid-name
- print(f"Union: {node.show()}")
-
- def visit_Typedef(self, node):
- # pylint: disable=invalid-name
- # system defined
- if not node.name:
- return
-
- if not node.name.startswith("wasm_"):
- return
-
- if node.name in IGNORE_SYMOLS:
- return
-
- self.visit(node.type)
-
- if node.name == self.get_type_name(node.type):
- return
- else:
- self.ret += f"{node.name} = {self.get_type_name(node.type)}\n"
- self.ret += "\n"
-
- def visit_FuncDecl(self, node):
- # pylint: disable=invalid-name
- restype = self.get_type_name(node.type)
-
- if isinstance(node.type, c_ast.TypeDecl):
- func_name = node.type.declname
- elif isinstance(node.type, c_ast.PtrDecl):
- func_name = node.type.type.declname
- else:
- raise RuntimeError(f"unexpected type in FuncDecl: {type}")
-
- if not func_name.startswith("wasm_") or func_name.endswith("_t"):
- return
-
- if func_name in IGNORE_SYMOLS:
- return
-
- params_len = 0
- for arg in node.args.params:
- # ignore void but not void*
- if isinstance(arg.type, c_ast.TypeDecl):
- type_name = self.get_type_name(arg.type)
- if "None" == type_name:
- continue
-
- params_len += 1
-
- args = (
- "" if not params_len else ",".join([f"arg{i}" for i in range(params_len)])
- )
- argtypes = f"[{self.get_type_name(node.args)}]" if params_len else "None"
-
- self.ret += (
- f"def {func_name}({args}):\n"
- f"{INDENT}_{func_name} = libiwasm.{func_name}\n"
- f"{INDENT}_{func_name}.restype = {restype}\n"
- f"{INDENT}_{func_name}.argtypes = {argtypes}\n"
- f"{INDENT}return _{func_name}({args})\n"
- )
- self.ret += "\n"
-
- def visit_Enum(self, node):
- # pylint: disable=invalid-name
- elem_value = 0
- # generate enum elementes directly as consts with values
- for i, elem in enumerate(node.values.enumerators):
- self.ret += f"{elem.name}"
-
- if elem.value:
- elem_value = int(elem.value.value)
- else:
- if 0 == i:
- elem_value = 0
- else:
- elem_value += 1
-
- self.ret += f" = {elem_value}\n"
-
- self.ret += "\n"
-
-
-def preflight_check(workspace):
- wamr_repo = workspace
- file_check_list = [
- wamr_repo.exists(),
- wamr_repo.joinpath(WASM_C_API_HEADER).exists(),
- ]
-
- if not all(file_check_list):
- print(
- "please run utils/download_wamr.py to download the repo, or re-download the repo"
- )
- return False
-
- if not shutil.which("gcc"):
- print("please install gcc")
- return False
-
- return True
-
-
-def do_parse(workspace):
- filename = workspace.joinpath(WASM_C_API_HEADER)
- filename = str(filename)
-
- ast = parse_file(
- filename,
- use_cpp=True,
- cpp_path="gcc",
- cpp_args=[
- "-E",
- "-D__attribute__(x)=",
- "-D__asm__(x)=",
- "-D__asm(x)=",
- "-D__builtin_va_list=int",
- "-D__extension__=",
- "-D__inline__=",
- "-D__restrict=",
- "-D__restrict__=",
- "-D_Static_assert(x, y)=",
- "-D__signed=",
- "-D__volatile__(x)=",
- "-Dstatic_assert(x, y)=",
- ],
- )
-
- ast_visitor = Visitor()
- ast_visitor.visit(ast)
- return ast_visitor.ret
-
-
-def main():
- current_file = pathlib.Path(__file__)
- if current_file.is_symlink():
- current_file = pathlib.Path(os.readlink(current_file))
-
- current_dir = current_file.parent.resolve()
- root_dir = current_dir.joinpath("../../../..").resolve()
-
- if not preflight_check(root_dir):
- return False
-
- wamr_repo = root_dir
- binding_file_path = root_dir.joinpath(BINDING_PATH)
- with open(binding_file_path, "wt", encoding="utf-8") as binding_file:
- binding_file.write(do_parse(wamr_repo))
-
- return True
-
-
-if __name__ == "__main__":
- sys.exit(0 if main() else 1)