-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
libusb: add stdio.h header #1327
base: master
Are you sure you want to change the base?
Conversation
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'd say that relying on implicit behavior in general is one of the sources of eternal evil.
Out of curiosity: which compiler did catch this (or what was special about the build environment otherwise)? |
MinGW specifically |
Just wondering which version of MinGW? Take note we do not really support MinGW.org 32bit compiler (but minor PR will be reviewed and accepted if appropriate). We recommend MSYS2 distribution of mingw32/mingw64 (and accept PRs to improve MSYS2 environment like ucrt64, clang32, clang64 and clangarm64). https://www.msys2.org/docs/environments/
|
Ubuntu MinGW 64 cross compile. |
I see. Then this PR is good to me. |
I also always cross-compile on Ubuntu (20.04, gcc 9.3) or Debian (gcc 12.2). But I don't see the warning. Do you add extra flags? Build log extract? |
I'm pretty sure this is compiler-version specific. I've seen it multiple times when after a compiler upgrade some of the standard headers are no longer implicitly inlcluded - and that is perfectly in align with The Standard. |
And if it is needed in libusb/libusbi.h if ENABLE_LOGGING is not set? I need to understand this better before I can approve the patch. |
Caught me. So the real motivation for this change is to try to fix the following warnings:
The issue is that MinGW has a macro defined in stdio.h which switches between printf and gnu_printf. Example of how a different project handles this: https://github.com/Exiv2/exiv2/blob/main/src/image_int.hpp#L15 This PR was meant as a first step to fixing that. |
So if we do like exiv and conditionally use __MINGW_PRINTF_FORMAT the warnings go away? Which version of gcc are you using? Do you use non-default configuration options or flags? |
and yes. currently the printf attribute is set with configure.ac, which would have to be modified. |
added configure.ac change thanks to ChatGPT. I don't really speak Autotools. |
I have no idea why there are 4 different build systems here. Sounds horrible to maintain. |
libusb/libusbi.h
Outdated
@@ -30,6 +30,7 @@ | |||
#include <inttypes.h> | |||
#include <stdarg.h> | |||
#include <stddef.h> | |||
#include <stdio.h> |
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.
with the chanes to configure.ac
do we still need these?
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.
any comments?
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.
yes this is still needed.
Because of the unclear copyright situation I am not comfortable with merging stuff coming straight out of ChatGPT or code copilot etc (as long as I know it, which I of course cannot unless people are frank about it) into a GPL project. To "clean room" design this (I haven't looked at the suggested change), can someone explain what needs to be done in configure.ac and I'll try to implement it and compare afterwards? Or someone who did look at it confirm it is 100% trivial and copyright safe. |
It’s not a direct copy. It’s changed from the original output, as most things have to be with ChatGPT. edit: anyway, check if __MINGW_PRINTF_FORMAT is defined and if it is, use it for PRINTF_FORMAT. |
Such a test could be something along:
But I am not sure this is the correct way to deal with the issue, even if it would work in your case. The __MINGW_PRINTF_FORMAT macro is something internal to MinGW and not something we should have to deal with. If this is a needed workaround for a known bug in MinGW, it could be considered, but then we have to know more about this. What is needed to reproduce your problem? |
This macro is needed as libusb implements its own formatting functions based on printf. I posted the compilation warnings earlier. |
anything else missing here? |
Using __MINGW_PRINTF_FORMAT, which is what the headers use. add stdio.h header to get it defined. Needed for printf functions. Not always included implicitly. Signed-off-by: Rosen Penev <rosenp@gmail.com>
I think there is not enough explanation here. Please don't be afraid of being verbose and adding context, background and examples. I think you are using some special flags, but you have not mentioned which and why. My remarks above remain. E.g. stdio.h is conditionally included in libusbi.h Also, can this be related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95130 or https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-gcc/0300-override-builtin-printf-format.patch ? |
There are no special flags being passed. Context is that if -Wformat is passed, these warnings show up. Those links seem unrelated. |
Not comfortable including any ML-generated code in this project. The original source is unknown and it is possible it does not comply with our licensing or libusb may not comply with it. ChatGPT is less AI than it is a huge copyright infringement tool :p. That aside, why are we using m4 to define this instead of just defining it in the header where it is used? That removes the need for any m4 changes. |
Opened #1352 to remove the unnecessary m4. Should make it easier to write your patch. |
Needed for printf functions. Not always included implicitly.