diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-07-21T23·34+0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-07-23T04·53+0000 |
commit | 855995325e7f8a48a8015d85ee1ad8e8080b5058 (patch) | |
tree | 3319b7d538f425e3437cbcc9db05bf88a9f49cf6 /third_party | |
parent | b1c0866037ea63b670055883de88a9fe4e8891e2 (diff) |
feat(3p/nix): remove builtins.importNative r/1424
This is the shared object equivalent of builtins.exec, or a plugins equivalent accessible from the Nix language. Either way, since we don't have builtins.exec or plugins any more, I think it makes sense to remove this builtin. This will also allow us to drop the allow-unsafe-native-code-during-evaluation option, which formerly controlled whether builtins.exec and builtins.importNative were enabled. Cc: Griffin Smith <grfn@gws.fyi> Cc: Profpatsch <mail@profpatsch.de> Change-Id: I8993a8a79d559c102647308a2684c089bbc06713 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1340 Reviewed-by: glittershark <grfn@gws.fyi> Reviewed-by: Profpatsch <mail@profpatsch.de> Tested-by: BuildkiteCI
Diffstat (limited to '')
-rw-r--r-- | third_party/nix/src/libexpr/primops.cc | 50 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/primops.hh | 5 |
2 files changed, 0 insertions, 55 deletions
diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index 107cacb963d9..06b9788bdf09 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -5,7 +5,6 @@ #include <regex> #include <absl/strings/str_split.h> -#include <dlfcn.h> #include <glog/logging.h> #include <sys/stat.h> #include <sys/types.h> @@ -162,52 +161,6 @@ static void prim_scopedImport(EvalState& state, const Pos& pos, Value** args, } } -/* Want reasonable symbol names, so extern C */ -/* !!! Should we pass the Pos or the file name too? */ -extern "C" using ValueInitializer = void(*)(EvalState&, Value&); - -/* Load a ValueInitializer from a DSO and return whatever it initializes */ -void prim_importNative(EvalState& state, const Pos& pos, Value** args, - Value& v) { - PathSet context; - Path path = state.coerceToPath(pos, *args[0], context); - - try { - state.realiseContext(context); - } catch (InvalidPathError& e) { - throw EvalError( - format("cannot import '%1%', since path '%2%' is not valid, at %3%") % - path % e.path % pos); - } - - path = state.checkSourcePath(path); - - std::string sym = state.forceStringNoCtx(*args[1], pos); - - void* handle = dlopen(path.c_str(), RTLD_LAZY | RTLD_LOCAL); - if (handle == nullptr) { - throw EvalError(format("could not open '%1%': %2%") % path % dlerror()); - } - - dlerror(); - auto func = (ValueInitializer)dlsym(handle, sym.c_str()); - if (func == nullptr) { - char* message = dlerror(); - if (message != nullptr) { - throw EvalError(format("could not load symbol '%1%' from '%2%': %3%") % - sym % path % message); - } - throw EvalError(format("symbol '%1%' from '%2%' resolved to NULL when a " - "function pointer was expected") % - sym % path); - } - - (func)(state, v); - - /* We don't dlclose because v may be a primop referencing a function in the - * shared object file */ -} - /* Return a string representing the type of the expression. */ static void prim_typeOf(EvalState& state, const Pos& pos, Value** args, Value& v) { @@ -2239,9 +2192,6 @@ void EvalState::createBaseEnv() { mkApp(v, *vScopedImport, *v2); forceValue(v); addConstant("import", v); - if (evalSettings.enableNativeCode) { - addPrimOp("__importNative", 2, prim_importNative); - } addPrimOp("__typeOf", 1, prim_typeOf); addPrimOp("isNull", 1, prim_isNull); addPrimOp("__isFunction", 1, prim_isFunction); diff --git a/third_party/nix/src/libexpr/primops.hh b/third_party/nix/src/libexpr/primops.hh index 388066f39010..0c9f6ccab1f7 100644 --- a/third_party/nix/src/libexpr/primops.hh +++ b/third_party/nix/src/libexpr/primops.hh @@ -14,9 +14,4 @@ struct RegisterPrimOp { RegisterPrimOp(const std::string& name, size_t arity, PrimOpFun fun); }; -/* These primops are disabled without enableNativeCode */ -/* Load a ValueInitializer from a DSO and return whatever it initializes */ -void prim_importNative(EvalState& state, const Pos& pos, Value** args, - Value& v); - } // namespace nix |