unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: "Basil L. Contovounesios" <contovob@tcd.ie>,
	"João Távora" <joaotavora@gmail.com>,
	emacs-devel <emacs-devel@gnu.org>
Subject: Re: 31395511: "Don’t attempt to modify constant strings"
Date: Fri, 05 Jun 2020 09:48:55 +0000	[thread overview]
Message-ID: <87wo4l267s.fsf@gmail.com> (raw)
In-Reply-To: <8e691d13-8db0-2066-8725-ea8afab7c506@cs.ucla.edu> (Paul Eggert's message of "Thu, 4 Jun 2020 16:10:10 -0700")

Paul Eggert <eggert@cs.ucla.edu> writes:

> On 6/4/20 1:43 PM, Pip Cet wrote:
>
>> I'd prefer a mutablep predicate, with a strong warning not
>> to use it
>
> I'd rather not not build/support/advertise predicates that shouldn't
> be used....

It's perfectly usable in most situations, it's just that you shouldn't
use it to decide whether your function has side effects or not.

>>> No such error is thrown now and Emacs can crash or worse - but I
>>> plan to arrange for one to be thrown.
>> 
>> Have those plans been discussed anywhere? I get the impression it would
>> help me to understand what you're planning to do.
>
> A few weeks ago, a bit. The idea I have is pretty simple: the Emacs
> interpreter
> throws an error if you attempt to modify a string constant. Although the
> interpreter done this for years, (a) its test for whether a string is
> a constant
> has always been spotty and (b) the test has gone downhill recently.

I think there was only CHECK_IMPURE, which relies on PURE_P, which is
effectively a nop in post-dump binaries. (I still think we should remove
pure space entirely, but even if we don't we should stop wasting so much
binary size on zeroes. But let's wait for Emacs 27 first, as Eli
suggested).

>> I fail to see how that code is broken: it uses an ephemeral string
>> literal
>
> String literals are not ephemeral;

I still believe this one is. It's used in a top-level form in a defvar.

> they can be coalesced, or retained, or put into read-only memory.

Really? Is there code in Emacs (other than purecopy, which isn't the
problem here) that does any of that today?

> And when Emacs does that your program's behavior becomes squirrelly.

If Emacs were to, a lot of code would break, yes. IMHO, that's a good
reason to leave things as they are for now, deal with the pure space
issues first, and then decide whether immutable objects are worth it at
all...

>> (text-properties-at N STRING) returns the
>> string's actual plist, so you can mutate it, which seems useless and
>> potentially dangerous to me. (Please, let's change that?)
>
> We could do something along those lines eventually. The immediate problem that
> I'm looking at is just the string itself.
>
>> Would you consider (text-properties-at N STRING) to be part of the
>> string object itself, or an object it points at?
>
> My earlier email was assuming the current implementation, which is the latter.
> However, I don't think this matters much, since string literals shouldn't have
> text properties.

But if text properties aren't part of "the string itself", they can be
given text properties.

>> Which undefined behavior is that, precisely?
>
> I was referring to code that modifies literal strings' contents or properties.
> We don't really define how that works, and in practice it doesn't work the way
> people might naively expect since strings might be coalesced and their
> contents
> might be in read-only memory.

You're saying "in practice ... their contents might be in read-only
memory"? How?



  parent reply	other threads:[~2020-06-05  9:48 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03 21:52 31395511: "Don’t attempt to modify constant strings" João Távora
2020-06-03 22:41 ` Paul Eggert
2020-06-03 22:52   ` Pip Cet
2020-06-03 23:20     ` Paul Eggert
2020-06-03 23:20     ` Basil L. Contovounesios
2020-06-03 22:41 ` Pip Cet
2020-06-03 23:08   ` Basil L. Contovounesios
2020-06-03 23:31     ` Basil L. Contovounesios
2020-06-03 23:48   ` João Távora
2020-06-04  0:43     ` Paul Eggert
2020-06-04  1:19       ` Paul Eggert
2020-06-04  7:26         ` Pip Cet
2020-06-04 11:11           ` Basil L. Contovounesios
2020-06-04 19:46             ` Paul Eggert
2020-06-04 20:25               ` João Távora
2020-06-04 20:29                 ` Paul Eggert
2020-06-04 21:21                   ` Drew Adams
2020-06-04 20:43               ` Pip Cet
2020-06-04 21:27                 ` Stefan Monnier
2020-06-04 21:42                   ` Pip Cet
2020-06-04 23:10                 ` Paul Eggert
2020-06-05  2:09                   ` Clément Pit-Claudel
2020-06-05  6:44                     ` Paul Eggert
2020-06-05 12:44                       ` Stefan Monnier
2020-06-05 17:01                     ` Drew Adams
2020-06-05  9:48                   ` Pip Cet [this message]
2020-06-05 18:37                     ` Paul Eggert
2020-06-04 22:33               ` Basil L. Contovounesios
2020-06-05 15:25       ` João Távora
2020-06-05 17:14         ` Dmitry Gutov
2020-06-05 23:19           ` João Távora
2020-06-05 23:32             ` Dmitry Gutov
2020-06-06  1:34               ` FW: " Drew Adams
2020-06-06  0:23             ` Drew Adams
2020-06-06  1:43             ` Paul Eggert
2020-06-06  4:06               ` Richard Stallman
2020-06-06 11:41               ` João Távora
2020-06-06 11:47                 ` João Távora
2020-06-04  4:38     ` Pip Cet
2020-06-04  9:31       ` João Távora

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=87wo4l267s.fsf@gmail.com \
    --to=pipcet@gmail.com \
    --cc=contovob@tcd.ie \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=joaotavora@gmail.com \
    /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).