This is the mail archive of the libc-hacker@sourceware.cygnus.com 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]

Patch for malloc.h



Hi,

the inclusion of 
#include <stdlib.h>
#include <malloc.h>

leads to the following warnings:

$ /opt/egcs/bin/g++ stat-test.C -o stat-test -Wall -pedantic
In file included from stat-test.C:2:
/usr/include/malloc.h:90: warning: declaration of `malloc(size_t)' throws different exceptions
/usr/include/stdlib.h:474: warning: previous declaration here
/usr/include/malloc.h:93: warning: declaration of `calloc(size_t, size_t)' throws different exceptions
/usr/include/stdlib.h:476: warning: previous declaration here
/usr/include/malloc.h:97: warning: declaration of `realloc(void *, size_t)' throws different exceptions
/usr/include/stdlib.h:482: warning: previous declaration here
/usr/include/malloc.h:100: warning: declaration of `free(void *)' throws different exceptions
/usr/include/stdlib.h:484: warning: previous declaration here
/usr/include/malloc.h:103: warning: declaration of `cfree(void *)' throws different exceptions
/usr/include/stdlib.h:488: warning: previous declaration here
/usr/include/malloc.h:109: warning: declaration of `valloc(size_t)' throws different exceptions
/usr/include/stdlib.h:497: warning: previous declaration here

I'm appending a patch to fix this.

Andreas

1999-05-23  Andreas Jaeger  <aj@arthur.rhein-neckar.de>

	* malloc/malloc.h: Add __THROW for __MALLOC_P to synch with usage
	of __P in the rest of glibc; define __MALLOC_PMT and use it.
        Reported by Stephan Kulow <coolo@kde.org>.

--- malloc/malloc.h.~1~	Sat Jan 17 10:59:02 1998
+++ malloc/malloc.h	Sun May 23 20:51:07 1999
@@ -1,5 +1,5 @@
 /* Prototypes and definition for malloc implementation.
-   Copyright (C) 1996, 1997 Free Software Foundation, Inc.
+   Copyright (C) 1996, 1997, 1999 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
@@ -55,11 +55,36 @@
 # define __malloc_ptrdiff_t ptrdiff_t
 #endif
 
-#if defined __STDC__ || defined __cplusplus || defined __GNUC__
-# define __MALLOC_P(args)        args
-#else
-# define __MALLOC_P(args)        ()
-#endif
+#ifdef __GNUC__
+
+/* GCC can always grok prototypes.  For C++ programs we add throw()
+   to help it optimize the function calls.  But this works only with
+   gcc 2.8.x and egcs.  */
+# if defined __cplusplus && __GNUC_MINOR__ >= 8
+#  define __THROW	throw ()
+# else
+#  define __THROW
+# endif
+# define __MALLOC_P(args)	args __THROW
+/* This macro will be used for functions which might take C++ callback
+   functions.  */
+# define __MALLOC_PMT(args)	args
+
+#else	/* Not GCC.  */
+
+# if (defined __STDC__ && __STDC__) || defined __cplusplus
+
+#  define __MALLOC_P(args)	args
+#  define __MALLOC_PMT(args)	args
+
+# else	/* Not ANSI C or C++.  */
+
+#  define __MALLOC_P(args)	()	/* No prototypes.  */
+#  define __MALLOC_PMT(args)	()
+
+# endif	/* ANSI C or C++.  */
+
+#endif	/* GCC.  */
 
 #ifndef NULL
 # ifdef __cplusplus
@@ -114,7 +139,7 @@
 
 /* Underlying allocation function; successive calls should return
    contiguous pieces of memory.  */
-extern __malloc_ptr_t (*__morecore) __MALLOC_P ((ptrdiff_t __size));
+extern __malloc_ptr_t (*__morecore) __MALLOC_PMT ((ptrdiff_t __size));
 
 /* Default value of `__morecore'.  */
 extern __malloc_ptr_t __default_morecore __MALLOC_P ((ptrdiff_t __size));
@@ -180,18 +205,18 @@
 
 #if defined __GLIBC__ || defined MALLOC_HOOKS
 /* Hooks for debugging versions. */
-extern void (*__malloc_initialize_hook) __MALLOC_P ((void));
-extern void (*__free_hook) __MALLOC_P ((__malloc_ptr_t __ptr,
+extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
+extern void (*__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
 					__const __malloc_ptr_t));
-extern __malloc_ptr_t (*__malloc_hook) __MALLOC_P ((size_t __size,
+extern __malloc_ptr_t (*__malloc_hook) __MALLOC_PMT ((size_t __size,
 						    __const __malloc_ptr_t));
-extern __malloc_ptr_t (*__realloc_hook) __MALLOC_P ((__malloc_ptr_t __ptr,
+extern __malloc_ptr_t (*__realloc_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
 						     size_t __size,
 						     __const __malloc_ptr_t));
-extern __malloc_ptr_t (*__memalign_hook) __MALLOC_P ((size_t __size,
+extern __malloc_ptr_t (*__memalign_hook) __MALLOC_PMT ((size_t __size,
 						      size_t __alignment,
 						      __const __malloc_ptr_t));
-extern void (*__after_morecore_hook) __MALLOC_P ((void));
+extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
 
 /* Activate a standard set of debugging hooks. */
 extern void __malloc_check_init __MALLOC_P ((void));

-- 
 Andreas Jaeger   aj@arthur.rhein-neckar.de    jaeger@informatik.uni-kl.de
  for pgp-key finger ajaeger@aixd1.rhrk.uni-kl.de

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