This is the mail archive of the libc-hacker@sourceware.org mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix realloc prototype (BZ #4792)


Hi,

> info gcc says on the malloc attribute:
> `malloc'
>      The `malloc' attribute is used to tell the compiler that a function
>      may be treated as if any non-`NULL' pointer it returns cannot
>      alias any other pointer valid when the function returns.  This
>      will often improve optimization.  Standard functions with this
>      property include `malloc' and `calloc'.  `realloc'-like functions
>      have this property as long as the old pointer is never referred to
>      (including comparing it to the new pointer) after the function
>      returns a non-`NULL' value.

That text is IMHO completely correct and adequate.  But note that the
last sentence after "as long as" refers to a case that is _undefined_
by the C standard for the realloc function.  If realloc returns
non-NULL, the "old pointer" must not be used any more, it is just as
if free() had been called on it.  In other words, our "realloc" in
libc is not just "realloc-like" but it is _the_ C realloc.

> 2007-07-16  Jakub Jelinek  <jakub@redhat.com>
> 
> 	[BZ #4792]
> 	* stdlib/stdlib.h (realloc): Remove __attribute_malloc__.
> 	* malloc/malloc.h (realloc): Likewise.

Based on the argument above, I disagree with this change.

Within gcc, I guess you are referring to:

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32748

But maybe that is an internal "realloc-like" function were comparison
with the old pointer is intended and useful?  For libc, did you have a
particular issue/bug in mind beyond general principles?

Regards,
Wolfram.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]