Skip to content

Commit 8a179c5

Browse files
fix(linux): disable std.log which crashes in shared library context
std.log uses std.io.getStdErr() internally, which can segfault when called from a dynamically loaded shared library on Linux because the Zig runtime isn't properly initialized in that context.
1 parent f6fd91f commit 8a179c5

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

zig/src/changes_vtab.zig

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,15 @@ const sync_bit = @import("sync_bit.zig");
3838
const site_identity = @import("site_identity.zig");
3939
const stmt_cache = @import("stmt_cache.zig");
4040

41-
// Platform-aware logging: use std.log on native, no-op on WASM/freestanding
42-
const log = if (builtin.os.tag == .freestanding or builtin.cpu.arch == .wasm32 or builtin.cpu.arch == .wasm64)
43-
struct {
44-
// No-op logger for WASM/freestanding
45-
pub fn debug(comptime fmt: []const u8, args: anytype) void {
46-
_ = fmt;
47-
_ = args;
48-
}
41+
// Logging disabled: std.log uses std.io.getStdErr() which crashes when called from
42+
// a dynamically loaded shared library on Linux. The Zig runtime isn't properly
43+
// initialized in that context, causing segfaults.
44+
const log = struct {
45+
pub fn debug(comptime fmt: []const u8, args: anytype) void {
46+
_ = fmt;
47+
_ = args;
4948
}
50-
else
51-
std.log.scoped(.changes_vtab);
49+
};
5250

5351
// Type conversion between vtab's opaque types and api's opaque types.
5452
// Both represent the same underlying SQLite types, just declared separately.

zig/src/sqlite/vtab.zig

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,15 @@
6969
const std = @import("std");
7070
const builtin = @import("builtin");
7171

72-
// Platform-aware logging: use std.log on native, no-op on WASM/freestanding
73-
const log = if (builtin.os.tag == .freestanding or builtin.cpu.arch == .wasm32 or builtin.cpu.arch == .wasm64)
74-
struct {
75-
// No-op logger for WASM/freestanding
76-
pub fn debug(comptime fmt: []const u8, args: anytype) void {
77-
_ = fmt;
78-
_ = args;
79-
}
72+
// Logging disabled: std.log uses std.io.getStdErr() which crashes when called from
73+
// a dynamically loaded shared library on Linux. The Zig runtime isn't properly
74+
// initialized in that context, causing segfaults.
75+
const log = struct {
76+
pub fn debug(comptime fmt: []const u8, args: anytype) void {
77+
_ = fmt;
78+
_ = args;
8079
}
81-
else
82-
std.log.scoped(.vtab);
80+
};
8381

8482
// =============================================================================
8583
// SQLite C ABI Type Definitions

0 commit comments

Comments
 (0)