Skip to content

Commit 9375776

Browse files
committed
Move primop registration to the plugin mechanism.
1 parent c6597bd commit 9375776

File tree

5 files changed

+14
-40
lines changed

5 files changed

+14
-40
lines changed

src/libexpr/primops.cc

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "json.hh"
1212
#include "value-to-json.hh"
1313
#include "value-to-xml.hh"
14-
#include "primops.hh"
1514

1615
#include <sys/types.h>
1716
#include <sys/stat.h>
@@ -2023,21 +2022,6 @@ static void prim_fetchTarball(EvalState & state, const Pos & pos, Value * * args
20232022
}
20242023

20252024

2026-
/*************************************************************
2027-
* Primop registration
2028-
*************************************************************/
2029-
2030-
2031-
RegisterPrimOp::PrimOps * RegisterPrimOp::primOps;
2032-
2033-
2034-
RegisterPrimOp::RegisterPrimOp(std::string name, size_t arity, PrimOpFun fun)
2035-
{
2036-
if (!primOps) primOps = new PrimOps;
2037-
primOps->emplace_back(name, arity, fun);
2038-
}
2039-
2040-
20412025
void EvalState::createBaseEnv()
20422026
{
20432027
baseEnv.up = 0;
@@ -2224,10 +2208,6 @@ void EvalState::createBaseEnv()
22242208
}
22252209
addConstant("__nixPath", v);
22262210

2227-
if (RegisterPrimOp::primOps)
2228-
for (auto & primOp : *RegisterPrimOp::primOps)
2229-
addPrimOp(std::get<0>(primOp), std::get<1>(primOp), std::get<2>(primOp));
2230-
22312211
for (const auto & plugin : settings.plugins.evalPlugins)
22322212
plugin(*this);
22332213

src/libexpr/primops.hh

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/libexpr/primops/fetchGit.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "primops.hh"
21
#include "eval-inline.hh"
32
#include "download.hh"
43
#include "store-api.hh"
@@ -238,6 +237,11 @@ static void prim_fetchGit(EvalState & state, const Pos & pos, Value * * args, Va
238237
state.allowedPaths->insert(gitInfo.storePath);
239238
}
240239

241-
static RegisterPrimOp r("fetchGit", 1, prim_fetchGit);
240+
static void reg(EvalState & state)
241+
{
242+
state.addPrimOp("fetchGit", 1, prim_fetchGit);
243+
}
244+
245+
static RegisterPlugin r(Plugin(PluginTag<PluginType::EvalPlugin>(), reg));
242246

243247
}

src/libexpr/primops/fetchMercurial.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include "primops.hh"
21
#include "eval-inline.hh"
32
#include "download.hh"
43
#include "store-api.hh"
@@ -204,6 +203,11 @@ static void prim_fetchMercurial(EvalState & state, const Pos & pos, Value * * ar
204203
state.allowedPaths->insert(hgInfo.storePath);
205204
}
206205

207-
static RegisterPrimOp r("fetchMercurial", 1, prim_fetchMercurial);
206+
static void reg(EvalState & state)
207+
{
208+
state.addPrimOp("fetchMercurial", 1, prim_fetchMercurial);
209+
}
210+
211+
static RegisterPlugin r(Plugin(PluginTag<PluginType::EvalPlugin>(), reg));
208212

209213
}

src/libstore/plugins.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
* 1. Construct a nix::RegisterPlugin before the call to
1212
* initPlugins(), usually as a static initialization. This can be
1313
* used by nix itself, external programs using libnixmain
14-
* directly, or LD_PRELOADed libraries.
14+
* directly, or LD_PRELOADed libraries. See the bottom of
15+
* src/libexpr/primops/fetchGit.cc for an example.
1516
* 2. Add a file to the 'plugin-files' nix configuration setting. It
1617
* is expected that that file can be safely dlopened by nix (i.e.
1718
* it is a DSO compiled against the same headers as the running

0 commit comments

Comments
 (0)