xen: Minor modifications to platform.h to make it C++-friendly
PATCH 1/1 xen: Minor modifications to platform.h to make it C++-friendly
Moved the definition of struct xenpf_efi_guid up, and rearranged struct xenpf_efi_time in the containing union to avoid compilation errors with C++ (structs defined inside unnamed structs become unavailable outside their scope with C++). The change allows C++ applications to use platform.h with no consequences for current C clients.
--- xen/include/public/platform.h | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-)
xen/include/public/platform.h +21 -19
@@ -141,6 +141,13 @@ 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_runtime_call {uint32_t function;/*
@@ -152,24 +159,24 @@ struct xenpf_efi_runtime_call {xen_ulong_t status;union {#define XEN_EFI_GET_TIME_SET_CLEARS_NS 0x00000001 +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; + } set_time; +struct { -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; -struct xenpf_efi_time set_time; -#define XEN_EFI_GET_WAKEUP_TIME_ENABLED 0x00000001#define XEN_EFI_GET_WAKEUP_TIME_PENDING 0x00000002struct xenpf_efi_time get_wakeup_time;
@@ -185,12 +192,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
1.7.9.5
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 10:34, <[email protected]> wrote:
Moved the definition of struct
xenpf_efi_guidup, and rearranged structxenpf_efi_timein the containing union to avoid compilation errors with C++ (structs defined inside unnamed structs become unavailable outside their scope with C++). The change allows C++ applications to useplatform.hwith no consequences for current C clients.
What's wrong with simply naming the union/struct, making for a much smaller change?
Quoted 6 lines
xen/include/public/platform.h +2
-0@@ -152,24 +159,24 @@ struct xenpf_efi_runtime_call {xen_ulong_t status;union {#define XEN_EFI_GET_TIME_SET_CLEARS_NS 0x00000001 +struct xenpf_efi_time { +uint16_t year;
xen/include/public/platform.h struct xenpf_efi_runtime_call { · line 173
Quoted 10 lines
xen/include/public/platform.h +10
-0+uint8_t month; +uint8_t day; +uint8_t hour; +uint8_t min; +uint8_t sec; +uint32_t ns; +int16_t tz; +uint8_t daylight; + } set_time; +
If we were to go this proposed route, the insertion would need to happen above the #define.
Jan
Quoted 10 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 10:34, <[email protected]> wrote:
Moved the definition of struct
xenpf_efi_guidup, and rearranged structxenpf_efi_timein the containing union to avoid compilation errors with C++ (structs defined inside unnamed structs become unavailable outside their scope with C++). The change allows C++ applications to useplatform.hwith no consequences for current C clients.What's wrong with simply naming the union/struct, making for a much smaller change?
The bigger issue is not that the containing struct is unnamed, it is that from C++'s standpoint the inner struct needs to be explictly qualified, as if it were in a namespace. The fact that the outer struct is unnamed makes it impossible to refer to the inner struct, but even if it were possible to refer to it (by naming the outer struct), it would still not be valid C code (and the change would arguably not be much smaller anyway):
154 #define XEN_EFI_GET_TIME_SET_CLEARS_NS 0x00000001
155 struct get_time_t {
156 struct xenpf_efi_time {
157 uint16_t year; 158 uint8_t month; 159 uint8_t day; 160 uint8_t hour; 161 uint8_t min; 162 uint8_t sec; 163 uint32_t ns; 164 int16_t tz; 165 uint8_t daylight; 166 } time; 167 uint32_t resolution; 168 uint32_t accuracy;
169 } get_time;
170
171 struct get_time_t::xenpf_efi_time set_time;
172
173 #define XEN_EFI_GET_WAKEUP_TIME_ENABLED 0x00000001 174 #define XEN_EFI_GET_WAKEUP_TIME_PENDING 0x00000002
175 struct get_time_t::xenpf_efi_time get_wakeup_time;
176
177 #define XEN_EFI_SET_WAKEUP_TIME_ENABLE 0x00000001
178 #define XEN_EFI_SET_WAKEUP_TIME_ENABLE_ONLY 0x00000002
179 struct get_time_t::xenpf_efi_time set_wakeup_time;
This is why I think the proposed solution works best for everyone.
Quoted 11 lines
Quoted 11 lines
xen/include/public/platform.h +7
-0@@ -152,24 +159,24 @@ struct xenpf_efi_runtime_call {xen_ulong_t status;union {#define XEN_EFI_GET_TIME_SET_CLEARS_NS 0x00000001 +struct xenpf_efi_time { +uint16_t year; +uint8_t month; +uint8_t day; +uint8_t hour; +uint8_t min; +uint8_t sec;
Quoted 8 lines
xen/include/public/platform.h struct xenpf_efi_runtime_call { · line 173
Quoted 5 lines
xen/include/public/platform.h +5
-0+uint32_t ns; +int16_t tz; +uint8_t daylight; + } set_time; +If we were to go this proposed route, the insertion would need to happen above the #define.
Of course, if there are no other objections I'll move it above the #define and submit V2.
Thanks,
Razvan
Quoted 48 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 11:31, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 10:34, <[email protected]> wrote:
Moved the definition of struct
xenpf_efi_guidup, and rearranged structxenpf_efi_timein the containing union to avoid compilation errors with C++ (structs defined inside unnamed structs become unavailable outside their scope with C++). The change allows C++ applications to useplatform.hwith no consequences for current C clients.What's wrong with simply naming the union/struct, making for a much smaller change?
The bigger issue is not that the containing struct is unnamed, it is that from C++'s standpoint the inner struct needs to be explictly qualified, as if it were in a namespace. The fact that the outer struct is unnamed makes it impossible to refer to the inner struct, but even if it were possible to refer to it (by naming the outer struct), it would still not be valid C code (and the change would arguably not be much smaller anyway):
154 #define
XEN_EFI_GET_TIME_SET_CLEARS_NS0x00000001
155 structget_time_t{
156 structxenpf_efi_time{157 uint16_t year; 158 uint8_t month; 159 uint8_t day; 160 uint8_t hour; 161 uint8_t min; 162 uint8_t sec; 163 uint32_t ns; 164 int16_t tz; 165 uint8_t daylight; 166 } time; 167 uint32_t resolution; 168 uint32_t accuracy;169 }
get_time;
170
171 structget_time_t::xenpf_efi_timeset_time;
172
173 #defineXEN_EFI_GET_WAKEUP_TIME_ENABLED0x00000001174 #defineXEN_EFI_GET_WAKEUP_TIME_PENDING0x00000002
175 structget_time_t::xenpf_efi_timeget_wakeup_time;
176
177 #defineXEN_EFI_SET_WAKEUP_TIME_ENABLE0x00000001
178 #defineXEN_EFI_SET_WAKEUP_TIME_ENABLE_ONLY0x00000002
179 structget_time_t::xenpf_efi_timeset_wakeup_time;
Quoted 1 line
This is why I think the proposed solution works best for everyone.
Ah, right. But then ...
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xen/include/public/platform.h +4
-0@@ -152,24 +159,24 @@ struct xenpf_efi_runtime_call {xen_ulong_t status;union {#define XEN_EFI_GET_TIME_SET_CLEARS_NS 0x00000001 +struct xenpf_efi_time { +uint16_t year; +uint8_t month; +uint8_t day;
Quoted 8 lines
Quoted 8 lines
xen/include/public/platform.h struct xenpf_efi_runtime_call { · line 173
Quoted 8 lines
xen/include/public/platform.h +8
-0+uint8_t hour; +uint8_t min; +uint8_t sec; +uint32_t ns; +int16_t tz; +uint8_t daylight; + } set_time; +
... this should be moved out to file scope too, both for consistency and to avoid an eventual further adjustment going forward. Otoh I'm not convinced we need the headers to be C++ ready (nor am I convinced that there aren't any other obstacles preventing their unmodified use in C++). Co-maintainers, what do you think?
Jan
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
xen/include/public/platform.h +10
-0@@ -152,24 +159,24 @@ struct xenpf_efi_runtime_call {xen_ulong_t status;union {#define XEN_EFI_GET_TIME_SET_CLEARS_NS 0x00000001 +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;
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
xen/include/public/platform.h struct xenpf_efi_runtime_call { · line 173
Quoted 2 lines
xen/include/public/platform.h +2
-0+ } set_time; +... this should be moved out to file scope too, both for consistency and to avoid an eventual further adjustment going forward. Otoh I'm not convinced we need the headers to be C++ ready (nor am I convinced that there aren't any other obstacles preventing their unmodified use in C++). Co-maintainers, what do you think?
You're right, it's always better to be consistent. Will do.
As for the headers being C++ ready, there's already the precedent of at least my previous patch "xenctrl: Make the headers C++ friendly":
http://www.gossamer-threads.com/lists/xen/devel/337788
where it turned out that there's at least one other serious user of Xen with C++, Don Slutz.
I do understand and respect the fact that C++ is not a xen-devel target, but I also believe that there are a very small number of changes that could enlarge the Xen user base to include C++ developers, and that it can be done in completely painless manner for all involved.
Thanks,
Razvan
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 12:05, <[email protected]> wrote:
As for the headers being C++ ready, there's already the precedent of at least my previous patch "xenctrl: Make the headers C++ friendly":
http://www.gossamer-threads.com/lists/xen/devel/337788
where it turned out that there's at least one other serious user of Xen with C++, Don Slutz.
That's a different story - we're talking about the canonical public headers here.
Quoted 4 lines
I do understand and respect the fact that C++ is not a xen-devel target, but I also believe that there are a very small number of changes that could enlarge the Xen user base to include C++ developers, and that it can be done in completely painless manner for all involved.
No, if you want to do just that, it's going to get broken again. If we want the headers to be C++ ready, we ought to introduce a build time check similar to the one checking that they're plain ANSI C conforming. Which in turn, as a prerequisite, would need you to make sure they _all_ are usable in C++. (Such a build time check, in case you want to propose an extended series, should of course be conditional upon there being a C++ compiler available - we clearly don't want to enforce its installation onto everyone consuming Xen, even if we expect developers to have it installed in order for them to make sure their patches don't introduce build breakage).
Jan
Quoted 5 lines · Jan Beulich
... this should be moved out to file scope too, both for consistency and to avoid an eventual further adjustment going forward. Otoh I'm not convinced we need the headers to be C++ ready (nor am I convinced that there aren't any other obstacles preventing their unmodified use in C++). Co-maintainers, what do you think?
In general I'm against making C code uglier to keep C++ compilers happy (e.g. ISTR vetoing the idea of putting 'extern C' runes in our header files a while back). And we certainly don't _support_ the header files as C++.
OTOH, I think that just defining struct xenpf_efi_guid and struct xenpf_efi_time at file scope would be fine here -- if anything it's nicer to have these reused structs defined before first use. And if it happens to solve a problem for C++, too, that's great. :)
Cheers,
Tim.
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 23.02.15 at 12:09, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
... this should be moved out to file scope too, both for consistency and to avoid an eventual further adjustment going forward. Otoh I'm not convinced we need the headers to be C++ ready (nor am I convinced that there aren't any other obstacles preventing their unmodified use in C++). Co-maintainers, what do you think?
In general I'm against making C code uglier to keep C++ compilers happy (e.g. ISTR vetoing the idea of putting 'extern C' runes in our header files a while back). And we certainly don't _support_ the header files as C++.
Quoted 4 lines
OTOH, I think that just defining struct
xenpf_efi_guidand structxenpf_efi_timeat file scope would be fine here -- if anything it's nicer to have these reused structs defined before first use. And if it happens to solve a problem for C++, too, that's great. :)
But then I'd ask for consistency again - there are a couple of other similar structure definitions as it seems. And other than full C++ correctness I can't see how such a rule could be auto- enforced (to avoid introducing similar future issues - personally I'm in favor of defining things upon first use where possible, i.e. I'd be likely to introduce such "nested" structure definitions again unless prevented from doing so by some automatic check).
Jan
Quoted 3 lines · Jan Beulich
I'm not convinced we need the headers to be C++ ready (nor am I convinced that there aren't any other obstacles preventing their unmodified use in C++).
Sorry, I meant to answer the last part too. I'm using libxc and xenstore headers, as well as the public Xen headers with C++, and so far the only trouble I've had was what this patch is addressing, and there's something called "private" (a macro or a variable, I don't remember exactly) which is a keyword in C++. I've done the following to work around that:
extern "C" {
#include <xenstore.h>
#define private rprivate /* private is a C++ keyword */ #include <xen/mem_event.h>
#undef private
}
I've understood Tim's message about "extern "C"" so I've fixed it at #include-time in my code. :)
HTH,
Razvan