[PATCH] malloc: add free_sized and free_aligned_sized from C23

Justin King jcking@google.com
Wed Jun 18 21:47:45 GMT 2025


>
> I think we agreed in the context of discussion of Collin Funk's patches
> that the right way to do C23 updates to conform/ expectations (after the
> mechanical ones that have been done, to make it a copy of the C11
> expectations) involves complete updates of the expectations for a header
> for all changes in that header's contents in C23 (with appropriate XFAILs
> for features not implemented in glibc) rather than piecemeal updates only
> for particular features that have been implemented in glibc.


I am not super familiar, can you point me to that discussion or an example?
I just looked at roughly where aligned_alloc was referenced when doing this.


> The patch is missing a NEWS entry for the new feature.


Done.

 These appear to be inconsistently indented (spaces versus tabs).


Ugh, that is what I get for being lazy and using VSCode. Fixed with vim.

 Still missing space before '('.


Fixed. Sorry, not very used to the code style here.

"???" is not appropriate here, since we know what standard it is.


I followed aligned_alloc which put the same thing. Switched to ISO.

On Wed, Jun 18, 2025 at 1:46 PM Joseph Myers <josmyers@redhat.com> wrote:

> On Wed, 18 Jun 2025, Justin King wrote:
>
> > diff --git a/conform/data/stdlib.h-data b/conform/data/stdlib.h-data
> > index 0f6da09166..246a734ae1 100644
> > --- a/conform/data/stdlib.h-data
> > +++ b/conform/data/stdlib.h-data
> > @@ -185,6 +185,10 @@ function {void*} valloc (size_t)
> >  #endif
> >  function size_t wcstombs (char*, const wchar_t*, size_t)
> >  function int wctomb (char*, wchar_t)
> > +#if defined ISO23
> > +function void free_sized (void*, size_t)
> > +function void free_aligned_sized (void*, size_t, size_t)
> > +#endif
>
> I think we agreed in the context of discussion of Collin Funk's patches
> that the right way to do C23 updates to conform/ expectations (after the
> mechanical ones that have been done, to make it a copy of the C11
> expectations) involves complete updates of the expectations for a header
> for all changes in that header's contents in C23 (with appropriate XFAILs
> for features not implemented in glibc) rather than piecemeal updates only
> for particular features that have been implemented in glibc.
>
> The patch is missing a NEWS entry for the new feature.
>
> > diff --git a/malloc/Makefile b/malloc/Makefile
> > index 2f232f9238..04a6a356da 100644
> > --- a/malloc/Makefile
> > +++ b/malloc/Makefile
> > @@ -66,6 +66,8 @@ tests := \
> >    tst-tcfree1 tst-tcfree2 tst-tcfree3 tst-tcfree4 \
> >    tst-trim1 \
> >    tst-valloc \
> > +     tst-free-aligned-sized \
> > +     tst-free-sized \
> >  # tests
>
> These appear to be inconsistently indented (spaces versus tabs).
>
> > +void
> > +weak_function
> > +free_sized(void *ptr, __attribute__ ((__unused__)) size_t size)
>
> Still missing space before '('.
>
> > +{
> > +  /* We do not perform validation that size is the same as the original
> > +     requested size at this time. We leave that to the sanitizers. We
> > +     simply forward to `free`. This allows existing malloc replacements
> > +     to continue to work.  */
> > +
> > +  free(ptr);
>
> Likewise.
>
> > +}
> > +
> > +/* For ISO C23.  */
> > +void
> > +weak_function
> > +free_aligned_sized(void *ptr, __attribute__ ((__unused__)) size_t
> alignment,
>
> Likewise.
>
> > +                   __attribute__ ((__unused__)) size_t size)
> > +{
> > +  /* We do not perform validation that size and alignment is the same as
> > +     the original requested size and alignment at this time. We leave
> that
> > +     to the sanitizers. We simply forward to `free`. This allows
> existing
> > +     malloc replacements to continue to work.  */
> > +
> > +  free(ptr);
>
> Likewise.
>
> > diff --git a/manual/memory.texi b/manual/memory.texi
> > index 46f76c17ca..9da3e172f6 100644
> > --- a/manual/memory.texi
> > +++ b/manual/memory.texi
> > @@ -764,6 +764,34 @@ There is no point in freeing blocks at the end of a
> program, because all
> >  of the program's space is given back to the system when the process
> >  terminates.
> >
> > +@deftypefun void free_sized (void *@var{ptr}, size_t @var{size})
> > +@standards{???, stdlib.h}
>
> "???" is not appropriate here, since we know what standard it is.
>
> > +@deftypefun void free_aligned_sized (void *@var{ptr}, size_t
> @var{alignment}, size_t @var{size})
> > +@standards{???, stdlib.h}
>
> Likewise.
>
> --
> Joseph S. Myers
> josmyers@redhat.com
>
>

-- 

[image: Google Logo]
Justin King
Software Engineer
jcking@google.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250618/cb94f813/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5277 bytes
Desc: S/MIME Cryptographic Signature
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20250618/cb94f813/attachment.p7s>


More information about the Libc-alpha mailing list