[FFmpeg-devel] [PATCH] Doxygenate libavutil/mem.h
Stefano Sabatini
stefano.sabatini-lala
Sat Sep 22 11:46:10 CEST 2007
On date Friday 2007-09-21 15:02:05 -0400, Rich Felker encoded:
> On Fri, Sep 21, 2007 at 08:53:37PM +0300, Uoti Urpala wrote:
> > On Fri, 2007-09-21 at 19:06 +0200, Stefano Sabatini wrote:
> > > On date Friday 2007-09-21 08:18:45 -0400, Rich Felker encoded:
> > > > On Fri, Sep 21, 2007 at 11:33:14AM +0200, Diego Biurrun wrote:
> > > > > > + * Allocates or reallocates a block of memory.
> > > > > > + * Same semantics as glibc realloc: if \p ptr is NULL and \p size > 0,
> > > > > > + * identical to malloc(size). If \p size is zero, it is identical to
> > > > > > * free(ptr) and NULL is returned.
> > > >
> > > > It would be better to cite a well-known standard, ANSI/ISO C, rather
> > > > than glibc.... Realloc semantics are not glibc-specific.
> > >
> > > Good point, changed "glibc" to "ANSI/ISO C".
> >
> > ANSI/ISO C does not guarantee these semantics. A size-0 realloc need not
> > return NULL.
>
> Oh, sorry, I was looking at only half of it, the free behavior. You're
> right, ANSI/ISO C allows returning a unique pointer that's utterly
> useless. However, doesn't glibc actually take this second brain-dead
> option? I know glibc's malloc returns a non-NULL value for
> malloc(0)... not sure what realloc does.
#include <stdlib.h>
#include <stdio.h>
/* test the behaviour of glibc realloc */
int main (void) {
int *ptr;
/* allocate */
ptr = realloc (NULL, 100);
printf ("realloc(NULL, 100) is: %d\n", ptr);
ptr = realloc (ptr, 0);
printf ("realloc(ptr, 0) is: %d\n", ptr);
ptr = realloc (NULL, 0);
printf ("realloc(NULL, 0) is: %d\n", ptr);
return 0;
}
make realloc; and realloc
cc realloc.c -o realloc
realloc(NULL, 100) is: 134520840
realloc(ptr, 0) is: 0
realloc(NULL, 0) is: 134520840
The latter behaviour is not explicitely documented in the glibc
manual, but it is the more obvious one (always returns a non-NULL
pointer if it can allocate memory).
Changing realloc with av_realloc issues the same result.
And I reverted the previous change, so now it is stated:
"same semantics as glibc realloc"
Regards.
--
Stefano Sabatini
Linux user number 337176 (see http://counter.li.org)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: doxygenate-mem-h-03.patch
Type: text/x-diff
Size: 2508 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070922/a996aa1a/attachment.patch>
More information about the ffmpeg-devel
mailing list