Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcmd/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/primops/fromTOML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/print.cc
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ class Printer

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())
Expand Down
2 changes: 1 addition & 1 deletion src/libmain/progress-bar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class ProgressBar : public Logger
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)
Expand Down
2 changes: 1 addition & 1 deletion src/libstore/daemon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
5 changes: 0 additions & 5 deletions src/libutil/include/nix/util/strings.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/libutil/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class SimpleLogger : public Logger
std::ostringstream oss;
showErrorInfo(oss, ei, loggerSettings.showTrace.get());

log(ei.level, toView(oss));
log(ei.level, oss.view());
}

void startActivity(
Expand Down
17 changes: 0 additions & 17 deletions src/libutil/strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/nix/config-check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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.");
Expand All @@ -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.");
Expand Down
4 changes: 2 additions & 2 deletions src/nix/nix-build/nix-build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/nix/nix-env/user-env.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading