Sophie

Sophie

distrib > * > 2008.0 > x86_64 > media > main-updates-src > by-pkgid > cc712de1bb668738943d02e6bd0fe837 > files > 52

glibc-2.6.1-4.3mdv2008.0.src.rpm

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.
and internally while GCC uses malloc attribute on malloc etc., it doesn't
use it for realloc.
http://gcc.gnu.org/ml/gcc-patches/2004-01/msg00189.html

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

===================================================================
RCS file: /cvs/glibc/libc/stdlib/stdlib.h,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -r1.117 -r1.118
--- libc/stdlib/stdlib.h	2007/04/17 18:35:42	1.117
+++ libc/stdlib/stdlib.h	2007/07/19 17:05:07	1.118
@@ -597,8 +597,11 @@
 __BEGIN_NAMESPACE_STD
 /* Re-allocate the previously allocated block
    in PTR, making the new block SIZE bytes long.  */
+/* __attribute_malloc__ is not used, because if realloc returns
+   the same pointer that was passed to it, aliasing needs to be allowed
+   between objects pointed by the old and new pointers.  */
 extern void *realloc (void *__ptr, size_t __size)
-     __THROW __attribute_malloc__ __attribute_warn_unused_result__;
+     __THROW __attribute_warn_unused_result__;
 /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
 extern void free (void *__ptr) __THROW;
 __END_NAMESPACE_STD
===================================================================
RCS file: /cvs/glibc/libc/malloc/malloc.h,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- libc/malloc/malloc.h	2005/03/08 00:44:45	1.29
+++ libc/malloc/malloc.h	2007/07/19 17:05:07	1.30
@@ -1,5 +1,6 @@
 /* Prototypes and definition for malloc implementation.
-   Copyright (C) 1996,97,99,2000,2002-2004,2005 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1999, 2000, 2002-2004, 2005, 2007
+   Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -54,8 +55,11 @@
 
 /* Re-allocate the previously allocated block in __ptr, making the new
    block SIZE bytes long.  */
+/* __attribute_malloc__ is not used, because if realloc returns
+   the same pointer that was passed to it, aliasing needs to be allowed
+   between objects pointed by the old and new pointers.  */
 extern void *realloc __MALLOC_P ((void *__ptr, size_t __size))
-       __attribute_malloc__ __attribute_warn_unused_result__;
+       __attribute_warn_unused_result__;
 
 /* Free a block allocated by `malloc', `realloc' or `calloc'.  */
 extern void free __MALLOC_P ((void *__ptr));