Skip to content

mdbx: preserve debug callback types across cgo - #265

Merged
AskAlexSharov merged 1 commit into
erigontech:masterfrom
jyj117:codex/fix-cgo-debug-logger-warnings
Nov 9, 2026
Merged

AskAlexSharov merged 1 commit into
erigontech:masterfrom
jyj117:codex/fix-cgo-debug-logger-warnings

Conversation

@jyj117

@jyj117 jyj117 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #264.

GCC reports -Wpedantic warnings because cgo represents direct function-pointer arguments/results as void * in its generated C bridge. This affects both MDBX_LOGGER_DONTCHANGE and the logger argument to mdbx_setup_debug.

This change carries MDBX_debug_func in a small typed C struct passed and returned by value. The C wrappers forward the original callback without function-pointer/object-pointer casts. LoggerDoNotChange keeps its Go type, and Env.SetDebug keeps its public signature and existing return behavior. Storage and transaction code are unchanged.

The two compiler-specific flags -Wno-unknown-warning-option and -Wno-enum-int-mismatch are removed from the Go binding CFLAGS. -Wpedantic remains enabled; no warning suppression is added.

A subprocess regression test checks a real C callback, the keep-current sentinel, and a nil logger. Isolation is needed because libmdbx logger configuration is process-global and cgo cannot be imported directly from a Go test file.

Validation:

  • Linux/amd64, Go 1.27.1, GCC 11.4: package tests and race tests passed; a forced rebuild also passed with -Werror=pedantic scoped to the mdbx package.
  • Alpine Linux/amd64, Go 1.27.1, GCC 15.2: go test -race -count=1 ./mdbx ./exp/mdbxpool and go vet ./mdbx ./exp/mdbxpool passed.
  • Go 1.25.0, matching the upstream CI toolchain: package tests passed; golangci-lint v2.12.2 reported 0 issues.
  • git diff --check passed.

macOS and Windows have not been tested locally and still need CI coverage.

@AskAlexSharov, could you review this approach to fixing the warnings while preserving the callback API?

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the changes preserving C callback types across the cgo boundary.

No open issues 🎉

What changed in this PR

Addresses #264 by preserving C callback types across the cgo boundary, avoiding function-pointer conversion warnings while keeping the public Go API and logger behavior unchanged.

Changes:

  • Adds typed C wrappers for debug callbacks and the keep-current sentinel.
  • Removes two compiler-specific warning flags while retaining -Wpedantic.
  • Adds subprocess regression coverage for custom callbacks, the keep-current sentinel, and nil loggers.
File Description
mdbx/​testdata/​debuglogger/​main.go Adds an isolated program checking all three logger behaviors.
mdbx/​mdbxgo.h Declares the callback struct and typed bridge functions.
mdbx/​mdbxgo.c Implements wrappers that preserve C function-pointer types.
mdbx/​mdbx.go Removes two compiler-specific warning flags.
mdbx/​env.go Routes logger configuration through the typed wrappers.
mdbx/​env_test.go Runs the logger regression program in a subprocess.

Review effort: Balanced

@AskAlexSharov
AskAlexSharov merged commit 8aafc96 into erigontech:master Nov 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v0.44.1: GCC -Wpedantic warnings in CGO logger bindings (MDBX_LOGGER_DONTCHANGE / mdbx_setup_debug)

3 participants