unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Pip Cet <pipcet@gmail.com>
Cc: 41520@debbugs.gnu.org, stefan@marxist.se
Subject: bug#41520: 28.0.50; Crash in character.h due to assertion error
Date: Tue, 26 May 2020 19:17:15 +0300	[thread overview]
Message-ID: <831rn6vfg4.fsf@gnu.org> (raw)
In-Reply-To: <CAOqdjBcBgD71YWHLPHKCGSXhYYhbf89v-o-HXWA+8F-biTF1WA@mail.gmail.com> (message from Pip Cet on Mon, 25 May 2020 20:39:06 +0000)

> From: Pip Cet <pipcet@gmail.com>
> Date: Mon, 25 May 2020 20:39:06 +0000
> Cc: stefan@marxist.se, 41520@debbugs.gnu.org
> 
> The plan is to introduce additional struct-valued macros for things
> like PT/PT_BYTE:
> 
> #define PT_POS POS (PT, PT_BYTE)
> 
> In particular, it's not an lvalue. That's important to me, since
> assigning to PT_POS would be a severe bug.

So all the places where we now access PT and PT_BYTE separately will
now dereference a struct?

(Btw, PT and PT_BYTE are already non-lvalues, so we have this
covered.)

> > Like GPT, for example?
> 
> That's difficult. GPT is, of course, very special.

How so?  It's just like any other buffer position.

> > What about BEGV and ZV?
> 
> BEG, BEGV, ZV, and Z would all have _POS equivalents, and very often
> using them results in more readable code.
> 
> > IOW, I don't understand the goal here.
> 
> There are multiple goals: I think this significantly aids readability,
> and I think there might still be some minor bugs to catch, and future
> bugs to avoid.
> 
> For debug builds only, it might make sense to include the object that
> the bytepos-charpos relation is valid for, to catch cases where one
> object's correspondence is used for another object.
> 
> > I think I did understand when we were talking about accessing characters by buffer positions, and
> > the bugs related to incorrect usage there, but now it sounds like the plot thickens?
> 
> I hope that most code will follow a basic structure of being passed a
> Lisp_Object or two (charpos/marker and object), converting that to a
> pos_t, handing that to internal APIs, potentially receiving a pos_t
> back and converting it back to a Lisp_Object, with only a few lines of
> code deep down the call stacks actually unwrapping the pos_t and
> manipulating it directly. That means there are a few more cases than
> accessing buffer text: comparing two positions, for example, walking a
> buffer or string by incrementing or decrementing them, adding two
> positions or subtracting them.
> 
> (It's true that all kinds of crazy experiments would be easier with
> code that follows this structure, but that's a side effect: the goal
> really is to increase readability a little in a lot of places.)

I cannot judge readability: I'm too accustomed to the current
variables.  But it's clear that this will hurt speed, and in the
innermost loops of our code.  Having to maintain 2 values, recompute
one from another, and move them into and out of a structure each adds
overhead, some small, some large.  They will add up.  I don't think I
see how we can justify that, as the current code is not horribly
unreadable.

Let's see what others think.

>     ch = bidi_fetch_char (cpos += nc, bpos += clen, &disp_pos, &dpp, &bs,
>                   bidi_it->w, fwp, &clen, &nc)
> 
> "nc" and "clen" belong together, and so do cpos and bpos. I find the
> names don't make that very obvious, and simply reducing the number of
> arguments bidi_fetch_char takes by two helps a little.

We can use more descriptive names, that's easy and has zero overhead.
Converting all of our sources to using a struct as positions is
something different.





  reply	other threads:[~2020-05-26 16:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-25  7:05 bug#41520: 28.0.50; Crash in character.h due to assertion error Stefan Kangas
2020-05-25  7:28 ` Pip Cet
2020-05-25  7:41   ` Pip Cet
2020-05-25 14:18   ` Eli Zaretskii
2020-05-25 14:30     ` Pip Cet
2020-05-25 15:07       ` Eli Zaretskii
2020-05-25 15:16         ` Pip Cet
2020-05-25 16:09           ` Eli Zaretskii
2020-05-25 17:54             ` Pip Cet
2020-05-25 19:30               ` Eli Zaretskii
2020-05-25 20:39                 ` Pip Cet
2020-05-26 16:17                   ` Eli Zaretskii [this message]
2020-09-27 14:36         ` Lars Ingebrigtsen
2020-09-27 15:15           ` Eli Zaretskii
2020-09-27 15:42             ` Lars Ingebrigtsen
2020-09-27 16:00               ` Eli Zaretskii

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=831rn6vfg4.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=41520@debbugs.gnu.org \
    --cc=pipcet@gmail.com \
    --cc=stefan@marxist.se \
    /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).