mirror of
https://github.com/NixOS/nix.git
synced 2025-11-24 11:19:35 +01:00
libexpr: use allocBytes() to allocate StringData
This commit is contained in:
parent
9b9446e860
commit
7cd3252946
17 changed files with 79 additions and 76 deletions
|
|
@ -168,9 +168,9 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
|
||||||
? state.rootPath(absPath(getCommandBaseDir()))
|
? state.rootPath(absPath(getCommandBaseDir()))
|
||||||
: state.rootPath(".")));
|
: state.rootPath(".")));
|
||||||
},
|
},
|
||||||
[&](const AutoArgString & arg) { v->mkString(arg.s); },
|
[&](const AutoArgString & arg) { v->mkString(arg.s, state.mem); },
|
||||||
[&](const AutoArgFile & arg) { v->mkString(readFile(arg.path.string())); },
|
[&](const AutoArgFile & arg) { v->mkString(readFile(arg.path.string()), state.mem); },
|
||||||
[&](const AutoArgStdin & arg) { v->mkString(readFile(STDIN_FILENO)); }},
|
[&](const AutoArgStdin & arg) { v->mkString(readFile(STDIN_FILENO), state.mem); }},
|
||||||
arg);
|
arg);
|
||||||
res.insert(state.symbols.create(name), v);
|
res.insert(state.symbols.create(name), v);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -515,7 +515,7 @@ nix_err nix_init_string(nix_c_context * context, nix_value * value, const char *
|
||||||
context->last_err_code = NIX_OK;
|
context->last_err_code = NIX_OK;
|
||||||
try {
|
try {
|
||||||
auto & v = check_value_out(value);
|
auto & v = check_value_out(value);
|
||||||
v.mkString(std::string_view(str));
|
v.mkString(std::string_view(str), *value->mem);
|
||||||
}
|
}
|
||||||
NIXC_CATCH_ERRS
|
NIXC_CATCH_ERRS
|
||||||
}
|
}
|
||||||
|
|
@ -526,7 +526,7 @@ nix_err nix_init_path_string(nix_c_context * context, EvalState * s, nix_value *
|
||||||
context->last_err_code = NIX_OK;
|
context->last_err_code = NIX_OK;
|
||||||
try {
|
try {
|
||||||
auto & v = check_value_out(value);
|
auto & v = check_value_out(value);
|
||||||
v.mkPath(s->state.rootPath(nix::CanonPath(str)));
|
v.mkPath(s->state.rootPath(nix::CanonPath(str)), s->state.mem);
|
||||||
}
|
}
|
||||||
NIXC_CATCH_ERRS
|
NIXC_CATCH_ERRS
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ TEST_F(JSONValueTest, StringQuotes)
|
||||||
TEST_F(JSONValueTest, DISABLED_Path)
|
TEST_F(JSONValueTest, DISABLED_Path)
|
||||||
{
|
{
|
||||||
Value v;
|
Value v;
|
||||||
v.mkPath(state.rootPath(CanonPath("/test")));
|
v.mkPath(state.rootPath(CanonPath("/test")), state.mem);
|
||||||
ASSERT_EQ(getJSONValue(v), "\"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x\"");
|
ASSERT_EQ(getJSONValue(v), "\"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x\"");
|
||||||
}
|
}
|
||||||
} /* namespace nix */
|
} /* namespace nix */
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ struct StringPrintingTests : LibExprTest
|
||||||
void test(std::string_view literal, std::string_view expected, unsigned int maxLength, A... args)
|
void test(std::string_view literal, std::string_view expected, unsigned int maxLength, A... args)
|
||||||
{
|
{
|
||||||
Value v;
|
Value v;
|
||||||
v.mkString(literal);
|
v.mkString(literal, state.mem);
|
||||||
|
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
printValue(state, out, v, PrintOptions{.maxStringLength = maxLength});
|
printValue(state, out, v, PrintOptions{.maxStringLength = maxLength});
|
||||||
|
|
@ -353,7 +353,7 @@ TEST_F(ValuePrintingTests, ansiColorsStringElided)
|
||||||
TEST_F(ValuePrintingTests, ansiColorsPath)
|
TEST_F(ValuePrintingTests, ansiColorsPath)
|
||||||
{
|
{
|
||||||
Value v;
|
Value v;
|
||||||
v.mkPath(state.rootPath(CanonPath("puppy")));
|
v.mkPath(state.rootPath(CanonPath("puppy")), state.mem);
|
||||||
|
|
||||||
test(v, ANSI_GREEN "/puppy" ANSI_NORMAL, PrintOptions{.ansiColors = true});
|
test(v, ANSI_GREEN "/puppy" ANSI_NORMAL, PrintOptions{.ansiColors = true});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -81,20 +81,20 @@ static const char * makeImmutableString(std::string_view s)
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringData & StringData::alloc(size_t size)
|
StringData & StringData::alloc(EvalMemory & mem, size_t size)
|
||||||
{
|
{
|
||||||
void * t = GC_MALLOC_ATOMIC(sizeof(StringData) + size + 1);
|
void * t = mem.allocBytes(sizeof(StringData) + size + 1);
|
||||||
if (!t)
|
if (!t)
|
||||||
throw std::bad_alloc();
|
throw std::bad_alloc();
|
||||||
auto res = new (t) StringData(size);
|
auto res = new (t) StringData(size);
|
||||||
return *res;
|
return *res;
|
||||||
}
|
}
|
||||||
|
|
||||||
const StringData & StringData::make(std::string_view s)
|
const StringData & StringData::make(EvalMemory & mem, std::string_view s)
|
||||||
{
|
{
|
||||||
if (s.empty())
|
if (s.empty())
|
||||||
return ""_sds;
|
return ""_sds;
|
||||||
auto & res = alloc(s.size());
|
auto & res = alloc(mem, s.size());
|
||||||
std::memcpy(&res.data_, s.data(), s.size());
|
std::memcpy(&res.data_, s.data(), s.size());
|
||||||
res.data_[s.size()] = '\0';
|
res.data_[s.size()] = '\0';
|
||||||
return res;
|
return res;
|
||||||
|
|
@ -849,9 +849,9 @@ DebugTraceStacker::DebugTraceStacker(EvalState & evalState, DebugTrace t)
|
||||||
evalState.runDebugRepl(nullptr, trace.env, trace.expr);
|
evalState.runDebugRepl(nullptr, trace.env, trace.expr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::mkString(std::string_view s)
|
void Value::mkString(std::string_view s, EvalMemory & mem)
|
||||||
{
|
{
|
||||||
mkStringNoCopy(StringData::make(s));
|
mkStringNoCopy(StringData::make(mem, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
Value::StringWithContext::Context *
|
Value::StringWithContext::Context *
|
||||||
|
|
@ -862,13 +862,13 @@ Value::StringWithContext::Context::fromBuilder(const NixStringContext & context,
|
||||||
|
|
||||||
auto ctx = new (mem.allocBytes(sizeof(Context) + context.size() * sizeof(value_type))) Context(context.size());
|
auto ctx = new (mem.allocBytes(sizeof(Context) + context.size() * sizeof(value_type))) Context(context.size());
|
||||||
std::ranges::transform(
|
std::ranges::transform(
|
||||||
context, ctx->elems, [](const NixStringContextElem & elt) { return &StringData::make(elt.to_string()); });
|
context, ctx->elems, [&](const NixStringContextElem & elt) { return &StringData::make(mem, elt.to_string()); });
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::mkString(std::string_view s, const NixStringContext & context, EvalMemory & mem)
|
void Value::mkString(std::string_view s, const NixStringContext & context, EvalMemory & mem)
|
||||||
{
|
{
|
||||||
mkStringNoCopy(StringData::make(s), Value::StringWithContext::Context::fromBuilder(context, mem));
|
mkStringNoCopy(StringData::make(mem, s), Value::StringWithContext::Context::fromBuilder(context, mem));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::mkStringMove(const StringData & s, const NixStringContext & context, EvalMemory & mem)
|
void Value::mkStringMove(const StringData & s, const NixStringContext & context, EvalMemory & mem)
|
||||||
|
|
@ -876,9 +876,9 @@ void Value::mkStringMove(const StringData & s, const NixStringContext & context,
|
||||||
mkStringNoCopy(s, Value::StringWithContext::Context::fromBuilder(context, mem));
|
mkStringNoCopy(s, Value::StringWithContext::Context::fromBuilder(context, mem));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Value::mkPath(const SourcePath & path)
|
void Value::mkPath(const SourcePath & path, EvalMemory & mem)
|
||||||
{
|
{
|
||||||
mkPath(&*path.accessor, StringData::make(path.path.abs()));
|
mkPath(&*path.accessor, StringData::make(mem, path.path.abs()));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
|
inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
|
||||||
|
|
@ -943,7 +943,7 @@ void EvalState::mkPos(Value & v, PosIdx p)
|
||||||
auto origin = positions.originOf(p);
|
auto origin = positions.originOf(p);
|
||||||
if (auto path = std::get_if<SourcePath>(&origin)) {
|
if (auto path = std::get_if<SourcePath>(&origin)) {
|
||||||
auto attrs = buildBindings(3);
|
auto attrs = buildBindings(3);
|
||||||
attrs.alloc(s.file).mkString(path->path.abs());
|
attrs.alloc(s.file).mkString(path->path.abs(), mem);
|
||||||
makePositionThunks(*this, p, attrs.alloc(s.line), attrs.alloc(s.column));
|
makePositionThunks(*this, p, attrs.alloc(s.line), attrs.alloc(s.column));
|
||||||
v.mkAttrs(attrs);
|
v.mkAttrs(attrs);
|
||||||
} else
|
} else
|
||||||
|
|
@ -2139,9 +2139,9 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
|
||||||
for (const auto & part : strings) {
|
for (const auto & part : strings) {
|
||||||
resultStr += *part;
|
resultStr += *part;
|
||||||
}
|
}
|
||||||
v.mkPath(state.rootPath(CanonPath(resultStr)));
|
v.mkPath(state.rootPath(CanonPath(resultStr)), state.mem);
|
||||||
} else {
|
} else {
|
||||||
auto & resultStr = StringData::alloc(sSize);
|
auto & resultStr = StringData::alloc(state.mem, sSize);
|
||||||
auto * tmp = resultStr.data();
|
auto * tmp = resultStr.data();
|
||||||
for (const auto & part : strings) {
|
for (const auto & part : strings) {
|
||||||
std::memcpy(tmp, part->data(), part->size());
|
std::memcpy(tmp, part->data(), part->size());
|
||||||
|
|
|
||||||
|
|
@ -232,13 +232,13 @@ public:
|
||||||
* Allocate StringData on the (possibly) GC-managed heap and copy
|
* Allocate StringData on the (possibly) GC-managed heap and copy
|
||||||
* the contents of s to it.
|
* the contents of s to it.
|
||||||
*/
|
*/
|
||||||
static const StringData & make(std::string_view s);
|
static const StringData & make(EvalMemory & mem, std::string_view s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allocate StringData on the (possibly) GC-managed heap.
|
* Allocate StringData on the (possibly) GC-managed heap.
|
||||||
* @param size Length of the string (without the NUL terminator).
|
* @param size Length of the string (without the NUL terminator).
|
||||||
*/
|
*/
|
||||||
static StringData & alloc(size_t size);
|
static StringData & alloc(EvalMemory & mem, size_t size);
|
||||||
|
|
||||||
size_t size() const
|
size_t size() const
|
||||||
{
|
{
|
||||||
|
|
@ -1147,13 +1147,13 @@ public:
|
||||||
setStorage(StringWithContext{.str = &s, .context = context});
|
setStorage(StringWithContext{.str = &s, .context = context});
|
||||||
}
|
}
|
||||||
|
|
||||||
void mkString(std::string_view s);
|
void mkString(std::string_view s, EvalMemory & mem);
|
||||||
|
|
||||||
void mkString(std::string_view s, const NixStringContext & context, EvalMemory & mem);
|
void mkString(std::string_view s, const NixStringContext & context, EvalMemory & mem);
|
||||||
|
|
||||||
void mkStringMove(const StringData & s, const NixStringContext & context, EvalMemory & mem);
|
void mkStringMove(const StringData & s, const NixStringContext & context, EvalMemory & mem);
|
||||||
|
|
||||||
void mkPath(const SourcePath & path);
|
void mkPath(const SourcePath & path, EvalMemory & mem);
|
||||||
|
|
||||||
inline void mkPath(SourceAccessor * accessor, const StringData & path) noexcept
|
inline void mkPath(SourceAccessor * accessor, const StringData & path) noexcept
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ public:
|
||||||
bool string(string_t & val) override
|
bool string(string_t & val) override
|
||||||
{
|
{
|
||||||
forceNoNullByte(val);
|
forceNoNullByte(val);
|
||||||
rs->value(state).mkString(val);
|
rs->value(state).mkString(val, state.mem);
|
||||||
rs->add();
|
rs->add();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ RegisterPrimOp::PrimOps & RegisterPrimOp::primOps()
|
||||||
static inline Value * mkString(EvalState & state, const std::csub_match & match)
|
static inline Value * mkString(EvalState & state, const std::csub_match & match)
|
||||||
{
|
{
|
||||||
Value * v = state.allocValue();
|
Value * v = state.allocValue();
|
||||||
v->mkString({match.first, match.second});
|
v->mkString({match.first, match.second}, state.mem);
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -230,12 +230,12 @@ void derivationToValue(
|
||||||
NixStringContextElem::DrvDeep{.drvPath = storePath},
|
NixStringContextElem::DrvDeep{.drvPath = storePath},
|
||||||
},
|
},
|
||||||
state.mem);
|
state.mem);
|
||||||
attrs.alloc(state.s.name).mkString(drv.env["name"]);
|
attrs.alloc(state.s.name).mkString(drv.env["name"], state.mem);
|
||||||
|
|
||||||
auto list = state.buildList(drv.outputs.size());
|
auto list = state.buildList(drv.outputs.size());
|
||||||
for (const auto & [i, o] : enumerate(drv.outputs)) {
|
for (const auto & [i, o] : enumerate(drv.outputs)) {
|
||||||
mkOutputString(state, attrs, storePath, o);
|
mkOutputString(state, attrs, storePath, o);
|
||||||
(list[i] = state.allocValue())->mkString(o.first);
|
(list[i] = state.allocValue())->mkString(o.first, state.mem);
|
||||||
}
|
}
|
||||||
attrs.alloc(state.s.outputs).mkList(list);
|
attrs.alloc(state.s.outputs).mkList(list);
|
||||||
|
|
||||||
|
|
@ -519,7 +519,7 @@ static void prim_typeOf(EvalState & state, const PosIdx pos, Value ** args, Valu
|
||||||
v.mkStringNoCopy("lambda"_sds);
|
v.mkStringNoCopy("lambda"_sds);
|
||||||
break;
|
break;
|
||||||
case nExternal:
|
case nExternal:
|
||||||
v.mkString(args[0]->external()->typeOf());
|
v.mkString(args[0]->external()->typeOf(), state.mem);
|
||||||
break;
|
break;
|
||||||
case nFloat:
|
case nFloat:
|
||||||
v.mkStringNoCopy("float"_sds);
|
v.mkStringNoCopy("float"_sds);
|
||||||
|
|
@ -1176,7 +1176,7 @@ static void prim_getEnv(EvalState & state, const PosIdx pos, Value ** args, Valu
|
||||||
{
|
{
|
||||||
std::string name(
|
std::string name(
|
||||||
state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.getEnv"));
|
state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.getEnv"));
|
||||||
v.mkString(state.settings.restrictEval || state.settings.pureEval ? "" : getEnv(name).value_or(""));
|
v.mkString(state.settings.restrictEval || state.settings.pureEval ? "" : getEnv(name).value_or(""), state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_getEnv({
|
static RegisterPrimOp primop_getEnv({
|
||||||
|
|
@ -1842,8 +1842,10 @@ static RegisterPrimOp primop_derivationStrict(
|
||||||
‘out’. */
|
‘out’. */
|
||||||
static void prim_placeholder(EvalState & state, const PosIdx pos, Value ** args, Value & v)
|
static void prim_placeholder(EvalState & state, const PosIdx pos, Value ** args, Value & v)
|
||||||
{
|
{
|
||||||
v.mkString(hashPlaceholder(
|
v.mkString(
|
||||||
state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.placeholder")));
|
hashPlaceholder(state.forceStringNoCtx(
|
||||||
|
*args[0], pos, "while evaluating the first argument passed to builtins.placeholder")),
|
||||||
|
state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_placeholder({
|
static RegisterPrimOp primop_placeholder({
|
||||||
|
|
@ -2027,7 +2029,7 @@ static void prim_dirOf(EvalState & state, const PosIdx pos, Value ** args, Value
|
||||||
state.forceValue(*args[0], pos);
|
state.forceValue(*args[0], pos);
|
||||||
if (args[0]->type() == nPath) {
|
if (args[0]->type() == nPath) {
|
||||||
auto path = args[0]->path();
|
auto path = args[0]->path();
|
||||||
v.mkPath(path.path.isRoot() ? path : path.parent());
|
v.mkPath(path.path.isRoot() ? path : path.parent(), state.mem);
|
||||||
} else {
|
} else {
|
||||||
NixStringContext context;
|
NixStringContext context;
|
||||||
auto path = state.coerceToString(
|
auto path = state.coerceToString(
|
||||||
|
|
@ -2144,7 +2146,7 @@ static void prim_findFile(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||||
auto path =
|
auto path =
|
||||||
state.forceStringNoCtx(*args[1], pos, "while evaluating the second argument passed to builtins.findFile");
|
state.forceStringNoCtx(*args[1], pos, "while evaluating the second argument passed to builtins.findFile");
|
||||||
|
|
||||||
v.mkPath(state.findFile(lookupPath, path, pos));
|
v.mkPath(state.findFile(lookupPath, path, pos), state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_findFile(
|
static RegisterPrimOp primop_findFile(
|
||||||
|
|
@ -2293,7 +2295,7 @@ static void prim_hashFile(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||||
|
|
||||||
auto path = realisePath(state, pos, *args[1]);
|
auto path = realisePath(state, pos, *args[1]);
|
||||||
|
|
||||||
v.mkString(hashString(*ha, path.readFile()).to_string(HashFormat::Base16, false));
|
v.mkString(hashString(*ha, path.readFile()).to_string(HashFormat::Base16, false), state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_hashFile({
|
static RegisterPrimOp primop_hashFile({
|
||||||
|
|
@ -2382,7 +2384,7 @@ static void prim_readDir(EvalState & state, const PosIdx pos, Value ** args, Val
|
||||||
// detailed node info quickly in this case we produce a thunk to
|
// detailed node info quickly in this case we produce a thunk to
|
||||||
// query the file type lazily.
|
// query the file type lazily.
|
||||||
auto epath = state.allocValue();
|
auto epath = state.allocValue();
|
||||||
epath->mkPath(path / name);
|
epath->mkPath(path / name, state.mem);
|
||||||
if (!readFileType)
|
if (!readFileType)
|
||||||
readFileType = &state.getBuiltin("readFileType");
|
readFileType = &state.getBuiltin("readFileType");
|
||||||
attr.mkApp(readFileType, epath);
|
attr.mkApp(readFileType, epath);
|
||||||
|
|
@ -2763,7 +2765,7 @@ bool EvalState::callPathFilter(Value * filterFun, const SourcePath & path, PosId
|
||||||
/* Call the filter function. The first argument is the path, the
|
/* Call the filter function. The first argument is the path, the
|
||||||
second is a string indicating the type of the file. */
|
second is a string indicating the type of the file. */
|
||||||
Value arg1;
|
Value arg1;
|
||||||
arg1.mkString(path.path.abs());
|
arg1.mkString(path.path.abs(), mem);
|
||||||
|
|
||||||
// assert that type is not "unknown"
|
// assert that type is not "unknown"
|
||||||
Value * args[]{&arg1, const_cast<Value *>(&fileTypeToString(*this, st.type))};
|
Value * args[]{&arg1, const_cast<Value *>(&fileTypeToString(*this, st.type))};
|
||||||
|
|
@ -4541,7 +4543,7 @@ static void prim_hashString(EvalState & state, const PosIdx pos, Value ** args,
|
||||||
auto s =
|
auto s =
|
||||||
state.forceString(*args[1], context, pos, "while evaluating the second argument passed to builtins.hashString");
|
state.forceString(*args[1], context, pos, "while evaluating the second argument passed to builtins.hashString");
|
||||||
|
|
||||||
v.mkString(hashString(*ha, s).to_string(HashFormat::Base16, false));
|
v.mkString(hashString(*ha, s).to_string(HashFormat::Base16, false), state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_hashString({
|
static RegisterPrimOp primop_hashString({
|
||||||
|
|
@ -4574,7 +4576,7 @@ static void prim_convertHash(EvalState & state, const PosIdx pos, Value ** args,
|
||||||
HashFormat hf = parseHashFormat(
|
HashFormat hf = parseHashFormat(
|
||||||
state.forceStringNoCtx(*iteratorToHashFormat->value, pos, "while evaluating the attribute 'toHashFormat'"));
|
state.forceStringNoCtx(*iteratorToHashFormat->value, pos, "while evaluating the attribute 'toHashFormat'"));
|
||||||
|
|
||||||
v.mkString(Hash::parseAny(hash, ha).to_string(hf, hf == HashFormat::SRI));
|
v.mkString(Hash::parseAny(hash, ha).to_string(hf, hf == HashFormat::SRI), state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_convertHash({
|
static RegisterPrimOp primop_convertHash({
|
||||||
|
|
@ -4992,8 +4994,8 @@ static void prim_parseDrvName(EvalState & state, const PosIdx pos, Value ** args
|
||||||
state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.parseDrvName");
|
state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.parseDrvName");
|
||||||
DrvName parsed(name);
|
DrvName parsed(name);
|
||||||
auto attrs = state.buildBindings(2);
|
auto attrs = state.buildBindings(2);
|
||||||
attrs.alloc(state.s.name).mkString(parsed.name);
|
attrs.alloc(state.s.name).mkString(parsed.name, state.mem);
|
||||||
attrs.alloc("version").mkString(parsed.version);
|
attrs.alloc("version").mkString(parsed.version, state.mem);
|
||||||
v.mkAttrs(attrs);
|
v.mkAttrs(attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5048,7 +5050,7 @@ static void prim_splitVersion(EvalState & state, const PosIdx pos, Value ** args
|
||||||
}
|
}
|
||||||
auto list = state.buildList(components.size());
|
auto list = state.buildList(components.size());
|
||||||
for (const auto & [n, component] : enumerate(components))
|
for (const auto & [n, component] : enumerate(components))
|
||||||
(list[n] = state.allocValue())->mkString(std::move(component));
|
(list[n] = state.allocValue())->mkString(std::move(component), state.mem);
|
||||||
v.mkList(list);
|
v.mkList(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -5192,7 +5194,7 @@ void EvalState::createBaseEnv(const EvalSettings & evalSettings)
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!settings.pureEval)
|
if (!settings.pureEval)
|
||||||
v.mkString(settings.getCurrentSystem());
|
v.mkString(settings.getCurrentSystem(), mem);
|
||||||
addConstant(
|
addConstant(
|
||||||
"__currentSystem",
|
"__currentSystem",
|
||||||
v,
|
v,
|
||||||
|
|
@ -5224,7 +5226,7 @@ void EvalState::createBaseEnv(const EvalSettings & evalSettings)
|
||||||
.impureOnly = true,
|
.impureOnly = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
v.mkString(nixVersion);
|
v.mkString(nixVersion, mem);
|
||||||
addConstant(
|
addConstant(
|
||||||
"__nixVersion",
|
"__nixVersion",
|
||||||
v,
|
v,
|
||||||
|
|
@ -5249,7 +5251,7 @@ void EvalState::createBaseEnv(const EvalSettings & evalSettings)
|
||||||
)",
|
)",
|
||||||
});
|
});
|
||||||
|
|
||||||
v.mkString(store->storeDir);
|
v.mkString(store->storeDir, mem);
|
||||||
addConstant(
|
addConstant(
|
||||||
"__storeDir",
|
"__storeDir",
|
||||||
v,
|
v,
|
||||||
|
|
@ -5314,8 +5316,8 @@ void EvalState::createBaseEnv(const EvalSettings & evalSettings)
|
||||||
auto list = buildList(lookupPath.elements.size());
|
auto list = buildList(lookupPath.elements.size());
|
||||||
for (const auto & [n, i] : enumerate(lookupPath.elements)) {
|
for (const auto & [n, i] : enumerate(lookupPath.elements)) {
|
||||||
auto attrs = buildBindings(2);
|
auto attrs = buildBindings(2);
|
||||||
attrs.alloc("path").mkString(i.path.s);
|
attrs.alloc("path").mkString(i.path.s, mem);
|
||||||
attrs.alloc("prefix").mkString(i.prefix.s);
|
attrs.alloc("prefix").mkString(i.prefix.s, mem);
|
||||||
(list[n] = allocValue())->mkAttrs(attrs);
|
(list[n] = allocValue())->mkAttrs(attrs);
|
||||||
}
|
}
|
||||||
v.mkList(list);
|
v.mkList(list);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ static void prim_unsafeDiscardStringContext(EvalState & state, const PosIdx pos,
|
||||||
NixStringContext context;
|
NixStringContext context;
|
||||||
auto s = state.coerceToString(
|
auto s = state.coerceToString(
|
||||||
pos, *args[0], context, "while evaluating the argument passed to builtins.unsafeDiscardStringContext");
|
pos, *args[0], context, "while evaluating the argument passed to builtins.unsafeDiscardStringContext");
|
||||||
v.mkString(*s);
|
v.mkString(*s, state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_unsafeDiscardStringContext({
|
static RegisterPrimOp primop_unsafeDiscardStringContext({
|
||||||
|
|
@ -218,7 +218,7 @@ static void prim_getContext(EvalState & state, const PosIdx pos, Value ** args,
|
||||||
if (!info.second.outputs.empty()) {
|
if (!info.second.outputs.empty()) {
|
||||||
auto list = state.buildList(info.second.outputs.size());
|
auto list = state.buildList(info.second.outputs.size());
|
||||||
for (const auto & [i, output] : enumerate(info.second.outputs))
|
for (const auto & [i, output] : enumerate(info.second.outputs))
|
||||||
(list[i] = state.allocValue())->mkString(output);
|
(list[i] = state.allocValue())->mkString(output, state.mem);
|
||||||
infoAttrs.alloc(state.s.outputs).mkList(list);
|
infoAttrs.alloc(state.s.outputs).mkList(list);
|
||||||
}
|
}
|
||||||
attrs.alloc(state.store->printStorePath(info.first)).mkAttrs(infoAttrs);
|
attrs.alloc(state.store->printStorePath(info.first)).mkAttrs(infoAttrs);
|
||||||
|
|
|
||||||
|
|
@ -86,12 +86,12 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value ** ar
|
||||||
auto attrs2 = state.buildBindings(8);
|
auto attrs2 = state.buildBindings(8);
|
||||||
state.mkStorePathString(storePath, attrs2.alloc(state.s.outPath));
|
state.mkStorePathString(storePath, attrs2.alloc(state.s.outPath));
|
||||||
if (input2.getRef())
|
if (input2.getRef())
|
||||||
attrs2.alloc("branch").mkString(*input2.getRef());
|
attrs2.alloc("branch").mkString(*input2.getRef(), state.mem);
|
||||||
// Backward compatibility: set 'rev' to
|
// Backward compatibility: set 'rev' to
|
||||||
// 0000000000000000000000000000000000000000 for a dirty tree.
|
// 0000000000000000000000000000000000000000 for a dirty tree.
|
||||||
auto rev2 = input2.getRev().value_or(Hash(HashAlgorithm::SHA1));
|
auto rev2 = input2.getRev().value_or(Hash(HashAlgorithm::SHA1));
|
||||||
attrs2.alloc("rev").mkString(rev2.gitRev());
|
attrs2.alloc("rev").mkString(rev2.gitRev(), state.mem);
|
||||||
attrs2.alloc("shortRev").mkString(rev2.gitRev().substr(0, 12));
|
attrs2.alloc("shortRev").mkString(rev2.gitRev().substr(0, 12), state.mem);
|
||||||
if (auto revCount = input2.getRevCount())
|
if (auto revCount = input2.getRevCount())
|
||||||
attrs2.alloc("revCount").mkInt(*revCount);
|
attrs2.alloc("revCount").mkInt(*revCount);
|
||||||
v.mkAttrs(attrs2);
|
v.mkAttrs(attrs2);
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ void emitTreeAttrs(
|
||||||
// FIXME: support arbitrary input attributes.
|
// FIXME: support arbitrary input attributes.
|
||||||
|
|
||||||
if (auto narHash = input.getNarHash())
|
if (auto narHash = input.getNarHash())
|
||||||
attrs.alloc("narHash").mkString(narHash->to_string(HashFormat::SRI, true));
|
attrs.alloc("narHash").mkString(narHash->to_string(HashFormat::SRI, true), state.mem);
|
||||||
|
|
||||||
if (input.getType() == "git")
|
if (input.getType() == "git")
|
||||||
attrs.alloc("submodules").mkBool(fetchers::maybeGetBoolAttr(input.attrs, "submodules").value_or(false));
|
attrs.alloc("submodules").mkBool(fetchers::maybeGetBoolAttr(input.attrs, "submodules").value_or(false));
|
||||||
|
|
@ -43,13 +43,13 @@ void emitTreeAttrs(
|
||||||
if (!forceDirty) {
|
if (!forceDirty) {
|
||||||
|
|
||||||
if (auto rev = input.getRev()) {
|
if (auto rev = input.getRev()) {
|
||||||
attrs.alloc("rev").mkString(rev->gitRev());
|
attrs.alloc("rev").mkString(rev->gitRev(), state.mem);
|
||||||
attrs.alloc("shortRev").mkString(rev->gitShortRev());
|
attrs.alloc("shortRev").mkString(rev->gitShortRev(), state.mem);
|
||||||
} else if (emptyRevFallback) {
|
} else if (emptyRevFallback) {
|
||||||
// Backwards compat for `builtins.fetchGit`: dirty repos return an empty sha1 as rev
|
// Backwards compat for `builtins.fetchGit`: dirty repos return an empty sha1 as rev
|
||||||
auto emptyHash = Hash(HashAlgorithm::SHA1);
|
auto emptyHash = Hash(HashAlgorithm::SHA1);
|
||||||
attrs.alloc("rev").mkString(emptyHash.gitRev());
|
attrs.alloc("rev").mkString(emptyHash.gitRev(), state.mem);
|
||||||
attrs.alloc("shortRev").mkString(emptyHash.gitShortRev());
|
attrs.alloc("shortRev").mkString(emptyHash.gitShortRev(), state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto revCount = input.getRevCount())
|
if (auto revCount = input.getRevCount())
|
||||||
|
|
@ -59,13 +59,14 @@ void emitTreeAttrs(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto dirtyRev = fetchers::maybeGetStrAttr(input.attrs, "dirtyRev")) {
|
if (auto dirtyRev = fetchers::maybeGetStrAttr(input.attrs, "dirtyRev")) {
|
||||||
attrs.alloc("dirtyRev").mkString(*dirtyRev);
|
attrs.alloc("dirtyRev").mkString(*dirtyRev, state.mem);
|
||||||
attrs.alloc("dirtyShortRev").mkString(*fetchers::maybeGetStrAttr(input.attrs, "dirtyShortRev"));
|
attrs.alloc("dirtyShortRev").mkString(*fetchers::maybeGetStrAttr(input.attrs, "dirtyShortRev"), state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto lastModified = input.getLastModified()) {
|
if (auto lastModified = input.getLastModified()) {
|
||||||
attrs.alloc("lastModified").mkInt(*lastModified);
|
attrs.alloc("lastModified").mkInt(*lastModified);
|
||||||
attrs.alloc("lastModifiedDate").mkString(fmt("%s", std::put_time(std::gmtime(&*lastModified), "%Y%m%d%H%M%S")));
|
attrs.alloc("lastModifiedDate")
|
||||||
|
.mkString(fmt("%s", std::put_time(std::gmtime(&*lastModified), "%Y%m%d%H%M%S")), state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
v.mkAttrs(attrs);
|
v.mkAttrs(attrs);
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||||
case toml::value_t::string: {
|
case toml::value_t::string: {
|
||||||
auto s = toml::get<std::string_view>(t);
|
auto s = toml::get<std::string_view>(t);
|
||||||
forceNoNullByte(s);
|
forceNoNullByte(s);
|
||||||
v.mkString(s);
|
v.mkString(s, state.mem);
|
||||||
} break;
|
} break;
|
||||||
case toml::value_t::local_datetime:
|
case toml::value_t::local_datetime:
|
||||||
case toml::value_t::offset_datetime:
|
case toml::value_t::offset_datetime:
|
||||||
|
|
@ -142,7 +142,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||||
s << t;
|
s << t;
|
||||||
auto str = s.view();
|
auto str = s.view();
|
||||||
forceNoNullByte(str);
|
forceNoNullByte(str);
|
||||||
attrs.alloc("value").mkString(str);
|
attrs.alloc("value").mkString(str, state.mem);
|
||||||
v.mkAttrs(attrs);
|
v.mkAttrs(attrs);
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error("Dates and times are not supported");
|
throw std::runtime_error("Dates and times are not supported");
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,7 @@ static void prim_parseFlakeRef(EvalState & state, const PosIdx pos, Value ** arg
|
||||||
auto & vv = binds.alloc(s);
|
auto & vv = binds.alloc(s);
|
||||||
std::visit(
|
std::visit(
|
||||||
overloaded{
|
overloaded{
|
||||||
[&vv](const std::string & value) { vv.mkString(value); },
|
[&vv, &state](const std::string & value) { vv.mkString(value, state.mem); },
|
||||||
[&vv](const uint64_t & value) { vv.mkInt(value); },
|
[&vv](const uint64_t & value) { vv.mkInt(value); },
|
||||||
[&vv](const Explicit<bool> & value) { vv.mkBool(value.t); }},
|
[&vv](const Explicit<bool> & value) { vv.mkBool(value.t); }},
|
||||||
value);
|
value);
|
||||||
|
|
@ -156,7 +156,7 @@ static void prim_flakeRefToString(EvalState & state, const PosIdx pos, Value **
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto flakeRef = FlakeRef::fromAttrs(state.fetchSettings, attrs);
|
auto flakeRef = FlakeRef::fromAttrs(state.fetchSettings, attrs);
|
||||||
v.mkString(flakeRef.to_string());
|
v.mkString(flakeRef.to_string(), state.mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
nix::PrimOp flakeRefToString({
|
nix::PrimOp flakeRefToString({
|
||||||
|
|
|
||||||
|
|
@ -956,7 +956,7 @@ void callFlake(EvalState & state, const LockedFlake & lockedFlake, Value & vRes)
|
||||||
auto key = keyMap.find(node);
|
auto key = keyMap.find(node);
|
||||||
assert(key != keyMap.end());
|
assert(key != keyMap.end());
|
||||||
|
|
||||||
override.alloc(state.symbols.create("dir")).mkString(CanonPath(subdir).rel());
|
override.alloc(state.symbols.create("dir")).mkString(CanonPath(subdir).rel(), state.mem);
|
||||||
|
|
||||||
overrides.alloc(state.symbols.create(key->second)).mkAttrs(override);
|
overrides.alloc(state.symbols.create(key->second)).mkAttrs(override);
|
||||||
}
|
}
|
||||||
|
|
@ -966,7 +966,7 @@ void callFlake(EvalState & state, const LockedFlake & lockedFlake, Value & vRes)
|
||||||
Value * vCallFlake = requireInternalFile(state, CanonPath("call-flake.nix"));
|
Value * vCallFlake = requireInternalFile(state, CanonPath("call-flake.nix"));
|
||||||
|
|
||||||
auto vLocks = state.allocValue();
|
auto vLocks = state.allocValue();
|
||||||
vLocks->mkString(lockFileStr);
|
vLocks->mkString(lockFileStr, state.mem);
|
||||||
|
|
||||||
auto vFetchFinalTree = get(state.internalPrimOps, "fetchFinalTree");
|
auto vFetchFinalTree = get(state.internalPrimOps, "fetchFinalTree");
|
||||||
assert(vFetchFinalTree);
|
assert(vFetchFinalTree);
|
||||||
|
|
|
||||||
|
|
@ -271,7 +271,7 @@ static void showHelp(std::vector<std::string> subcommand, NixArgs & toplevel)
|
||||||
);
|
);
|
||||||
|
|
||||||
auto vDump = state.allocValue();
|
auto vDump = state.allocValue();
|
||||||
vDump->mkString(toplevel.dumpCli());
|
vDump->mkString(toplevel.dumpCli(), state.mem);
|
||||||
|
|
||||||
auto vRes = state.allocValue();
|
auto vRes = state.allocValue();
|
||||||
Value * args[]{&state.getBuiltin("false"), vDump};
|
Value * args[]{&state.getBuiltin("false"), vDump};
|
||||||
|
|
|
||||||
|
|
@ -132,7 +132,7 @@ static void getAllExprs(EvalState & state, const SourcePath & path, StringSet &
|
||||||
}
|
}
|
||||||
/* Load the expression on demand. */
|
/* Load the expression on demand. */
|
||||||
auto vArg = state.allocValue();
|
auto vArg = state.allocValue();
|
||||||
vArg->mkPath(path2);
|
vArg->mkPath(path2, state.mem);
|
||||||
if (seen.size() == maxAttrs)
|
if (seen.size() == maxAttrs)
|
||||||
throw Error("too many Nix expressions in directory '%1%'", path);
|
throw Error("too many Nix expressions in directory '%1%'", path);
|
||||||
attrs.alloc(attrName).mkApp(&state.getBuiltin("import"), vArg);
|
attrs.alloc(attrName).mkApp(&state.getBuiltin("import"), vArg);
|
||||||
|
|
@ -483,7 +483,7 @@ static bool keep(PackageInfo & drv)
|
||||||
static void setMetaFlag(EvalState & state, PackageInfo & drv, const std::string & name, const std::string & value)
|
static void setMetaFlag(EvalState & state, PackageInfo & drv, const std::string & name, const std::string & value)
|
||||||
{
|
{
|
||||||
auto v = state.allocValue();
|
auto v = state.allocValue();
|
||||||
v->mkString(value);
|
v->mkString(value, state.mem);
|
||||||
drv.setMeta(name, v);
|
drv.setMeta(name, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,20 +58,20 @@ bool createUserEnv(
|
||||||
auto attrs = state.buildBindings(7 + outputs.size());
|
auto attrs = state.buildBindings(7 + outputs.size());
|
||||||
|
|
||||||
attrs.alloc(state.s.type).mkStringNoCopy("derivation"_sds);
|
attrs.alloc(state.s.type).mkStringNoCopy("derivation"_sds);
|
||||||
attrs.alloc(state.s.name).mkString(i.queryName());
|
attrs.alloc(state.s.name).mkString(i.queryName(), state.mem);
|
||||||
auto system = i.querySystem();
|
auto system = i.querySystem();
|
||||||
if (!system.empty())
|
if (!system.empty())
|
||||||
attrs.alloc(state.s.system).mkString(system);
|
attrs.alloc(state.s.system).mkString(system, state.mem);
|
||||||
attrs.alloc(state.s.outPath).mkString(state.store->printStorePath(i.queryOutPath()));
|
attrs.alloc(state.s.outPath).mkString(state.store->printStorePath(i.queryOutPath()), state.mem);
|
||||||
if (drvPath)
|
if (drvPath)
|
||||||
attrs.alloc(state.s.drvPath).mkString(state.store->printStorePath(*drvPath));
|
attrs.alloc(state.s.drvPath).mkString(state.store->printStorePath(*drvPath), state.mem);
|
||||||
|
|
||||||
// Copy each output meant for installation.
|
// Copy each output meant for installation.
|
||||||
auto outputsList = state.buildList(outputs.size());
|
auto outputsList = state.buildList(outputs.size());
|
||||||
for (const auto & [m, j] : enumerate(outputs)) {
|
for (const auto & [m, j] : enumerate(outputs)) {
|
||||||
(outputsList[m] = state.allocValue())->mkString(j.first);
|
(outputsList[m] = state.allocValue())->mkString(j.first, state.mem);
|
||||||
auto outputAttrs = state.buildBindings(2);
|
auto outputAttrs = state.buildBindings(2);
|
||||||
outputAttrs.alloc(state.s.outPath).mkString(state.store->printStorePath(*j.second));
|
outputAttrs.alloc(state.s.outPath).mkString(state.store->printStorePath(*j.second), state.mem);
|
||||||
attrs.alloc(j.first).mkAttrs(outputAttrs);
|
attrs.alloc(j.first).mkAttrs(outputAttrs);
|
||||||
|
|
||||||
/* This is only necessary when installing store paths, e.g.,
|
/* This is only necessary when installing store paths, e.g.,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue