Message ID | 1456858641-20776-3-git-send-email-andrew.cooper3@citrix.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On 3/1/16 12:57 PM, Andrew Cooper wrote: > The inclusion rules conditions for errno.h were unnecesserily complicated, and > required the includer to jump through hoops if they wished to avoid getting > multiple namespaces worth of constants. > > Vastly simply the logic, and document what is going on. > > Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> Reviewed-by: Doug Goldstein <cardoe@cardoe.com> > --- > CC: Jan Beulich <JBeulich@suse.com> > CC: Tim Deegan <tim@xen.org> > CC: Doug Goldstein <cardoe@cardoe.com> > --- > xen/include/public/errno.h | 55 ++++++++++++++++++++++++++++++---------------- > xen/include/xen/errno.h | 6 ++--- > 2 files changed, 38 insertions(+), 23 deletions(-) > > diff --git a/xen/include/public/errno.h b/xen/include/public/errno.h > index dbac396..fa375be 100644 > --- a/xen/include/public/errno.h > +++ b/xen/include/public/errno.h > @@ -1,20 +1,36 @@ > -#ifndef __XEN_PUBLIC_ERRNO_H__ > - > -#ifndef __ASSEMBLY__ > - > -#define XEN_ERRNO(name, value) XEN_##name = value, > -enum xen_errno { > +/* > + * There are two expected ways of including this header. > + * > + * 1) The "default" case (expected from tools etc). > + * > + * Simply #include <public/errno.h> > + * > + * In this circumstance, normal header guards apply and the includer shall get > + * an enumeration in the XEN_xxx namespace. > + * > + * 2) The special case where the includer provides a XEN_ERRNO() in scope. > + * > + * In this case, no inclusion guards apply and the caller is responsible for > + * their XEN_ERRNO() being appropriate in the included context. > + */ > > -#else /* !__ASSEMBLY__ */ > +#ifndef XEN_ERRNO > > -#define XEN_ERRNO(name, value) .equ XEN_##name, value > +/* > + * Includer has not provided a custom XEN_ERRNO(). Arrange an automatic enum > + * and constants in the XEN_xxx namespace. > + */ > +#define XEN_ERRNO_DEFAULT_INCLUDE > > -#endif /* __ASSEMBLY__ */ > +#ifndef __XEN_PUBLIC_ERRNO_H__ > +#define __XEN_PUBLIC_ERRNO_H__ > > -/* ` enum neg_errnoval { [ -Efoo for each Efoo in the list below ] } */ > -/* ` enum errnoval { */ > +#define XEN_ERRNO(name, value) XEN_##name = value, > +enum { > > #endif /* __XEN_PUBLIC_ERRNO_H__ */ > +#endif /* !XEN_ERRNO */ > + > > #ifdef XEN_ERRNO > > @@ -82,16 +98,17 @@ XEN_ERRNO(EISCONN, 106) /* Transport endpoint is already connected */ > XEN_ERRNO(ENOTCONN, 107) /* Transport endpoint is not connected */ > XEN_ERRNO(ETIMEDOUT, 110) /* Connection timed out */ > > -#undef XEN_ERRNO > #endif /* XEN_ERRNO */ > > -#ifndef __XEN_PUBLIC_ERRNO_H__ > -#define __XEN_PUBLIC_ERRNO_H__ > > -/* ` } */ > +#ifdef XEN_ERRNO_DEFAULT_INCLUDE > > -#ifndef __ASSEMBLY__ > -}; > -#endif > +/* > + * Clean up from a default include. Close the enum and remove the default > + * XEN_ERRNO from scope. > + */ > +#undef XEN_ERRNO_DEFAULT_INCLUDE > +#undef XEN_ERRNO > +} ; > > -#endif /* __XEN_PUBLIC_ERRNO_H__ */ > +#endif /* XEN_ERRNO_DEFAULT_INCLUDE */ > diff --git a/xen/include/xen/errno.h b/xen/include/xen/errno.h > index 3178466..69b28dd 100644 > --- a/xen/include/xen/errno.h > +++ b/xen/include/xen/errno.h > @@ -1,18 +1,16 @@ > #ifndef __XEN_ERRNO_H__ > #define __XEN_ERRNO_H__ > > -#include <public/errno.h> > - > #ifndef __ASSEMBLY__ > > -#define XEN_ERRNO(name, value) name = XEN_##name, > +#define XEN_ERRNO(name, value) name = value, > enum { > #include <public/errno.h> > }; > > #else /* !__ASSEMBLY__ */ > > -#define XEN_ERRNO(name, value) .equ name, XEN_##name > +#define XEN_ERRNO(name, value) .equ name, value > #include <public/errno.h> > > #endif /* __ASSEMBLY__ */ >
>>> On 01.03.16 at 19:57, <andrew.cooper3@citrix.com> wrote: > The inclusion rules conditions for errno.h were unnecesserily complicated, and > required the includer to jump through hoops if they wished to avoid getting > multiple namespaces worth of constants. > > Vastly simply the logic, and document what is going on. Nice. While the enforcement of the creation of the XEN_* variants was intentional, you're right that it's not really necessary. > --- a/xen/include/public/errno.h > +++ b/xen/include/public/errno.h > @@ -1,20 +1,36 @@ > -#ifndef __XEN_PUBLIC_ERRNO_H__ > - > -#ifndef __ASSEMBLY__ > - > -#define XEN_ERRNO(name, value) XEN_##name = value, > -enum xen_errno { > +/* > + * There are two expected ways of including this header. > + * > + * 1) The "default" case (expected from tools etc). > + * > + * Simply #include <public/errno.h> > + * > + * In this circumstance, normal header guards apply and the includer shall get > + * an enumeration in the XEN_xxx namespace. > + * > + * 2) The special case where the includer provides a XEN_ERRNO() in scope. > + * > + * In this case, no inclusion guards apply and the caller is responsible for > + * their XEN_ERRNO() being appropriate in the included context. > + */ > > -#else /* !__ASSEMBLY__ */ > +#ifndef XEN_ERRNO > > -#define XEN_ERRNO(name, value) .equ XEN_##name, value > +/* > + * Includer has not provided a custom XEN_ERRNO(). Arrange an automatic enum > + * and constants in the XEN_xxx namespace. > + */ > +#define XEN_ERRNO_DEFAULT_INCLUDE > > -#endif /* __ASSEMBLY__ */ > +#ifndef __XEN_PUBLIC_ERRNO_H__ > +#define __XEN_PUBLIC_ERRNO_H__ > > -/* ` enum neg_errnoval { [ -Efoo for each Efoo in the list below ] } */ > -/* ` enum errnoval { */ > +#define XEN_ERRNO(name, value) XEN_##name = value, > +enum { > > #endif /* __XEN_PUBLIC_ERRNO_H__ */ > +#endif /* !XEN_ERRNO */ > + > > #ifdef XEN_ERRNO This eliminates the default creation of equates in the assembly case, which - with the header being part of 4.6.x - we can't do. > @@ -82,16 +98,17 @@ XEN_ERRNO(EISCONN, 106) /* Transport endpoint is already > connected */ > XEN_ERRNO(ENOTCONN, 107) /* Transport endpoint is not connected */ > XEN_ERRNO(ETIMEDOUT, 110) /* Connection timed out */ > > -#undef XEN_ERRNO > #endif /* XEN_ERRNO */ > > -#ifndef __XEN_PUBLIC_ERRNO_H__ > -#define __XEN_PUBLIC_ERRNO_H__ > > -/* ` } */ > +#ifdef XEN_ERRNO_DEFAULT_INCLUDE > > -#ifndef __ASSEMBLY__ > -}; > -#endif > +/* > + * Clean up from a default include. Close the enum and remove the default > + * XEN_ERRNO from scope. > + */ > +#undef XEN_ERRNO_DEFAULT_INCLUDE > +#undef XEN_ERRNO > +} ; Stray blank. Jan
diff --git a/xen/include/public/errno.h b/xen/include/public/errno.h index dbac396..fa375be 100644 --- a/xen/include/public/errno.h +++ b/xen/include/public/errno.h @@ -1,20 +1,36 @@ -#ifndef __XEN_PUBLIC_ERRNO_H__ - -#ifndef __ASSEMBLY__ - -#define XEN_ERRNO(name, value) XEN_##name = value, -enum xen_errno { +/* + * There are two expected ways of including this header. + * + * 1) The "default" case (expected from tools etc). + * + * Simply #include <public/errno.h> + * + * In this circumstance, normal header guards apply and the includer shall get + * an enumeration in the XEN_xxx namespace. + * + * 2) The special case where the includer provides a XEN_ERRNO() in scope. + * + * In this case, no inclusion guards apply and the caller is responsible for + * their XEN_ERRNO() being appropriate in the included context. + */ -#else /* !__ASSEMBLY__ */ +#ifndef XEN_ERRNO -#define XEN_ERRNO(name, value) .equ XEN_##name, value +/* + * Includer has not provided a custom XEN_ERRNO(). Arrange an automatic enum + * and constants in the XEN_xxx namespace. + */ +#define XEN_ERRNO_DEFAULT_INCLUDE -#endif /* __ASSEMBLY__ */ +#ifndef __XEN_PUBLIC_ERRNO_H__ +#define __XEN_PUBLIC_ERRNO_H__ -/* ` enum neg_errnoval { [ -Efoo for each Efoo in the list below ] } */ -/* ` enum errnoval { */ +#define XEN_ERRNO(name, value) XEN_##name = value, +enum { #endif /* __XEN_PUBLIC_ERRNO_H__ */ +#endif /* !XEN_ERRNO */ + #ifdef XEN_ERRNO @@ -82,16 +98,17 @@ XEN_ERRNO(EISCONN, 106) /* Transport endpoint is already connected */ XEN_ERRNO(ENOTCONN, 107) /* Transport endpoint is not connected */ XEN_ERRNO(ETIMEDOUT, 110) /* Connection timed out */ -#undef XEN_ERRNO #endif /* XEN_ERRNO */ -#ifndef __XEN_PUBLIC_ERRNO_H__ -#define __XEN_PUBLIC_ERRNO_H__ -/* ` } */ +#ifdef XEN_ERRNO_DEFAULT_INCLUDE -#ifndef __ASSEMBLY__ -}; -#endif +/* + * Clean up from a default include. Close the enum and remove the default + * XEN_ERRNO from scope. + */ +#undef XEN_ERRNO_DEFAULT_INCLUDE +#undef XEN_ERRNO +} ; -#endif /* __XEN_PUBLIC_ERRNO_H__ */ +#endif /* XEN_ERRNO_DEFAULT_INCLUDE */ diff --git a/xen/include/xen/errno.h b/xen/include/xen/errno.h index 3178466..69b28dd 100644 --- a/xen/include/xen/errno.h +++ b/xen/include/xen/errno.h @@ -1,18 +1,16 @@ #ifndef __XEN_ERRNO_H__ #define __XEN_ERRNO_H__ -#include <public/errno.h> - #ifndef __ASSEMBLY__ -#define XEN_ERRNO(name, value) name = XEN_##name, +#define XEN_ERRNO(name, value) name = value, enum { #include <public/errno.h> }; #else /* !__ASSEMBLY__ */ -#define XEN_ERRNO(name, value) .equ name, XEN_##name +#define XEN_ERRNO(name, value) .equ name, value #include <public/errno.h> #endif /* __ASSEMBLY__ */
The inclusion rules conditions for errno.h were unnecesserily complicated, and required the includer to jump through hoops if they wished to avoid getting multiple namespaces worth of constants. Vastly simply the logic, and document what is going on. Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com> --- CC: Jan Beulich <JBeulich@suse.com> CC: Tim Deegan <tim@xen.org> CC: Doug Goldstein <cardoe@cardoe.com> --- xen/include/public/errno.h | 55 ++++++++++++++++++++++++++++++---------------- xen/include/xen/errno.h | 6 ++--- 2 files changed, 38 insertions(+), 23 deletions(-)