Skip to content
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

Quiet some warnings #2695

Merged
merged 2 commits into from
Jul 30, 2023
Merged

Quiet some warnings #2695

merged 2 commits into from
Jul 30, 2023

Conversation

nicowilliams
Copy link
Contributor

No description provided.

@nicowilliams nicowilliams marked this pull request as ready for review July 10, 2023 23:29
@@ -1723,6 +1724,7 @@ gethex(struct dtoa_context* C, CONST char **sp, U *rvp, int rounding, int sign)
case '-':
esign = 1;
/* no break */
JQ_FALLTHROUGH;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need no break comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, this isn't our code, and the no break comments never had any effect as far as compilers and linters go, and I think leaving them there as a bread-crumb on what to look for in history might be useful. Though, yeah, they serve no purpose now and you can still find them in the history, so I could drop those. Your call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, maybe we shouldn't edit jv_dtoa.c for any purpose.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is definitely an option, though it's been edited some -- first of all by @stedolan.

Copy link
Contributor

@itchyny itchyny Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find the original base code of dtoa.c when included into the repository, but I think the original diff was only jvp_ prefix and MALLOC/FREE definitions. The latest version is available at https://www.netlib.org/fp/ so I downloaded dtoa.c and g_fmt.c to compare against jv_dtoa.c, and there seems to be some bug fixes. I don't confirm jq will be affected by the fixes, but hopefully we could follow the upstream. Since it's just compiler warnings, it's better to avoid edits, report to the original author (maybe along with 6151f20), and then include the updates.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember finding the original and seeing that @stedolan made some modifications to the default representation of numbers. But it's been years since I looked.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/jv.h Outdated
# define JQ_FALLTHROUGH DISPATCH_FALLTHROUGH
#else
# if defined(__GNUC__)
# if __GNUC__ >= 7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just check __has_attribute(__fallthrough__)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I'll update this PR tomorrow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nicowilliams ping :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#if defined(DISPATCH_FALLTHROUGH)
# define JQ_FALLTHROUGH DISPATCH_FALLTHROUGH
#else
# if defined __has_attribute
#  if __has_attribute(__fallthrough__)
#   define JQ_FALLTHROUGH __attribute__((fallthrough))
#  endif
# else
#  define JQ_FALLTHROUGH do {} while (0) /* fallthrough */
# endif
#endif

look ok?

src/jv.h Outdated
# define JQ_FALLTHROUGH do {} while (0) /* fallthrough */
# endif
# else
# define JQ_FALLTHROUGH do {} while (0) /* fallthrough */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found fallthrough macro in Linux code and the code using it looks nice, but should we use JQ_ prefix to avoid conflict?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@itchyny well, we need one that is portable to not-Linux, including BSDs, OS X, and Windows, as well as different compilers. I did struggle with: what header file to put this in, and what to call this macro.

It's very annoying that there isn't a universally available way to do this...

@emanuele6
Copy link
Member

emanuele6 commented Jul 16, 2023

This seems ok, but this PR doesn't silence all warnings:

src/util.c:3: warning: "_GNU_SOURCE" redefined                                       
    3 | #define _GNU_SOURCE               
      |                                                                              
<command-line>: note: this is the location of the previous definition

Since we are using AC_USE_SYSTEM_EXTENSIONS in configure.ac, on GNU/Linux, -D_GNU_SOURCE=1 will be passed to the compiler.

I think either wrapping that #define in #ifndef _GNU_SOURCE or just removing it should fix that.

@nicowilliams nicowilliams changed the title Quiet warnings Quiet some warnings Jul 16, 2023
@nicowilliams
Copy link
Contributor Author

This seems ok, but this PR doesn't silence all warnings:

I have updated the caption! :)

@itchyny
Copy link
Contributor

itchyny commented Jul 27, 2023

I thought __has_attribute(__fallthrough__) is the correct way of checking the availability of attributes, but after some observations in code search, I noticed some complicated situations of clang. Some implementations suggests me that on Clang < 10, __has_attribute(fallthrough) produces 1 even if it does not support C-style (but only supports C++-style) fallthrough attribute. Clang 10 is released on Mar 24, 2020, so we may need to support older versions. Since __has_attribute check is not reliable, I end up concluded that checking the version is the stable way.

#if (defined(__GNUC__) && __GNUC__ >= 7 && !defined(__clang__) || \
    defined(__clang__) && __clang_major__ >= 10)
# define JQ_FALLTHROUGH __attribute__((fallthrough))
#else
# define JQ_FALLTHROUGH
#endif

What do you think?

src/jv.h Outdated
@@ -5,6 +5,18 @@
#include <stdint.h>
#include <stdio.h>

#if defined(DISPATCH_FALLTHROUGH)
# define JQ_FALLTHROUGH DISPATCH_FALLTHROUGH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came from libdispatch? Are you sure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this from Heimdal :) The link is helpful. I'll update this.

@emanuele6 emanuele6 added this to the 1.7 release milestone Jul 28, 2023
@nicowilliams
Copy link
Contributor Author

nicowilliams commented Jul 29, 2023

[...] I noticed some complicated situations of clang.

Bummer. Your link shows use of JE_COMPILABLE to deal with this -- that strikes me as the best option, and I'll integrate that now. I'll integrate a version of the code you proposed.

BTW, thank you for that research! I should have done that myself.

@@ -2367,10 +2372,12 @@ jvp_strtod
case '-':
sign = 1;
/* no break */
JQ_FALLTHROUGH;
case '+':
if (*++s)
goto break2;
/* no break */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant comment

@@ -3699,6 +3707,7 @@ jvp_dtoa
case 2:
leftright = 0;
/* no break */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant comment

@@ -3707,6 +3716,7 @@ jvp_dtoa
case 3:
leftright = 0;
/* no break */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant comment

@@ -2367,10 +2372,12 @@ jvp_strtod
case '-':
sign = 1;
/* no break */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant comment

@@ -1723,6 +1724,7 @@ gethex(struct dtoa_context* C, CONST char **sp, U *rvp, int rounding, int sign)
case '-':
esign = 1;
/* no break */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redundant comment

@nicowilliams
Copy link
Contributor Author

@emanuele6 I wanted to leave the original no break commentary in src/jv_dtoa.c.

@emanuele6
Copy link
Member

Ok, that's fine then

@emanuele6 emanuele6 merged commit f733a15 into jqlang:master Jul 30, 2023
28 checks passed
@emanuele6
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants