RFC: Make xen's public headers a little friendlier for C++.
PATCH 1/1 RFC: Make xen's public headers a little friendlier for C++.
Shuffle some struct definitions up to file scope so that they remain in scope in C++ when they're used again later.
Add an automatic check for similar C++ pitfalls, to be run only when g++ is available.
RFC because it's not clear whether we want to make any commitments to have the public headers be C++-friendly.
Explicitly _not_ addressing the use of 'private' in various fields, since we'd previously decided not to fix that.
--- .gitignore | 1 + xen/include/Makefile | 12 +++++++++--- xen/include/public/platform.h | 39 ++++++++++++++++++++++----------------- 3 files changed, 32 insertions(+), 20 deletions(-)
.gitignore +1 -0
@@ -233,6 +233,7 @@ xen/arch/*/efi/compat.c xen/arch/*/efi/efi.h xen/arch/*/efi/runtime.c xen/include/headers.chk +xen/include/headers++.chk xen/include/asm xen/include/asm-*/asm-offsets.h xen/include/compat/*
xen/include/Makefile +9 -3
@@ -87,13 +87,19 @@ compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile ifeq ($(XEN_TARGET_ARCH),$(XEN_COMPILE_ARCH)) -all: headers.chk +all: headers.chk headers++.chk -headers.chk: $(filter-out public/arch-% public/%ctl.h public/xsm/% public/%hvm/save.h, $(wildcard public/*.h public/*/*.h) $(public-y)) Makefile +PUBLIC_HEADERS_TO_CHECK := $(filter-out public/arch-% public/%ctl.h public/xsm/% public/%hvm/save.h, $(wildcard public/*.h public/*/*.h) $(public-y)) + +headers.chk: $(PUBLIC_HEADERS_TO_CHECK) Makefile for i in $(filter %.h,$^); do $(CC) -ansi -include stdint.h -Wall -W -Werror -S -o /dev/null -x c $$i || exit 1; echo $$i; done >[email protected] mv [email protected] $@ +headers++.chk: $(PUBLIC_HEADERS_TO_CHECK) Makefile + if g++ -v >/dev/null; then for i in $(filter %.h,$^); do g++ -ansi -include stdint.h -Wall -W -Werror -S -o /dev/null -x c++ -Dprivate=private_is_a_keyword_in_c_plus_plus $$i || exit 1; echo $$i; done ; fi >[email protected] + mv [email protected] $@ + endif clean:: - rm -rf compat headers.chk + rm -rf compat headers.chk headers++.chk
xen/include/public/platform.h +22 -17
@@ -126,6 +126,26 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_platform_quirk_t);#define XEN_EFI_query_variable_info 9#define XEN_EFI_query_capsule_capabilities 10#define XEN_EFI_update_capsule 11 + +struct xenpf_efi_guid { +uint32_t data1; +uint16_t data2; +uint16_t data3; +uint8_t data4[8 ]; +}; + +struct xenpf_efi_time { +uint16_t year; +uint8_t month; +uint8_t day; +uint8_t hour; +uint8_t min; +uint8_t sec; +uint32_t ns; +int16_t tz; +uint8_t daylight; +}; +struct xenpf_efi_runtime_call {uint32_t function;/*
@@ -138,17 +158,7 @@ struct xenpf_efi_runtime_call {union {#define XEN_EFI_GET_TIME_SET_CLEARS_NS 0x00000001struct { -struct xenpf_efi_time { -uint16_t year; -uint8_t month; -uint8_t day; -uint8_t hour; -uint8_t min; -uint8_t sec; -uint32_t ns; -int16_t tz; -uint8_t daylight; - } time; +struct xenpf_efi_time time;uint32_t resolution;uint32_t accuracy; } get_time;
@@ -170,12 +180,7 @@ struct xenpf_efi_runtime_call {XEN_GUEST_HANDLE (void ) name;/* UCS-2/UTF-16 string */ xen_ulong_t size;XEN_GUEST_HANDLE (void ) data; -struct xenpf_efi_guid { -uint32_t data1; -uint16_t data2; -uint16_t data3; -uint8_t data4[8 ]; - } vendor_guid; +struct xenpf_efi_guid vendor_guid; } get_variable, set_variable;struct {
Signature · 1 line
2.1.4
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 14:11, <[email protected]> wrote:
Shuffle some struct definitions up to file scope so that they remain in scope in C++ when they're used again later.
Add an automatic check for similar C++ pitfalls, to be run only when g++ is available.
RFC because it's not clear whether we want to make any commitments to have the public headers be C++-friendly.
I like this, and it looks it was easier to do than I thought. Albeit ...
Quoted 7 lines
xen/include/Makefile +0
-1@@ -87,13 +87,19 @@ compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile ifeq ($(XEN_TARGET_ARCH),$(XEN_COMPILE_ARCH)) -all: headers.chk
xen/include/Makefile compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile · line 98
Quoted 10 lines
xen/include/Makefile +5
-1+all: headers.chk headers++.chk -headers.chk: $(filter-out public/arch-% public/%ctl.h public/xsm/% public/%hvm/save.h, $(wildcard public/*.h public/*/*.h) $(public-y)) Makefile +PUBLIC_HEADERS_TO_CHECK := $(filter-out public/arch-% public/%ctl.h public/xsm/% public/%hvm/save.h, $(wildcard public/*.h public/*/*.h) $(public-y)) + +headers.chk: $(PUBLIC_HEADERS_TO_CHECK) Makefile for i in $(filter %.h,$^); do $(CC) -ansi -include stdint.h -Wall -W -Werror -S -o /dev/null -x c $$i || exit 1; echo $$i; done >[email protected] mv [email protected] $@ +headers++.chk: $(PUBLIC_HEADERS_TO_CHECK) Makefile
... I don't think limiting this to a subset of the headers is the right thing here: C++ consumers are (most likely) going to be user space, i.e. tools, and those would want to be able to use those excluded headers.
xen/include/Makefile compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile · line 99
Quoted 1 line
xen/include/Makefile +1
-0+ if g++ -v >/dev/null; then for i in $(filter %.h,$^); do g++ -ansi -include stdint.h -Wall -W -Werror -S -o /dev/null -x c++ -Dprivate=private_is_a_keyword_in_c_plus_plus $$i || exit 1; echo $$i; done ; fi >[email protected]
You may want to define __XEN_TOOLS__ (and un-define __XEN__) here. Also g++ ought to by abstracted to $(CXX), and I don't see how this step is being avoided when there's no C++ compiler there.
xen/include/public/platform.h
Quoted 2 lines
xen/include/public/platform.h +0
-0
These changes went in a few minutes ago.
Jan
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 14:11, <[email protected]> wrote:
xen/include/Makefile +3
-1-headers.chk: $(filter-out public/arch-% public/%ctl.h public/xsm/% public/%hvm/save.h, $(wildcard public/*.h public/*/*.h) $(public-y)) Makefile +PUBLIC_HEADERS_TO_CHECK := $(filter-out public/arch-% public/%ctl.h public/xsm/% public/%hvm/save.h, $(wildcard public/*.h public/*/*.h) $(public-y)) + +headers.chk: $(PUBLIC_HEADERS_TO_CHECK) Makefile for i in $(filter %.h,$^); do $(CC) -ansi -include stdint.h -Wall -W -Werror -S -o /dev/null -x c $$i || exit 1; echo $$i; done >[email protected] mv [email protected] $@
Quoted 6 lines
Quoted 1 line
+headers++.chk: $(PUBLIC_HEADERS_TO_CHECK)
Makefile... I don't think limiting this to a subset of the headers is the right thing here: C++ consumers are (most likely) going to be user space, i.e. tools, and those would want to be able to use those excluded headers.
OK. I'll have a look through that list. I presume I'll still want to exclude e.g. the arch/ headers on the grounds that users shouldn't be including them directly (and we won't want cross-arch includes)?
If I'm extending this to cover more headers than the ANSI-C check does, should I also relax the '-ansi' requirement to, e.g. '-std=gnu++98'?
Quoted 4 lines
xen/include/Makefile compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile · line 99
Quoted 1 line
xen/include/Makefile +1
-0+ if g++ -v >/dev/null; then for i in $(filter %.h,$^); do g++ -ansi -include stdint.h -Wall -W -Werror -S -o /dev/null -x c++ -Dprivate=private_is_a_keyword_in_c_plus_plus $$i || exit 1; echo $$i; done ; fi >[email protected]You may want to define
__XEN_TOOLS__(and un-define__XEN__) here.
OK. I wonder how many more things will break when I do that. :)
Quoted 1 line
Also g++ ought to by abstracted to $(CXX)
Sure, I'll define up $(CXX) in StdGnu.mk.
Quoted 2 lines
and I don't see
how this step is being avoided when there's no C++ compiler there.
if g++ isn't on the path, 'g++ -v' fails and we end up with an empty headers++.chk file. It doesn't deal with a present-but-broken g++ but that way lies autoconf.
Quoted 4 lines
xen/include/public/platform.h
Quoted 2 lines
xen/include/public/platform.h +0
-0These changes went in a few minutes ago.
Good-oh; I'll drop them from a v2.
Tim.
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 16:22, <[email protected]> wrote:
Quoted 3 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 14:11, <[email protected]> wrote:
+headers++.chk: $(PUBLIC_HEADERS_TO_CHECK)
Makefile
Quoted 8 lines
Quoted 4 lines
... I don't think limiting this to a subset of the headers is the right thing here: C++ consumers are (most likely) going to be user space, i.e. tools, and those would want to be able to use those excluded headers.
OK. I'll have a look through that list. I presume I'll still want to exclude e.g. the
arch/headers on the grounds that users shouldn't be including them directly (and we won't want cross-arch includes)?
Aren't even our tools doing cross-arch includes. I've been trying to remember why they're excluded from the C check, but can't.
Quoted 2 lines
If I'm extending this to cover more headers than the ANSI-C check does, should I also relax the '-ansi' requirement to, e.g. '-std=gnu++98'?
I think that would be reasonable nowadays. Anyone wanting compatibility farther back could contribute a patch...
Quoted 5 lines
Quoted 2 lines
and I don't see
how this step is being avoided when there's no C++ compiler there.if g++ isn't on the path, 'g++ -v' fails and we end up with an empty headers++.chk file.
The line is so long that I overlooked that "if g++ -v" at the beginning (having expected some different mechanism, like suppressing the dependency in that case). Sorry for the noise.
Jan
PATCH v2 1/1 RFC: Automatically check xen's public headers for C++ pitfalls.
In reply to Tim DeeganAdd a check, like the existing check for non-ANSI C in the public headers, that runs the public headers through a C++ compiler to flag non-C++-friendly constructs.
Unlike the ANSI C check, we accept GCC-isms (gnu++98), and we also check various tools-only headers.
Explicitly _not_ addressing the use of 'private' in various fields, since we'd previously decided not to fix that.
Also tidy up the runes for these checks to be a bit more readable.
---
v2: test more headers;
define __XEN_TOOLS__;
use g++98 rather than ansi;
tidy the makefile for readability;
add a missing include to flask_op.h, which uses evtchn_port_t.
---
.gitignore | 1 +
config/StdGNU.mk | 2 ++
config/SunOS.mk | 1 +
xen/include/Makefile | 28 ++++++++++++++++++++++++----
xen/include/public/platform.h | 39 ++++++++++++++++++++++-----------------
xen/include/public/xsm/flask_op.h | 2 ++
6 files changed, 52 insertions(+), 21 deletions(-).gitignore +1 -0
@@ -233,6 +233,7 @@ xen/arch/*/efi/compat.c xen/arch/*/efi/efi.h xen/arch/*/efi/runtime.c xen/include/headers.chk +xen/include/headers++.chk xen/include/asm xen/include/asm-*/asm-offsets.h xen/include/compat/*
config/StdGNU.mk +2 -0
@@ -2,9 +2,11 @@ AS = $(CROSS_COMPILE)as LD = $(CROSS_COMPILE)ld ifeq ($(clang),y) CC = $(CROSS_COMPILE)clang +CXX = $(CROSS_COMPILE)clang++ LD_LTO = $(CROSS_COMPILE)llvm-ld else CC = $(CROSS_COMPILE)gcc +CXX = $(CROSS_COMPILE)g++ LD_LTO = $(CROSS_COMPILE)ld endif CPP = $(CC) -E
config/SunOS.mk +1 -0
@@ -2,6 +2,7 @@ AS = $(CROSS_COMPILE)gas LD = $(CROSS_COMPILE)gld CC = $(CROSS_COMPILE)gcc CPP = $(CROSS_COMPILE)gcc -E +CXX = $(CROSS_COMPILE)g++ AR = $(CROSS_COMPILE)gar RANLIB = $(CROSS_COMPILE)granlib NM = $(CROSS_COMPILE)gnm
xen/include/Makefile +24 -4
@@ -87,13 +87,33 @@ compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile ifeq ($(XEN_TARGET_ARCH),$(XEN_COMPILE_ARCH)) -all: headers.chk +all: headers.chk headers++.chk -headers.chk: $(filter-out public/arch-% public/%ctl.h public/xsm/% public/%hvm/save.h, $(wildcard public/*.h public/*/*.h) $(public-y)) Makefile - for i in $(filter %.h,$^); do $(CC) -ansi -include stdint.h -Wall -W -Werror -S -o /dev/null -x c $$i || exit 1; echo $$i; done >[email protected] +PUBLIC_HEADERS := $(filter-out public/arch-% public/dom0_ops.h, $(wildcard public/*.h public/*/*.h) $(public-y)) + +PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/% public/%hvm/save.h, $(PUBLIC_HEADERS)) + +headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile + for i in $(filter %.h,$^); do \ + $(CC) -x c -ansi -Wall -Werror -include stdint.h \ + -S -o /dev/null $$i || exit 1; \ + echo $$i; \ + done >[email protected] + mv [email protected] $@ + +headers++.chk: $(PUBLIC_HEADERS) Makefile + if $(CXX) -v >/dev/null 2>&1; then \ + for i in $(filter %.h,$^); do \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ + -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \ + -include stdint.h -include public/xen.h \ + -S -o /dev/null $$i || exit 1; \ + echo $$i; \ + done ; \ + fi >[email protected] mv [email protected] $@ endif clean:: - rm -rf compat headers.chk + rm -rf compat headers.chk headers++.chk
xen/include/public/platform.h +22 -17
@@ -126,6 +126,26 @@ DEFINE_XEN_GUEST_HANDLE(xenpf_platform_quirk_t);#define XEN_EFI_query_variable_info 9#define XEN_EFI_query_capsule_capabilities 10#define XEN_EFI_update_capsule 11 + +struct xenpf_efi_guid { +uint32_t data1; +uint16_t data2; +uint16_t data3; +uint8_t data4[8 ]; +}; + +struct xenpf_efi_time { +uint16_t year; +uint8_t month; +uint8_t day; +uint8_t hour; +uint8_t min; +uint8_t sec; +uint32_t ns; +int16_t tz; +uint8_t daylight; +}; +struct xenpf_efi_runtime_call {uint32_t function;/*
@@ -138,17 +158,7 @@ struct xenpf_efi_runtime_call {union {#define XEN_EFI_GET_TIME_SET_CLEARS_NS 0x00000001struct { -struct xenpf_efi_time { -uint16_t year; -uint8_t month; -uint8_t day; -uint8_t hour; -uint8_t min; -uint8_t sec; -uint32_t ns; -int16_t tz; -uint8_t daylight; - } time; +struct xenpf_efi_time time;uint32_t resolution;uint32_t accuracy; } get_time;
@@ -170,12 +180,7 @@ struct xenpf_efi_runtime_call {XEN_GUEST_HANDLE (void ) name;/* UCS-2/UTF-16 string */ xen_ulong_t size;XEN_GUEST_HANDLE (void ) data; -struct xenpf_efi_guid { -uint32_t data1; -uint16_t data2; -uint16_t data3; -uint8_t data4[8 ]; - } vendor_guid; +struct xenpf_efi_guid vendor_guid; } get_variable, set_variable;struct {
xen/include/public/xsm/flask_op.h +2 -0
@@ -25,6 +25,8 @@#ifndef __FLASK_OP_H__#define __FLASK_OP_H__ +#include "../event_channel.h" +#define XEN_FLASK_INTERFACE_VERSION 1 struct xen_flask_load {
Signature · 1 line
2.1.4
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 3 lines · Tim Deegan
Add a check, like the existing check for non-ANSI C in the public headers, that runs the public headers through a C++ compiler to flag non-C++-friendly constructs.
Oops, this still has the EFI changes in it. v3, rebased, is on its way.
Quoted 5 lines
Unlike the ANSI C check, we accept GCC-isms (gnu++98), and we also check various tools-only headers.
Explicitly _not_ addressing the use of 'private' in various fields, since we'd previously decided not to fix that.
BTW, ring.h is the only instance of that, so the extra diff to clear that up too is pretty small (see below).
Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
xen/include/Makefile +1 -2
@@ -104,8 +104,7 @@ headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile headers++.chk: $(PUBLIC_HEADERS) Makefile if $(CXX) -v >/dev/null 2>&1; then \ for i in $(filter %.h,$^); do \ - $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ - -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror -D__XEN_TOOLS__ \ -include stdint.h -include public/xen.h \ -S -o /dev/null $$i || exit 1; \ echo $$i; \
xen/include/public/io/ring.h +2 -2
@@ -111,7 +111,7 @@ struct __name##_sring { \uint8_t msg; \ } tapif_user; \uint8_t pvt_pad[4 ]; \ - } private; \ + } local; \uint8_t __pad[44 ]; \ union __name##_sring_entry ring[1]; /* variable-length */ \ }; \
@@ -156,7 +156,7 @@ typedef struct __name##_back_ring __name##_back_ring_t#define SHARED_RING_INIT (_s) do { \ (_s)->req_prod = (_s)->rsp_prod = 0; \ (_s)->req_event = (_s)->rsp_event = 1; \ - (void)memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad)); \ + (void)memset((_s)->local.pvt_pad, 0, sizeof((_s)->local.pvt_pad)); \ (void)memset((_s)->__pad, 0, sizeof((_s)->__pad)); \ } while(0)
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 9 lines · Tim Deegan
Quoted 3 lines · Tim Deegan
Add a check, like the existing check for non-ANSI C in the public headers, that runs the public headers through a C++ compiler to flag non-C++-friendly constructs.
Oops, this still has the EFI changes in it. v3, rebased, is on its way.
Quoted 3 lines
Unlike the ANSI C check, we accept GCC-isms (gnu++98), and we also check various tools-only headers.
Quoted 8 lines
Quoted 2 lines
Explicitly _not_ addressing the use of 'private' in various fields, since we'd previously decided not to fix that.
BTW,
ring.his the only instance of that, so the extra diff to clear that up too is pretty small (see below).Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
It is basically no effort, wont (directly) break consumers, and will make the headers fully friendly (other than extern C, which can be dealt with using the C++ #include <c$FOO> pattern).
+1 throw this in and be done with the incompatibilities for good.
~Andrew
Quoted 44 lines
xen/include/Makefile +1
-2@@ -104,8 +104,7 @@ headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile headers++.chk: $(PUBLIC_HEADERS) Makefile if $(CXX) -v >/dev/null 2>&1; then \ for i in $(filter %.h,$^); do \ - $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ - -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror -D__XEN_TOOLS__ \ -include stdint.h -include public/xen.h \ -S -o /dev/null $$i || exit 1; \ echo $$i; \xen/include/public/io/ring.h +2
-2@@ -111,7 +111,7 @@ struct __name##_sring { \uint8_t msg; \ } tapif_user; \uint8_t pvt_pad[4 ]; \ - } private; \ + } local; \uint8_t __pad[44 ]; \ union __name##_sring_entry ring[1]; /* variable-length */ \ }; \@@ -156,7 +156,7 @@ typedef struct __name##_back_ring __name##_back_ring_t#define SHARED_RING_INIT (_s) do { \ (_s)->req_prod = (_s)->rsp_prod = 0; \ (_s)->req_event = (_s)->rsp_event = 1; \ - (void)memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad)); \ + (void)memset((_s)->local.pvt_pad, 0, sizeof((_s)->local.pvt_pad)); \ (void)memset((_s)->__pad, 0, sizeof((_s)->__pad)); \ } while(0)_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
In reply to Tim DeeganQuoted 11 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 17:28, <[email protected]> wrote:
Quoted 2 lines · Tim Deegan
Explicitly _not_ addressing the use of 'private' in various fields, since we'd previously decided not to fix that.
BTW,
ring.his the only instance of that, so the extra diff to clear that up too is pretty small (see below).Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
linux-2.6.18-xen.hg always having consumed them (almost) verbatim, I don't think we should break users not massaging the headers. I.e. at least make the field name conditional upon using C vs C++.
Jan
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 8 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 17:28, <[email protected]> wrote:
Quoted 2 lines · Tim Deegan
Explicitly _not_ addressing the use of 'private' in various fields, since we'd previously decided not to fix that.
BTW,
ring.his the only instance of that, so the extra diff to clear that up too is pretty small (see below).
Quoted 8 lines
Quoted 3 lines
Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
linux-2.6.18-xen.hg always having consumed them (almost) verbatim, I don't think we should break users not massaging the headers. I.e. at least make the field name conditional upon using C vs C++.
Something like this? This is the kind of uglification that I would like to avoid, though (and I don't like '#define private pvt' much either).
Tim.
xen/include/Makefile +1 -2
@@ -104,8 +104,7 @@ headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile headers++.chk: $(PUBLIC_HEADERS) Makefile if $(CXX) -v >/dev/null 2>&1; then \ for i in $(filter %.h,$^); do \ - $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ - -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror -D__XEN_TOOLS__ \ -include stdint.h -include public/xen.h \ -S -o /dev/null $$i || exit 1; \ echo $$i; \
xen/include/public/io/ring.h +12 -2
@@ -35,6 +35,15 @@#define xen_wmb () wmb()#endif +#ifdef __cplusplus +/* 'private' is a keyword in C++, so we have to use a different name for +* private state there. Leaving the C name alone to avoid unnecessary +* pain for the existing users. */ +#define XEN_RING_PRIVATE pvt +#else +#define XEN_RING_PRIVATE private +#endif +typedef unsigned int RING_IDX ;/* Round a 32-bit unsigned constant down to the nearest power of two. */
@@ -111,7 +120,7 @@ struct __name##_sring { \uint8_t msg; \ } tapif_user; \uint8_t pvt_pad[4 ]; \ - } private; \ + }XEN_RING_PRIVATE ; \uint8_t __pad[44 ]; \ union __name##_sring_entry ring[1]; /* variable-length */ \ }; \
@@ -156,7 +165,8 @@ typedef struct __name##_back_ring __name##_back_ring_t#define SHARED_RING_INIT (_s) do { \ (_s)->req_prod = (_s)->rsp_prod = 0; \ (_s)->req_event = (_s)->rsp_event = 1; \ - (void)memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad)); \ + (void)memset((_s)->XEN_RING_PRIVATE.pvt_pad, 0, \ + sizeof((_s)->XEN_RING_PRIVATE.pvt_pad)); \ (void)memset((_s)->__pad, 0, sizeof((_s)->__pad)); \ } while(0)
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
xen/include/public/io/ring.h line 45
Quoted 8 lines · Tim Deegan
xen/include/public/io/ring.h +8
-0+#ifdef __cplusplus +/* 'private' is a keyword in C++, so we have to use a different name for +* private state there. Leaving the C name alone to avoid unnecessary +* pain for the existing users. */ +#define XEN_RING_PRIVATE pvt +#else +#define XEN_RING_PRIVATE private +#endif
Are there likely to be many users outside of the ones using that code with mem_event? Because if there aren't, there are much more drastic changes happening in Tamas' pending series, so perhaps seen that way the change becomes more acceptable.
Thanks,
Razvan
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 12 lines · Razvan Cojocaru
xen/include/public/io/ring.h line 45
Quoted 8 lines · Tim Deegan
xen/include/public/io/ring.h +8
-0+#ifdef __cplusplus +/* 'private' is a keyword in C++, so we have to use a different name for +* private state there. Leaving the C name alone to avoid unnecessary +* pain for the existing users. */ +#define XEN_RING_PRIVATE pvt +#else +#define XEN_RING_PRIVATE private +#endif Are there likely to be many users outside of the ones using that code with
mem_event?
Yes, lots. It's used to implement split drivers for net, block, etc. Most users will have taken copies of this header into their own trees, though, and so won't face build breakage, and this isn't an ABI change.
So far, I've seen David and Andrew in favour of just changing the field's name and letting out-of-tree users update their copies when/if they want to. Jan would prefer to avoid changing the field name for C users. I'm not delighted with any of these options but I think this ifdeffery is worse than the others. :)
Let's see what anyone else has to say.
Cheers,
Tim.
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 18 lines · Tim Deegan
Quoted 12 lines · Razvan Cojocaru
xen/include/public/io/ring.h line 45
Quoted 8 lines · Tim Deegan
xen/include/public/io/ring.h +8
-0+#ifdef __cplusplus +/* 'private' is a keyword in C++, so we have to use a different name for +* private state there. Leaving the C name alone to avoid unnecessary +* pain for the existing users. */ +#define XEN_RING_PRIVATE pvt +#else +#define XEN_RING_PRIVATE private +#endif Are there likely to be many users outside of the ones using that code with
mem_event?Yes, lots. It's used to implement split drivers for net, block, etc. Most users will have taken copies of this header into their own trees, though, and so won't face build breakage, and this isn't an ABI change.
Quoted 8 lines
So far, I've seen David and Andrew in favour of just changing the field's name and letting out-of-tree users update their copies when/if they want to. Jan would prefer to avoid changing the field name for C users. I'm not delighted with any of these options but I think this ifdeffery is worse than the others. :)
Let's see what anyone else has to say.
Since I am one of the user of C++ and Xen headers, I like this a lot. I do not like the ifdeffery above. I am in favour of just changing the the field's name.
-Don Slutz
Quoted 9 lines
Cheers,
Tim.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
In reply to Tim DeeganQuoted 14 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 18:01, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 17:28, <[email protected]> wrote:
Quoted 2 lines · Tim Deegan
Explicitly _not_ addressing the use of 'private' in various fields, since we'd previously decided not to fix that.
BTW,
ring.his the only instance of that, so the extra diff to clear that up too is pretty small (see below).Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
Quoted 8 lines
Quoted 4 lines
linux-2.6.18-xen.hg always having consumed them (almost) verbatim, I don't think we should break users not massaging the headers. I.e. at least make the field name conditional upon using C vs C++.
Something like this? This is the kind of uglification that I would like to avoid, though (and I don't like '#define private pvt' much either).
Yes, and perhaps the definition part put into xen-compat.h instead of io/ring.h (e.g. as XEN_PRIVATE, or - leaving room in case C++ grows more keywords - a more generic XEN_CXX()). I don't view this as all that ugly.
Jan
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
In reply to Tim DeeganQuoted 7 lines · Tim Deegan
BTW,
ring.his the only instance of that, so the extra diff to clear that up too is pretty small (see below).Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
With my linux maintainer hat on, this is fine by me.
David
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
In reply to Tim DeeganQuoted 6 lines · Tim Deegan
BTW,
ring.his the only instance of that, so the extra diff to clear that up too is pretty small (see below).Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
So I've seen four responses in favour of just renaming the field (Andrew Cooper, Razvan Cojocaru, Don Slutz and David Vrabel) and one in favour of #ifdeffing it so it's only renamed in C++ (Jan Beulich). I really don't like adding more #ifdefs to an already hard-to-read file; I'd rather just rename the field, or else leaving it alone and letting C++ users carry the fixup in their own code.
CC'ing the other "THE REST" maintainers for their opinions.
Tim.
Quoted 38 lines
xen/include/Makefile +1
-2@@ -104,8 +104,7 @@ headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile headers++.chk: $(PUBLIC_HEADERS) Makefile if $(CXX) -v >/dev/null 2>&1; then \ for i in $(filter %.h,$^); do \ - $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ - -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror -D__XEN_TOOLS__ \ -include stdint.h -include public/xen.h \ -S -o /dev/null $$i || exit 1; \ echo $$i; \xen/include/public/io/ring.h +2
-2@@ -111,7 +111,7 @@ struct __name##_sring { \uint8_t msg; \ } tapif_user; \uint8_t pvt_pad[4 ]; \ - } private; \ + } local; \uint8_t __pad[44 ]; \ union __name##_sring_entry ring[1]; /* variable-length */ \ }; \@@ -156,7 +156,7 @@ typedef struct __name##_back_ring __name##_back_ring_t#define SHARED_RING_INIT (_s) do { \ (_s)->req_prod = (_s)->rsp_prod = 0; \ (_s)->req_event = (_s)->rsp_event = 1; \ - (void)memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad)); \ + (void)memset((_s)->local.pvt_pad, 0, sizeof((_s)->local.pvt_pad)); \ (void)memset((_s)->__pad, 0, sizeof((_s)->__pad)); \ } while(0)
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 8 lines · Tim Deegan
Quoted 6 lines · Tim Deegan
BTW,
ring.his the only instance of that, so the extra diff to clear that up too is pretty small (see below).Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
Quoted 8 lines
So I've seen four responses in favour of just renaming the field (Andrew Cooper, Razvan Cojocaru, Don Slutz and David Vrabel) and one in favour of #ifdeffing it so it's only renamed in C++ (Jan Beulich). I really don't like adding more #ifdefs to an already hard-to-read file; I'd rather just rename the field, or else leaving it alone and letting C++ users carry the fixup in their own code.
CC'ing the other "THE REST" maintainers for their opinions.
Rather than ifdefs for C++, don't we need them based on __XEN_INTERFACE_VERSION__?
I don't much like that (I'd rather just change the name) but I think that's what we are supposed to do here.
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 05.03.15 at 12:35, <[email protected]> wrote:
Quoted 15 lines · Tim Deegan
Quoted 6 lines · Tim Deegan
BTW,
ring.his the only instance of that, so the extra diff to clear that up too is pretty small (see below).Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
So I've seen four responses in favour of just renaming the field (Andrew Cooper, Razvan Cojocaru, Don Slutz and David Vrabel) and one in favour of #ifdeffing it so it's only renamed in C++ (Jan Beulich). I really don't like adding more #ifdefs to an already hard-to-read file; I'd rather just rename the field, or else leaving it alone and letting C++ users carry the fixup in their own code.
Quoted 4 lines
Quoted 1 line
CC'ing the other "THE REST" maintainers for their opinions.
Rather than ifdefs for C++, don't we need them based on
__XEN_INTERFACE_VERSION__?
That's not applicable to the stuff under public/io/.
Jan
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 17 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line · On 05.03.15 at 12:35, <[email protected]> wrote:
Quoted 15 lines · Tim Deegan
Quoted 6 lines · Tim Deegan
BTW,
ring.his the only instance of that, so the extra diff to clear that up too is pretty small (see below).Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
So I've seen four responses in favour of just renaming the field (Andrew Cooper, Razvan Cojocaru, Don Slutz and David Vrabel) and one in favour of #ifdeffing it so it's only renamed in C++ (Jan Beulich). I really don't like adding more #ifdefs to an already hard-to-read file; I'd rather just rename the field, or else leaving it alone and letting C++ users carry the fixup in their own code.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
CC'ing the other "THE REST" maintainers for their opinions.
Rather than ifdefs for C++, don't we need them based on
__XEN_INTERFACE_VERSION__?That's not applicable to the stuff under public/io/.
In which case I'd certainly prefer just changing the name and getting it over with.
mini-os would need checking, since that's (AFAIK) the only intree user of these headers. (Probably now that it is split out it ought to do as everything else now does and take a copy)
Ian.
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 23 lines · Ian Campbell
Quoted 22 lines · Jan Beulich
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 05.03.15 at 12:35, <[email protected]> wrote:
Quoted 8 lines · Tim Deegan
Quoted 6 lines · Tim Deegan
BTW,
ring.his the only instance of that, so the extra diff to clear that up too is pretty small (see below).Not sure what people think about that though - it might be quite a PITA for downstream users of it, though they ought really to be using local copies so they can update in a controlled way.
Quoted 8 lines
So I've seen four responses in favour of just renaming the field (Andrew Cooper, Razvan Cojocaru, Don Slutz and David Vrabel) and one in favour of #ifdeffing it so it's only renamed in C++ (Jan Beulich). I really don't like adding more #ifdefs to an already hard-to-read file; I'd rather just rename the field, or else leaving it alone and letting C++ users carry the fixup in their own code.
CC'ing the other "THE REST" maintainers for their opinions.
Rather than ifdefs for C++, don't we need them based on
__XEN_INTERFACE_VERSION__?
Quoted 9 lines
Quoted 1 line
That's not applicable to the stuff under public/io/.
In which case I'd certainly prefer just changing the name and getting it over with.
mini-os would need checking, since that's (AFAIK) the only intree user of these headers. (Probably now that it is split out it ought to do as everything else now does and take a copy)
Yes, mini-os now is just like any other Xen guests, which carries a copy of all Xen public headers. Taking a new copy is OK.
Wei.
Quoted 1 line
Ian.
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 2 lines · Wei Liu
Yes, mini-os now is just like any other Xen guests, which carries a copy of all Xen public headers. Taking a new copy is OK.
Ah, I forgot you'd already done this. Super!
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
In reply to Ian CampbellQuoted 15 lines · Ian Campbell
Quoted 14 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 05.03.15 at 12:35, <[email protected]> wrote:
Quoted 8 lines · Tim Deegan
So I've seen four responses in favour of just renaming the field (Andrew Cooper, Razvan Cojocaru, Don Slutz and David Vrabel) and one in favour of #ifdeffing it so it's only renamed in C++ (Jan Beulich). I really don't like adding more #ifdefs to an already hard-to-read file; I'd rather just rename the field, or else leaving it alone and letting C++ users carry the fixup in their own code.
CC'ing the other "THE REST" maintainers for their opinions.
Rather than ifdefs for C++, don't we need them based on
__XEN_INTERFACE_VERSION__?
Quoted 7 lines
Quoted 1 line
That's not applicable to the stuff under public/io/.
In which case I'd certainly prefer just changing the name and getting it over with.
mini-os would need checking, since that's (AFAIK) the only intree user of these headers.
mini-os doesn't in fact use this field; it's a blktap2-ism. Here's a (non-RFC) patch to rename it and update blktap2:
Quoted 1 line
From
a97715b97a02c3182914cee90b363d2939c5d416Mon Sep 17 00:00:00 2001
From: Tim Deegan <[email protected]>
Date: Thu, 5 Mar 2015 12:11:25 +0000
Subject: [PATCH] xen: don't use C++ keyword 'private' in public headers.
The 'private' field in io/ring.h (for blktap2, see 1b9cecdb) is the last thing in the Xen public headers that a C++ compiler will object to.
Rename it to pvt, update the only in-tree user, and remove the workaround in the C++ compatibility check.
--- tools/blktap2/drivers/tapdisk-vbd.c | 2 +- xen/include/Makefile | 3 +-- xen/include/public/io/ring.h | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-)
tools/blktap2/drivers/tapdisk-vbd.c +1 -1
@@ -1684,7 +1684,7 @@ tapdisk_vbd_check_ring_message(td_vbd_t *vbd)if (!vbd->ring.sring)return -EINVAL ; -switch (vbd->ring.sring->private.tapif_user.msg) { +switch (vbd->ring.sring->pvt.tapif_user.msg) {case 0 :return 0 ;
xen/include/Makefile +1 -2
@@ -104,8 +104,7 @@ headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile headers++.chk: $(PUBLIC_HEADERS) Makefile if $(CXX) -v >/dev/null 2>&1; then \ for i in $(filter %.h,$^); do \ - $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ - -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror -D__XEN_TOOLS__ \ -include stdint.h -include public/xen.h \ -S -o /dev/null $$i || exit 1; \ echo $$i; \
xen/include/public/io/ring.h +2 -2
@@ -111,7 +111,7 @@ struct __name##_sring { \uint8_t msg; \ } tapif_user; \uint8_t pvt_pad[4 ]; \ - } private; \ + } pvt; \uint8_t __pad[44 ]; \ union __name##_sring_entry ring[1]; /* variable-length */ \ }; \
@@ -156,7 +156,7 @@ typedef struct __name##_back_ring __name##_back_ring_t#define SHARED_RING_INIT (_s) do { \ (_s)->req_prod = (_s)->rsp_prod = 0; \ (_s)->req_event = (_s)->rsp_event = 1; \ - (void)memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad)); \ + (void)memset((_s)->pvt.pvt_pad, 0, sizeof((_s)->pvt.pvt_pad)); \ (void)memset((_s)->__pad, 0, sizeof((_s)->__pad)); \ } while(0)
Signature · 1 line
2.1.4
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 18 lines · Tim Deegan
Quoted 17 lines · Ian Campbell
Quoted 15 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 05.03.15 at 12:35, <[email protected]> wrote:
Quoted 7 lines · Tim Deegan
So I've seen four responses in favour of just renaming the field (Andrew Cooper, Razvan Cojocaru, Don Slutz and David Vrabel) and one in favour of #ifdeffing it so it's only renamed in C++ (Jan Beulich). I really don't like adding more #ifdefs to an already hard-to-read file; I'd rather just rename the field, or else leaving it alone and letting C++ users carry the fixup in their own code.
Quoted 4 lines
Quoted 1 line
CC'ing the other "THE REST" maintainers for their opinions.
Rather than ifdefs for C++, don't we need them based on
__XEN_INTERFACE_VERSION__?That's not applicable to the stuff under public/io/.
Quoted 8 lines
Quoted 5 lines
In which case I'd certainly prefer just changing the name and getting it over with.
mini-os would need checking, since that's (AFAIK) the only intree user of these headers.
mini-os doesn't in fact use this field; it's a blktap2-ism. Here's a (non-RFC) patch to rename it and update blktap2:
Ian, Jan, can I get an Ack or Nack on this so I can clear it off my plate? :)
Tim.
Quoted 71 lines
From
a97715b97a02c3182914cee90b363d2939c5d416Mon Sep 17 00:00:00 2001
From: Tim Deegan <[email protected]>
Date: Thu, 5 Mar 2015 12:11:25 +0000
Subject: [PATCH] xen: don't use C++ keyword 'private' in public headers.The 'private' field in
io/ring.h(for blktap2, see1b9cecdb) is the last thing in the Xen public headers that a C++ compiler will object to.Rename it to pvt, update the only in-tree user, and remove the workaround in the C++ compatibility check.
Signed-off-by Tim Deegan <[email protected]>--- tools/blktap2/drivers/tapdisk-vbd.c | 2 +- xen/include/Makefile | 3 +-- xen/include/public/io/ring.h | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-)tools/blktap2/drivers/tapdisk-vbd.c +1
-1@@ -1684,7 +1684,7 @@ tapdisk_vbd_check_ring_message(td_vbd_t *vbd)if (!vbd->ring.sring)return -EINVAL ; -switch (vbd->ring.sring->private.tapif_user.msg) { +switch (vbd->ring.sring->pvt.tapif_user.msg) {case 0 :return 0 ;xen/include/Makefile +1
-2@@ -104,8 +104,7 @@ headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile headers++.chk: $(PUBLIC_HEADERS) Makefile if $(CXX) -v >/dev/null 2>&1; then \ for i in $(filter %.h,$^); do \ - $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ - -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror -D__XEN_TOOLS__ \ -include stdint.h -include public/xen.h \ -S -o /dev/null $$i || exit 1; \ echo $$i; \xen/include/public/io/ring.h +2
-2@@ -111,7 +111,7 @@ struct __name##_sring { \uint8_t msg; \ } tapif_user; \uint8_t pvt_pad[4 ]; \ - } private; \ + } pvt; \uint8_t __pad[44 ]; \ union __name##_sring_entry ring[1]; /* variable-length */ \ }; \@@ -156,7 +156,7 @@ typedef struct __name##_back_ring __name##_back_ring_t#define SHARED_RING_INIT (_s) do { \ (_s)->req_prod = (_s)->rsp_prod = 0; \ (_s)->req_event = (_s)->rsp_event = 1; \ - (void)memset((_s)->private.pvt_pad, 0, sizeof((_s)->private.pvt_pad)); \ + (void)memset((_s)->pvt.pvt_pad, 0, sizeof((_s)->pvt.pvt_pad)); \ (void)memset((_s)->__pad, 0, sizeof((_s)->__pad)); \ } while(0)Signature · 1 line
2.1.4
Ian Campbell
Acked-byRe: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 22 lines · Tim Deegan
Quoted 21 lines · Tim Deegan
Quoted 20 lines · Ian Campbell
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 05.03.15 at 12:35, <[email protected]> wrote:
Quoted 7 lines · Tim Deegan
So I've seen four responses in favour of just renaming the field (Andrew Cooper, Razvan Cojocaru, Don Slutz and David Vrabel) and one in favour of #ifdeffing it so it's only renamed in C++ (Jan Beulich). I really don't like adding more #ifdefs to an already hard-to-read file; I'd rather just rename the field, or else leaving it alone and letting C++ users carry the fixup in their own code.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
CC'ing the other "THE REST" maintainers for their opinions.
Rather than ifdefs for C++, don't we need them based on
__XEN_INTERFACE_VERSION__?That's not applicable to the stuff under public/io/.
In which case I'd certainly prefer just changing the name and getting it over with.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
mini-os would need checking, since that's (AFAIK) the only intree user of these headers.
mini-os doesn't in fact use this field; it's a blktap2-ism. Here's a (non-RFC) patch to rename it and update blktap2:
Ian, Jan, can I get an Ack or Nack on this so I can clear it off my plate? :)
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 26 lines · Ian Campbell
Quoted 25 lines · Tim Deegan
Quoted 24 lines · Tim Deegan
Quoted 22 lines · Ian Campbell
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 05.03.15 at 12:35, <[email protected]> wrote:
Quoted 7 lines · Tim Deegan
So I've seen four responses in favour of just renaming the field (Andrew Cooper, Razvan Cojocaru, Don Slutz and David Vrabel) and one in favour of #ifdeffing it so it's only renamed in C++ (Jan Beulich). I really don't like adding more #ifdefs to an already hard-to-read file; I'd rather just rename the field, or else leaving it alone and letting C++ users carry the fixup in their own code.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
CC'ing the other "THE REST" maintainers for their opinions.
Rather than ifdefs for C++, don't we need them based on
__XEN_INTERFACE_VERSION__?That's not applicable to the stuff under public/io/.
In which case I'd certainly prefer just changing the name and getting it over with.
mini-os would need checking, since that's (AFAIK) the only intree user of these headers.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
mini-os doesn't in fact use this field; it's a blktap2-ism. Here's a (non-RFC) patch to rename it and update blktap2:
Ian, Jan, can I get an Ack or Nack on this so I can clear it off my plate? :)
Acked-by Ian Campbell <[email protected]>
And pushed, thanks.
Tim.
Re: [PATCH v2] RFC: Automatically check xen's public headers for C++ pitfalls.
In reply to Tim DeeganQuoted 23 lines
Quoted 1 line
Quoted 1 line · On 12.03.15 at 11:03, <[email protected]> wrote:
Quoted 21 lines · Tim Deegan
Quoted 20 lines · Ian Campbell
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 05.03.15 at 12:35, <[email protected]> wrote:
Quoted 7 lines · Tim Deegan
So I've seen four responses in favour of just renaming the field (Andrew Cooper, Razvan Cojocaru, Don Slutz and David Vrabel) and one in favour of #ifdeffing it so it's only renamed in C++ (Jan Beulich). I really don't like adding more #ifdefs to an already hard-to-read file; I'd rather just rename the field, or else leaving it alone and letting C++ users carry the fixup in their own code.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
CC'ing the other "THE REST" maintainers for their opinions.
Rather than ifdefs for C++, don't we need them based on
__XEN_INTERFACE_VERSION__?That's not applicable to the stuff under public/io/.
In which case I'd certainly prefer just changing the name and getting it over with.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
mini-os would need checking, since that's (AFAIK) the only intree user of these headers.
mini-os doesn't in fact use this field; it's a blktap2-ism. Here's a (non-RFC) patch to rename it and update blktap2:
Ian, Jan, can I get an Ack or Nack on this so I can clear it off my plate? :)
In fact I'm not enough against the change to NAK it, but I'm also not really in favor of it, so wouldn't want to ack it. I.e. - Ian?
Jan
PATCH v3 1/1 RFC: Automatically check xen's public headers for C++ pitfalls.
In reply to Tim DeeganAdd a check, like the existing check for non-ANSI C in the public headers, that runs the public headers through a C++ compiler to flag non-C++-friendly constructs.
Unlike the ANSI C check, we accept GCC-isms (gnu++98), and we also check various tools-only headers.
Explicitly _not_ addressing the use of 'private' in various fields, since we'd previously decided not to fix that.
Also tidy up the runes for these checks to be a bit more readable.
---
v3: rebase on staging.
v2: test more headers;
define __XEN_TOOLS__;
use g++98 rather than ansi;
tidy the makefile for readability;
add a missing include to flask_op.h, which uses evtchn_port_t.
---
.gitignore | 1 +
config/StdGNU.mk | 2 ++
config/SunOS.mk | 1 +
xen/include/Makefile | 28 ++++++++++++++++++++++++----
xen/include/public/xsm/flask_op.h | 2 ++
5 files changed, 30 insertions(+), 4 deletions(-).gitignore +1 -0
@@ -233,6 +233,7 @@ xen/arch/*/efi/compat.c xen/arch/*/efi/efi.h xen/arch/*/efi/runtime.c xen/include/headers.chk +xen/include/headers++.chk xen/include/asm xen/include/asm-*/asm-offsets.h xen/include/compat/*
config/StdGNU.mk +2 -0
@@ -2,9 +2,11 @@ AS = $(CROSS_COMPILE)as LD = $(CROSS_COMPILE)ld ifeq ($(clang),y) CC = $(CROSS_COMPILE)clang +CXX = $(CROSS_COMPILE)clang++ LD_LTO = $(CROSS_COMPILE)llvm-ld else CC = $(CROSS_COMPILE)gcc +CXX = $(CROSS_COMPILE)g++ LD_LTO = $(CROSS_COMPILE)ld endif CPP = $(CC) -E
config/SunOS.mk +1 -0
@@ -2,6 +2,7 @@ AS = $(CROSS_COMPILE)gas LD = $(CROSS_COMPILE)gld CC = $(CROSS_COMPILE)gcc CPP = $(CROSS_COMPILE)gcc -E +CXX = $(CROSS_COMPILE)g++ AR = $(CROSS_COMPILE)gar RANLIB = $(CROSS_COMPILE)granlib NM = $(CROSS_COMPILE)gnm
xen/include/Makefile +24 -4
@@ -87,13 +87,33 @@ compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile ifeq ($(XEN_TARGET_ARCH),$(XEN_COMPILE_ARCH)) -all: headers.chk +all: headers.chk headers++.chk -headers.chk: $(filter-out public/arch-% public/%ctl.h public/xsm/% public/%hvm/save.h, $(wildcard public/*.h public/*/*.h) $(public-y)) Makefile - for i in $(filter %.h,$^); do $(CC) -ansi -include stdint.h -Wall -W -Werror -S -o /dev/null -x c $$i || exit 1; echo $$i; done >[email protected] +PUBLIC_HEADERS := $(filter-out public/arch-% public/dom0_ops.h, $(wildcard public/*.h public/*/*.h) $(public-y)) + +PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/% public/%hvm/save.h, $(PUBLIC_HEADERS)) + +headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile + for i in $(filter %.h,$^); do \ + $(CC) -x c -ansi -Wall -Werror -include stdint.h \ + -S -o /dev/null $$i || exit 1; \ + echo $$i; \ + done >[email protected] + mv [email protected] $@ + +headers++.chk: $(PUBLIC_HEADERS) Makefile + if $(CXX) -v >/dev/null 2>&1; then \ + for i in $(filter %.h,$^); do \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ + -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \ + -include stdint.h -include public/xen.h \ + -S -o /dev/null $$i || exit 1; \ + echo $$i; \ + done ; \ + fi >[email protected] mv [email protected] $@ endif clean:: - rm -rf compat headers.chk + rm -rf compat headers.chk headers++.chk
xen/include/public/xsm/flask_op.h +2 -0
@@ -25,6 +25,8 @@#ifndef __FLASK_OP_H__#define __FLASK_OP_H__ +#include "../event_channel.h" +#define XEN_FLASK_INTERFACE_VERSION 1 struct xen_flask_load {
Signature · 1 line
2.1.4
Re: [PATCH v3] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 9 lines · Tim Deegan
Add a check, like the existing check for non-ANSI C in the public headers, that runs the public headers through a C++ compiler to flag non-C++-friendly constructs.
Unlike the ANSI C check, we accept GCC-isms (gnu++98), and we also check various tools-only headers.
Explicitly _not_ addressing the use of 'private' in various fields, since we'd previously decided not to fix that.
This sentence and the "-Dprivate=private_is_a_keyword_in_cpp" below appear to be at odds. Maybe add something like:
The check ignores the use of 'private'.
Quoted 9 lines
Also tidy up the runes for these checks to be a bit more readable.
Reported-by Razvan Cojocaru <[email protected]>Signed-off-by Tim Deegan <[email protected]>Cc Jan Beulich <[email protected]>---
You can add my
-Don Slutz
Quoted 111 lines
v3: rebase on staging.
v2: test more headers; define __XEN_TOOLS__; use g++98 rather than ansi; tidy the makefile for readability; add a missing include to flask_op.h, which uses evtchn_port_t. --- .gitignore | 1 + config/StdGNU.mk | 2 ++ config/SunOS.mk | 1 + xen/include/Makefile | 28 ++++++++++++++++++++++++---- xen/include/public/xsm/flask_op.h | 2 ++ 5 files changed, 30 insertions(+), 4 deletions(-).gitignore +1
-0@@ -233,6 +233,7 @@ xen/arch/*/efi/compat.c xen/arch/*/efi/efi.h xen/arch/*/efi/runtime.c xen/include/headers.chk +xen/include/headers++.chk xen/include/asm xen/include/asm-*/asm-offsets.h xen/include/compat/*config/StdGNU.mk +2
-0@@ -2,9 +2,11 @@ AS = $(CROSS_COMPILE)as LD = $(CROSS_COMPILE)ld ifeq ($(clang),y) CC = $(CROSS_COMPILE)clang +CXX = $(CROSS_COMPILE)clang++ LD_LTO = $(CROSS_COMPILE)llvm-ld else CC = $(CROSS_COMPILE)gcc +CXX = $(CROSS_COMPILE)g++ LD_LTO = $(CROSS_COMPILE)ld endif CPP = $(CC) -Econfig/SunOS.mk +1
-0@@ -2,6 +2,7 @@ AS = $(CROSS_COMPILE)gas LD = $(CROSS_COMPILE)gld CC = $(CROSS_COMPILE)gcc CPP = $(CROSS_COMPILE)gcc -E +CXX = $(CROSS_COMPILE)g++ AR = $(CROSS_COMPILE)gar RANLIB = $(CROSS_COMPILE)granlib NM = $(CROSS_COMPILE)gnmxen/include/Makefile +24
-4@@ -87,13 +87,33 @@ compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile ifeq ($(XEN_TARGET_ARCH),$(XEN_COMPILE_ARCH)) -all: headers.chk +all: headers.chk headers++.chk -headers.chk: $(filter-out public/arch-% public/%ctl.h public/xsm/% public/%hvm/save.h, $(wildcard public/*.h public/*/*.h) $(public-y)) Makefile - for i in $(filter %.h,$^); do $(CC) -ansi -include stdint.h -Wall -W -Werror -S -o /dev/null -x c $$i || exit 1; echo $$i; done >[email protected] +PUBLIC_HEADERS := $(filter-out public/arch-% public/dom0_ops.h, $(wildcard public/*.h public/*/*.h) $(public-y)) + +PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/% public/%hvm/save.h, $(PUBLIC_HEADERS)) + +headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile + for i in $(filter %.h,$^); do \ + $(CC) -x c -ansi -Wall -Werror -include stdint.h \ + -S -o /dev/null $$i || exit 1; \ + echo $$i; \ + done >[email protected] + mv [email protected] $@ + +headers++.chk: $(PUBLIC_HEADERS) Makefile + if $(CXX) -v >/dev/null 2>&1; then \ + for i in $(filter %.h,$^); do \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ + -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \ + -include stdint.h -include public/xen.h \ + -S -o /dev/null $$i || exit 1; \ + echo $$i; \ + done ; \ + fi >[email protected] mv [email protected] $@ endif clean:: - rm -rf compat headers.chk + rm -rf compat headers.chk headers++.chkxen/include/public/xsm/flask_op.h +2
-0@@ -25,6 +25,8 @@#ifndef __FLASK_OP_H__#define __FLASK_OP_H__ +#include "../event_channel.h" +#define XEN_FLASK_INTERFACE_VERSION 1 struct xen_flask_load {
Re: [PATCH v3] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 6 lines · Don Slutz
Quoted 2 lines · Tim Deegan
Explicitly _not_ addressing the use of 'private' in various fields, since we'd previously decided not to fix that.
This sentence and the "-Dprivate=private_is_a_keyword_in_cpp" below appear to be at odds.
Yes, that's not very clear; will reword as I apply.
Quoted 3 lines
You can add my
Tested-by Don Slutz <[email protected]>
Thanks.
Tim.
Re: [PATCH v3] RFC: Automatically check xen's public headers for C++ pitfalls.
In reply to Tim DeeganQuoted 6 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 17:24, <[email protected]> wrote:
xen/include/Makefile +5
-0+PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/% public/%hvm/save.h, $(PUBLIC_HEADERS)) + +headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile + for i in $(filter %.h,$^); do \ + $(CC) -x c -ansi -Wall -Werror -include stdint.h \
xen/include/Makefile compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile · line 108
Quoted 10 lines
xen/include/Makefile +10
-0+ -S -o /dev/null $$i || exit 1; \ + echo $$i; \ + done >[email protected] + mv [email protected] $@ + +headers++.chk: $(PUBLIC_HEADERS) Makefile + if $(CXX) -v >/dev/null 2>&1; then \ + for i in $(filter %.h,$^); do \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ + -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \
With -D__XEN_TOOLS__ added, did you check that domctl.h and sysctl.h still actually need to be excluded from this test?
Jan
Re: [PATCH v3] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 17:24, <[email protected]> wrote:
xen/include/Makefile +10
-0+PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/% public/%hvm/save.h, $(PUBLIC_HEADERS)) + +headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile + for i in $(filter %.h,$^); do \ + $(CC) -x c -ansi -Wall -Werror -include stdint.h \ + -S -o /dev/null $$i || exit 1; \ + echo $$i; \ + done >[email protected] + mv [email protected] $@ +
Quoted 8 lines
xen/include/Makefile compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile · line 108
Quoted 5 lines
xen/include/Makefile +5
-0+headers++.chk: $(PUBLIC_HEADERS) Makefile + if $(CXX) -v >/dev/null 2>&1; then \ + for i in $(filter %.h,$^); do \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ + -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \With -D__XEN_TOOLS__ added, did you check that
domctl.handsysctl.hstill actually need to be excluded from this test?
The C++ check includes those headers and defines __XEN_TOOLS__; the ANSI C check does neither (as before). Would you like to change that too?
Tim.
Re: [PATCH v3] RFC: Automatically check xen's public headers for C++ pitfalls.
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 27.02.15 at 10:22, <[email protected]> wrote:
Quoted 2 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 26.02.15 at 17:24, <[email protected]> wrote:
+PUBLIC_ANSI_HEADERS := $(filter-out public/%ctl.h public/xsm/%
public/%hvm/save.h, $(PUBLIC_HEADERS))
Quoted 9 lines
Quoted 9 lines
xen/include/Makefile +9
-0+ +headers.chk: $(PUBLIC_ANSI_HEADERS) Makefile + for i in $(filter %.h,$^); do \ + $(CC) -x c -ansi -Wall -Werror -include stdint.h \ + -S -o /dev/null $$i || exit 1; \ + echo $$i; \ + done >[email protected] + mv [email protected] $@ +Quoted 8 lines
xen/include/Makefile compat/xlat.h: $(addprefix compat/.xlat/,$(xlat-y)) Makefile · line 108
Quoted 5 lines
xen/include/Makefile +5
-0+headers++.chk: $(PUBLIC_HEADERS) Makefile + if $(CXX) -v >/dev/null 2>&1; then \ + for i in $(filter %.h,$^); do \ + $(CXX) -x c++ -std=gnu++98 -Wall -Werror \ + -D__XEN_TOOLS__ -Dprivate=private_is_a_keyword_in_cpp \With -D__XEN_TOOLS__ added, did you check that
domctl.handsysctl.hstill actually need to be excluded from this test?
Quoted 2 lines
The C++ check includes those headers and defines
__XEN_TOOLS__; the ANSI C check does neither (as before).
Argh - I again didn't look closely enough; I'm sorry.
Quoted 1 line
Would you like to change that too?
No.
Ack on v3 then.
Jan