diff mbox series

[for-6.0?,4/6] osdep: Make os-win32.h and os-posix.h handle 'extern "C"' themselves

Message ID 20210416135543.20382-5-peter.maydell@linaro.org (mailing list archive)
State New
Headers show
Series extern "C" overhaul for C++ files | expand

Commit Message

Peter Maydell April 16, 2021, 1:55 p.m. UTC
Both os-win32.h and os-posix.h include system header files. Instead
of having osdep.h include them inside its 'extern "C"' block, make
these headers handle that themselves, so that we don't include the
system headers inside 'extern "C"'.

This doesn't fix any current problems, but it's conceptually the
right way to handle system headers.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 include/qemu/osdep.h      | 8 ++++----
 include/sysemu/os-posix.h | 8 ++++++++
 include/sysemu/os-win32.h | 8 ++++++++
 3 files changed, 20 insertions(+), 4 deletions(-)

Comments

Paolo Bonzini April 16, 2021, 4:25 p.m. UTC | #1
On 16/04/21 15:55, Peter Maydell wrote:
>   #ifdef _WIN32
>   #include "sysemu/os-win32.h"
>   #endif
> @@ -143,6 +139,10 @@ extern "C" {
>   #include "sysemu/os-posix.h"
>   #endif
>   
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
>   #include "qemu/typedefs.h"
>   
>   /*
> diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
> index 629c8c648b7..2edf33658a4 100644
> --- a/include/sysemu/os-posix.h
> +++ b/include/sysemu/os-posix.h
> @@ -38,6 +38,10 @@
>   #include <sys/sysmacros.h>
>   #endif
>   
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +

include/sysemu/ is also the wrong directory to have these headers, which 
probably should be split into a qemu/osdep-{win32,posix}.h part and an 
actual sysemu/os-{win32,posix}.h part.  But this is good enough for now.

Paolo
Peter Maydell April 16, 2021, 4:25 p.m. UTC | #2
On Fri, 16 Apr 2021 at 17:25, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 16/04/21 15:55, Peter Maydell wrote:
> >   #ifdef _WIN32
> >   #include "sysemu/os-win32.h"
> >   #endif
> > @@ -143,6 +139,10 @@ extern "C" {
> >   #include "sysemu/os-posix.h"
> >   #endif
> >
> > +#ifdef __cplusplus
> > +extern "C" {
> > +#endif
> > +
> >   #include "qemu/typedefs.h"
> >
> >   /*
> > diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
> > index 629c8c648b7..2edf33658a4 100644
> > --- a/include/sysemu/os-posix.h
> > +++ b/include/sysemu/os-posix.h
> > @@ -38,6 +38,10 @@
> >   #include <sys/sysmacros.h>
> >   #endif
> >
> > +#ifdef __cplusplus
> > +extern "C" {
> > +#endif
> > +
>
> include/sysemu/ is also the wrong directory to have these headers, which
> probably should be split into a qemu/osdep-{win32,posix}.h part and an
> actual sysemu/os-{win32,posix}.h part.  But this is good enough for now.

Yeah, I thought as I was writing this that it was odd that these are
in sysemu/ but osdep itself is in qemu/...

thanks
-- PMM
Richard Henderson April 16, 2021, 5:17 p.m. UTC | #3
On 4/16/21 6:55 AM, Peter Maydell wrote:
> Both os-win32.h and os-posix.h include system header files. Instead
> of having osdep.h include them inside its 'extern "C"' block, make
> these headers handle that themselves, so that we don't include the
> system headers inside 'extern "C"'.
> 
> This doesn't fix any current problems, but it's conceptually the
> right way to handle system headers.
> 
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
>   include/qemu/osdep.h      | 8 ++++----
>   include/sysemu/os-posix.h | 8 ++++++++
>   include/sysemu/os-win32.h | 8 ++++++++
>   3 files changed, 20 insertions(+), 4 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
diff mbox series

Patch

diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h
index cb2a07e472e..4c6f2390be4 100644
--- a/include/qemu/osdep.h
+++ b/include/qemu/osdep.h
@@ -131,10 +131,6 @@  QEMU_EXTERN_C int daemon(int, int);
  */
 #include "glib-compat.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 #ifdef _WIN32
 #include "sysemu/os-win32.h"
 #endif
@@ -143,6 +139,10 @@  extern "C" {
 #include "sysemu/os-posix.h"
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "qemu/typedefs.h"
 
 /*
diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index 629c8c648b7..2edf33658a4 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -38,6 +38,10 @@ 
 #include <sys/sysmacros.h>
 #endif
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 void os_set_line_buffering(void);
 void os_set_proc_name(const char *s);
 void os_setup_signal_handling(void);
@@ -92,4 +96,8 @@  static inline void qemu_funlockfile(FILE *f)
     funlockfile(f);
 }
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index 5346d51e890..43f569b5c21 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -30,6 +30,10 @@ 
 #include <windows.h>
 #include <ws2tcpip.h>
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #if defined(_WIN64)
 /* On w64, setjmp is implemented by _setjmp which needs a second parameter.
  * If this parameter is NULL, longjump does no stack unwinding.
@@ -194,4 +198,8 @@  ssize_t qemu_recv_wrap(int sockfd, void *buf, size_t len, int flags);
 ssize_t qemu_recvfrom_wrap(int sockfd, void *buf, size_t len, int flags,
                            struct sockaddr *addr, socklen_t *addrlen);
 
+#ifdef __cplusplus
+}
+#endif
+
 #endif