Closed pmalek closed 1 year ago
I see similar issues install clipboard via brew in Fish in iTerm 2:
But if I download the prebuilt binary from releases, it looks like I think it should:
Maybe it's an issue with how the brew package is configured? I hope it's fixed because if I manually install this I won't remember to update it :(
Same here
looks like an issue with the brew package, as I just tested the compiled version on my Mac Mini at MacStadium and it looks just fine, but I don't believe this issue could have been caused in the first place?
here is the code that deals with the colors:
std::string formatColors(const std::string_view& str, bool colorful) {
std::string temp(str);
for (size_t i = 0; (i = temp.find('[', i)) != std::string::npos; i++) {
auto j = temp.find(']', i);
if (j == std::string::npos) break;
const std::string_view result = temp.substr(i, j - i + 1);
for (const auto& key : colors) {
if (key.first == result) {
temp.replace(i, result.length(), colorful ? key.second : "");
if (!colorful) i--; // because i may be at the start of the next color
break;
}
}
}
return temp;
}
judging by how this only happens on Homebrew, this looks like it's a compiler bug (which would be sad).
@pmalek @mccartykim are you able to see which compiler compiled the Homebrew binary with objdump -s $(which cb)
?
You may also want to open an issue here: https://github.com/Homebrew/homebrew-core/issues
Check this out: https://github.com/Homebrew/homebrew-core/issues/136551
We applied a workaround at Homebrew which should fix this issue. You can do brew update && brew upgrade clipboard
to pick up the fix.
However, it looks like this was caused by a bug in either of Clipboard or in Clang, so we should try to fix it if it's the former or report it upstream if it's the latter.
Looks good now! Thanks!
I just went through some of my compile logs, and it turns out that there was a warning from Clang that said something about a deleted memory location once some string construction is done.
What this meant was, the reason this issue happened in the first place is because there is a Clang optimization that only happens with Os on ARM, where the memory of the found replacement result became nothing, so no colors ever got replaced. The reason I couldn't catch this is because CB switched to CMake's Release mode (O3) for all official builds, so it never happened in testing on my Mac Mini.
Last night, I made an optimization to this function that just so happened to fix the underlying issue once and for all by properly utilizing memory. And today, I made the whole thing 2x faster by making a manual comparison function.
This means that the specific O2 workaround can be removed without breaking anything. Unfortunately, in my testing, it turns out that with this new manual comparison function, Os (the default) is SLOWER than even O1 because of tons of function calls that aren't inlined. A similar thing is also present, at a much larger scale, elsewhere in the project. Therefore, the new O2 option is needed to keep performance high.
Describe the bug
CLI output on Mac in zsh seems broken
To Reproduce
Steps to reproduce the behavior:
brew install clipboard
cb
Expected behavior
CLI prints clearly and can be understood without any problems.
Screenshots
Version