From owner-freebsd-arch@FreeBSD.ORG Tue Dec 6 17:27:17 2011 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D5B17106567B; Tue, 6 Dec 2011 17:27:17 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id AB5B48FC19; Tue, 6 Dec 2011 17:27:17 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) by cyrus.watson.org (Postfix) with ESMTPSA id 5D77646B0C; Tue, 6 Dec 2011 12:27:17 -0500 (EST) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id E2F53B94F; Tue, 6 Dec 2011 12:27:16 -0500 (EST) From: John Baldwin To: mdf@freebsd.org Date: Tue, 6 Dec 2011 12:27:15 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p8; KDE/4.5.5; amd64; ; ) References: <201111301032.04102.jhb@freebsd.org> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201112061227.15438.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 06 Dec 2011 12:27:17 -0500 (EST) Cc: Zack Kirsch , freebsd-arch@freebsd.org Subject: Re: Use of bool / stdbool.h in kernel X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Dec 2011 17:27:17 -0000 On Sunday, December 04, 2011 11:49:08 am mdf@freebsd.org wrote: > On Wed, Nov 30, 2011 at 7:32 AM, John Baldwin wrote: > > On Wednesday, November 30, 2011 12:13:53 am Bruce Evans wrote: > >> On Tue, 29 Nov 2011 mdf@freebsd.org wrote: > >> > >> > At $WORK we have a hack in one of the *.mk files to allow including > >> > stdbool.h in the kernel and we use it extensively. This is not > >> > allowed by style(9), as far as I can tell, because the file is in > >> > include/stdbool.h and those files are not allowed to be included in > >> > kernel sources. > >> > >> Including stdbool.h in the kernel is not a style bug, but unsupported. > >> > >> > What I want to check on is, would it be acceptable to move stdbool.h > >> > from include/stdbool.h to sys/sys/stdbool.h (i.e. like errno.h) and > >> > then include it in the kernel as ? That is, is the > >> > >> Would be a larger style bug, especially if it were actually used. > >> Even its spellings of TRUE and FALSE are strange. Even in userland > >> stdbool.h is considered so useful that it is never used in src/bin > >> and is only used a few times on other src/*bin. src/bin never uses > >> TRUE of FALSE either. > > > > I suspect there is some bias here though due to the fact that there wasn't > > a standard bool type when most of this code was written. :) I don't think > > that means we have to forgo use of the new type now that it is in fact > > standardized in C99. I would be happy to have 'bool' available and the > > lowercase 'true' and 'false' are fine with me. > > In further thinking, there's also a style issue of nested headers. > FreeBSD expects most types defined in sys/types.h so that it can be > included first and other files alphabetically. Using > would require any header with a bool parameter, return code, or struct > member to include . Alternatively, I could instead put > the same guards as stdbool.h uses and define bool, true, and false in > sys/types.h, but only for _KERNEL use (however, this also would create > issues with any file that is built in both user-space and kernel, and > unconditionally defining in sys/types.h could break existing buggy > applications). Userland apps that #define _KERNEL deserve to be broken and deal with the fallout accordingly. :) I think exposing it in the kernel via would be fine. -- John Baldwin