Fix Python module

extensions
Volodymyr Shymanskyy 3 years ago
parent 0b69623b32
commit 36c45dad0d

@ -15,10 +15,12 @@ jobs:
- {target: clang, cc: clang, }
- {target: clang-x86, cc: clang, flags: -DCMAKE_C_FLAGS="-m32", install: "gcc-multilib" }
- {target: gcc, cc: gcc, }
- {target: gcc-debug, cc: gcc, flags: -DCMAKE_BUILD_TYPE=Debug }
# Builds without uvwasi
- {target: gcc-no-uvwasi, cc: gcc, flags: -DBUILD_WASI=simple }
- {target: clang-no-uvwasi, cc: clang, flags: -DBUILD_WASI=simple }
# Debug builds
- {target: gcc-debug, cc: gcc, flags: -DCMAKE_BUILD_TYPE=Debug, cflags: -DDEBUG }
- {target: gcc-no-uvwasi-debug, cc: gcc, flags: -DCMAKE_BUILD_TYPE=Debug -DBUILD_WASI=simple, cflags: -DDEBUG }
# TODO: fails on numeric operations
#- {target: gcc-x86, cc: gcc, flags: "-m32", install: "gcc-multilib" }
@ -28,11 +30,11 @@ jobs:
- name: Install ${{ matrix.config.install }}
if: ${{ matrix.config.install }}
run: |
sudo apt update
sudo apt install ${{ matrix.config.install }}
- name: Configure
env:
CC: ${{ matrix.config.cc }}
CFLAGS: ${{ matrix.config.cflags }}
run: |
mkdir build
cd build
@ -300,7 +302,6 @@ jobs:
sudo dpkg -i $DEB
- name: Install ${{ matrix.config.toolchain }}
run: |
sudo apt update
sudo apt install ${{ matrix.config.toolchain }}
- name: Build
run: |
@ -527,7 +528,6 @@ jobs:
- uses: actions/checkout@v2
- name: Install sponge
run: |
sudo apt update
sudo apt install moreutils
- name: Build
run: |

@ -2,8 +2,6 @@
#include "wasm3.h"
#include "m3_api_defs.h"
/* FIXME: remove when there is a public API to get module/function names */
#include "m3_env.h"
#define MAX_ARGS 32
@ -54,6 +52,7 @@ static PyObject *
formatError(PyObject *exception, IM3Runtime runtime, M3Result err)
{
M3ErrorInfo info;
memset(&info, 0, sizeof(info));
m3_GetErrorInfo (runtime, &info);
if (strlen(info.message)) {
PyErr_Format(exception, "%s (%s)", err, info.message);
@ -198,7 +197,7 @@ static PyType_Slot M3_Runtime_Type_slots[] = {
static PyObject *
Module_name(m3_module *self, void * closure)
{
return PyUnicode_FromString(self->m->name); // TODO
return PyUnicode_FromString(m3_GetModuleName(self->m));
}
m3ApiRawFunction(CallImport)
@ -265,7 +264,7 @@ M3_Module_link_function(m3_module *self, PyObject *args)
M3Result err = m3_LinkRawFunctionEx (self->m, PyUnicode_AsUTF8(mod_name), PyUnicode_AsUTF8(func_name),
PyUnicode_AsUTF8(func_sig), CallImport, pFunc);
if (err && err != m3Err_functionLookupFailed) {
return formatError(PyExc_RuntimeError, self->m->runtime, err);
return formatError(PyExc_RuntimeError, m3_GetModuleRuntime(self->m), err);
}
Py_INCREF(pFunc);
Py_RETURN_NONE;
@ -292,9 +291,9 @@ static PyType_Slot M3_Module_Type_slots[] = {
};
static PyObject *
get_result_from_stack(IM3Function f)
get_result_from_stack(m3_function *func)
{
int nRets = m3_GetRetCount(f);
int nRets = m3_GetRetCount(func->f);
if (nRets <= 0) {
Py_RETURN_NONE;
}
@ -317,12 +316,12 @@ get_result_from_stack(IM3Function f)
for (int i = 0; i < nRets; i++) {
valptrs[i] = &valbuff[i];
}
M3Result err = m3_GetResults (f, nRets, valptrs);
M3Result err = m3_GetResults (func->f, nRets, valptrs);
if (err) {
return formatError(PyExc_RuntimeError, f->module->runtime, err);
return formatError(PyExc_RuntimeError, func->r, err);
}
return get_arg_from_stack(valptrs[0], m3_GetRetType(f, 0));
return get_arg_from_stack(valptrs[0], m3_GetRetType(func->f, 0));
}
static PyObject *
@ -335,10 +334,10 @@ M3_Function_call_argv(m3_function *func, PyObject *args)
}
M3Result err = m3_CallArgv(func->f, size, argv);
if (err) {
return formatError(PyExc_RuntimeError, func->f->module->runtime, err);
return formatError(PyExc_RuntimeError, func->r, err);
}
return get_result_from_stack(func->f);
return get_result_from_stack(func);
}
static PyObject*
@ -367,16 +366,16 @@ M3_Function_call(m3_function *self, PyObject *args, PyObject *kwargs)
M3Result err = m3_Call (f, nArgs, valptrs);
if (err) {
return formatError(PyExc_RuntimeError, f->module->runtime, err);
return formatError(PyExc_RuntimeError, self->r, err);
}
return get_result_from_stack(f);
return get_result_from_stack(self);
}
static PyObject*
Function_name(m3_function *self, void * closure)
{
return PyUnicode_FromString(GetFunctionName(self->f)); // TODO
return PyUnicode_FromString(m3_GetFunctionName(self->f));
}
static PyObject*

@ -1090,16 +1090,21 @@ M3Result m3Error (M3Result i_result, IM3Runtime i_runtime, IM3Module i_module,
void m3_GetErrorInfo (IM3Runtime i_runtime, M3ErrorInfo* o_info)
{
*o_info = i_runtime->error;
m3_ResetErrorInfo (i_runtime);
if (i_runtime)
{
*o_info = i_runtime->error;
m3_ResetErrorInfo (i_runtime);
}
}
void m3_ResetErrorInfo (IM3Runtime i_runtime)
{
M3_INIT(i_runtime->error);
i_runtime->error.message = "";
if (i_runtime)
{
M3_INIT(i_runtime->error);
i_runtime->error.message = "";
}
}
uint8_t * m3_GetMemory (IM3Runtime i_runtime, uint32_t * o_memorySizeInBytes, uint32_t i_memoryIndex)

@ -109,3 +109,9 @@ const char* m3_GetModuleName (IM3Module i_module)
return i_module->name;
}
IM3Runtime m3_GetModuleRuntime (IM3Module i_module)
{
return i_module ? i_module->runtime : NULL;
}

@ -224,6 +224,7 @@ d_m3ErrorConst (trapStackOverflow, "[trap] stack overflow")
const void * i_userdata);
const char* m3_GetModuleName (IM3Module i_module);
IM3Runtime m3_GetModuleRuntime (IM3Module i_module);
//-------------------------------------------------------------------------------------------------------------------------------
// functions

Loading…
Cancel
Save