-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No scratch
for absPath
?
#9775
base: master
Are you sure you want to change the base?
No scratch
for absPath
?
#9775
Conversation
fe178aa
to
966b3e3
Compare
561ba93
to
6caad76
Compare
I found a way to avoid the `scratch` variable I just introduced in NixOS#9759, but I am not sure whether this makes this code easier or harder to read 😅.
6caad76
to
2512c4a
Compare
@tfc I am curious whether you think this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like creating one central function std::string getCwd
that hides all the legacy mem management issues would be nicer.
return canonPath(path, resolveSymlinks); | ||
"/", | ||
path)), | ||
resolveSymlinks); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see the elegance in point-free programming in general, but the if-branched ersion that we had before was more readable.
{ | ||
std::string scratch; | ||
return std::unique_ptr<char, FreeDeleter> { getcwd(NULL, 0) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this called so often that it must be really fast and small, so that it is worth spilling this memory management over the code that wants the cwd string?
If no, then please create a function like std::string getCwd()
that copies the content and then frees the original string. this way we don't need anyone to know about custom deleters for this purpose.
free(buf); | ||
getcwd(buf, sizeof(buf)) | ||
? buf | ||
: throw SysError("cannot get cwd"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't we encapsulate these two branches and the whole legacy mem management issue simply into a function std::string getCwd()
that does it all automagically (with the performance-question yes/no from earler in mind)?
this seems like an unnecessary dance for a function whose concern is making paths absolute.
@tfc and I discussed this. Yes I'll stop being a weenie and do @roberth and I further discussed @tfc's caching idea, and @roberth had the code idea that we can wrap |
Motivation
I found a way to avoid the
scratch
variable I just introduced in #9759, but I am not sure whether this makes this code easier or harder to read 😅.Context
See conversation in #9759
Priorities and Process
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.