replay: Fix build with -Werror=unused-result
PATCH 1/1 replay: Fix build with -Werror=unused-result
If compiling with -Werror=unused-result, replay-internal.c won't build due to a call to fwrite() where the returned value is ignored. A simple cast to (void) is not sufficient on recent GCCs, so this fixes it.
--- replay/replay-internal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
replay/replay-internal.c +1 -1
@@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size) {if (replay_file) {replay_put_dword (size); -fwrite (buf,1 , size, replay_file); + (void )(fwrite (buf,1 , size, replay_file)+1 ); } }
Signature · 1 line
1.9.5
Quoted 15 lines
From: Felipe Franciosi [mailto:[email protected]]
If compiling with -Werror=unused-result,replay-internal.cwon't build due to a call tofwrite()where the returned value is ignored. A simple cast to (void) is not sufficient on recent GCCs, so this fixes it.Signed-off-by Felipe Franciosi <[email protected]>--- replay/replay-internal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)replay/replay-internal.c +0
-0
replay/replay-internal.c void replay_put_array(const uint8_t *buf, size_t size) · line 70
Quoted 7 lines
replay/replay-internal.c +1
-1@@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size) {if (replay_file) {replay_put_dword (size); -fwrite (buf,1 , size, replay_file); + (void )(fwrite (buf,1 , size, replay_file)+1 ); } }
This looks very weird.
I think it would be better to check the return value and stop the simulation in case of error.
Pavel Dovgalyuk
Quoted 10 lines · Pavel Dovgalyuk
Quoted 10 lines
From: Felipe Franciosi [mailto:[email protected]]
If compiling with -Werror=unused-result,replay-internal.cwon't build due to a call tofwrite()where the returned value is ignored. A simple cast to (void) is not sufficient on recent GCCs, so this fixes it.Signed-off-by Felipe Franciosi <[email protected]>--- replay/replay-internal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 16 lines
replay/replay-internal.c void replay_put_array(const uint8_t *buf, size_t size) · line 70
Quoted 12 lines
replay/replay-internal.c +1
-1@@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size) {if (replay_file) {replay_put_dword (size); -fwrite (buf,1 , size, replay_file); + (void )(fwrite (buf,1 , size, replay_file)+1 ); } }This looks very weird.
I think it would be better to check the return value and stop the simulation in case of error.
Ignoring errors is wrong more often than not. Whether it's wrong in this case I can't say. What I can say is 1. the commit message needs to explain *why* the error can be ignored, and 2. the way you ignore the error is scandalously ugly :) You say gcc doesn't honor the traditional cast to void anymore. What's the exact error message you see?
Quoted 15 lines · Markus Armbruster
Quoted 10 lines · Pavel Dovgalyuk
Quoted 10 lines
From: Felipe Franciosi [mailto:[email protected]]
If compiling with -Werror=unused-result,replay-internal.cwon't build due to a call tofwrite()where the returned value is ignored. A simple cast to (void) is not sufficient on recent GCCs, so this fixes it.Signed-off-by Felipe Franciosi <[email protected]>---
replay/replay-internal.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
replay/replay-internal.c +0
-0@@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size) {Quoted 8 lines
replay/replay-internal.c void replay_put_array(const uint8_t *buf, size_t size) · line 70
Quoted 6 lines
replay/replay-internal.c +1
-1if (replay_file) {replay_put_dword (size); -fwrite (buf,1 , size, replay_file); + (void )(fwrite (buf,1 , size, replay_file)+1 ); } }This looks very weird.
Oh I couldn't agree more. I hate this syntax. It is, however, the simplest way to get around this issue. See:
http://stackoverflow.com/questions/11888594/ignoring-return-values-in-c
That doesn't mean we should do it. I actually rather we didn't. :)
I sent this patch to discuss how the maintainers feel about it given no one bumped into this yet (apparently).
Quoted 2 lines
Quoted 2 lines
I think it would be better to check the return value and stop the simulation in case of error.
We can also make replay_put_array() return an int indicating whether an error occurred. The callers can then decide whether to care or not. I'll send a v2 doing that instead for comments.
Quoted 2 lines
Ignoring errors is wrong more often than not. Whether it's wrong in this case I can't say.
True that. That's why I think a better first step is to make functions that can fail return an error code. Callers can make that decision later. Unfortunately, glibc decided that fwrite() should be tagged with WUR and that triggers this build failure.
Quoted 2 lines
What I can say is 1. the commit message needs to
explain *why* the error can be ignored,
The error is already ignored today. I'll send a v2 that makes replay_put_array() reflect the error, the callers can then decide to ignore it.
Quoted 2 lines
and 2. the way you ignore the
error is scandalously ugly :)
Oh we all agree on that. :-D
Quoted 2 lines
You say gcc doesn't honor the traditional
cast to void anymore. What's the exact error message you see?
See this (lengthly discussion) for more details:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509
Thanks,
Felipe
Quoted 44 lines
From: Felipe Franciosi [mailto:[email protected]]
Quoted 29 lines · Markus Armbruster
Quoted 24 lines · Pavel Dovgalyuk
Quoted 15 lines
From: Felipe Franciosi [mailto:[email protected]]
If compiling with -Werror=unused-result,replay-internal.cwon't build due to a call tofwrite()where the returned value is ignored. A simple cast to (void) is not sufficient on recent GCCs, so this fixes it.Signed-off-by Felipe Franciosi <[email protected]>---
replay/replay-internal.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)replay/replay-internal.c +0
-0replay/replay-internal.c void replay_put_array(const uint8_t *buf, size_t size) · line 70
Quoted 7 lines
replay/replay-internal.c +1
-1@@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size) {if (replay_file) {replay_put_dword (size); -fwrite (buf,1 , size, replay_file); + (void )(fwrite (buf,1 , size, replay_file)+1 ); } }This looks very weird.
Quoted 2 lines
Quoted 2 lines
I think it would be better to check the return value and stop the simulation in case of error.
We can also make
replay_put_array()return an int indicating whether an error occurred. The callers can then decide whether to care or not. I'll send a v2 doing that instead for comments.Quoted 2 lines
Ignoring errors is wrong more often than not. Whether it's wrong in this case I can't say.
True that. That's why I think a better first step is to make functions that can fail return an error code. Callers can make that decision later. Unfortunately, glibc decided that
fwrite()should be tagged with WUR and that triggers this build failure.
Quoted 5 lines
Quoted 2 lines
What I can say is 1. the commit message needs to
explain *why* the error can be ignored,The error is already ignored today. I'll send a v2 that makes
replay_put_array()reflect the error, the callers can then decide to ignore it.
There is no need to return an error.
When rr log cannot be created there is no need in executing in record mode. Therefore execution has to be stopped in case of an error.
Pavel Dovgalyuk
Quoted 30 lines · Felipe Franciosi
Quoted 15 lines · Markus Armbruster
Quoted 10 lines · Pavel Dovgalyuk
Quoted 10 lines
From: Felipe Franciosi [mailto:[email protected]]
If compiling with -Werror=unused-result,replay-internal.cwon't build due to a call tofwrite()where the returned value is ignored. A simple cast to (void) is not sufficient on recent GCCs, so this fixes it.Signed-off-by Felipe Franciosi <[email protected]>---
replay/replay-internal.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
replay/replay-internal.c +0
-0@@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size) {Quoted 8 lines
replay/replay-internal.c void replay_put_array(const uint8_t *buf, size_t size) · line 70
Quoted 6 lines
replay/replay-internal.c +1
-1if (replay_file) {replay_put_dword (size); -fwrite (buf,1 , size, replay_file); + (void )(fwrite (buf,1 , size, replay_file)+1 ); } }This looks very weird.
Quoted 2 lines
Oh I couldn't agree more. I hate this syntax. It is, however, the simplest way to get around this issue. See:
http://stackoverflow.com/questions/11888594/ignoring-return-values-in-c
If we want to ignore return value reliably, lets just pull in the ignore_value macro from gnulib which is known to work across GCC versions
/* Normally casting an expression to void discards its value, but GCC
versions 3.4 and newer have __attribute__ ((__warn_unused_result__)) which may cause unwanted diagnostics in that case. Use __typeof__ and __extension__ to work around the problem, if the workaround is known to be needed. */
#if 3 < __GNUC__ + (4 <= __GNUC_MINOR__)
# define ignore_value(x) \
(__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
#else
# define ignore_value(x) ((void) (x))
#endifGNULIB makes it availavble under LGPLv2.1+
eg used as:
ignore_value(fwrite(buf, 1, size, replay_file));
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 34 lines · Daniel P. Berrange
Quoted 30 lines · Felipe Franciosi
Quoted 29 lines · Markus Armbruster
Quoted 24 lines · Pavel Dovgalyuk
Quoted 15 lines
From: Felipe Franciosi [mailto:[email protected]]
If compiling with -Werror=unused-result,replay-internal.cwon't build due to a call tofwrite()where the returned value is ignored. A simple cast to (void) is not sufficient on recent GCCs, so this fixes it.Signed-off-by Felipe Franciosi <[email protected]>---
replay/replay-internal.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)replay/replay-internal.c +0
-0replay/replay-internal.c void replay_put_array(const uint8_t *buf, size_t size) · line 70
Quoted 7 lines
replay/replay-internal.c +1
-1@@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size) {if (replay_file) {replay_put_dword (size); -fwrite (buf,1 , size, replay_file); + (void )(fwrite (buf,1 , size, replay_file)+1 ); } }This looks very weird.
Quoted 6 lines
Quoted 2 lines
Oh I couldn't agree more. I hate this syntax. It is, however, the simplest way to get around this issue. See:
http://stackoverflow.com/questions/11888594/ignoring-return-values-in-cIf we want to ignore return value reliably, lets just pull in the
ignore_valuemacro from gnulib which is known to work across GCC versions
I like that better. Do you want a series with a patch to add this macro to include/qemu/compiler.h and another making replay_put_array() use it?
Cheers,
Felipe
Quoted 27 lines
/* Normally casting an expression to void discards its value, but GCC
versions 3.4 and newer have__attribute__((__warn_unused_result__)) which may cause unwanted diagnostics in that case. Use__typeof__and__extension__to work around the problem, if the workaround is known to be needed. */
#if 3 <__GNUC__+ (4 <=__GNUC_MINOR__)# define ignore_value(x) \ (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endifGNULIB makes it availavble under LGPLv2.1+
eg used as:
ignore_value(fwrite(buf, 1, size, replay_file));Regards,
DanielSignature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Actually, I just noticed Pavel is in the middle of submitting a "replay additions" series (currently at v4).
Pavel: is this something you can address as part of that series?
Thanks,
Felipe
Quoted 76 lines · Felipe Franciosi
Quoted 35 lines · Daniel P. Berrange
Quoted 30 lines · Felipe Franciosi
Quoted 29 lines · Markus Armbruster
Quoted 24 lines · Pavel Dovgalyuk
Quoted 15 lines
From: Felipe Franciosi [mailto:[email protected]]
If compiling with -Werror=unused-result,replay-internal.cwon't build due to a call tofwrite()where the returned value is ignored. A simple cast to (void) is not sufficient on recent GCCs, so this fixes it.Signed-off-by Felipe Franciosi <[email protected]>---
replay/replay-internal.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)replay/replay-internal.c +0
-0replay/replay-internal.c void replay_put_array(const uint8_t *buf, size_t size) · line 70
Quoted 7 lines
replay/replay-internal.c +1
-1@@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size) {if (replay_file) {replay_put_dword (size); -fwrite (buf,1 , size, replay_file); + (void )(fwrite (buf,1 , size, replay_file)+1 ); } }This looks very weird.
Quoted 6 lines
Quoted 2 lines
Oh I couldn't agree more. I hate this syntax. It is, however, the simplest way to get around this issue. See:
http://stackoverflow.com/questions/11888594/ignoring-return-values-in-cIf we want to ignore return value reliably, lets just pull in the
ignore_valuemacro from gnulib which is known to work across GCC versionsI like that better. Do you want a series with a patch to add this macro to
include/qemu/compiler.hand another makingreplay_put_array()use it?Cheers,
FelipeQuoted 27 lines
/* Normally casting an expression to void discards its value, but GCC
versions 3.4 and newer have__attribute__((__warn_unused_result__)) which may cause unwanted diagnostics in that case. Use__typeof__and__extension__to work around the problem, if the workaround is known to be needed. */
#if 3 <__GNUC__+ (4 <=__GNUC_MINOR__)# define ignore_value(x) \ (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endifGNULIB makes it availavble under LGPLv2.1+
eg used as:
ignore_value(fwrite(buf, 1, size, replay_file));Regards,
DanielSignature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 45 lines · Daniel P. Berrange
Quoted 30 lines · Felipe Franciosi
Quoted 15 lines · Markus Armbruster
Quoted 10 lines · Pavel Dovgalyuk
Quoted 10 lines
From: Felipe Franciosi [mailto:[email protected]]
If compiling with -Werror=unused-result,replay-internal.cwon't build due to a call tofwrite()where the returned value is ignored. A simple cast to (void) is not sufficient on recent GCCs, so this fixes it.Signed-off-by Felipe Franciosi <[email protected]>---
replay/replay-internal.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
Quoted 6 lines
Quoted 6 lines
replay/replay-internal.c +0
-0@@ -65,7 +65,7 @@ void replay_put_array(const uint8_t *buf, size_t size) {Quoted 8 lines
replay/replay-internal.c void replay_put_array(const uint8_t *buf, size_t size) · line 70
Quoted 6 lines
replay/replay-internal.c +1
-1if (replay_file) {replay_put_dword (size); -fwrite (buf,1 , size, replay_file); + (void )(fwrite (buf,1 , size, replay_file)+1 ); } }This looks very weird.
Quoted 2 lines
Oh I couldn't agree more. I hate this syntax. It is, however, the simplest way to get around this issue. See:
http://stackoverflow.com/questions/11888594/ignoring-return-values-in-cIf we want to ignore return value reliably, lets just pull in the
ignore_valuemacro from gnulib which is known to work across GCC versions/* Normally casting an expression to void discards its value, but GCC
versions 3.4 and newer have__attribute__((__warn_unused_result__)) which may cause unwanted diagnostics in that case. Use__typeof__and__extension__to work around the problem, if the workaround is known to be needed. */
#if 3 <__GNUC__+ (4 <=__GNUC_MINOR__)
Quoted 5 lines
# define ignore_value(x) \
(__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
#else
# define ignore_value(x) ((void) (x))
#endifCasting a value to void is the traditional and obvious way to say "yes, I mean to ignore this value". Now compilers start to reply "no, you don't". We can invent new (and less obvious) ways to say "yes, I do", and compilers can then learn them so they can again reply "no, you don't". Why have compilers started to behave like two-year-olds?
[...]
Quoted 18 lines · Markus Armbruster
Quoted 12 lines
If we want to ignore return value reliably, lets just pull in the
ignore_valuemacro from gnulib which is known to work across GCC versions/* Normally casting an expression to void discards its value, but GCC
versions 3.4 and newer have__attribute__((__warn_unused_result__)) which may cause unwanted diagnostics in that case. Use__typeof__and__extension__to work around the problem, if the workaround is known to be needed. */
#if 3 <__GNUC__+ (4 <=__GNUC_MINOR__)Quoted 5 lines
# define ignore_value(x) \ (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endif
Quoted 5 lines
Casting a value to void is the traditional and obvious way to say "yes, I mean to ignore this value". Now compilers start to reply "no, you don't". We can invent new (and less obvious) ways to say "yes, I do", and compilers can then learn them so they can again reply "no, you don't". Why have compilers started to behave like two-year-olds?
gcc has been doing the "__warn_unused_value__ means cast-to-void is insufficient" complaint for years (since at least 2008, per the gnulib history). But the gnulib workaround has also been effectively silencing it for years (it was actually my work in 2011, commit 939dedd, which came up with the form listed above). The other nice thing about "ignore_value(wur_function())" is that you are avoiding a cast in your local code, and the burden of shutting up the annoying compiler is hidden behind a macro that can easily be changed to affect all clients of the macro, should gcc regress yet again and we need some other formula to shut it up.
And yes, the gnulib mailing list has threads complaining about gcc's behavior back when the macro had to be invented, and again when glibc added wur markings to functions that can legitimately be ignored (fread() is one of them; because there are valid programming paradigms where you check ferror() later on rather than having to check every intermediate fread(), at the expense of less-specific error messages).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 39 lines · Eric Blake
Quoted 18 lines · Markus Armbruster
Quoted 12 lines
If we want to ignore return value reliably, lets just pull in the
ignore_valuemacro from gnulib which is known to work across GCC versions/* Normally casting an expression to void discards its value, but GCC
versions 3.4 and newer have__attribute__((__warn_unused_result__)) which may cause unwanted diagnostics in that case. Use__typeof__and__extension__to work around the problem, if the workaround is known to be needed. */
#if 3 <__GNUC__+ (4 <=__GNUC_MINOR__)Quoted 5 lines
# define ignore_value(x) \ (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endifQuoted 5 lines
Casting a value to void is the traditional and obvious way to say "yes, I mean to ignore this value". Now compilers start to reply "no, you don't". We can invent new (and less obvious) ways to say "yes, I do", and compilers can then learn them so they can again reply "no, you don't". Why have compilers started to behave like two-year-olds?
gcc has been doing the "
__warn_unused_value__means cast-to-void is insufficient" complaint for years (since at least 2008, per the gnulib history). But the gnulib workaround has also been effectively silencing it for years (it was actually my work in 2011, commit 939dedd, which came up with the form listed above). The other nice thing about "ignore_value(wur_function())" is that you are avoiding a cast in your local code, and the burden of shutting up the annoying compiler is hidden behind a macro that can easily be changed to affect all clients of the macro, should gcc regress yet again and we need some other formula to shut it up.
Quoted 6 lines
And yes, the gnulib mailing list has threads complaining about gcc's behavior back when the macro had to be invented, and again when glibc added wur markings to functions that can legitimately be ignored (
fread()is one of them; because there are valid programming paradigms where you checkferror()later on rather than having to check every intermediatefread(), at the expense of less-specific error messages).
What's the best way to bring gnulib's ignore-value.h into Qemu? I'd think we could just add to include/qemu/compiler.h something like:
----------------------8<----------------------
#if QEMU_GNUC_PREREQ(3, 4)
/* From gnulib's ignore-value.h by Jim Meyering, Eric Blake and Padraig Brady */
# define ignore_value(x) \
(__extension__ ({ __typeof__ (x) __x = (x); (void) __x; }))
#else
# define ignore_value(x) ((void) (x))
#endif
----------------------8<----------------------But I'm not sure if that suffices to meet GPL's requirements.
Thanks,
Felipe
Quoted 5 lines
Signature · 3 lines
-- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 51 lines · Felipe Franciosi
Quoted 39 lines · Eric Blake
Quoted 18 lines · Markus Armbruster
Quoted 12 lines
If we want to ignore return value reliably, lets just pull in the
ignore_valuemacro from gnulib which is known to work across GCC versions/* Normally casting an expression to void discards its value, but GCC
versions 3.4 and newer have__attribute__((__warn_unused_result__)) which may cause unwanted diagnostics in that case. Use__typeof__and__extension__to work around the problem, if the workaround is known to be needed. */
#if 3 <__GNUC__+ (4 <=__GNUC_MINOR__)Quoted 5 lines
# define ignore_value(x) \ (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endifQuoted 5 lines
Casting a value to void is the traditional and obvious way to say "yes, I mean to ignore this value". Now compilers start to reply "no, you don't". We can invent new (and less obvious) ways to say "yes, I do", and compilers can then learn them so they can again reply "no, you don't". Why have compilers started to behave like two-year-olds?
gcc has been doing the "
__warn_unused_value__means cast-to-void is insufficient" complaint for years (since at least 2008, per the gnulib history). But the gnulib workaround has also been effectively silencing it for years (it was actually my work in 2011, commit 939dedd, which came up with the form listed above). The other nice thing about "ignore_value(wur_function())" is that you are avoiding a cast in your local code, and the burden of shutting up the annoying compiler is hidden behind a macro that can easily be changed to affect all clients of the macro, should gcc regress yet again and we need some other formula to shut it up.Quoted 6 lines
And yes, the gnulib mailing list has threads complaining about gcc's behavior back when the macro had to be invented, and again when glibc added wur markings to functions that can legitimately be ignored (
fread()is one of them; because there are valid programming paradigms where you checkferror()later on rather than having to check every intermediatefread(), at the expense of less-specific error messages).What's the best way to bring gnulib's
ignore-value.hinto Qemu? I'd think we could just add toinclude/qemu/compiler.hsomething like:----------------------8<----------------------
#ifQEMU_GNUC_PREREQ(3, 4)
/* From gnulib'signore-value.hby Jim Meyering, Eric Blake and Padraig Brady */
Quoted 8 lines
# define ignore_value(x) \, (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endif ----------------------8<----------------------But I'm not sure if that suffices to meet GPL's requirements.
The compiler.h file has no license header, just a comment saying "public domain", which is obviously not the case if you add this macro.
Given that you'll need to explicitly mention the license terms for ignore_value. eg with a comment line like
/* The ignore_value() macro is taken from GNULIB ignore-value.h,
* licensed under the terms of the LGPLv2+
*/
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 68 lines · Daniel P. Berrange
Quoted 51 lines · Felipe Franciosi
Quoted 39 lines · Eric Blake
Quoted 18 lines · Markus Armbruster
Quoted 12 lines
If we want to ignore return value reliably, lets just pull in the
ignore_valuemacro from gnulib which is known to work across GCC versions/* Normally casting an expression to void discards its value, but GCC
versions 3.4 and newer have__attribute__((__warn_unused_result__)) which may cause unwanted diagnostics in that case. Use__typeof__and__extension__to work around the problem, if the workaround is known to be needed. */
#if 3 <__GNUC__+ (4 <=__GNUC_MINOR__)Quoted 5 lines
# define ignore_value(x) \ (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endifQuoted 5 lines
Casting a value to void is the traditional and obvious way to say "yes, I mean to ignore this value". Now compilers start to reply "no, you don't". We can invent new (and less obvious) ways to say "yes, I do", and compilers can then learn them so they can again reply "no, you don't". Why have compilers started to behave like two-year-olds?
gcc has been doing the "
__warn_unused_value__means cast-to-void is insufficient" complaint for years (since at least 2008, per the gnulib history). But the gnulib workaround has also been effectively silencing it for years (it was actually my work in 2011, commit 939dedd, which came up with the form listed above). The other nice thing about "ignore_value(wur_function())" is that you are avoiding a cast in your local code, and the burden of shutting up the annoying compiler is hidden behind a macro that can easily be changed to affect all clients of the macro, should gcc regress yet again and we need some other formula to shut it up.Quoted 6 lines
And yes, the gnulib mailing list has threads complaining about gcc's behavior back when the macro had to be invented, and again when glibc added wur markings to functions that can legitimately be ignored (
fread()is one of them; because there are valid programming paradigms where you checkferror()later on rather than having to check every intermediatefread(), at the expense of less-specific error messages).What's the best way to bring gnulib's
ignore-value.hinto Qemu? I'd think we could just add toinclude/qemu/compiler.hsomething like:----------------------8<----------------------
#ifQEMU_GNUC_PREREQ(3, 4)
/* From gnulib'signore-value.hby Jim Meyering, Eric Blake and Padraig Brady */Quoted 8 lines
# define ignore_value(x) \, (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endif ----------------------8<----------------------But I'm not sure if that suffices to meet GPL's requirements.
The
compiler.hfile has no license header, just a comment saying "public domain", which is obviously not the case if you add this macro.
Quoted 6 lines
Given that you'll need to explicitly mention the license terms for
ignore_value. eg with a comment line like/* The
ignore_value()macro is taken from GNULIBignore-value.h,
* licensed under the terms of the LGPLv2+
*/
Awesome, thanks!
I think it's better to fit it in compiler.h than to add a separate header file, which would then need to be included by any potential user.
Felipe
Quoted 8 lines
Regards,
DanielSignature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 5 lines · Daniel P. Berrange
Quoted 1 line
But I'm not sure if that suffices to meet GPL's requirements.
The
compiler.hfile has no license header, just a comment saying "public domain", which is obviously not the case if you add this macro.
Oh, I missed that; I was assuming compiler.h was GPLv2+ per the usual project defaults; but that file is explicitly looser.
Quoted 7 lines
Given that you'll need to explicitly mention the license terms for
ignore_value. eg with a comment line like/* The
ignore_value()macro is taken from GNULIBignore-value.h,
* licensed under the terms of the LGPLv2+
*/
Yes, adding that solves any questions of origin.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 65 lines · Daniel P. Berrange
Quoted 51 lines · Felipe Franciosi
Quoted 39 lines · Eric Blake
Quoted 18 lines · Markus Armbruster
Quoted 12 lines
If we want to ignore return value reliably, lets just pull in the
ignore_valuemacro from gnulib which is known to work across GCC versions/* Normally casting an expression to void discards its value, but GCC
versions 3.4 and newer have__attribute__((__warn_unused_result__)) which may cause unwanted diagnostics in that case. Use__typeof__and__extension__to work around the problem, if the workaround is known to be needed. */
#if 3 <__GNUC__+ (4 <=__GNUC_MINOR__)Quoted 5 lines
# define ignore_value(x) \ (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endifQuoted 5 lines
Casting a value to void is the traditional and obvious way to say "yes, I mean to ignore this value". Now compilers start to reply "no, you don't". We can invent new (and less obvious) ways to say "yes, I do", and compilers can then learn them so they can again reply "no, you don't". Why have compilers started to behave like two-year-olds?
gcc has been doing the "
__warn_unused_value__means cast-to-void is insufficient" complaint for years (since at least 2008, per the gnulib history). But the gnulib workaround has also been effectively silencing it for years (it was actually my work in 2011, commit 939dedd, which came up with the form listed above). The other nice thing about "ignore_value(wur_function())" is that you are avoiding a cast in your local code, and the burden of shutting up the annoying compiler is hidden behind a macro that can easily be changed to affect all clients of the macro, should gcc regress yet again and we need some other formula to shut it up.Quoted 6 lines
And yes, the gnulib mailing list has threads complaining about gcc's behavior back when the macro had to be invented, and again when glibc added wur markings to functions that can legitimately be ignored (
fread()is one of them; because there are valid programming paradigms where you checkferror()later on rather than having to check every intermediatefread(), at the expense of less-specific error messages).What's the best way to bring gnulib's
ignore-value.hinto Qemu? I'd think we could just add toinclude/qemu/compiler.hsomething like:----------------------8<----------------------
#ifQEMU_GNUC_PREREQ(3, 4)
/* From gnulib'signore-value.hby Jim Meyering, Eric Blake and Padraig Brady */Quoted 8 lines
# define ignore_value(x) \, (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endif ----------------------8<----------------------But I'm not sure if that suffices to meet GPL's requirements.
The
compiler.hfile has no license header, just a comment saying "public domain", which is obviously not the case if you add this macro.
Quoted 6 lines
Given that you'll need to explicitly mention the license terms for
ignore_value. eg with a comment line like/* The
ignore_value()macro is taken from GNULIBignore-value.h,
* licensed under the terms of the LGPLv2+
*/
Our tree has a mix of licenses, which is enough of a pain. Mixing licenses within *files* is even worse, and might not even be legally sound.
Relicense the whole file under our preferred license GPLv2+?
Quoted 11 lines · Markus Armbruster
Quoted 10 lines
The
compiler.hfile has no license header, just a comment saying "public domain", which is obviously not the case if you add this macro.Given that you'll need to explicitly mention the license terms for
ignore_value. eg with a comment line like/* The
ignore_value()macro is taken from GNULIBignore-value.h,
* licensed under the terms of the LGPLv2+
*/
Quoted 5 lines
Our tree has a mix of licenses, which is enough of a pain. Mixing licenses within *files* is even worse, and might not even be legally sound.
Relicense the whole file under our preferred license GPLv2+?
That works too. No one can legally complain - the current license is so permissive that marking the entire file LGPLv2+ is permitted by the current license. It's a one-way conversion (we can't go back once we do it), but I would be fine with that approach.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 17 lines · Eric Blake
Quoted 15 lines · Markus Armbruster
Quoted 10 lines
The
compiler.hfile has no license header, just a comment saying "public domain", which is obviously not the case if you add this macro.Given that you'll need to explicitly mention the license terms for
ignore_value. eg with a comment line like/* The
ignore_value()macro is taken from GNULIBignore-value.h,
* licensed under the terms of the LGPLv2+
*/Our tree has a mix of licenses, which is enough of a pain. Mixing licenses within *files* is even worse, and might not even be legally sound.
Quoted 6 lines
Quoted 1 line
Relicense the whole file under our preferred license GPLv2+?
That works too. No one can legally complain - the current license is so permissive that marking the entire file LGPLv2+ is permitted by the current license. It's a one-way conversion (we can't go back once we do it), but I would be fine with that approach.
I think the file probably should not have been listed as public domain in the first place, as its initial contents were copied from qemu-common.h which is not public domain.
Regards,
Daniel
Signature · 4 lines
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
Quoted 20 lines · Daniel P. Berrange
Quoted 19 lines · Eric Blake
Quoted 16 lines · Markus Armbruster
Quoted 10 lines
The
compiler.hfile has no license header, just a comment saying "public domain", which is obviously not the case if you add this macro.Given that you'll need to explicitly mention the license terms for
ignore_value. eg with a comment line like/* The
ignore_value()macro is taken from GNULIBignore-value.h,
* licensed under the terms of the LGPLv2+
*/Our tree has a mix of licenses, which is enough of a pain. Mixing licenses within *files* is even worse, and might not even be legally sound.
Relicense the whole file under our preferred license GPLv2+?
Quoted 8 lines
Quoted 4 lines
That works too. No one can legally complain - the current license is so permissive that marking the entire file LGPLv2+ is permitted by the current license. It's a one-way conversion (we can't go back once we do it), but I would be fine with that approach.
I think the file probably should not have been listed as public domain in the first place, as its initial contents were copied from
qemu-common.hwhich is not public domain.
Ewww! Needs fixing.
Since qemu-common.h carries no license, GPLv2+ applies.
Quoted 6 lines · Markus Armbruster
Quoted 4 lines
I think the file probably should not have been listed as public domain in the first place, as its initial contents were copied from
qemu-common.hwhich is not public domain.Ewww! Needs fixing.
Indeed. Commit 5c02632 shows the initial file creation, but Luiz used a different email address at that time. What would be the best line to list as a copyright holder on both qemu-common.h and on compiler.h?
Quoted 3 lines
Since
qemu-common.hcarries no license, GPLv2+ applies.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 11 lines · Eric Blake
Quoted 6 lines · Markus Armbruster
Quoted 4 lines
I think the file probably should not have been listed as public domain in the first place, as its initial contents were copied from
qemu-common.hwhich is not public domain.Ewww! Needs fixing.
Indeed. Commit 5c02632 shows the initial file creation, but Luiz used a different email address at that time. What would be the best line to list as a copyright holder on both
qemu-common.hand oncompiler.h?
Since qemu-common.h carried no licence notice back then[*], adding the line "/* public domain */" was to compiler.h was wrong, and is probably legally void. The immediate fix is therefore dropping that line. Then the project-wide license applies: GPLv2+.
We can always copy the standard GPLv2+ licence notice to files that don't have one, if we think that's useful.
Quoted 1 line
Quoted 1 line
Since
qemu-common.hcarries no license, GPLv2+ applies.
[*] It still doesn't, but that's immaterial.
Quoted 22 lines · Markus Armbruster
Quoted 11 lines · Eric Blake
Quoted 6 lines · Markus Armbruster
Quoted 4 lines
I think the file probably should not have been listed as public domain in the first place, as its initial contents were copied from
qemu-common.hwhich is not public domain.Ewww! Needs fixing.
Indeed. Commit 5c02632 shows the initial file creation, but Luiz used a different email address at that time. What would be the best line to list as a copyright holder on both
qemu-common.hand oncompiler.h?Since
qemu-common.hcarried no licence notice back then[*], adding the line "/* public domain */" was tocompiler.hwas wrong, and is probably legally void. The immediate fix is therefore dropping that line. Then the project-wide license applies: GPLv2+.
Quoted 7 lines
We can always copy the standard GPLv2+ licence notice to files that don't have one, if we think that's useful.
Quoted 1 line
Quoted 1 line
Since
qemu-common.hcarries no license, GPLv2+ applies.[*] It still doesn't, but that's immaterial.
Seems like all of us agree on that, so I sent another patch just for this. Once it's in, we can go back to adding the 'ignore_value()' macro and figuring out what to do with 'replay'.
http://lists.nongnu.org/archive/html/qemu-devel/2016-09/msg06206.html
Cheers,
Felipe
Quoted 6 lines · Felipe Franciosi
What's the best way to bring gnulib's
ignore-value.hinto Qemu? I'd think we could just add toinclude/qemu/compiler.hsomething like:----------------------8<----------------------
#ifQEMU_GNUC_PREREQ(3, 4)
/* From gnulib'signore-value.hby Jim Meyering, Eric Blake and Padraig Brady */
Quoted 8 lines
# define ignore_value(x) \ (__extension__ ({ __typeof__ (x) __x = (x); (void) __x; })) #else # define ignore_value(x) ((void) (x)) #endif ----------------------8<----------------------But I'm not sure if that suffices to meet GPL's requirements.
As Dan already pointed out, gnulib's ignore_value() is available under LGPLv2+ (the full gnulib.git/lib/ignore-value.h file states GPLv3+, for ease of copying into other GPLv3 projects; but the modules/ignore-value file states what additional licenses it can be used under). Using 'gnulib-tool --lgpl=2 ignore-value' would give you the modified version; but it is probably overkill for this situation (we can skip straight to the end result instead of going through intermediate steps).
Furthermore, I'm the original author of that code snippet as listed (as gnulib.git will show); where the only modification made after I wrote it was whitespace changes and the addition of __extension__, and I'm just fine with those lines being used as-is in qemu.git (there's benefits when an original author states intentions :)
So copying and pasting the relevant snippet into compiler.h is indeed the way to go; in fact, you can probably get away with a comment that just says "/* From gnulib's LGPLv2+ ignore-value.h */" without having to call out particular authors. Don't bother creating any new header or worrying about copyright boilerplate changes; and you can point to this message-id in the commit message if you are worried about a paper trail; you are not violating the GPL in this instance.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Your series seems to have some coding style problems. See output below for more information:
Hi,
Your series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH] replay: Fix build with -Werror=unused-result
=== TEST SCRIPT BEGIN ===
#!/bin/bash
BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0
# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True
commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do
echo "Checking PATCH $n/$total: $(git show --no-patch --format=%s $c)..."
if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
failed=1
echo
fi
n=$((n+1))done
exit $failed
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
4439fa6 replay: Fix build with -Werror=unused-result
=== OUTPUT BEGIN ===
Checking PATCH 1/1: replay: Fix build with -Werror=unused-result...
ERROR: spaces required around that '+' (ctx:VxV)
#22: FILE: replay/replay-internal.c:68:
+ (void)(fwrite(buf, 1, size, replay_file)+1);
^total: 1 errors, 0 warnings, 8 lines checked
Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===
Test command exited with code: 1
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]