Subject: Re: bug#79200: 31.0.50; Duplicated elements for '#<marker at' in buffer-undo-list

From: Pip Cet <[email-masked]>
Date: Sat, 09 Aug 2025 09:21:04 +0000

Óscar Fuentes via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <[email-masked]> writes:

> Gerd Möllmann <[email-masked]> writes:
>
>> Óscar Fuentes <[email-masked]> writes:
>>
>>> emacs -Q
>>>
>>> write in *scratch* some lines with random words:
>>>
>>> arins
>>> arseina
>>> aierni
>>>
>>> iosrn nioni
>>> ionugfw
>>>
>>> sronuf
>>>
>>> Now undo a few of those lines (C-_), move the cursor and C-_ again to
>>> redo.
>>
>> Interesting. I come from a slightly different angle, that in my mac+igc
>> port I had sometimes only 3 undos before I got "no more undo
>> information". and I thought I had messed up something.
>
> Same here, but igc/Linux. Please note that the recipe on my report is
> with yesterday's master, though.

If there's a problem with master, we should fix that first :-)

However, one reason that results may be somewhat unpredictable is that
buffer-undo-list can change when GC is triggered (on master): marker
entries don't prevent the marker from being collected and the list
entries are removed in that case.

>> So far I can't see what is the cause. I would have guessed something in
>> or around primitive-undo, but that hasn't changed forever.
>
> Eli in emacs-devel pointed to the possibility that something is creating
> lots of markers. Checking if those repeated elements in buffer-undo-list
> point to the same marker or to different ones would be revealing.

Calling sxhash-eq is probably the quickest way to establish whether two
markers are eq. If the same marker turned up twice in the same section
of an undo list, that would be a bug somewhere:

(dolist (el buffer-undo-list)
  (and (consp el)
       (markerp (car el))
       (message "%S %S" (car el) (sxhash-eq (car el)))))

> Or not: I don't even know if getting markers to the same place in a
> buffer yield the same object or new ones.

New ones, in general.

Pip