diff --git a/.github/workflows/repro.yml b/.github/workflows/repro.yml index 952f2cd..e6275a8 100644 --- a/.github/workflows/repro.yml +++ b/.github/workflows/repro.yml @@ -12,7 +12,8 @@ jobs: build: strategy: matrix: - os: [macos-latest, ubuntu-latest, windows-latest] + # os: [macos-latest, ubuntu-latest, windows-latest] + os: [ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} steps: diff --git a/embed/bcw2/bcw2.wasm b/embed/bcw2/bcw2.wasm index e5006bc..f32d434 100755 Binary files a/embed/bcw2/bcw2.wasm and b/embed/bcw2/bcw2.wasm differ diff --git a/embed/sqlite3.wasm b/embed/sqlite3.wasm index 1c6a535..44deb9e 100755 Binary files a/embed/sqlite3.wasm and b/embed/sqlite3.wasm differ diff --git a/func.go b/func.go index 09c1b7a..f907fa9 100644 --- a/func.go +++ b/func.go @@ -175,26 +175,24 @@ func stepCallback(ctx context.Context, mod api.Module, pCtx, pAgg, pApp ptr_t, n fn.Step(Context{db, pCtx}, args[:nArg]...) } -func finalCallback(ctx context.Context, mod api.Module, pCtx, pAgg, pApp ptr_t) { +func valueCallback(ctx context.Context, mod api.Module, pCtx, pAgg, pApp ptr_t, final int32) { db := ctx.Value(connKey{}).(*Conn) fn, handle := callbackAggregate(db, pAgg, pApp) fn.Value(Context{db, pCtx}) - var err error - if handle != 0 { - err = util.DelHandle(ctx, handle) - } else if c, ok := fn.(io.Closer); ok { - err = c.Close() - } - if err != nil { - Context{db, pCtx}.ResultError(err) - return // notest - } -} -func valueCallback(ctx context.Context, mod api.Module, pCtx, pAgg ptr_t) { - db := ctx.Value(connKey{}).(*Conn) - fn := util.GetHandle(db.ctx, pAgg).(AggregateFunction) - fn.Value(Context{db, pCtx}) + // Cleanup. + if final != 0 { + var err error + if handle != 0 { + err = util.DelHandle(ctx, handle) + } else if c, ok := fn.(io.Closer); ok { + err = c.Close() + } + if err != nil { + Context{db, pCtx}.ResultError(err) + return // notest + } + } } func inverseCallback(ctx context.Context, mod api.Module, pCtx, pAgg ptr_t, nArg int32, pArg ptr_t) { diff --git a/sqlite.go b/sqlite.go index 5b0497b..9e2d1d3 100644 --- a/sqlite.go +++ b/sqlite.go @@ -317,8 +317,7 @@ func exportCallbacks(env wazero.HostModuleBuilder) wazero.HostModuleBuilder { util.ExportFuncVI(env, "go_destroy", destroyCallback) util.ExportFuncVIIII(env, "go_func", funcCallback) util.ExportFuncVIIIII(env, "go_step", stepCallback) - util.ExportFuncVIII(env, "go_final", finalCallback) - util.ExportFuncVII(env, "go_value", valueCallback) + util.ExportFuncVIIII(env, "go_value", valueCallback) util.ExportFuncVIIII(env, "go_inverse", inverseCallback) util.ExportFuncVIIII(env, "go_collation_needed", collationCallback) util.ExportFuncIIIIII(env, "go_compare", compareCallback) diff --git a/sqlite3/func.c b/sqlite3/func.c index 9bb830c..e2b5ac1 100644 --- a/sqlite3/func.c +++ b/sqlite3/func.c @@ -11,9 +11,8 @@ int go_compare(go_handle, int, const void *, int, const void *); void go_func(sqlite3_context *, go_handle, int, sqlite3_value **); void go_step(sqlite3_context *, go_handle *, go_handle, int, sqlite3_value **); -void go_final(sqlite3_context *, go_handle, go_handle); -void go_value(sqlite3_context *, go_handle); -void go_inverse(sqlite3_context *, go_handle *, int, sqlite3_value **); +void go_value(sqlite3_context *, go_handle *, go_handle, bool); +void go_inverse(sqlite3_context *, go_handle, int, sqlite3_value **); void go_func_wrapper(sqlite3_context *ctx, int nArg, sqlite3_value **pArg) { go_func(ctx, sqlite3_user_data(ctx), nArg, pArg); @@ -28,22 +27,26 @@ void go_step_wrapper(sqlite3_context *ctx, int nArg, sqlite3_value **pArg) { go_step(ctx, agg, data, nArg, pArg); } +void go_value_wrapper(sqlite3_context *ctx) { + go_handle *agg = sqlite3_aggregate_context(ctx, 4); + go_handle data = NULL; + if (agg == NULL || *agg == NULL) { + data = sqlite3_user_data(ctx); + } + go_value(ctx, agg, data, /*final=*/false); +} + void go_final_wrapper(sqlite3_context *ctx) { go_handle *agg = sqlite3_aggregate_context(ctx, 0); go_handle data = NULL; if (agg == NULL || *agg == NULL) { data = sqlite3_user_data(ctx); } - go_final(ctx, agg, data); -} - -void go_value_wrapper(sqlite3_context *ctx) { - go_handle *agg = sqlite3_aggregate_context(ctx, 4); - go_value(ctx, *agg); + go_value(ctx, agg, data, /*final=*/true); } void go_inverse_wrapper(sqlite3_context *ctx, int nArg, sqlite3_value **pArg) { - go_handle *agg = sqlite3_aggregate_context(ctx, 4); + go_handle *agg = sqlite3_aggregate_context(ctx, 0); go_inverse(ctx, *agg, nArg, pArg); }