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
libcaption: Optimize branch conditons #9184
Conversation
8efc166
to
d5b055a
Compare
The first word for each commit should be capitalized. |
Aren't there other things that also fail on RISC-V right now? e.g. because our SIMDe library is somewhat out of date. This also fails on macOS right now. |
I don't think this is the right approach (and it's not even exhaustive as the compilation failure on macOS demonstrates). My hunch is that the code specifically checks for the situation that So making this a |
I don't think it should be accepted because the code comparing the signed byte with 0 might be checking the most significant bit of the byte. If it's unsigned, the test is meaningless. We should either ensure the byte is interpreted as signed or completely eliminate checking the most significant byte by the sign. |
obs-studio/deps/libcaption/src/utf8.c Lines 53 to 56 in 38d1093
In this code, it looks the expression |
|
I found it not easy because it seems there isn't a unified way to do that. Different compiler need different |
It’s not a fix because it forces a sign mismatch on other platforms which we guard against on macOS. I also have to admit I don’t understand what the issue is - the check may be superfluous on platforms where it’s always an unsigned type, but it’s also not malicious or will lead to false positives as far as I can see. The proper fix would probably be to use |
What I mean is to use
I think the point of this warning is: if the condition clause isn't explicitly eliminated, the one who wrote the code must be expecting some runtime check. If it's definitive, the code won't work as the programmer expected. You should either eliminate it explicitly if the condition is exactly what you expect, or change it if it's not. |
obs-studio_29.1.3 currently fails to build on these archs, because on this archs gcc-13.2.0 uses
(the architecture names are the ones used in Debian) you probably might think that |
also note, that in the same function (a few lines below the erroneous code), there's already some type-casting to ensure the proper-signedness obs-studio/deps/libcaption/src/utf8.c Line 59 in 211a812
so 👍 for #9184 (comment) |
Thank you for your information and I'll push the fix soon, then. |
The optimization silences the warning about type limits on platforms with `char` type as `unsigned char`. The original condition is semantically identical to the optimized one because the signed-to-unsigned cast is well-defined in C standard.
utf8_char_t
is signed
Any progress there? |
The recent version of the change seems innocuous enough, I don't really have any major concerns about that. It should be noted that we do not support any other platforms apart from the ones we provide our own builds for (this includes RISC-V or Raspberry Pi). In general patches necessary to build on any unsupported platform need to be applied locally. @RytoEX any objections? |
As you said, it seems innocuous enough. Mostly, I don't want to get into the slippery slope of having to be concerned about patches for other platforms that we do not officially support, as you also mentioned. |
I think the change in this particular PR still can be considered a better practice, according to C standard documents. Generally it's better to comply with the standards if you're oblivious of the unsupported platform things, isn't it? |
The comment was not aimed at this particular fix but that merging this requires us to make an exception for two policies at the same time and that's the slippery slope mentioned. |
Are these policies documented somewhere? My personal experience with this project is that fixes for people's problems are deferred to obscure policies and private discussions of the team and then left hanging in a limbo. This is not exactly satisfying. |
For supported operating systems or platforms, we call out "unsupported builds" here: For architectures, generally, if we don't provide a binary for it, we don't support it. OBS may or may not work on any other architecture, your mileage may vary. We don't have an official Knowledge Base or Wiki page stating this. We could make one, though the low volume/frequency of requests about supported architectures makes me wonder if it's truly necessary to maintain one.
Some of us who regularly work on the project have off-thread communications to clarify our understanding and collect our thoughts before responding on GitHub to make sure that we're giving an accurate response. In this specific case, @PatTheMav and I briefly discussed this PR off-thread, and I replied here with the summary of my thoughts from that conversation. That is mostly to reduce the noise and round-trip time of he and I talking at each other on this PR. In this specific instance, most of my hesitance is due to the fact that libcaption is a vendored third-party dependency. Normally, I would suggest that fixes be sent to the source repo, and then we can update the dependency. However, libcaption is archived and no longer being updated, so we're effectively responsible for any new changes. This change itself as it is now is fine (it used to be more involved), and I didn't say that I opposed merging this change. What I don't want to signal, however, is merging this PR being an indicator that we suddenly provide first-party RISC-V support. We don't have the time, hardware, or capacity to ensure that everything builds and runs correctly there. That's all I wanted to clarify. This PR is actually likely to be merged because it is simple, concise, and fixes undefined behavior. That it happens to fix a bug with RISC-V is coincidental to those concerns. I just wanted to publicly document my thoughts regarding the slippery slope first or I would likely forget to do so. |
fair enough. and thanks for the long reply.
exactly. and i'm guilty as charged for bringing in other architectures that you do "not support" (armel, armhf, ppc64el, s390x). but i really think it is always good to listen to unsupported architectures: i don't think anybody is going to run obs-studio on BigEndian machines anytime soon, but I find that being able to compile (and ideally run tests) on such exotic architectures is often a good way to spot implicit (and wrong) assumptions buried in the code. as such, i think fixes coming from such attempts should be embraced, even if you do not plan to support any additional architectures/OSs/... in the foreseeable future. |
Description
Optimize the condition expression of
c[0] >= 0 && c[0] <= ' '
to avoid warnings on platforms wherechar
is equivalent tounsigned char
.Motivation and Context
I'm packaging OBS Studio for RISC-V architecture and it fails with an error message:
According to C reference:
As we define
utf8_char_t
aschar
, which is equivalent tounsigned char
in some platforms,c[0] >= 0
will always be true and a warning will be raised, leading to a build failure.How Has This Been Tested?
I have tested it on HiFive Unmatched and qemu-user-riscv64, the code compiles correctly.
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist: