-
Notifications
You must be signed in to change notification settings - Fork 366
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
Add printf format attribute #1097
Conversation
Re: MSVC errors, the Internet tells me about Microsoft source-code annotation language (SAL), described in this Q/A. Some example implementations from GDAL and Folly. So (somewhat tested) something like: #ifdef _MSC_VER
#include <sal.h>
typedef void (*GEOSMessageHandler)(_Printf_format_string_ const char *fmt, ...);
#else
typedef void (*GEOSMessageHandler)(const char *fmt, ...) __attribute__ (( format(printf, 1, 0) ));
#endif Should |
@mwtoews good idea about adding the -WSuggest-attribute=format in CMakeLists.txt will see about doing that. For the record, the downstream suggestion/failures can be seen here: |
For the record, PostGIS uses this:
|
CI builds with warnings-as-errors, so now you need to actually follow up all the warnings :) |
as suggested by -Wsuggest-attribute=format
For now I've removed the -Wsuggest-attribute=format from the Makefile as I hadn't understood which line enables it only for the compiler supporting the attribute syntax. |
So, MingW suggests the gnu_printf attribute but I don't know if it supports passing attribute ../capi/geos_ts_c.cpp:301:31: error: function 'void GEOSContextHandle_HS::NOTICE_MESSAGE(const char*, ...)' might be a candidate for 'gnu_printf' format attribute [-Werror=suggest-attribute=format] |
The Windows / mingw-w64 keeps suggesting the attribute even if we're now defining it. I surrender. I don't even know why I'm wasting my time trying to make window builds happy |
@strk should I take a look at the msvc/mingw aspects? I can plop some commits here if needed. |
Yes please. If you can push directly go ahead, otherwise send a PR against this new branch. |
The mingw issue is a mystery (why it want's to add attributes to built-ins), and I'm able to replicate this locally. This oddity is side-stepped to ignore the warning within The MSVC printf format stuff is handled differently, so it is probably easiest to put some portability macros into include/geos/export.h (I'd rather not create a separate port.h for this minor thing). MSVC's Additional review / commits welcome! |
include/geos/export.h is not included in geos_c.h so they should be replicated there for clients |
Looks fine to me: Line 86 in effd6cb
And I've just checked that these files are installed to the prefix, e.g. |
Oh then it's perfect for me, I'll just go ahead and merge this. It probably needs a NEWS entry too at some point |
This change actually added warnings for me...
|
Considering changing the macro to this:
|
and why not simply just not defining GEOSMessageHandler in lwgeom_geos.h, since it is available in geos_c.h ... ? |
@strk can explain I guess he wants that extra attribute when he's compiling against older GEOS versions that don't have the attribute in the library include typedef. (Looks dodgy to me too.) |
Because until GEOS 3.13 the typedef of GEOSMessageHandler was not passing the printf attribute thus resulting in a warning about "why not add an attribute printf ?" Where did you get 201112L from ? |
ChatGPT 🫢 |
Well, that doesn't work because in CI we have C declaring itself to be 1999 and yet still also complaining about the attribute warning. Why don't we just turn off that warning for all GEOS < 3.13? Fixing GEOS warnings in PostGIS by redefining GEOS types feels off to me.
Something like this in the configure.ac? So far works for me quieting builds on the GH CI.
|
May I suggest to move this discussion to the PostGIS issue tracker instead ?
|
Fixes warnings on downstream projects with -Wsuggest-attribute=format