mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 05:59:14 +00:00
Towards shared modules: refactor.
This commit is contained in:
19
module.go
19
module.go
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user