osdep: allow including qemu/osdep.h outside extern "C"
cover osdep: allow including qemu/osdep.h outside extern "C"
qemu/osdep.h is quite special in that, despite being part of QEMU sources, it is included by C++ source files as well.
disas/nanomips.cpp is doing so within an 'extern "C"' block, which breaks with latest glib due to the inclusion of templates in glib.h.
These patches implement Daniel Berrangé's idea of pushing the 'extern "C"' block within glib.h and including system headers (including glib.h, and in fact QEMU's own glib-compat.h too) *outside* the block.
(CI has not finished running yet, but it seems encouraging).
Paolo
Paolo Bonzini (2):
osdep: include glib-compat.h before other QEMU headers
osdep: protect qemu/osdep.h with extern "C"
disas/nanomips.cpp | 2 +- include/qemu/compiler.h | 6 ++++++ include/qemu/osdep.h | 13 +++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-)
Signature · 1 line
2.30.1
PATCH 1/2 osdep: include glib-compat.h before other QEMU headers
glib-compat.h is sort of like a system header, and it needs to include system headers (glib.h) that may dislike being included under 'extern "C"'. Move it right after all system headers and before all other QEMU headers.
--- include/qemu/osdep.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/qemu/osdep.h +2 -1
@@ -111,6 +111,8 @@ extern int daemon(int, int);#define WEXITSTATUS (x) (x)#endif +#include "glib-compat.h" +#ifdef _WIN32#include "sysemu/os-win32.h" #endif
@@ -123,7 +125,6 @@ extern int daemon(int, int);#include <AvailabilityMacros.h> #endif -#include "glib-compat.h" #include "qemu/typedefs.h" /*
Signature · 1 line
2.30.1
PATCH 2/2 osdep: protect qemu/osdep.h with extern "C"
In reply to Paolo BonziniSystem headers may include templates if compiled with a C++ compiler, which cause the compiler to complain if qemu/osdep.h is included within a C++ source file's 'extern "C"' block. Add
an 'extern "C"' block directly to qemu/osdep.h, so that system headers can be kept out of it.
There is a stray declaration early in qemu/osdep.h, which needs to be special cased. Add a definition in qemu/compiler.h to make it look nice.
config-host.h, CONFIG_TARGET, exec/poison.h and qemu/compiler.h are included outside the 'extern "C"' block; that is not an issue because they consist entirely of preprocessor directives.
--- disas/nanomips.cpp | 2 +- include/qemu/compiler.h | 6 ++++++ include/qemu/osdep.h | 10 +++++++++- 3 files changed, 16 insertions(+), 2 deletions(-)
disas/nanomips.cpp +1 -1
@@ -27,8 +27,8 @@ * Reference Manual", Revision 01.01, April 27, 2018 */ -extern "C" { #include "qemu/osdep.h" +extern "C" { #include "disas/dis-asm.h" }
include/qemu/compiler.h +6 -0
@@ -11,6 +11,12 @@#define QEMU_STATIC_ANALYSIS 1#endif +#ifdef __cplusplus +#define QEMU_EXTERN_C extern "C" +#else +#define QEMU_EXTERN_C extern +#endif +#define QEMU_NORETURN __attribute__ ((__noreturn__))#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
include/qemu/osdep.h +9 -1
@@ -57,7 +57,7 @@#define daemon qemu_fake_daemon_function#include <stdlib.h> #undef daemon -extern int daemon (int ,int ); +QEMU_EXTERN_C int daemon(int, int);#endif #ifdef _WIN32
@@ -113,6 +113,10 @@ extern int daemon(int, int);#include "glib-compat.h" +#ifdef __cplusplus +extern "C" { +#endif +#ifdef _WIN32#include "sysemu/os-win32.h" #endif
@@ -723,4 +727,8 @@ static inline int platform_does_not_support_system(const char *command) }#endif /* !HAVE_SYSTEM_FUNCTION */ +#ifdef __cplusplus +} +#endif +#endif
Signature · 1 line
2.30.1
Re: [PATCH 2/2] osdep: protect qemu/osdep.h with extern "C"
Quoted 67 lines · Paolo Bonzini
System headers may include templates if compiled with a C++ compiler, which cause the compiler to complain if
qemu/osdep.his included within a C++ source file's 'extern "C"' block. Add
an 'extern "C"' block directly toqemu/osdep.h, so that system headers can be kept out of it.There is a stray declaration early in
qemu/osdep.h, which needs to be special cased. Add a definition inqemu/compiler.hto make it look nice.
config-host.h,CONFIG_TARGET,exec/poison.handqemu/compiler.hare included outside the 'extern "C"' block; that is not an issue because they consist entirely of preprocessor directives.Signed-off-by Paolo Bonzini <[email protected]>--- disas/nanomips.cpp | 2 +- include/qemu/compiler.h | 6 ++++++ include/qemu/osdep.h | 10 +++++++++- 3 files changed, 16 insertions(+), 2 deletions(-)disas/nanomips.cpp +1
-1@@ -27,8 +27,8 @@ * Reference Manual", Revision 01.01, April 27, 2018 */ -extern "C" { #include "qemu/osdep.h" +extern "C" { #include "disas/dis-asm.h" }include/qemu/compiler.h +6
-0@@ -11,6 +11,12 @@#define QEMU_STATIC_ANALYSIS 1#endif +#ifdef __cplusplus +#define QEMU_EXTERN_C extern "C" +#else +#define QEMU_EXTERN_C extern +#endif +#define QEMU_NORETURN __attribute__ ((__noreturn__))#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))include/qemu/osdep.h +1
-1@@ -57,7 +57,7 @@#define daemon qemu_fake_daemon_function#include <stdlib.h> #undef daemon -extern int daemon (int ,int ); +QEMU_EXTERN_C int daemon(int, int);#endif #ifdef _WIN32
include/qemu/osdep.h extern int daemon(int, int); · line 122
Quoted 10 lines
include/qemu/osdep.h +4
-0@@ -113,6 +113,10 @@ extern int daemon(int, int);#include "glib-compat.h" +#ifdef __cplusplus +extern "C" { +#endif +#ifdef _WIN32#include "sysemu/os-win32.h" #endif
There are some system header includes in osdep.h below this point (sys/shm.h and sys/uio.h) -- don't they need to be moved up to go with the other system includes first ?
thanks
-- PMM
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [PATCH 0/2] osdep: allow including qemu/osdep.h outside extern "C"
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== 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]
Switched to a new branch 'test'
992fa52 osdep: protect qemu/osdep.h with extern "C" bc2310f osdep: include glib-compat.h before other QEMU headers
=== OUTPUT BEGIN ===
1/2 Checking commit bc2310f731a5 (osdep: include glib-compat.h before other QEMU headers) 2/2 Checking commit 992fa52da413 (osdep: protect qemu/osdep.h with extern "C")
WARNING: architecture specific defines should be avoided
#51: FILE: include/qemu/compiler.h:14:
+#ifdef __cplusplus
ERROR: storage class should be at the beginning of the declaration #52: FILE: include/qemu/compiler.h:15:
+#define QEMU_EXTERN_C extern "C"
ERROR: storage class should be at the beginning of the declaration #54: FILE: include/qemu/compiler.h:17:
+#define QEMU_EXTERN_C extern
WARNING: architecture specific defines should be avoided #77: FILE: include/qemu/osdep.h:116:
+#ifdef __cplusplus
WARNING: architecture specific defines should be avoided #88: FILE: include/qemu/osdep.h:730:
+#ifdef __cplusplus
total: 2 errors, 3 warnings, 47 lines checked
Patch 2/2 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
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Cc'ing MediaTek reviewers.
Quoted 23 lines · Paolo Bonzini
qemu/osdep.his quite special in that, despite being part of QEMU sources, it is included by C++ source files as well.disas/nanomips.cpp is doing so within an 'extern "C"' block, which breaks with latest glib due to the inclusion of templates in
glib.h.These patches implement Daniel Berrangé's idea of pushing the 'extern "C"' block within
glib.hand including system headers (includingglib.h, and in fact QEMU's ownglib-compat.htoo) *outside* the block.(CI has not finished running yet, but it seems encouraging).
Paolo
Paolo Bonzini (2):
osdep: includeglib-compat.hbefore other QEMU headers
osdep: protectqemu/osdep.hwith extern "C"disas/nanomips.cpp | 2 +- include/qemu/compiler.h | 6 ++++++ include/qemu/osdep.h | 13 +++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-)
Hi Paolo,
Can you specify how to reproduce the issue ? We need more details about environment.
In my case, everything seems to work fine for the newest version of glib (2.68).
Thank you,
Aleksandar
Quoted 18 lines
qemu/osdep.his quite special in that, despite being part of QEMU sources, it is included by C++ source files as well.disas/nanomips.cpp is doing so within an 'extern "C"' block, which breaks with latest glib due to the inclusion of templates in
glib.h.These patches implement Daniel Berrangé's idea of pushing the 'extern "C"' block within
glib.hand including system headers (includingglib.h, and in fact QEMU's ownglib-compat.htoo) *outside* the block.(CI has not finished running yet, but it seems encouraging).
Paolo
Paolo Bonzini (2):
osdep: includeglib-compat.hbefore other QEMU headers
osdep: protectqemu/osdep.hwith extern "C"
Quoted 7 lines
disas/nanomips.cpp | 2 +- include/qemu/compiler.h | 6 ++++++ include/qemu/osdep.h | 13 +++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-)--
2.30.1
________________________________
From: Philippe Mathieu-Daudé <[email protected]> on behalf of Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, April 13, 2021 5:58 PM
To: Paolo Bonzini <[email protected]>; [email protected] <[email protected]>
Cc: [email protected] <[email protected]>; [email protected] <[email protected]>; Aleksandar Rikalo <[email protected]>; [email protected] <[email protected]>; Petar Jovanovic <[email protected]>; Filip Vidojevic <[email protected]>
Subject: Re: [PATCH 0/2] osdep: allow including qemu/osdep.h outside extern "C"
Cc'ing MediaTek reviewers.
Quoted 23 lines · Paolo Bonzini
qemu/osdep.his quite special in that, despite being part of QEMU sources, it is included by C++ source files as well.disas/nanomips.cpp is doing so within an 'extern "C"' block, which breaks with latest glib due to the inclusion of templates in
glib.h.These patches implement Daniel Berrangé's idea of pushing the 'extern "C"' block within
glib.hand including system headers (includingglib.h, and in fact QEMU's ownglib-compat.htoo) *outside* the block.(CI has not finished running yet, but it seems encouraging).
Paolo
Paolo Bonzini (2):
osdep: includeglib-compat.hbefore other QEMU headers
osdep: protectqemu/osdep.hwith extern "C"disas/nanomips.cpp | 2 +- include/qemu/compiler.h | 6 ++++++ include/qemu/osdep.h | 13 +++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-)