mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
Merge pull request #14154 from NixOS/fix-segfault-toView
treewide: Remove toView() because it leads to segfaults when compiled…
This commit is contained in:
commit
7ba3ef21a6
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";
|
||||
}
|
||||
|
||||
auto markdown = toView(ss);
|
||||
auto markdown = ss.view();
|
||||
logger->cout(trim(renderMarkdownToTerminal(markdown)));
|
||||
|
||||
} else
|
||||
|
|
|
|||
|
|
@ -591,7 +591,7 @@ std::optional<EvalState::Doc> EvalState::getDoc(Value & v)
|
|||
.name = name,
|
||||
.arity = 0, // FIXME: figure out how deep by syntax only? It's not semantically useful though...
|
||||
.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)) {
|
||||
|
|
@ -1811,7 +1811,7 @@ void ExprAssert::eval(EvalState & state, Env & env, Value & v)
|
|||
if (!state.evalBool(env, cond, pos, "in the condition of the assert statement")) {
|
||||
std::ostringstream out;
|
||||
cond->show(state.symbols, out);
|
||||
auto exprStr = toView(out);
|
||||
auto exprStr = out.view();
|
||||
|
||||
if (auto eq = dynamic_cast<ExprOpEq *>(cond)) {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -2412,7 +2412,7 @@ static void prim_toXML(EvalState & state, const PosIdx pos, Value ** args, Value
|
|||
std::ostringstream out;
|
||||
NixStringContext context;
|
||||
printValueAsXML(state, true, false, *args[0], out, context, pos);
|
||||
v.mkString(toView(out), context);
|
||||
v.mkString(out.view(), context);
|
||||
}
|
||||
|
||||
static RegisterPrimOp primop_toXML({
|
||||
|
|
@ -2520,7 +2520,7 @@ static void prim_toJSON(EvalState & state, const PosIdx pos, Value ** args, Valu
|
|||
std::ostringstream out;
|
||||
NixStringContext context;
|
||||
printValueAsJSON(state, true, *args[0], pos, out, context);
|
||||
v.mkString(toView(out), context);
|
||||
v.mkString(out.view(), context);
|
||||
}
|
||||
|
||||
static RegisterPrimOp primop_toJSON({
|
||||
|
|
|
|||
|
|
@ -139,7 +139,7 @@ static void prim_fromTOML(EvalState & state, const PosIdx pos, Value ** args, Va
|
|||
attrs.alloc("_type").mkStringNoCopy("timestamp");
|
||||
std::ostringstream s;
|
||||
s << t;
|
||||
auto str = toView(s);
|
||||
auto str = s.view();
|
||||
forceNoNullByte(str);
|
||||
attrs.alloc("value").mkString(str);
|
||||
v.mkAttrs(attrs);
|
||||
|
|
|
|||
|
|
@ -461,7 +461,7 @@ private:
|
|||
|
||||
std::ostringstream s;
|
||||
s << state.positions[v.lambda().fun->pos];
|
||||
output << " @ " << filterANSIEscapes(toView(s));
|
||||
output << " @ " << filterANSIEscapes(s.view());
|
||||
}
|
||||
} else if (v.isPrimOp()) {
|
||||
if (v.primOp())
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ public:
|
|||
std::ostringstream oss;
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ struct TunnelLogger : public Logger
|
|||
showErrorInfo(oss, ei, false);
|
||||
|
||||
StringSink buf;
|
||||
buf << STDERR_NEXT << toView(oss);
|
||||
buf << STDERR_NEXT << oss.view();
|
||||
enqueueMsg(buf.s);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,11 +12,6 @@
|
|||
|
||||
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.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ public:
|
|||
std::ostringstream oss;
|
||||
showErrorInfo(oss, ei, loggerSettings.showTrace.get());
|
||||
|
||||
log(ei.level, toView(oss));
|
||||
log(ei.level, oss.view());
|
||||
}
|
||||
|
||||
void startActivity(
|
||||
|
|
|
|||
|
|
@ -8,23 +8,6 @@
|
|||
|
||||
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 StringSet 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";
|
||||
for (auto & dir : dirs)
|
||||
ss << " " << dir << "\n";
|
||||
return checkFail(toView(ss));
|
||||
return checkFail(ss.view());
|
||||
}
|
||||
|
||||
return checkPass("PATH contains only one nix version.");
|
||||
|
|
@ -143,7 +143,7 @@ struct CmdConfigCheck : StoreCommand
|
|||
for (auto & dir : dirs)
|
||||
ss << " " << dir << "\n";
|
||||
ss << "\n";
|
||||
return checkFail(toView(ss));
|
||||
return checkFail(ss.view());
|
||||
}
|
||||
|
||||
return checkPass("All profiles are gcroots.");
|
||||
|
|
@ -162,7 +162,7 @@ struct CmdConfigCheck : StoreCommand
|
|||
<< "sync with the daemon.\n\n"
|
||||
<< "Client protocol: " << formatProtocol(clientProto) << "\n"
|
||||
<< "Store protocol: " << formatProtocol(storeProto) << "\n\n";
|
||||
return checkFail(toView(ss));
|
||||
return checkFail(ss.view());
|
||||
}
|
||||
|
||||
return checkPass("Client protocol matches store protocol.");
|
||||
|
|
|
|||
|
|
@ -285,10 +285,10 @@ static void main_nix_build(int argc, char ** argv)
|
|||
execArgs,
|
||||
interpreter,
|
||||
escapeShellArgAlways(script),
|
||||
toView(joined));
|
||||
joined.view());
|
||||
} else {
|
||||
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 = ({
|
||||
std::ostringstream str;
|
||||
printAmbiguous(manifest, state.symbols, str, nullptr, std::numeric_limits<int>::max());
|
||||
StringSource source{toView(str)};
|
||||
StringSource source{str.view()};
|
||||
state.store->addToStoreFromDump(
|
||||
source,
|
||||
"env-manifest.nix",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue