From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30294 invoked by alias); 16 Jul 2007 09:58:53 -0000 Received: (qmail 30277 invoked by uid 22791); 16 Jul 2007 09:58:53 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 16 Jul 2007 09:58:51 +0000 Received: from sunsite.mff.cuni.cz (localhost.localdomain [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.8/8.13.8) with ESMTP id l6GA2Fd3017043; Mon, 16 Jul 2007 12:02:15 +0200 Received: (from jakub@localhost) by sunsite.mff.cuni.cz (8.13.8/8.13.8/Submit) id l6GA2F7X017036; Mon, 16 Jul 2007 12:02:15 +0200 Date: Mon, 16 Jul 2007 09:58:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix realloc prototype (BZ #4792) Message-ID: <20070716100214.GP4603@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.2.2i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2007-07/txt/msg00018.txt.bz2 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 [BZ #4792] * stdlib/stdlib.h (realloc): Remove __attribute_malloc__. * malloc/malloc.h (realloc): Likewise. --- libc/stdlib/stdlib.h.jj 2007-07-03 12:37:00.000000000 +0200 +++ libc/stdlib/stdlib.h 2007-07-16 10:31:04.000000000 +0200 @@ -597,8 +597,11 @@ __END_NAMESPACE_STD __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 --- libc/malloc/malloc.h.jj 2005-03-08 01:44:45.000000000 +0100 +++ libc/malloc/malloc.h 2007-07-16 10:32:25.000000000 +0200 @@ -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 @@ extern void *calloc __MALLOC_P ((size_t /* 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)); Jakub