mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 03:56:01 +01:00
Merge pull request #14179 from NixOS/backport-14154-to-2.31-maintenance
[Backport 2.31-maintenance] treewide: Remove toView() because it leads to segfaults when compiled…
This commit is contained in:
commit
66f6ad1292
13 changed files with 16 additions and 38 deletions
|
|
@ -669,7 +669,7 @@ ProcessLineResult NixRepl::processLine(std::string line)
|
||||||
ss << "No documentation found.\n\n";
|
ss << "No documentation found.\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
auto markdown = toView(ss);
|
auto markdown = ss.view();
|
||||||
logger->cout(trim(renderMarkdownToTerminal(markdown)));
|
logger->cout(trim(renderMarkdownToTerminal(markdown)));
|
||||||
|
|
||||||
} else
|
} else
|
||||||
|
|
|
||||||
|
|
@ -649,7 +649,7 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
|
||||||
.name = name,
|
.name = name,
|
||||||
.arity = 0, // FIXME: figure out how deep by syntax only? It's not semantically useful though...
|
.arity = 0, // FIXME: figure out how deep by syntax only? It's not semantically useful though...
|
||||||
.args = {},
|
.args = {},
|
||||||
.doc = makeImmutableString(toView(s)), // NOTE: memory leak when compiled without GC
|
.doc = makeImmutableString(s.view()), // NOTE: memory leak when compiled without GC
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (isFunctor(v)) {
|
if (isFunctor(v)) {
|
||||||
|
|
@ -1845,7 +1845,7 @@ void ExprAssert::eval(EvalState & state, Env & env, Value & v)
|
||||||
if (!state.evalBool(env, cond, pos, "in the condition of the assert statement")) {
|
if (!state.evalBool(env, cond, pos, "in the condition of the assert statement")) {
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
cond->show(state.symbols, out);
|
cond->show(state.symbols, out);
|
||||||
auto exprStr = toView(out);
|
auto exprStr = out.view();
|
||||||
|
|
||||||
if (auto eq = dynamic_cast<ExprOpEq *>(cond)) {
|
if (auto eq = dynamic_cast<ExprOpEq *>(cond)) {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -2350,7 +2350,7 @@ static void prim_toXML(EvalState & state, const PosIdx pos, Value ** args, Value
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
NixStringContext context;
|
NixStringContext context;
|
||||||
printValueAsXML(state, true, false, *args[0], out, context, pos);
|
printValueAsXML(state, true, false, *args[0], out, context, pos);
|
||||||
v.mkString(toView(out), context);
|
v.mkString(out.view(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_toXML({
|
static RegisterPrimOp primop_toXML({
|
||||||
|
|
@ -2458,7 +2458,7 @@ static void prim_toJSON(EvalState & state, const PosIdx pos, Value ** args, Valu
|
||||||
std::ostringstream out;
|
std::ostringstream out;
|
||||||
NixStringContext context;
|
NixStringContext context;
|
||||||
printValueAsJSON(state, true, *args[0], pos, out, context);
|
printValueAsJSON(state, true, *args[0], pos, out, context);
|
||||||
v.mkString(toView(out), context);
|
v.mkString(out.view(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_toJSON({
|
static RegisterPrimOp primop_toJSON({
|
||||||
|
|
|
||||||
|
|
@ -139,7 +139,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
||||||
attrs.alloc("_type").mkString("timestamp");
|
attrs.alloc("_type").mkString("timestamp");
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << t;
|
s << t;
|
||||||
auto str = toView(s);
|
auto str = s.view();
|
||||||
forceNoNullByte(str);
|
forceNoNullByte(str);
|
||||||
attrs.alloc("value").mkString(str);
|
attrs.alloc("value").mkString(str);
|
||||||
v.mkAttrs(attrs);
|
v.mkAttrs(attrs);
|
||||||
|
|
|
||||||
|
|
@ -460,7 +460,7 @@ private:
|
||||||
|
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
s << state.positions[v.lambda().fun->pos];
|
s << state.positions[v.lambda().fun->pos];
|
||||||
output << " @ " << filterANSIEscapes(toView(s));
|
output << " @ " << filterANSIEscapes(s.view());
|
||||||
}
|
}
|
||||||
} else if (v.isPrimOp()) {
|
} else if (v.isPrimOp()) {
|
||||||
if (v.primOp())
|
if (v.primOp())
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ public:
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
||||||
|
|
||||||
log(*state, ei.level, toView(oss));
|
log(*state, ei.level, oss.view());
|
||||||
}
|
}
|
||||||
|
|
||||||
void log(State & state, Verbosity lvl, std::string_view s)
|
void log(State & state, Verbosity lvl, std::string_view s)
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ struct TunnelLogger : public Logger
|
||||||
showErrorInfo(oss, ei, false);
|
showErrorInfo(oss, ei, false);
|
||||||
|
|
||||||
StringSink buf;
|
StringSink buf;
|
||||||
buf << STDERR_NEXT << toView(oss);
|
buf << STDERR_NEXT << oss.view();
|
||||||
enqueueMsg(buf.s);
|
enqueueMsg(buf.s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,6 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
/*
|
|
||||||
* workaround for unavailable view() method (C++20) of std::ostringstream under MacOS with clang-16
|
|
||||||
*/
|
|
||||||
std::string_view toView(const std::ostringstream & os);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* String tokenizer.
|
* String tokenizer.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ public:
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
||||||
|
|
||||||
log(ei.level, toView(oss));
|
log(ei.level, oss.view());
|
||||||
}
|
}
|
||||||
|
|
||||||
void startActivity(
|
void startActivity(
|
||||||
|
|
|
||||||
|
|
@ -8,23 +8,6 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
struct view_stringbuf : public std::stringbuf
|
|
||||||
{
|
|
||||||
inline std::string_view toView()
|
|
||||||
{
|
|
||||||
auto begin = pbase();
|
|
||||||
return {begin, begin + pubseekoff(0, std::ios_base::cur, std::ios_base::out)};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
__attribute__((no_sanitize("undefined"))) std::string_view toView(const std::ostringstream & os)
|
|
||||||
{
|
|
||||||
/* Downcasting like this is very much undefined behavior, so we disable
|
|
||||||
UBSAN for this function. */
|
|
||||||
auto buf = static_cast<view_stringbuf *>(os.rdbuf());
|
|
||||||
return buf->toView();
|
|
||||||
}
|
|
||||||
|
|
||||||
template std::list<std::string> tokenizeString(std::string_view s, std::string_view separators);
|
template std::list<std::string> tokenizeString(std::string_view s, std::string_view separators);
|
||||||
template StringSet tokenizeString(std::string_view s, std::string_view separators);
|
template StringSet tokenizeString(std::string_view s, std::string_view separators);
|
||||||
template std::vector<std::string> tokenizeString(std::string_view s, std::string_view separators);
|
template std::vector<std::string> tokenizeString(std::string_view s, std::string_view separators);
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ struct CmdConfigCheck : StoreCommand
|
||||||
ss << "Multiple versions of nix found in PATH:\n";
|
ss << "Multiple versions of nix found in PATH:\n";
|
||||||
for (auto & dir : dirs)
|
for (auto & dir : dirs)
|
||||||
ss << " " << dir << "\n";
|
ss << " " << dir << "\n";
|
||||||
return checkFail(toView(ss));
|
return checkFail(ss.view());
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkPass("PATH contains only one nix version.");
|
return checkPass("PATH contains only one nix version.");
|
||||||
|
|
@ -143,7 +143,7 @@ struct CmdConfigCheck : StoreCommand
|
||||||
for (auto & dir : dirs)
|
for (auto & dir : dirs)
|
||||||
ss << " " << dir << "\n";
|
ss << " " << dir << "\n";
|
||||||
ss << "\n";
|
ss << "\n";
|
||||||
return checkFail(toView(ss));
|
return checkFail(ss.view());
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkPass("All profiles are gcroots.");
|
return checkPass("All profiles are gcroots.");
|
||||||
|
|
@ -162,7 +162,7 @@ struct CmdConfigCheck : StoreCommand
|
||||||
<< "sync with the daemon.\n\n"
|
<< "sync with the daemon.\n\n"
|
||||||
<< "Client protocol: " << formatProtocol(clientProto) << "\n"
|
<< "Client protocol: " << formatProtocol(clientProto) << "\n"
|
||||||
<< "Store protocol: " << formatProtocol(storeProto) << "\n\n";
|
<< "Store protocol: " << formatProtocol(storeProto) << "\n\n";
|
||||||
return checkFail(toView(ss));
|
return checkFail(ss.view());
|
||||||
}
|
}
|
||||||
|
|
||||||
return checkPass("Client protocol matches store protocol.");
|
return checkPass("Client protocol matches store protocol.");
|
||||||
|
|
|
||||||
|
|
@ -285,10 +285,10 @@ static void main_nix_build(int argc, char ** argv)
|
||||||
execArgs,
|
execArgs,
|
||||||
interpreter,
|
interpreter,
|
||||||
escapeShellArgAlways(script),
|
escapeShellArgAlways(script),
|
||||||
toView(joined));
|
joined.view());
|
||||||
} else {
|
} else {
|
||||||
envCommand =
|
envCommand =
|
||||||
fmt("exec %1% %2% %3% %4%", execArgs, interpreter, escapeShellArgAlways(script), toView(joined));
|
fmt("exec %1% %2% %3% %4%", execArgs, interpreter, escapeShellArgAlways(script), joined.view());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ bool createUserEnv(
|
||||||
auto manifestFile = ({
|
auto manifestFile = ({
|
||||||
std::ostringstream str;
|
std::ostringstream str;
|
||||||
printAmbiguous(manifest, state.symbols, str, nullptr, std::numeric_limits<int>::max());
|
printAmbiguous(manifest, state.symbols, str, nullptr, std::numeric_limits<int>::max());
|
||||||
StringSource source{toView(str)};
|
StringSource source{str.view()};
|
||||||
state.store->addToStoreFromDump(
|
state.store->addToStoreFromDump(
|
||||||
source,
|
source,
|
||||||
"env-manifest.nix",
|
"env-manifest.nix",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue