Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,16 @@ KernelStatusCode kernel_session_config_set_custom_header(KernelSessionConfig* co
* subscriber was already installed (no kernel subscriber installed). */
KernelStatusCode kernel_init_logging(const char* level, const char* file_path);

/* The C ABI version this library implements. A consumer that loads the
* kernel as a shared library (.so/.dylib/.dll) at run time should call this
* right after loading and refuse to proceed if the value differs from the
* version it was built against — turning an ABI mismatch (a wrong or stale
* shared library) into a clear error instead of silent memory corruption.
* Bumped on every breaking C ABI change (added/removed/renumbered function,
* changed struct layout or signature). Not the crate semver — tracks only
* the C ABI shape. Starts at 1. Takes no pointers; always safe to call. */
uint32_t kernel_abi_version(void);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — The header declares the runtime accessor kernel_abi_version() but exposes no companion compile-time constant (e.g. #define DATABRICKS_KERNEL_ABI_VERSION 1). The documented usage is to compare the runtime value against "the version it was built against", but a C/ODBC consumer building against this header has nothing in the header to compare against — it must hardcode the literal 1 itself, which is exactly the drift the check is meant to prevent (a stale header would keep comparing against a stale hardcoded constant).

Consider emitting the constant into the header alongside the declaration so consumers can write if (kernel_abi_version() != DATABRICKS_KERNEL_ABI_VERSION) { ... }. The Rust side already has KERNEL_C_ABI_VERSION; keeping the header macro in lockstep with it (the same way the KernelStatusCode enum is kept in lockstep) closes the loop for the header's own consumers.


/* ─── Proxy / TLS (optional) ──────────────────────────────────────────
*
* All optional; defaults are: no explicit proxy (reqwest honours
Expand Down
25 changes: 25 additions & 0 deletions src/c_abi/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,31 @@ pub unsafe extern "C" fn kernel_init_logging(
}
}

/// The C ABI version this shared library implements. A consumer that loads the
/// kernel as a shared library (`.so`/`.dylib`/`.dll`) at run time should call
/// this immediately after `dlopen` and refuse to proceed if the value does not
/// match the version it was built against — turning an ABI mismatch (a wrong or
/// stale library dropped next to the binary) into a clear, actionable error
/// instead of silent memory corruption or a crash.
///
/// This matters most while the C ABI is pre-1.0: per this crate's own docs the
/// struct layouts and function set "may change freely" until v1.0, so a
/// statically-linked consumer is protected by the compiler but a dynamically
/// linked one needs a runtime check. Bump this on every breaking C ABI change
/// (added/removed/renumbered function, changed struct layout or signature).
/// It is intentionally NOT the crate's semver — it tracks only the C ABI shape.
///
/// # Safety
/// None — takes no pointers and reads no shared state.
#[no_mangle]
pub extern "C" fn kernel_abi_version() -> u32 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — No test accompanies the new symbol. A one-line unit test asserting kernel_abi_version() == KERNEL_C_ABI_VERSION (and == 1) is cheap and guards against an accidental value/type regression and confirms the symbol links — mirroring the napi version() test at napi/src/lib.rs:72. Very minor given the function just returns a const, but the repo convention is that new src/ behavior carries coverage.

KERNEL_C_ABI_VERSION
}

/// Current C ABI version. See `kernel_abi_version`. Start at 1; increment on any
/// breaking change to the C ABI (databricks_kernel.h).
pub const KERNEL_C_ABI_VERSION: u32 = 1;

/// Add (or overwrite) one server-bound session-conf entry. Unknown keys
/// are filtered against the kernel allowlist at `open()` time, matching
/// the Rust-crate path.
Expand Down
Loading