This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Re: malloc patch for 2.2.4
Hello,
> Of course, they cause a huge performance penalty, but that's a
> consequence of getting the behaviour you want. It's usually much
> better to just mark the appropriate variables 'volatile' explicitly.
OK, see the patch below.
> I wasn't here talking about what ISO requires---as you say, threads
> are not dealt with by the C standard. I was saying what the compiler
> will actually do.
Actually do? I've tested and found that gcc-2.95 generates _exactly
the same code_ for malloc.o with or without the patch below applied,
at least with -O and -O2. I wouldn't have expected otherwise..
> In this case, 'a' is not declared volatile and so it can't possibly be
> a 'volatile sig_atomic_t'.
OK, for a bit more potential portability I'm presenting the patch
below, although I couldn't find evidence that it actually makes a
difference for gcc.
Regards,
Wolfram.
2001-08-27 Wolfram Gloger <wg@malloc.de>
* malloc/malloc.h: Add volatile to hook pointer declarations.
* malloc/malloc.c: Add volatile to hook pointer definitions.
--- malloc/malloc.h~ Mon Jul 23 19:54:38 2001
+++ malloc/malloc.h Mon Aug 27 15:54:16 2001
@@ -220,16 +220,14 @@
pointers. */
extern void (*__malloc_initialize_hook) __MALLOC_PMT ((void));
/* Hooks for debugging and user-defined versions. */
-extern void (*__free_hook) __MALLOC_PMT ((__malloc_ptr_t __ptr,
- __const __malloc_ptr_t));
-extern __malloc_ptr_t (*__malloc_hook) __MALLOC_PMT ((size_t __size,
- __const __malloc_ptr_t));
-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_PMT ((size_t __alignment,
- size_t __size,
- __const __malloc_ptr_t));
+extern void (*volatile __free_hook)
+ __MALLOC_PMT ((__malloc_ptr_t __ptr, __const __malloc_ptr_t));
+extern __malloc_ptr_t (*volatile __malloc_hook)
+ __MALLOC_PMT ((size_t __size, __const __malloc_ptr_t));
+extern __malloc_ptr_t (*volatile __realloc_hook)
+ __MALLOC_PMT ((__malloc_ptr_t __ptr, size_t __size, __const __malloc_ptr_t));
+extern __malloc_ptr_t (*volatile __memalign_hook)
+ __MALLOC_PMT ((size_t __alignment, size_t __size, __const __malloc_ptr_t));
extern void (*__after_morecore_hook) __MALLOC_PMT ((void));
/* Activate a standard set of debugging hooks. */
--- malloc/malloc.c~ Tue Aug 21 17:37:24 2001
+++ malloc/malloc.c Mon Aug 27 15:53:49 2001
@@ -1885,14 +1885,14 @@
}
void weak_variable (*__malloc_initialize_hook) __MALLOC_P ((void)) = NULL;
-void weak_variable (*__free_hook) __MALLOC_P ((__malloc_ptr_t __ptr,
- const __malloc_ptr_t)) = NULL;
-__malloc_ptr_t weak_variable (*__malloc_hook)
+void weak_variable (*volatile __free_hook)
+ __MALLOC_P ((__malloc_ptr_t __ptr, const __malloc_ptr_t)) = NULL;
+__malloc_ptr_t weak_variable (*volatile __malloc_hook)
__MALLOC_P ((size_t __size, const __malloc_ptr_t)) = malloc_hook_ini;
-__malloc_ptr_t weak_variable (*__realloc_hook)
+__malloc_ptr_t weak_variable (*volatile __realloc_hook)
__MALLOC_P ((__malloc_ptr_t __ptr, size_t __size, const __malloc_ptr_t))
= realloc_hook_ini;
-__malloc_ptr_t weak_variable (*__memalign_hook)
+__malloc_ptr_t weak_variable (*volatile __memalign_hook)
__MALLOC_P ((size_t __alignment, size_t __size, const __malloc_ptr_t))
= memalign_hook_ini;
void weak_variable (*__after_morecore_hook) __MALLOC_P ((void)) = NULL;