Towards shared modules: refactor.

This commit is contained in:
Nuno Cruces
2023-03-06 23:41:54 +00:00
parent d291738b81
commit 6c96a019e6
3 changed files with 49 additions and 49 deletions

View File

@@ -77,16 +77,18 @@ func compileModule() {
}
type module struct {
api.Module
ctx context.Context
mem memory
api sqliteAPI
}
func newModule(mod api.Module) (m *module, err error) {
m = &module{}
m.mem = memory{mod}
m.ctx = context.Background()
getFun := func(name string) api.Function {
f := m.ExportedFunction(name)
f := mod.ExportedFunction(name)
if f == nil {
err = noFuncErr + errorString(name)
return nil
@@ -95,7 +97,7 @@ func newModule(mod api.Module) (m *module, err error) {
}
getVal := func(name string) uint32 {
global := m.ExportedGlobal(name)
global := mod.ExportedGlobal(name)
if global == nil {
err = noGlobalErr + errorString(name)
return 0
@@ -103,11 +105,6 @@ func newModule(mod api.Module) (m *module, err error) {
return m.mem.readUint32(uint32(global.Get()))
}
m = &module{
Module: mod,
mem: memory{mod},
ctx: context.Background(),
}
m.api = sqliteAPI{
free: getFun("free"),
malloc: getFun("malloc"),
@@ -164,6 +161,10 @@ func newModule(mod api.Module) (m *module, err error) {
return
}
func (m *module) close() error {
return m.mem.mod.Close(m.ctx)
}
func (m *module) error(rc uint64, handle uint32, sql ...string) error {
if rc == _OK {
return nil