From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#48264: [PATCH v3 15/15] Add and use BVAR_FIELD macros Date: Fri, 07 May 2021 17:43:51 -0400 Message-ID: <87mtt6p6co.fsf@catern.com> References: <877dkbsj9d.fsf@catern.com> <20210506213346.9730-16-sbaugh@catern.com> <835yzudcvz.fsf@gnu.org> <87o8dmr96v.fsf@catern.com> <83tunebsiu.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26973"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 48264@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 07 23:45:21 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lf8Hh-0006tj-A9 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 07 May 2021 23:45:21 +0200 Original-Received: from localhost ([::1]:41456 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lf8Hf-0005fX-Ao for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 07 May 2021 17:45:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:39552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lf8HO-0005fK-Bg for bug-gnu-emacs@gnu.org; Fri, 07 May 2021 17:45:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34567) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lf8HO-0006oe-4X for bug-gnu-emacs@gnu.org; Fri, 07 May 2021 17:45:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lf8HN-0003mp-W7 for bug-gnu-emacs@gnu.org; Fri, 07 May 2021 17:45:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 07 May 2021 21:45:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 48264 X-GNU-PR-Package: emacs Original-Received: via spool by 48264-submit@debbugs.gnu.org id=B48264.162042384214518 (code B ref 48264); Fri, 07 May 2021 21:45:01 +0000 Original-Received: (at 48264) by debbugs.gnu.org; 7 May 2021 21:44:02 +0000 Original-Received: from localhost ([127.0.0.1]:46110 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lf8GP-0003lv-IN for submit@debbugs.gnu.org; Fri, 07 May 2021 17:44:02 -0400 Original-Received: from venus.catern.com ([68.183.49.163]:42718) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lf8GH-0003lc-10 for 48264@debbugs.gnu.org; Fri, 07 May 2021 17:44:00 -0400 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=98.7.229.235; helo=localhost; envelope-from=sbaugh@catern.com; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=catern.com; s=mail; t=1620423832; bh=hVMOu2b7ZD0Y4mDWjCsVGq9ekYruT176xG/j0lDKaas=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=FRN1OQFdrX6mH4I7lOFA4/Fjr/xMGOR7P3YkxETWXnMXvG97lVNQofemMwLIrx0yh itLoeqWJ3dXcCZr8AGhzHZc9D/8m/zU48Rd/zCBoyP20VtLIznpXaAw0ZL7UN1bWtp TcD1etymfhd+I4/9Uq5P1E4QSBvoZsPveMSl642s= Original-Received: from localhost (cpe-98-7-229-235.nyc.res.rr.com [98.7.229.235]) by venus.catern.com (Postfix) with ESMTPSA id 9500B2E9771; Fri, 7 May 2021 21:43:52 +0000 (UTC) In-Reply-To: <83tunebsiu.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:205965 Archived-At: Eli Zaretskii writes: >> From: Spencer Baugh >> Cc: 48264@debbugs.gnu.org >> Date: Fri, 07 May 2021 08:59:36 -0400 >> Ah, yes, I probably should have given a little more explanation of this. >> I'm not tied to this approach, if we can think of a better way to make >> it statically guaranteed that BVAR is only used with fields that have a >> default. > > If the sole purpose is to be able to detect coding mistakes, then > there are other possibilities to do that, if the compiler cannot help > in a way that leaves the sources readable. Hopefully. Although, I'm not sure this approach is fundamentally unreadable? The field names are already mangled with the trailing "_" to stop direct access; this is just further mangling them. >> > Hmm... I'm not sure I understand the effect of these. Does it mean C >> > code can no longer set the buffer-local value of these variables, only >> > the default value? >> >> No, this is purely just changing the name of the fields - it has no >> impact on functionality, C code can still set the buffer-local >> variables. > > Then I guess the _defaulted_ part is a misnomer? Possibly; by "defaulted" I intended to mean that the field is one which has a default. But I freely acknowledge it's not a great name. Keep in mind though, this name isn't exposed to the programmer anywhere - it might as well be _ABCDEFGHI_, nothing will change outside the definition of the BVAR_DEFAULTED_FIELD macro. >> >> +#define PER_BUFFER_VAR_DEFAULTED_OFFSET(VAR) \ >> >> + offsetof (struct buffer, BVAR_DEFAULTED_FIELD(VAR)) >> > >> > Likewise here: I don't see how such macros make the code more >> > readable. I think they make it less readable. >> >> I agree but I couldn't find a better way to ensure that BVAR and >> BVAR_OR_DEFAULT are used on the correct fields. > > Maybe someone could come up with a trick to have the diagnostics > without twisting the sources so much. Yes, I hope someone comes up with a better idea than me. > Failing that, maybe we should simply have a test to detect the > mistakes? That wouldn't prevent bad code from being compiled, but it > should reveal it soon enough, since tests are regularly run on hydra. A conditionally-compiled runtime check would be very easy to add - I'd just change BVAR to something like: (eassert (EQ (buffer_defaults->field ## _)); (buf)->field ## _) Which would make sure that it's not used on anything with a default. But of course that's substantially more annoying than a compile time check...