projects
/
debian
/
tar
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Import upstream version 1.27
[debian/tar]
/
gnu
/
malloca.c
diff --git
a/gnu/malloca.c
b/gnu/malloca.c
index 6b59638e2a5c730f17d17de24fd8d4b475489d2f..b6b223d6008e15b115e6213c67b7447721a24e44 100644
(file)
--- a/
gnu/malloca.c
+++ b/
gnu/malloca.c
@@
-1,7
+1,7
@@
/* -*- buffer-read-only: t -*- vi: set ro: */
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
/* Safe automatic memory allocation.
/* -*- buffer-read-only: t -*- vi: set ro: */
/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
/* Safe automatic memory allocation.
- Copyright (C) 2003, 2006-2007, 2009-201
0
Free Software Foundation, Inc.
+ Copyright (C) 2003, 2006-2007, 2009-201
3
Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software; you can redistribute it and/or modify
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software; you can redistribute it and/or modify
@@
-15,14
+15,18
@@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program; if not, see <http://www.gnu.org/licenses/>. */
+#define _GL_USE_STDLIB_ALLOC 1
#include <config.h>
/* Specification. */
#include "malloca.h"
#include <config.h>
/* Specification. */
#include "malloca.h"
+#include <stdint.h>
+
+#include "verify.h"
+
/* The speed critical point in this file is freea() applied to an alloca()
result: it must be fast, to match the speed of alloca(). The speed of
mmalloca() and freea() in the other case are not critical, because they
/* The speed critical point in this file is freea() applied to an alloca()
result: it must be fast, to match the speed of alloca(). The speed of
mmalloca() and freea() in the other case are not critical, because they
@@
-47,13
+51,18
@@
#define MAGIC_SIZE sizeof (int)
/* This is how the header info would look like without any alignment
considerations. */
#define MAGIC_SIZE sizeof (int)
/* This is how the header info would look like without any alignment
considerations. */
-struct preliminary_header { void *next;
char room[MAGIC_SIZE]
; };
+struct preliminary_header { void *next;
int magic
; };
/* But the header's size must be a multiple of sa_alignment_max. */
#define HEADER_SIZE \
(((sizeof (struct preliminary_header) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max)
/* But the header's size must be a multiple of sa_alignment_max. */
#define HEADER_SIZE \
(((sizeof (struct preliminary_header) + sa_alignment_max - 1) / sa_alignment_max) * sa_alignment_max)
-struct header { void *next; char room[HEADER_SIZE - sizeof (struct preliminary_header) + MAGIC_SIZE]; };
-/* Verify that HEADER_SIZE == sizeof (struct header). */
-typedef int verify1[2 * (HEADER_SIZE == sizeof (struct header)) - 1];
+union header {
+ void *next;
+ struct {
+ char room[HEADER_SIZE - MAGIC_SIZE];
+ int word;
+ } magic;
+};
+verify (HEADER_SIZE == sizeof (union header));
/* We make the hash table quite big, so that during lookups the probability
of empty hash buckets is quite high. There is no need to make the hash
table resizable, because when the hash table gets filled so much that the
/* We make the hash table quite big, so that during lookups the probability
of empty hash buckets is quite high. There is no need to make the hash
table resizable, because when the hash table gets filled so much that the
@@
-73,20
+82,21
@@
mmalloca (size_t n)
if (nplus >= n)
{
if (nplus >= n)
{
-
char *p = (char *)
malloc (nplus);
+
void *p =
malloc (nplus);
if (p != NULL)
{
size_t slot;
if (p != NULL)
{
size_t slot;
+ union header *h = p;
- p
+= HEADER_SIZE
;
+ p
= h + 1
;
/* Put a magic number into the indicator word. */
/* Put a magic number into the indicator word. */
-
((int *) p)[-1]
= MAGIC_NUMBER;
+
h->magic.word
= MAGIC_NUMBER;
/* Enter p into the hash table. */
/* Enter p into the hash table. */
- slot = (u
nsigned long
) p % HASH_TABLE_SIZE;
-
((struct header *) (p - HEADER_SIZE))
->next = mmalloca_results[slot];
+ slot = (u
intptr_t
) p % HASH_TABLE_SIZE;
+
h
->next = mmalloca_results[slot];
mmalloca_results[slot] = p;
return p;
mmalloca_results[slot] = p;
return p;
@@
-118,19
+128,21
@@
freea (void *p)
{
/* Looks like a mmalloca() result. To see whether it really is one,
perform a lookup in the hash table. */
{
/* Looks like a mmalloca() result. To see whether it really is one,
perform a lookup in the hash table. */
- size_t slot = (u
nsigned long
) p % HASH_TABLE_SIZE;
+ size_t slot = (u
intptr_t
) p % HASH_TABLE_SIZE;
void **chain = &mmalloca_results[slot];
for (; *chain != NULL;)
{
void **chain = &mmalloca_results[slot];
for (; *chain != NULL;)
{
+ union header *h = p;
if (*chain == p)
{
/* Found it. Remove it from the hash table and free it. */
if (*chain == p)
{
/* Found it. Remove it from the hash table and free it. */
-
char *p_begin = (char *) p - HEADER_SIZE
;
- *chain =
((struct header *) p_begin)
->next;
+
union header *p_begin = h - 1
;
+ *chain =
p_begin
->next;
free (p_begin);
return;
}
free (p_begin);
return;
}
- chain = &((struct header *) ((char *) *chain - HEADER_SIZE))->next;
+ h = *chain;
+ chain = &h[-1].next;
}
}
/* At this point, we know it was not a mmalloca() result. */
}
}
/* At this point, we know it was not a mmalloca() result. */