From 883d2ad4d2d689463f028b6be0b268f3683b1ff2 Mon Sep 17 00:00:00 2001 From: Puck Meerburg Date: Sun, 17 Mar 2024 16:04:36 +0000 Subject: [PATCH] libexpr: use std::function rather than C function pointers for primops In preparation for the C bindings, which use this. Change-Id: Ic1c58998951e69e66a794976585a381754dfbbeb --- src/libexpr/eval.hh | 2 +- src/libexpr/primops.cc | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 135e5fecb..2e3c73157 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -36,7 +36,7 @@ enum RepairFlag : bool; /** * Function that implements a primop. */ -typedef void (* PrimOpFun) (EvalState & state, const PosIdx pos, Value * * args, Value & v); +typedef std::function PrimOpFun; /** * Info about a primitive operation, and its implementation diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 86db527f6..236afb554 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -3279,8 +3279,11 @@ static void prim_sort(EvalState & state, const PosIdx pos, Value * * args, Value callFunction. */ /* TODO: (layus) this is absurd. An optimisation like this should be outside the lambda creation */ - if (args[0]->isPrimOp() && args[0]->primOp->fun == prim_lessThan) - return CompareValues(state, noPos, "while evaluating the ordering function passed to builtins.sort")(a, b); + if (args[0]->isPrimOp()) { + auto target = args[0]->primOp->fun.target(); + if (target && *target == prim_lessThan) + return CompareValues(state, noPos, "while evaluating the ordering function passed to builtins.sort")(a, b); + } Value * vs[] = {a, b}; Value vBool;