Fix Python module

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

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

@ -2,8 +2,6 @@
#include "wasm3.h" #include "wasm3.h"
#include "m3_api_defs.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 #define MAX_ARGS 32
@ -54,6 +52,7 @@ static PyObject *
formatError(PyObject *exception, IM3Runtime runtime, M3Result err) formatError(PyObject *exception, IM3Runtime runtime, M3Result err)
{ {
M3ErrorInfo info; M3ErrorInfo info;
memset(&info, 0, sizeof(info));
m3_GetErrorInfo (runtime, &info); m3_GetErrorInfo (runtime, &info);
if (strlen(info.message)) { if (strlen(info.message)) {
PyErr_Format(exception, "%s (%s)", err, info.message); PyErr_Format(exception, "%s (%s)", err, info.message);
@ -198,7 +197,7 @@ static PyType_Slot M3_Runtime_Type_slots[] = {
static PyObject * static PyObject *
Module_name(m3_module *self, void * closure) Module_name(m3_module *self, void * closure)
{ {
return PyUnicode_FromString(self->m->name); // TODO return PyUnicode_FromString(m3_GetModuleName(self->m));
} }
m3ApiRawFunction(CallImport) 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), M3Result err = m3_LinkRawFunctionEx (self->m, PyUnicode_AsUTF8(mod_name), PyUnicode_AsUTF8(func_name),
PyUnicode_AsUTF8(func_sig), CallImport, pFunc); PyUnicode_AsUTF8(func_sig), CallImport, pFunc);
if (err && err != m3Err_functionLookupFailed) { 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_INCREF(pFunc);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -292,9 +291,9 @@ static PyType_Slot M3_Module_Type_slots[] = {
}; };
static PyObject * 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) { if (nRets <= 0) {
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -317,12 +316,12 @@ get_result_from_stack(IM3Function f)
for (int i = 0; i < nRets; i++) { for (int i = 0; i < nRets; i++) {
valptrs[i] = &valbuff[i]; valptrs[i] = &valbuff[i];
} }
M3Result err = m3_GetResults (f, nRets, valptrs); M3Result err = m3_GetResults (func->f, nRets, valptrs);
if (err) { 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 * static PyObject *
@ -335,10 +334,10 @@ M3_Function_call_argv(m3_function *func, PyObject *args)
} }
M3Result err = m3_CallArgv(func->f, size, argv); M3Result err = m3_CallArgv(func->f, size, argv);
if (err) { 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* static PyObject*
@ -367,16 +366,16 @@ M3_Function_call(m3_function *self, PyObject *args, PyObject *kwargs)
M3Result err = m3_Call (f, nArgs, valptrs); M3Result err = m3_Call (f, nArgs, valptrs);
if (err) { 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* static PyObject*
Function_name(m3_function *self, void * closure) Function_name(m3_function *self, void * closure)
{ {
return PyUnicode_FromString(GetFunctionName(self->f)); // TODO return PyUnicode_FromString(m3_GetFunctionName(self->f));
} }
static PyObject* 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) void m3_GetErrorInfo (IM3Runtime i_runtime, M3ErrorInfo* o_info)
{ {
if (i_runtime)
{
*o_info = i_runtime->error; *o_info = i_runtime->error;
m3_ResetErrorInfo (i_runtime); m3_ResetErrorInfo (i_runtime);
}
} }
void m3_ResetErrorInfo (IM3Runtime i_runtime) void m3_ResetErrorInfo (IM3Runtime i_runtime)
{ {
if (i_runtime)
{
M3_INIT(i_runtime->error); M3_INIT(i_runtime->error);
i_runtime->error.message = ""; i_runtime->error.message = "";
}
} }
uint8_t * m3_GetMemory (IM3Runtime i_runtime, uint32_t * o_memorySizeInBytes, uint32_t i_memoryIndex) 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; 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 void * i_userdata);
const char* m3_GetModuleName (IM3Module i_module); const char* m3_GetModuleName (IM3Module i_module);
IM3Runtime m3_GetModuleRuntime (IM3Module i_module);
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
// functions // functions

Loading…
Cancel
Save