Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dnut committed Nov 5, 2024
1 parent d700032 commit 0537d4d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ledger/database/lmdb.zig
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ fn resetTxnFree(ctx: *anyopaque, _: []u8, _: u8, _: usize) void {
/// ```
fn returnOutput(fn_with_output: anytype, args: anytype) LmdbError!OutputType(fn_with_output) {
// create a local variable to hold the function's output.
const MaybeOutput = LastParam(fn_with_output).Pointer.child;
const MaybeOutput = LastParamChild(fn_with_output);
var maybe_output: MaybeOutput = switch (@typeInfo(MaybeOutput)) {
.Optional => null,
.Int => 0,
Expand All @@ -449,17 +449,18 @@ fn returnOutput(fn_with_output: anytype, args: anytype) LmdbError!OutputType(fn_
/// For an LMDB function that provides its output by writing to a pointer, this
/// is the data type of the output.
fn OutputType(fn_with_output: anytype) type {
const InnerType = LastParam(fn_with_output).Pointer.child;
const InnerType = LastParamChild(fn_with_output);
return switch (@typeInfo(InnerType)) {
.Optional => |o| o.child,
else => InnerType,
};
}

/// Returns the type of the last parameter of a function.
fn LastParam(function: anytype) type {
/// Returns the child type of the last parameter of a function,
/// assuming that parameter is a pointer.
fn LastParamChild(function: anytype) type {
const params = @typeInfo(@TypeOf(function)).Fn.params;
return @typeInfo(params[params.len - 1].type.?);
return @typeInfo(params[params.len - 1].type.?).Pointer.child;
}

fn cursorGet(
Expand Down

0 comments on commit 0537d4d

Please sign in to comment.