Repository navigation
Use wcwidth for u_char_width - #1198
Conversation
|
Nevermind about the first concern w/windows, I somehow got confused into thinking that cmus supported windows, and AFAICT, it does not. This might mean that the vendored implementation can be removed entirely, as windows is the only modern platform I'm aware that doesn't define |
gavtroy
left a comment
There was a problem hiding this comment.
The original u_char_width implementation would always return width of 1 for non-utf8 locales, even if it was a control character. I'm not sure if that was done for a specific reason, or if it was an oversight that never lead to issues in practice.
An oversight in 7e4ec7a, and yes I don't imagine control characters are encountered often.
windows
I'm not sure to what level it's supported, but cmus can be compiled with cygwin. I don't have cygwin to test how it handles wchar_t but google suggests it's probably 2 bytes / UTF-16.
| if (w >= 0) | ||
| return w; | ||
| else | ||
| return 2; |
There was a problem hiding this comment.
Assuming it's for the likes of U+FFFE "�" would 1 not make more sense? (Assuming we ever get here.)
There was a problem hiding this comment.
That would be my assumption, but my reading of the original source for this function lead me to believe it returned 2 for unknown characters, for reasons that aren't really clear to me:
/* ? */
if (u >= 0x30000U && u <= 0x3fffdU)
goto wide;
Maybe the intent was that overallocating space would be preferred to underallocating? I don't have a strong opinion either way, as I believe this should only be reached for private use characters, which is probably better set to a default width of 1, since they are unlikely to show up in song metadata, and if the user wants to use them in their status bar, they can manually pad it if need be.
There was a problem hiding this comment.
It's worth noting that it's not incredibly uncommon for wcwidth to be overriden with LD_PRELOAD to handle icon widths as well, for example https://github.com/powerman/wcwidth-icons.
I will change the default width to 1 unless there was a specific reason for the old behavior.
There was a problem hiding this comment.
I would have taken /* ? */ to mean "I don't know what to call this range but it seems to be filled with wide characters".
At least U+FFFE does hit this case for me and displays as only 1 column wide, so I'd go with 1.
It's worth noting that it's not incredibly uncommon for wcwidth to be overriden with LD_PRELOAD to handle icon widths as well
Not something I would have thought of, but I suppose it shouldn't matter to us? If anything this change might let it work properly.
The current code in this PR should work on windows because it will not use |
I.e. fix u_copy_chars() / u_skip_chars() to continue copying zero-width chars (combining marks) when no display width is left.
|
Furthermore, attaching that song title to another mp3 with audio and attempting to play it causes cmus to segfault. |
|
Nevermind, I believe this is entirely unrelated to the changes I've made based on the backtrace and likely has to do something with creating two songs of the exact same name and of different file formats. The segfault is actually caused when I try to open the metadata-only ogg version while there is a audio version of the same title under a different artist. |
Although this issue doesn't exist on the current release, it's already broken on master since a strcpy somewhere was replaced by a more intelligent function. This is actually fixed by #1151 although it's not clear why from the description (and I don't remember either, but this is the exact bug that prompted the fix 🙂).
It could be a side effect of a rare allocation issue fixed by #1152... or more likely it could be a separate issue as you're thinking. But it's probably worth cherry-picking that refactoring/fix before you dig too deep. |
|
I've been using this branch for close to two weeks (with CJK, cyrllic, emojis, and zalgotext) and have been unable to reproduce the crash after cherry picking that fix, I believe this should be ready for review for merging. |
|
Thanks a lot, finally merged! |
https://build.opensuse.org/request/show/1176840 by user mia + anag+factory - Update to 2.11.0 * Add support for .nomedia file gh#cmus/cmus#1190 * Fix a typo in an error message gh#cmus/cmus#1206 * Take opus output gain into account when checking replaygain_limit peak gh#cmus/cmus#1201 * #1219: Update Unofficial IRC channel gh#cmus/cmus#1220 * Recognize artist/album sort keys from ffmpeg plugin gh#cmus/cmus#1165 * Fix missing combining marks on last character in a field gh#cmus/cmus#1151 * Use wcwidth for u_char_width gh#cmus/cmus#1198 * Fix under-allocation when many zero-width characters are present gh#cmus/cmus#1152 * Draw title and command lines on first update gh#cmus/cmus#1257 * Switch to -latest os in build workflow gh#cmus/cmus#1265 * ip/mp4: Use MP4FindTrackId() rather than assuming it's



Resolves #1196.
Changes:
u_char_widthwas removed because it produced results inconsistent with wcwidth for many codepoints.u_char_widthuseswcwidthwcwidthhas been added from the musl libc, and will be used in situations wheresizeof(wchar_t) != sizeof(uchar)orwcwidthdoes not exist.Things that need to be addressed before this is ready to merge:
Test that the configure script and musl(see below)wcwidthwork on windows.u_char_widthimplementation would always return width of 1 for non-utf8 locales, even if it was a control character. I'm not sure if that was done for a specific reason, or if it was an oversight that never lead to issues in practice. The new implementation handle control characters even for non-utf8 locales, but this change might need to be reverted.