unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: emacs-devel@gnu.org
Subject: Re: FACE_FROM_ID vs FACE_OPT_FROM_ID
Date: Sat, 02 Jul 2016 12:50:57 +0300	[thread overview]
Message-ID: <831t3ctlku.fsf@gnu.org> (raw)
In-Reply-To: <576EF8FC.1040507@cs.ucla.edu> (message from Paul Eggert on Sat,  25 Jun 2016 23:34:52 +0200)

> Cc: emacs-devel@gnu.org
> From: Paul Eggert <eggert@cs.ucla.edu>
> Date: Sat, 25 Jun 2016 23:34:52 +0200
> 
> >   . Define FACE_FROM_ID as it was before:
> >
> >     #define FACE_FROM_ID(F, ID)				\
> > 	(UNSIGNED_CMP (ID, <, FRAME_FACE_CACHE (F)->used)	\
> > 	 ? FRAME_FACE_CACHE (F)->faces_by_id[ID]		\
> > 	 : NULL)
> >
> >   . In every place that calls FACE_FROM_ID and doesn't already include
> >     code to deal with a NULL value, do this:
> >
> >       face = FACE_FROM_ID (f, face_id);
> >       if (!face)
> >         emacs_abort ();
> >
> >   . Remove FACE_OPT_FROM_ID
> >
> 
> If we go this route, I suggest having a function NONNULL_FACE_FROM_ID 
> that packages up those three lines of code (which will occur in many 
> places). That is, instead of this:
> 
>    face = FACE_FROM_ID (f, face_id);
>    if (!face)
>      emacs_abort ();
> 
> we should write this:
> 
>    face = NONNULL_FACE_FROM_ID (f, face_id);
> 
> to mean the same thing. (Or perhaps you can think of a better name than 
> NONNULL_FACE_FROM_ID.)
> 
> This sort of thing should also suffice to remove the warning. A downside 
> is that it inserts unnecessary runtime checks in production code, as the 
> "if (!face) emacs_abort ();" won't detect errors in production usefully 
> earlier than the existing code does when it dereferences the pointer. In 
> practice the unnecessary checks probably won't cost that much, so it's 
> OK if nobody else cares about the performance degradation in production 
> code. (I tried hard to avoid slowing down Emacs merely to pacify GCC, 
> and if we go this route we'd be departing slightly from that tradition.)

OK, thanks.  I took all these arguments under consideration, and made
the corresponding changes in master commit 55d38fc.  Most of it is
just renaming FACE_OPT_FROM_ID to FACE_FROM_ID_OR_NULL (the latter is
IMO more telling about its purpose), but some of the changes change
the macro we call, either because the calling code can cope with a
NULL face pointer, or because it cannot, but the dereference was too
far for GCC 6 to notice it.

I decided not to abort when ENABLE_CHECKING is not defined, because
you convinced me that is unnecessary.



      reply	other threads:[~2016-07-02  9:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-23 20:03 FACE_FROM_ID vs FACE_OPT_FROM_ID Eli Zaretskii
2016-06-24  0:23 ` Paul Eggert
2016-06-24  8:49   ` Eli Zaretskii
2016-06-24  9:27     ` Paul Eggert
2016-06-24  9:57       ` Eli Zaretskii
2016-06-24 10:00       ` Eli Zaretskii
2016-06-24 11:17         ` Paul Eggert
2016-06-24 13:43           ` Eli Zaretskii
2016-06-24 21:34             ` Paul Eggert
2016-06-25  7:48               ` Eli Zaretskii
2016-06-25 21:34                 ` Paul Eggert
2016-07-02  9:50                   ` Eli Zaretskii [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=831t3ctlku.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).