From 48aa57549d514432d6621c1e29f051951eca2d7f Mon Sep 17 00:00:00 2001 From: Yorick van Pelt Date: Mon, 28 Aug 2023 18:20:23 +0200 Subject: [PATCH] primops: change to std::function, allowing the passing of user data --- src/libexpr/eval.hh | 3 ++- src/libexpr/primops.cc | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index f15d19653..a1b0e58e4 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -17,6 +17,7 @@ #include #include #include +#include namespace nix { @@ -72,7 +73,7 @@ struct PrimOp /** * Implementation of the primop. */ - PrimOpFun fun; + std::function::type> fun; /** * Optional experimental for this to be gated on. diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index db4237130..a619a627a 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -3402,8 +3402,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 ptr = args[0]->primOp->fun.target(); + if (ptr && *ptr == prim_lessThan) + return CompareValues(state, noPos, "while evaluating the ordering function passed to builtins.sort")(a, b); + } Value * vs[] = {a, b}; Value vBool;