public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/siddhesh/malloc-hooks] Simplify __malloc_initialized
@ 2021-07-12 4:56 Siddhesh Poyarekar
0 siblings, 0 replies; 6+ messages in thread
From: Siddhesh Poyarekar @ 2021-07-12 4:56 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c84632b74ab27fa0a605d2b47d1c6068f17e474b
commit c84632b74ab27fa0a605d2b47d1c6068f17e474b
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date: Mon Jul 5 02:18:41 2021 +0530
Simplify __malloc_initialized
Now that mcheck no longer needs to check __malloc_initialized (and no
other third party hook can since the symbol is not exported), make the
variable boolean and static so that it is used strictly within malloc.
Diff:
---
include/malloc.h | 6 ------
malloc/arena.c | 12 ++++++------
malloc/malloc.c | 24 ++++++++++++------------
3 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/include/malloc.h b/include/malloc.h
index b77761f74d..f9c9610548 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,12 +5,6 @@
# ifndef _ISOMAC
# include <rtld-malloc.h>
-/* In the GNU libc we rename the global variable
- `__malloc_initialized' to `__libc_malloc_initialized'. */
-#define __malloc_initialized __libc_malloc_initialized
-/* Nonzero if the malloc is already initialized. */
-extern int __malloc_initialized attribute_hidden;
-
struct malloc_state;
typedef struct malloc_state *mstate;
diff --git a/malloc/arena.c b/malloc/arena.c
index 9111b49589..840426f9fb 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -97,7 +97,7 @@ static mstate free_list;
__libc_lock_define_initialized (static, list_lock);
/* Already initialized? */
-int __malloc_initialized = -1;
+static bool __malloc_initialized = false;
/**************************************************************************/
@@ -143,7 +143,7 @@ int __malloc_initialized = -1;
void
__malloc_fork_lock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* We do not acquire free_list_lock here because we completely
@@ -163,7 +163,7 @@ __malloc_fork_lock_parent (void)
void
__malloc_fork_unlock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
for (mstate ar_ptr = &main_arena;; )
@@ -179,7 +179,7 @@ __malloc_fork_unlock_parent (void)
void
__malloc_fork_unlock_child (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* Push all arenas to the free list, except thread_arena, which is
@@ -286,10 +286,10 @@ static void tcache_key_initialize (void);
static void
ptmalloc_init (void)
{
- if (__malloc_initialized >= 0)
+ if (__malloc_initialized)
return;
- __malloc_initialized = 0;
+ __malloc_initialized = true;
#if USE_TCACHE
tcache_key_initialize ();
diff --git a/malloc/malloc.c b/malloc/malloc.c
index cf71314b2b..ed0316e690 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3195,7 +3195,7 @@ __libc_malloc (size_t bytes)
_Static_assert (PTRDIFF_MAX <= SIZE_MAX / 2,
"PTRDIFF_MAX is not more than half of SIZE_MAX");
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if USE_TCACHE
/* int_free also calls request2size, be careful to not pad twice. */
@@ -3308,7 +3308,7 @@ __libc_realloc (void *oldmem, size_t bytes)
void *newp; /* chunk to return */
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if REALLOC_ZERO_BYTES_FREES
@@ -3444,7 +3444,7 @@ libc_hidden_def (__libc_realloc)
void *
__libc_memalign (size_t alignment, size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3515,7 +3515,7 @@ libc_hidden_def (__libc_memalign)
void *
__libc_valloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3526,7 +3526,7 @@ __libc_valloc (size_t bytes)
void *
__libc_pvalloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3565,7 +3565,7 @@ __libc_calloc (size_t n, size_t elem_size)
sz = bytes;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
MAYBE_INIT_TCACHE ();
@@ -5022,7 +5022,7 @@ __malloc_trim (size_t s)
{
int result = 0;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
mstate ar_ptr = &main_arena;
@@ -5157,7 +5157,7 @@ __libc_mallinfo2 (void)
struct mallinfo2 m;
mstate ar_ptr;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
memset (&m, 0, sizeof (m));
@@ -5208,7 +5208,7 @@ __malloc_stats (void)
mstate ar_ptr;
unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
_IO_flockfile (stderr);
int old_flags2 = stderr->_flags2;
@@ -5377,7 +5377,7 @@ __libc_mallopt (int param_number, int value)
mstate av = &main_arena;
int res = 1;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
__libc_lock_lock (av->mutex);
@@ -5595,7 +5595,7 @@ __posix_memalign (void **memptr, size_t alignment, size_t size)
{
void *mem;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
/* Test whether the SIZE argument is valid. It must be a power of
@@ -5639,7 +5639,7 @@ __malloc_info (int options, FILE *fp)
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
fputs ("<malloc version=\"1\">\n", fp);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/siddhesh/malloc-hooks] Simplify __malloc_initialized
@ 2021-07-19 17:48 Siddhesh Poyarekar
0 siblings, 0 replies; 6+ messages in thread
From: Siddhesh Poyarekar @ 2021-07-19 17:48 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ee902be2c8650bf63901d65011858d0c958d7991
commit ee902be2c8650bf63901d65011858d0c958d7991
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date: Mon Jul 5 02:18:41 2021 +0530
Simplify __malloc_initialized
Now that mcheck no longer needs to check __malloc_initialized (and no
other third party hook can since the symbol is not exported), make the
variable boolean and static so that it is used strictly within malloc.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
Diff:
---
include/malloc.h | 6 ------
malloc/arena.c | 12 ++++++------
malloc/malloc.c | 24 ++++++++++++------------
3 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/include/malloc.h b/include/malloc.h
index b77761f74d..f9c9610548 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,12 +5,6 @@
# ifndef _ISOMAC
# include <rtld-malloc.h>
-/* In the GNU libc we rename the global variable
- `__malloc_initialized' to `__libc_malloc_initialized'. */
-#define __malloc_initialized __libc_malloc_initialized
-/* Nonzero if the malloc is already initialized. */
-extern int __malloc_initialized attribute_hidden;
-
struct malloc_state;
typedef struct malloc_state *mstate;
diff --git a/malloc/arena.c b/malloc/arena.c
index 9111b49589..840426f9fb 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -97,7 +97,7 @@ static mstate free_list;
__libc_lock_define_initialized (static, list_lock);
/* Already initialized? */
-int __malloc_initialized = -1;
+static bool __malloc_initialized = false;
/**************************************************************************/
@@ -143,7 +143,7 @@ int __malloc_initialized = -1;
void
__malloc_fork_lock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* We do not acquire free_list_lock here because we completely
@@ -163,7 +163,7 @@ __malloc_fork_lock_parent (void)
void
__malloc_fork_unlock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
for (mstate ar_ptr = &main_arena;; )
@@ -179,7 +179,7 @@ __malloc_fork_unlock_parent (void)
void
__malloc_fork_unlock_child (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* Push all arenas to the free list, except thread_arena, which is
@@ -286,10 +286,10 @@ static void tcache_key_initialize (void);
static void
ptmalloc_init (void)
{
- if (__malloc_initialized >= 0)
+ if (__malloc_initialized)
return;
- __malloc_initialized = 0;
+ __malloc_initialized = true;
#if USE_TCACHE
tcache_key_initialize ();
diff --git a/malloc/malloc.c b/malloc/malloc.c
index cf71314b2b..ed0316e690 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3195,7 +3195,7 @@ __libc_malloc (size_t bytes)
_Static_assert (PTRDIFF_MAX <= SIZE_MAX / 2,
"PTRDIFF_MAX is not more than half of SIZE_MAX");
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if USE_TCACHE
/* int_free also calls request2size, be careful to not pad twice. */
@@ -3308,7 +3308,7 @@ __libc_realloc (void *oldmem, size_t bytes)
void *newp; /* chunk to return */
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if REALLOC_ZERO_BYTES_FREES
@@ -3444,7 +3444,7 @@ libc_hidden_def (__libc_realloc)
void *
__libc_memalign (size_t alignment, size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3515,7 +3515,7 @@ libc_hidden_def (__libc_memalign)
void *
__libc_valloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3526,7 +3526,7 @@ __libc_valloc (size_t bytes)
void *
__libc_pvalloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3565,7 +3565,7 @@ __libc_calloc (size_t n, size_t elem_size)
sz = bytes;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
MAYBE_INIT_TCACHE ();
@@ -5022,7 +5022,7 @@ __malloc_trim (size_t s)
{
int result = 0;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
mstate ar_ptr = &main_arena;
@@ -5157,7 +5157,7 @@ __libc_mallinfo2 (void)
struct mallinfo2 m;
mstate ar_ptr;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
memset (&m, 0, sizeof (m));
@@ -5208,7 +5208,7 @@ __malloc_stats (void)
mstate ar_ptr;
unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
_IO_flockfile (stderr);
int old_flags2 = stderr->_flags2;
@@ -5377,7 +5377,7 @@ __libc_mallopt (int param_number, int value)
mstate av = &main_arena;
int res = 1;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
__libc_lock_lock (av->mutex);
@@ -5595,7 +5595,7 @@ __posix_memalign (void **memptr, size_t alignment, size_t size)
{
void *mem;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
/* Test whether the SIZE argument is valid. It must be a power of
@@ -5639,7 +5639,7 @@ __malloc_info (int options, FILE *fp)
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
fputs ("<malloc version=\"1\">\n", fp);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/siddhesh/malloc-hooks] Simplify __malloc_initialized
@ 2021-07-19 13:29 Siddhesh Poyarekar
0 siblings, 0 replies; 6+ messages in thread
From: Siddhesh Poyarekar @ 2021-07-19 13:29 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ee902be2c8650bf63901d65011858d0c958d7991
commit ee902be2c8650bf63901d65011858d0c958d7991
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date: Mon Jul 5 02:18:41 2021 +0530
Simplify __malloc_initialized
Now that mcheck no longer needs to check __malloc_initialized (and no
other third party hook can since the symbol is not exported), make the
variable boolean and static so that it is used strictly within malloc.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
Diff:
---
include/malloc.h | 6 ------
malloc/arena.c | 12 ++++++------
malloc/malloc.c | 24 ++++++++++++------------
3 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/include/malloc.h b/include/malloc.h
index b77761f74d..f9c9610548 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,12 +5,6 @@
# ifndef _ISOMAC
# include <rtld-malloc.h>
-/* In the GNU libc we rename the global variable
- `__malloc_initialized' to `__libc_malloc_initialized'. */
-#define __malloc_initialized __libc_malloc_initialized
-/* Nonzero if the malloc is already initialized. */
-extern int __malloc_initialized attribute_hidden;
-
struct malloc_state;
typedef struct malloc_state *mstate;
diff --git a/malloc/arena.c b/malloc/arena.c
index 9111b49589..840426f9fb 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -97,7 +97,7 @@ static mstate free_list;
__libc_lock_define_initialized (static, list_lock);
/* Already initialized? */
-int __malloc_initialized = -1;
+static bool __malloc_initialized = false;
/**************************************************************************/
@@ -143,7 +143,7 @@ int __malloc_initialized = -1;
void
__malloc_fork_lock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* We do not acquire free_list_lock here because we completely
@@ -163,7 +163,7 @@ __malloc_fork_lock_parent (void)
void
__malloc_fork_unlock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
for (mstate ar_ptr = &main_arena;; )
@@ -179,7 +179,7 @@ __malloc_fork_unlock_parent (void)
void
__malloc_fork_unlock_child (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* Push all arenas to the free list, except thread_arena, which is
@@ -286,10 +286,10 @@ static void tcache_key_initialize (void);
static void
ptmalloc_init (void)
{
- if (__malloc_initialized >= 0)
+ if (__malloc_initialized)
return;
- __malloc_initialized = 0;
+ __malloc_initialized = true;
#if USE_TCACHE
tcache_key_initialize ();
diff --git a/malloc/malloc.c b/malloc/malloc.c
index cf71314b2b..ed0316e690 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3195,7 +3195,7 @@ __libc_malloc (size_t bytes)
_Static_assert (PTRDIFF_MAX <= SIZE_MAX / 2,
"PTRDIFF_MAX is not more than half of SIZE_MAX");
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if USE_TCACHE
/* int_free also calls request2size, be careful to not pad twice. */
@@ -3308,7 +3308,7 @@ __libc_realloc (void *oldmem, size_t bytes)
void *newp; /* chunk to return */
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if REALLOC_ZERO_BYTES_FREES
@@ -3444,7 +3444,7 @@ libc_hidden_def (__libc_realloc)
void *
__libc_memalign (size_t alignment, size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3515,7 +3515,7 @@ libc_hidden_def (__libc_memalign)
void *
__libc_valloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3526,7 +3526,7 @@ __libc_valloc (size_t bytes)
void *
__libc_pvalloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3565,7 +3565,7 @@ __libc_calloc (size_t n, size_t elem_size)
sz = bytes;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
MAYBE_INIT_TCACHE ();
@@ -5022,7 +5022,7 @@ __malloc_trim (size_t s)
{
int result = 0;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
mstate ar_ptr = &main_arena;
@@ -5157,7 +5157,7 @@ __libc_mallinfo2 (void)
struct mallinfo2 m;
mstate ar_ptr;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
memset (&m, 0, sizeof (m));
@@ -5208,7 +5208,7 @@ __malloc_stats (void)
mstate ar_ptr;
unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
_IO_flockfile (stderr);
int old_flags2 = stderr->_flags2;
@@ -5377,7 +5377,7 @@ __libc_mallopt (int param_number, int value)
mstate av = &main_arena;
int res = 1;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
__libc_lock_lock (av->mutex);
@@ -5595,7 +5595,7 @@ __posix_memalign (void **memptr, size_t alignment, size_t size)
{
void *mem;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
/* Test whether the SIZE argument is valid. It must be a power of
@@ -5639,7 +5639,7 @@ __malloc_info (int options, FILE *fp)
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
fputs ("<malloc version=\"1\">\n", fp);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/siddhesh/malloc-hooks] Simplify __malloc_initialized
@ 2021-07-13 3:39 Siddhesh Poyarekar
0 siblings, 0 replies; 6+ messages in thread
From: Siddhesh Poyarekar @ 2021-07-13 3:39 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=537f77674265184fd660e47a8156f57c69a46444
commit 537f77674265184fd660e47a8156f57c69a46444
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date: Mon Jul 5 02:18:41 2021 +0530
Simplify __malloc_initialized
Now that mcheck no longer needs to check __malloc_initialized (and no
other third party hook can since the symbol is not exported), make the
variable boolean and static so that it is used strictly within malloc.
Diff:
---
include/malloc.h | 6 ------
malloc/arena.c | 12 ++++++------
malloc/malloc.c | 24 ++++++++++++------------
3 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/include/malloc.h b/include/malloc.h
index b77761f74d..f9c9610548 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,12 +5,6 @@
# ifndef _ISOMAC
# include <rtld-malloc.h>
-/* In the GNU libc we rename the global variable
- `__malloc_initialized' to `__libc_malloc_initialized'. */
-#define __malloc_initialized __libc_malloc_initialized
-/* Nonzero if the malloc is already initialized. */
-extern int __malloc_initialized attribute_hidden;
-
struct malloc_state;
typedef struct malloc_state *mstate;
diff --git a/malloc/arena.c b/malloc/arena.c
index 9111b49589..840426f9fb 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -97,7 +97,7 @@ static mstate free_list;
__libc_lock_define_initialized (static, list_lock);
/* Already initialized? */
-int __malloc_initialized = -1;
+static bool __malloc_initialized = false;
/**************************************************************************/
@@ -143,7 +143,7 @@ int __malloc_initialized = -1;
void
__malloc_fork_lock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* We do not acquire free_list_lock here because we completely
@@ -163,7 +163,7 @@ __malloc_fork_lock_parent (void)
void
__malloc_fork_unlock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
for (mstate ar_ptr = &main_arena;; )
@@ -179,7 +179,7 @@ __malloc_fork_unlock_parent (void)
void
__malloc_fork_unlock_child (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* Push all arenas to the free list, except thread_arena, which is
@@ -286,10 +286,10 @@ static void tcache_key_initialize (void);
static void
ptmalloc_init (void)
{
- if (__malloc_initialized >= 0)
+ if (__malloc_initialized)
return;
- __malloc_initialized = 0;
+ __malloc_initialized = true;
#if USE_TCACHE
tcache_key_initialize ();
diff --git a/malloc/malloc.c b/malloc/malloc.c
index cf71314b2b..ed0316e690 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3195,7 +3195,7 @@ __libc_malloc (size_t bytes)
_Static_assert (PTRDIFF_MAX <= SIZE_MAX / 2,
"PTRDIFF_MAX is not more than half of SIZE_MAX");
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if USE_TCACHE
/* int_free also calls request2size, be careful to not pad twice. */
@@ -3308,7 +3308,7 @@ __libc_realloc (void *oldmem, size_t bytes)
void *newp; /* chunk to return */
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if REALLOC_ZERO_BYTES_FREES
@@ -3444,7 +3444,7 @@ libc_hidden_def (__libc_realloc)
void *
__libc_memalign (size_t alignment, size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3515,7 +3515,7 @@ libc_hidden_def (__libc_memalign)
void *
__libc_valloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3526,7 +3526,7 @@ __libc_valloc (size_t bytes)
void *
__libc_pvalloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3565,7 +3565,7 @@ __libc_calloc (size_t n, size_t elem_size)
sz = bytes;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
MAYBE_INIT_TCACHE ();
@@ -5022,7 +5022,7 @@ __malloc_trim (size_t s)
{
int result = 0;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
mstate ar_ptr = &main_arena;
@@ -5157,7 +5157,7 @@ __libc_mallinfo2 (void)
struct mallinfo2 m;
mstate ar_ptr;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
memset (&m, 0, sizeof (m));
@@ -5208,7 +5208,7 @@ __malloc_stats (void)
mstate ar_ptr;
unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
_IO_flockfile (stderr);
int old_flags2 = stderr->_flags2;
@@ -5377,7 +5377,7 @@ __libc_mallopt (int param_number, int value)
mstate av = &main_arena;
int res = 1;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
__libc_lock_lock (av->mutex);
@@ -5595,7 +5595,7 @@ __posix_memalign (void **memptr, size_t alignment, size_t size)
{
void *mem;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
/* Test whether the SIZE argument is valid. It must be a power of
@@ -5639,7 +5639,7 @@ __malloc_info (int options, FILE *fp)
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
fputs ("<malloc version=\"1\">\n", fp);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/siddhesh/malloc-hooks] Simplify __malloc_initialized
@ 2021-07-09 2:35 Siddhesh Poyarekar
0 siblings, 0 replies; 6+ messages in thread
From: Siddhesh Poyarekar @ 2021-07-09 2:35 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4d7c1b9f9af70d0c091dbca7949a0df8a40a7887
commit 4d7c1b9f9af70d0c091dbca7949a0df8a40a7887
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date: Mon Jul 5 02:18:41 2021 +0530
Simplify __malloc_initialized
Now that mcheck no longer needs to check __malloc_initialized (and no
other third party hook can since the symbol is not exported), make the
variable boolean and static so that it is used strictly within malloc.
Diff:
---
include/malloc.h | 6 ------
malloc/arena.c | 12 ++++++------
malloc/malloc.c | 24 ++++++++++++------------
3 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/include/malloc.h b/include/malloc.h
index b77761f74d..f9c9610548 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,12 +5,6 @@
# ifndef _ISOMAC
# include <rtld-malloc.h>
-/* In the GNU libc we rename the global variable
- `__malloc_initialized' to `__libc_malloc_initialized'. */
-#define __malloc_initialized __libc_malloc_initialized
-/* Nonzero if the malloc is already initialized. */
-extern int __malloc_initialized attribute_hidden;
-
struct malloc_state;
typedef struct malloc_state *mstate;
diff --git a/malloc/arena.c b/malloc/arena.c
index 9111b49589..840426f9fb 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -97,7 +97,7 @@ static mstate free_list;
__libc_lock_define_initialized (static, list_lock);
/* Already initialized? */
-int __malloc_initialized = -1;
+static bool __malloc_initialized = false;
/**************************************************************************/
@@ -143,7 +143,7 @@ int __malloc_initialized = -1;
void
__malloc_fork_lock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* We do not acquire free_list_lock here because we completely
@@ -163,7 +163,7 @@ __malloc_fork_lock_parent (void)
void
__malloc_fork_unlock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
for (mstate ar_ptr = &main_arena;; )
@@ -179,7 +179,7 @@ __malloc_fork_unlock_parent (void)
void
__malloc_fork_unlock_child (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* Push all arenas to the free list, except thread_arena, which is
@@ -286,10 +286,10 @@ static void tcache_key_initialize (void);
static void
ptmalloc_init (void)
{
- if (__malloc_initialized >= 0)
+ if (__malloc_initialized)
return;
- __malloc_initialized = 0;
+ __malloc_initialized = true;
#if USE_TCACHE
tcache_key_initialize ();
diff --git a/malloc/malloc.c b/malloc/malloc.c
index cf71314b2b..ed0316e690 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3195,7 +3195,7 @@ __libc_malloc (size_t bytes)
_Static_assert (PTRDIFF_MAX <= SIZE_MAX / 2,
"PTRDIFF_MAX is not more than half of SIZE_MAX");
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if USE_TCACHE
/* int_free also calls request2size, be careful to not pad twice. */
@@ -3308,7 +3308,7 @@ __libc_realloc (void *oldmem, size_t bytes)
void *newp; /* chunk to return */
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if REALLOC_ZERO_BYTES_FREES
@@ -3444,7 +3444,7 @@ libc_hidden_def (__libc_realloc)
void *
__libc_memalign (size_t alignment, size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3515,7 +3515,7 @@ libc_hidden_def (__libc_memalign)
void *
__libc_valloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3526,7 +3526,7 @@ __libc_valloc (size_t bytes)
void *
__libc_pvalloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3565,7 +3565,7 @@ __libc_calloc (size_t n, size_t elem_size)
sz = bytes;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
MAYBE_INIT_TCACHE ();
@@ -5022,7 +5022,7 @@ __malloc_trim (size_t s)
{
int result = 0;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
mstate ar_ptr = &main_arena;
@@ -5157,7 +5157,7 @@ __libc_mallinfo2 (void)
struct mallinfo2 m;
mstate ar_ptr;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
memset (&m, 0, sizeof (m));
@@ -5208,7 +5208,7 @@ __malloc_stats (void)
mstate ar_ptr;
unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
_IO_flockfile (stderr);
int old_flags2 = stderr->_flags2;
@@ -5377,7 +5377,7 @@ __libc_mallopt (int param_number, int value)
mstate av = &main_arena;
int res = 1;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
__libc_lock_lock (av->mutex);
@@ -5595,7 +5595,7 @@ __posix_memalign (void **memptr, size_t alignment, size_t size)
{
void *mem;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
/* Test whether the SIZE argument is valid. It must be a power of
@@ -5639,7 +5639,7 @@ __malloc_info (int options, FILE *fp)
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
fputs ("<malloc version=\"1\">\n", fp);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [glibc/siddhesh/malloc-hooks] Simplify __malloc_initialized
@ 2021-07-08 13:21 Siddhesh Poyarekar
0 siblings, 0 replies; 6+ messages in thread
From: Siddhesh Poyarekar @ 2021-07-08 13:21 UTC (permalink / raw)
To: glibc-cvs
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=4d7c1b9f9af70d0c091dbca7949a0df8a40a7887
commit 4d7c1b9f9af70d0c091dbca7949a0df8a40a7887
Author: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date: Mon Jul 5 02:18:41 2021 +0530
Simplify __malloc_initialized
Now that mcheck no longer needs to check __malloc_initialized (and no
other third party hook can since the symbol is not exported), make the
variable boolean and static so that it is used strictly within malloc.
Diff:
---
include/malloc.h | 6 ------
malloc/arena.c | 12 ++++++------
malloc/malloc.c | 24 ++++++++++++------------
3 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/include/malloc.h b/include/malloc.h
index b77761f74d..f9c9610548 100644
--- a/include/malloc.h
+++ b/include/malloc.h
@@ -5,12 +5,6 @@
# ifndef _ISOMAC
# include <rtld-malloc.h>
-/* In the GNU libc we rename the global variable
- `__malloc_initialized' to `__libc_malloc_initialized'. */
-#define __malloc_initialized __libc_malloc_initialized
-/* Nonzero if the malloc is already initialized. */
-extern int __malloc_initialized attribute_hidden;
-
struct malloc_state;
typedef struct malloc_state *mstate;
diff --git a/malloc/arena.c b/malloc/arena.c
index 9111b49589..840426f9fb 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -97,7 +97,7 @@ static mstate free_list;
__libc_lock_define_initialized (static, list_lock);
/* Already initialized? */
-int __malloc_initialized = -1;
+static bool __malloc_initialized = false;
/**************************************************************************/
@@ -143,7 +143,7 @@ int __malloc_initialized = -1;
void
__malloc_fork_lock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* We do not acquire free_list_lock here because we completely
@@ -163,7 +163,7 @@ __malloc_fork_lock_parent (void)
void
__malloc_fork_unlock_parent (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
for (mstate ar_ptr = &main_arena;; )
@@ -179,7 +179,7 @@ __malloc_fork_unlock_parent (void)
void
__malloc_fork_unlock_child (void)
{
- if (__malloc_initialized < 1)
+ if (!__malloc_initialized)
return;
/* Push all arenas to the free list, except thread_arena, which is
@@ -286,10 +286,10 @@ static void tcache_key_initialize (void);
static void
ptmalloc_init (void)
{
- if (__malloc_initialized >= 0)
+ if (__malloc_initialized)
return;
- __malloc_initialized = 0;
+ __malloc_initialized = true;
#if USE_TCACHE
tcache_key_initialize ();
diff --git a/malloc/malloc.c b/malloc/malloc.c
index cf71314b2b..ed0316e690 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -3195,7 +3195,7 @@ __libc_malloc (size_t bytes)
_Static_assert (PTRDIFF_MAX <= SIZE_MAX / 2,
"PTRDIFF_MAX is not more than half of SIZE_MAX");
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if USE_TCACHE
/* int_free also calls request2size, be careful to not pad twice. */
@@ -3308,7 +3308,7 @@ __libc_realloc (void *oldmem, size_t bytes)
void *newp; /* chunk to return */
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
#if REALLOC_ZERO_BYTES_FREES
@@ -3444,7 +3444,7 @@ libc_hidden_def (__libc_realloc)
void *
__libc_memalign (size_t alignment, size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3515,7 +3515,7 @@ libc_hidden_def (__libc_memalign)
void *
__libc_valloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3526,7 +3526,7 @@ __libc_valloc (size_t bytes)
void *
__libc_pvalloc (size_t bytes)
{
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
void *address = RETURN_ADDRESS (0);
@@ -3565,7 +3565,7 @@ __libc_calloc (size_t n, size_t elem_size)
sz = bytes;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
MAYBE_INIT_TCACHE ();
@@ -5022,7 +5022,7 @@ __malloc_trim (size_t s)
{
int result = 0;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
mstate ar_ptr = &main_arena;
@@ -5157,7 +5157,7 @@ __libc_mallinfo2 (void)
struct mallinfo2 m;
mstate ar_ptr;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
memset (&m, 0, sizeof (m));
@@ -5208,7 +5208,7 @@ __malloc_stats (void)
mstate ar_ptr;
unsigned int in_use_b = mp_.mmapped_mem, system_b = in_use_b;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
_IO_flockfile (stderr);
int old_flags2 = stderr->_flags2;
@@ -5377,7 +5377,7 @@ __libc_mallopt (int param_number, int value)
mstate av = &main_arena;
int res = 1;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
__libc_lock_lock (av->mutex);
@@ -5595,7 +5595,7 @@ __posix_memalign (void **memptr, size_t alignment, size_t size)
{
void *mem;
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
/* Test whether the SIZE argument is valid. It must be a power of
@@ -5639,7 +5639,7 @@ __malloc_info (int options, FILE *fp)
- if (__malloc_initialized < 0)
+ if (!__malloc_initialized)
ptmalloc_init ();
fputs ("<malloc version=\"1\">\n", fp);
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-07-19 17:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-12 4:56 [glibc/siddhesh/malloc-hooks] Simplify __malloc_initialized Siddhesh Poyarekar
-- strict thread matches above, loose matches on Subject: below --
2021-07-19 17:48 Siddhesh Poyarekar
2021-07-19 13:29 Siddhesh Poyarekar
2021-07-13 3:39 Siddhesh Poyarekar
2021-07-09 2:35 Siddhesh Poyarekar
2021-07-08 13:21 Siddhesh Poyarekar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).