public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Alejandro Colomar <alx@kernel.org>
To: DJ Delorie <dj@redhat.com>, Russ Allbery <eagle@eyrie.org>
Cc: Andreas Schwab <schwab@linux-m68k.org>, libc-alpha@sourceware.org
Subject: Re: free(3) const void *
Date: Sat, 27 Jan 2024 00:25:05 +0100	[thread overview]
Message-ID: <ZbQ_UudJ6pwdzQSe@debian> (raw)
In-Reply-To: <xnle8bsr5x.fsf@greed.delorie.com>

[-- Attachment #1: Type: text/plain, Size: 1481 bytes --]

Hi DJ, Russ,

On Fri, Jan 26, 2024 at 04:47:38PM -0500, DJ Delorie wrote:
> Andreas Schwab <schwab@linux-m68k.org> writes:
> > Also, objects in the heap are never read-only.
> 
> I thought of that, but using "const" in a program can mean something
> other than "the object is read-only".  It can also act as a promise to
> the user and/or optimizer that an object is not written to, even if
> doing such is possible.
> 
> So the original problem of "having to keep a non-const pointer around
> just to free it" is valid.  My post was just to put me in the "too bad,
> deal with it" category ;-)

After some fresh air, I've been thinking about what Russ said, and it
makes a lot of sense.  While the attribute [[gnu::malloc()]] can tell
where some object is definitely terminated, there's no way to tell via
attributes where an object is definitely not terminated; you can only
guess that an object may or may not be terminated when a function
doesn't use the attribute.  So having `const` imply that an object is
not terminated is a feature.

If that means that we need to live with the fact that we need a writable
pointer to be able to free(3) an object, I guess the answer is indeed
"too bad, deal with it".  :-)

Maybe some day, attributes will give us full certainty about object
lifetime, but that day is not today.

Have a lovely night!
Alex 

-- 
<https://www.alejandro-colomar.es/>
Looking for a remote C programming job at the moment.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

      parent reply	other threads:[~2024-01-26 23:25 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26 13:21 Alejandro Colomar
2024-01-26 14:24 ` Arsen Arsenović
2024-01-26 15:35   ` Alejandro Colomar
2024-01-26 17:22     ` Arsen Arsenović
2024-01-26 17:55       ` Xi Ruoyao
2024-01-26 18:11         ` Alejandro Colomar
2024-01-26 20:04           ` Arsen Arsenović
2024-01-26 20:07         ` Arsen Arsenović
2024-01-26 17:40     ` Andreas Schwab
2024-01-26 19:45     ` Florian Weimer
2024-01-26 15:13 ` Andreas Schwab
2024-01-26 15:33   ` Alejandro Colomar
2024-01-26 18:09 ` Russ Allbery
2024-01-26 18:23   ` Alejandro Colomar
2024-01-26 18:36     ` Xi Ruoyao
2024-01-26 18:40       ` Alejandro Colomar
2024-01-26 18:49         ` Xi Ruoyao
2024-01-26 18:57           ` Alejandro Colomar
2024-01-26 18:40     ` Russ Allbery
2024-01-26 18:45       ` Alejandro Colomar
2024-01-26 19:41   ` Florian Weimer
2024-01-26 18:39 ` [PATCH] Use [[gnu::access(none)]] on free(3) Alejandro Colomar
2024-01-26 18:41   ` Alejandro Colomar
2024-01-26 21:23     ` Paul Eggert
2024-01-26 23:19       ` Alejandro Colomar
2024-01-27 13:21       ` Cristian Rodríguez
2024-02-13 15:19         ` Gabriel Ravier
2024-02-13 15:28           ` Alejandro Colomar
2024-01-26 21:11 ` free(3) const void * DJ Delorie
2024-01-26 21:30   ` Andreas Schwab
2024-01-26 21:47     ` DJ Delorie
2024-01-26 22:07       ` Andreas Schwab
2024-01-26 23:25       ` Alejandro Colomar [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

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

  git send-email \
    --in-reply-to=ZbQ_UudJ6pwdzQSe@debian \
    --to=alx@kernel.org \
    --cc=dj@redhat.com \
    --cc=eagle@eyrie.org \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@linux-m68k.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.
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).