[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
242/376: Add primop ‘attrValues’
From: |
Ludovic Courtès |
Subject: |
242/376: Add primop ‘attrValues’ |
Date: |
Wed, 28 Jan 2015 22:05:20 +0000 |
civodul pushed a commit to tag 1.8
in repository guix.
commit d4fcbe1687c3d212966e43118341622cf69612f3
Author: Eelco Dolstra <address@hidden>
Date: Sat Oct 4 16:41:24 2014 +0200
Add primop ‘attrValues’
---
src/libexpr/primops.cc | 24 +++++++++++++++++++++++-
tests/lang/eval-okay-attrnames.nix | 2 +-
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 072866a..fb37e21 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -974,7 +974,28 @@ static void prim_attrNames(EvalState & state, const Pos &
pos, Value * * args, V
for (auto & i : *args[0]->attrs)
mkString(*(v.list.elems[n++] = state.allocValue()), i.name);
- std::sort(v.list.elems, v.list.elems + n, [](Value * v1, Value * v2) {
return strcmp(v1->string.s, v2->string.s) < 0; });
+ std::sort(v.list.elems, v.list.elems + n,
+ [](Value * v1, Value * v2) { return strcmp(v1->string.s, v2->string.s)
< 0; });
+}
+
+
+/* Return the values of the attributes in a set as a list, in the same
+ order as attrNames. */
+static void prim_attrValues(EvalState & state, const Pos & pos, Value * *
args, Value & v)
+{
+ state.forceAttrs(*args[0], pos);
+
+ state.mkList(v, args[0]->attrs->size());
+
+ unsigned int n = 0;
+ for (auto & i : *args[0]->attrs)
+ v.list.elems[n++] = (Value *) &i;
+
+ std::sort(v.list.elems, v.list.elems + n,
+ [](Value * v1, Value * v2) { return (string) ((Attr *) v1)->name <
(string) ((Attr *) v2)->name; });
+
+ for (unsigned int i = 0; i < n; ++i)
+ v.list.elems[i] = ((Attr *) v.list.elems[i])->value;
}
@@ -1501,6 +1522,7 @@ void EvalState::createBaseEnv()
// Sets
addPrimOp("__attrNames", 1, prim_attrNames);
+ addPrimOp("__attrValues", 1, prim_attrValues);
addPrimOp("__getAttr", 2, prim_getAttr);
addPrimOp("__unsafeGetAttrPos", 2, prim_unsafeGetAttrPos);
addPrimOp("__hasAttr", 2, prim_hasAttr);
diff --git a/tests/lang/eval-okay-attrnames.nix
b/tests/lang/eval-okay-attrnames.nix
index 978138f..e5b26e9 100644
--- a/tests/lang/eval-okay-attrnames.nix
+++ b/tests/lang/eval-okay-attrnames.nix
@@ -8,4 +8,4 @@ let
values = map (name: builtins.getAttr name attrs) names;
-in concat values
+in assert values == builtins.attrValues attrs; concat values
- 294/376: Clean up temp roots in a more C++ way, (continued)
- 294/376: Clean up temp roots in a more C++ way, Ludovic Courtès, 2015/01/28
- 287/376: Don't use ADDR_LIMIT_3GB, Ludovic Courtès, 2015/01/28
- 255/376: binary download: Use $NIX_CURL_FLAGS, Ludovic Courtès, 2015/01/28
- 301/376: 'build-cache-failures' -> 'build-cache-failure' in nix.conf documentation., Ludovic Courtès, 2015/01/28
- 275/376: Revert "Revert "Revert "Temporarily disable darwin builds while hydra's darwin is borked""", Ludovic Courtès, 2015/01/28
- 302/376: Don't claim FreeBSD support, Ludovic Courtès, 2015/01/28
- 274/376: Don't pull in git when doing a nix-shell, Ludovic Courtès, 2015/01/28
- 247/376: mkList: Scrub better, Ludovic Courtès, 2015/01/28
- 248/376: Improved error message when encountering unsupported file types, Ludovic Courtès, 2015/01/28
- 295/376: nix-daemon: Call exit(), not _exit(), Ludovic Courtès, 2015/01/28
- 242/376: Add primop ‘attrValues’,
Ludovic Courtès <=
- 254/376: nix-store -q: Check for conflicting flags, Ludovic Courtès, 2015/01/28
- 265/376: Merge pull request #380 from shlevy/temp-disable-darwin, Ludovic Courtès, 2015/01/28
- 253/376: nix-channel: Add --rollback flag, Ludovic Courtès, 2015/01/28
- 289/376: Document functors, Ludovic Courtès, 2015/01/28
- 259/376: Export realiseContext in libnixexpr, Ludovic Courtès, 2015/01/28
- 284/376: SSH.pm: Print a friendlier message if connecting fails, Ludovic Courtès, 2015/01/28
- 278/376: Typo, Ludovic Courtès, 2015/01/28
- 292/376: Add a test for the binary tarball installer, Ludovic Courtès, 2015/01/28
- 296/376: Disable vacuuming the DB after garbage collection, Ludovic Courtès, 2015/01/28
- 298/376: Fix bad operator, Ludovic Courtès, 2015/01/28