Skip to content

Commit

Permalink
initialize global allocator only once
Browse files Browse the repository at this point in the history
  • Loading branch information
dgllghr committed Feb 18, 2024
1 parent 58ddc35 commit 758d218
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ pub export fn sqlite3_stanchion_init(
) callconv(.C) c_int {
c.sqlite3_api = api;

// To store data common to all table instances (global to the module), replace this allocator
// with a struct containing the common data (see `ModuleContext` in `zig-sqlite`)
allocator = GeneralPurposeAllocator(.{}){};

if (sqliteVersion() < min_sqlite_version) {
setErrorMsg(err_msg, "stanchion requires sqlite version >= 3.26.0");
return c.SQLITE_ERROR;
Expand Down Expand Up @@ -60,9 +64,6 @@ fn register(
api: *c.sqlite3_api_routines,
) callconv(.C) c_int {
_ = api;
// To store data common to all table instances (global to the module), replace this allocator
// with a struct containing the common data (see `ModuleContext` in `zig-sqlite`)
allocator = GeneralPurposeAllocator(.{}){};

var res = c.sqlite3_create_module_v2(
db,
Expand Down

0 comments on commit 758d218

Please sign in to comment.