Skip to content

Commit e9db0d8

Browse files
committed
1 parent dadf53e commit e9db0d8

File tree

6 files changed

+30
-29
lines changed

6 files changed

+30
-29
lines changed

.github/workflows/repro.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ jobs:
1212
build:
1313
strategy:
1414
matrix:
15-
os: [macos-latest, ubuntu-latest, windows-latest]
15+
# os: [macos-latest, ubuntu-latest, windows-latest]
16+
os: [ubuntu-latest, windows-latest]
1617
runs-on: ${{ matrix.os }}
1718

1819
steps:

embed/bcw2/bcw2.wasm

1 Byte
Binary file not shown.

embed/sqlite3.wasm

1 Byte
Binary file not shown.

func.go

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,26 +175,24 @@ func stepCallback(ctx context.Context, mod api.Module, pCtx, pAgg, pApp ptr_t, n
175175
fn.Step(Context{db, pCtx}, args[:nArg]...)
176176
}
177177

178-
func finalCallback(ctx context.Context, mod api.Module, pCtx, pAgg, pApp ptr_t) {
178+
func valueCallback(ctx context.Context, mod api.Module, pCtx, pAgg, pApp ptr_t, final int32) {
179179
db := ctx.Value(connKey{}).(*Conn)
180180
fn, handle := callbackAggregate(db, pAgg, pApp)
181181
fn.Value(Context{db, pCtx})
182-
var err error
183-
if handle != 0 {
184-
err = util.DelHandle(ctx, handle)
185-
} else if c, ok := fn.(io.Closer); ok {
186-
err = c.Close()
187-
}
188-
if err != nil {
189-
Context{db, pCtx}.ResultError(err)
190-
return // notest
191-
}
192-
}
193182

194-
func valueCallback(ctx context.Context, mod api.Module, pCtx, pAgg ptr_t) {
195-
db := ctx.Value(connKey{}).(*Conn)
196-
fn := util.GetHandle(db.ctx, pAgg).(AggregateFunction)
197-
fn.Value(Context{db, pCtx})
183+
// Cleanup.
184+
if final != 0 {
185+
var err error
186+
if handle != 0 {
187+
err = util.DelHandle(ctx, handle)
188+
} else if c, ok := fn.(io.Closer); ok {
189+
err = c.Close()
190+
}
191+
if err != nil {
192+
Context{db, pCtx}.ResultError(err)
193+
return // notest
194+
}
195+
}
198196
}
199197

200198
func inverseCallback(ctx context.Context, mod api.Module, pCtx, pAgg ptr_t, nArg int32, pArg ptr_t) {

sqlite.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ func exportCallbacks(env wazero.HostModuleBuilder) wazero.HostModuleBuilder {
317317
util.ExportFuncVI(env, "go_destroy", destroyCallback)
318318
util.ExportFuncVIIII(env, "go_func", funcCallback)
319319
util.ExportFuncVIIIII(env, "go_step", stepCallback)
320-
util.ExportFuncVIII(env, "go_final", finalCallback)
321-
util.ExportFuncVII(env, "go_value", valueCallback)
320+
util.ExportFuncVIIII(env, "go_value", valueCallback)
322321
util.ExportFuncVIIII(env, "go_inverse", inverseCallback)
323322
util.ExportFuncVIIII(env, "go_collation_needed", collationCallback)
324323
util.ExportFuncIIIIII(env, "go_compare", compareCallback)

sqlite3/func.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ int go_compare(go_handle, int, const void *, int, const void *);
1111
void go_func(sqlite3_context *, go_handle, int, sqlite3_value **);
1212

1313
void go_step(sqlite3_context *, go_handle *, go_handle, int, sqlite3_value **);
14-
void go_final(sqlite3_context *, go_handle, go_handle);
15-
void go_value(sqlite3_context *, go_handle);
16-
void go_inverse(sqlite3_context *, go_handle *, int, sqlite3_value **);
14+
void go_value(sqlite3_context *, go_handle *, go_handle, bool);
15+
void go_inverse(sqlite3_context *, go_handle, int, sqlite3_value **);
1716

1817
void go_func_wrapper(sqlite3_context *ctx, int nArg, sqlite3_value **pArg) {
1918
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) {
2827
go_step(ctx, agg, data, nArg, pArg);
2928
}
3029

31-
void go_final_wrapper(sqlite3_context *ctx) {
32-
go_handle *agg = sqlite3_aggregate_context(ctx, 0);
30+
void go_value_wrapper(sqlite3_context *ctx) {
31+
go_handle *agg = sqlite3_aggregate_context(ctx, 4);
3332
go_handle data = NULL;
3433
if (agg == NULL || *agg == NULL) {
3534
data = sqlite3_user_data(ctx);
3635
}
37-
go_final(ctx, agg, data);
36+
go_value(ctx, agg, data, /*final=*/false);
3837
}
3938

40-
void go_value_wrapper(sqlite3_context *ctx) {
41-
go_handle *agg = sqlite3_aggregate_context(ctx, 4);
42-
go_value(ctx, *agg);
39+
void go_final_wrapper(sqlite3_context *ctx) {
40+
go_handle *agg = sqlite3_aggregate_context(ctx, 0);
41+
go_handle data = NULL;
42+
if (agg == NULL || *agg == NULL) {
43+
data = sqlite3_user_data(ctx);
44+
}
45+
go_value(ctx, agg, data, /*final=*/true);
4346
}
4447

4548
void go_inverse_wrapper(sqlite3_context *ctx, int nArg, sqlite3_value **pArg) {
46-
go_handle *agg = sqlite3_aggregate_context(ctx, 4);
49+
go_handle *agg = sqlite3_aggregate_context(ctx, 0);
4750
go_inverse(ctx, *agg, nArg, pArg);
4851
}
4952

0 commit comments

Comments
 (0)