From patchwork Mon Mar 7 15:13:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 8520041 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 015A79F2B4 for ; Mon, 7 Mar 2016 15:16:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 28CF8200FF for ; Mon, 7 Mar 2016 15:16:55 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 32413200D0 for ; Mon, 7 Mar 2016 15:16:54 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1acwrM-0003A0-4l; Mon, 07 Mar 2016 15:14:12 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.84) (envelope-from ) id 1acwrK-00039o-GU for xen-devel@lists.xen.org; Mon, 07 Mar 2016 15:14:10 +0000 Received: from [85.158.137.68] by server-8.bemta-3.messagelabs.com id B6/1B-04050-1CA9DD65; Mon, 07 Mar 2016 15:14:09 +0000 X-Env-Sender: prvs=86744e631=Andrew.Cooper3@citrix.com X-Msg-Ref: server-9.tower-31.messagelabs.com!1457363647!5139009!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.11; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30310 invoked from network); 7 Mar 2016 15:14:08 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-9.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 7 Mar 2016 15:14:08 -0000 X-IronPort-AV: E=Sophos;i="5.22,551,1449532800"; d="scan'208";a="343744551" From: Andrew Cooper To: Xen-devel Date: Mon, 7 Mar 2016 15:13:42 +0000 Message-ID: <1457363622-29534-1-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <22233.45757.915716.14337@mariner.uk.xensource.com> References: <22233.45757.915716.14337@mariner.uk.xensource.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Andrew Cooper , Tim Deegan , Jan Beulich , Doug Goldstein Subject: [Xen-devel] [PATCH v4] xen/errno: Reduce complexity of inclusion X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Simply the logic, and document what is going on. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Tim Deegan CC: Doug Goldstein v3: * Reinstate magic documentation comments * Provide assembly-suitable defaults if appropriate v4: * Reintroduce broken #undef logic to be bug-compatible with the previous version. --- xen/include/public/errno.h | 41 ++++++++++++++++++++++++++++++++++------- xen/include/xen/errno.h | 6 ++---- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/xen/include/public/errno.h b/xen/include/public/errno.h index dbac396..a0dd0cf 100644 --- a/xen/include/public/errno.h +++ b/xen/include/public/errno.h @@ -1,4 +1,31 @@ +/* + * There are two expected ways of including this header. + * + * 1) The "default" case (expected from tools etc). + * + * Simply #include + * + * In this circumstance, normal header guards apply and the includer shall get + * an enumeration in the XEN_xxx namespace, appropriate for C or assembly. + * + * 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. The header + * will unilaterally #undef XEN_ERRNO(). + */ + +#ifndef XEN_ERRNO + +/* + * Includer has not provided a custom XEN_ERRNO(). Arrange for normal header + * guards, an automatic enum (for C code) and constants in the XEN_xxx + * namespace. + */ #ifndef __XEN_PUBLIC_ERRNO_H__ +#define __XEN_PUBLIC_ERRNO_H__ + +#define XEN_ERRNO_DEFAULT_INCLUDE #ifndef __ASSEMBLY__ @@ -11,11 +38,12 @@ enum xen_errno { #endif /* __ASSEMBLY__ */ +#endif /* __XEN_PUBLIC_ERRNO_H__ */ +#endif /* !XEN_ERRNO */ + /* ` enum neg_errnoval { [ -Efoo for each Efoo in the list below ] } */ /* ` enum errnoval { */ -#endif /* __XEN_PUBLIC_ERRNO_H__ */ - #ifdef XEN_ERRNO /* @@ -84,14 +112,13 @@ XEN_ERRNO(ETIMEDOUT, 110) /* Connection timed out */ #undef XEN_ERRNO #endif /* XEN_ERRNO */ - -#ifndef __XEN_PUBLIC_ERRNO_H__ -#define __XEN_PUBLIC_ERRNO_H__ - /* ` } */ +/* Clean up from a default include. Close the enum (for C). */ +#ifdef XEN_ERRNO_DEFAULT_INCLUDE +#undef XEN_ERRNO_DEFAULT_INCLUDE #ifndef __ASSEMBLY__ }; #endif -#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 - #ifndef __ASSEMBLY__ -#define XEN_ERRNO(name, value) name = XEN_##name, +#define XEN_ERRNO(name, value) name = value, enum { #include }; #else /* !__ASSEMBLY__ */ -#define XEN_ERRNO(name, value) .equ name, XEN_##name +#define XEN_ERRNO(name, value) .equ name, value #include #endif /* __ASSEMBLY__ */