Subject: bug#75845: mapconcat crashes for unreasonable self-modifications

From: Mattias Engdegård <[email-masked]>
Date: Fri, 21 Feb 2025 16:10:45 +0100

21 feb. 2025 kl. 13.35 skrev Pip Cet <[email-masked]>:

> (If we really want to optimize it further, let's get rid of the strange
> double loop in mapconcat first, which spreads the arguments then goes
> back over the list in reverse order to fill in the separators).

I don't think it's really a cache killer but will give it a look.

> I maintain that using strings as a sequence argument to the map*
> functions is so rare we should just turn them into a list or vector
> instead and drop the special-casing code.

I'll think about it.

> I'm still not convinced abolishing string mutation is a good idea,

Let's try to solve this bug in isolation. We're almost done!

> With maphash, this actually happens (it does, or did, in the nativecomp
> code) by accident.  I'm not sure the same is true for sequences, where
> "don't crash" is probably the best we can hope for.

Lisp shouldn't crash but it's impractical to be absolute about it. The programming interface is so rich that it's almost impossible to prevent crashes altogether, and performance considerations further reduce what checks we want to perform. For instance, the user can easily crash Emacs by running bad bytecode. But users expect more about basic Lisp primitives like mapcar & co and since it seems that a reasonable effort can prevent it, and it's not (too) expensive, let's try.

Feel free to commit your patch, or post it here if you want us to poke fun at it beforehand.