1
/* imalloc.h -- internal malloc definitions shared by source files. */
3
/* Copyright (C) 2001-2003 Free Software Foundation, Inc.
5
This file is part of GNU Bash, the Bourne Again SHell.
7
Bash is free software: you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
12
Bash is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with Bash. If not, see <http://www.gnu.org/licenses/>.
21
/* Must be included *after* config.h */
29
#define MALLOC_REGISTER
33
#define MALLOC_WRAPFUNCS
35
/* Generic pointer type. */
37
# if defined (__STDC__)
48
#if !defined (CPP_STRING)
49
# if defined (HAVE_STRINGIZE)
50
# define CPP_STRING(x) #x
52
# define CPP_STRING(x) "x"
53
# endif /* !HAVE_STRINGIZE */
54
#endif /* !__STRING */
57
# define FASTCOPY(s, d, n) __builtin_memcpy (d, s, n)
59
# if !defined (HAVE_BCOPY)
60
# if !defined (HAVE_MEMMOVE)
61
# define FASTCOPY(s, d, n) memcpy (d, s, n)
63
# define FASTCOPY(s, d, n) memmove (d, s, n)
64
# endif /* !HAVE_MEMMOVE */
65
# else /* HAVE_BCOPY */
66
# define FASTCOPY(s, d, n) bcopy (s, d, n)
67
# endif /* HAVE_BCOPY */
68
#endif /* !__GNUC__ */
71
# if defined (__STDC__) || defined (__GNUC__) || defined (__cplusplus) || defined (PROTOTYPES)
72
# define __P(protos) protos
74
# define __P(protos) ()
78
/* Use Duff's device for good zeroing/copying performance. DO NOT call the
79
Duff's device macros with NBYTES == 0. */
81
#define MALLOC_BZERO(charp, nbytes) \
83
if ((nbytes) <= 32) { \
84
size_t * mzp = (size_t *)(charp); \
85
unsigned long mctmp = (nbytes)/sizeof(size_t); \
87
if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp &= 7; } \
89
case 0: for(;;) { *mzp++ = 0; \
96
case 1: *mzp++ = 0; if(mcn <= 0) break; mcn--; } \
99
memset ((charp), 0, (nbytes)); \
102
#define MALLOC_ZERO(charp, nbytes) \
104
size_t mzsz = (nbytes); \
105
if (mzsz <= 9 * sizeof(mzsz) { \
106
size_t *mz = (size_t *)(charp); \
107
if(mzsz >= 5*sizeof(mzsz)) { *mz++ = 0; \
109
if(mzsz >= 7*sizeof(mzsz)) { *mz++ = 0; \
111
if(mzsz >= 9*sizeof(mzsz)) { *mz++ = 0; \
117
memset ((charp), 0, mzsz); \
120
#define MALLOC_MEMSET(charp, xch, nbytes) \
122
if ((nbytes) <= 32) { \
123
register char * mzp = (charp); \
124
unsigned long mctmp = (nbytes); \
126
if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp &= 7; } \
128
case 0: for(;;) { *mzp++ = xch; \
129
case 7: *mzp++ = xch; \
130
case 6: *mzp++ = xch; \
131
case 5: *mzp++ = xch; \
132
case 4: *mzp++ = xch; \
133
case 3: *mzp++ = xch; \
134
case 2: *mzp++ = xch; \
135
case 1: *mzp++ = xch; if(mcn <= 0) break; mcn--; } \
138
memset ((charp), (xch), (nbytes)); \
141
#define MALLOC_MEMCPY(dest,src,nbytes) \
143
if ((nbytes) <= 32) { \
144
size_t* mcsrc = (size_t*) src; \
145
size_t* mcdst = (size_t*) dest; \
146
unsigned long mctmp = (nbytes)/sizeof(size_t); \
148
if (mctmp < 8) mcn = 0; else { mcn = (mctmp-1)/8; mctmp &= 7; } \
150
case 0: for(;;) { *mcdst++ = *mcsrc++; \
151
case 7: *mcdst++ = *mcsrc++; \
152
case 6: *mcdst++ = *mcsrc++; \
153
case 5: *mcdst++ = *mcsrc++; \
154
case 4: *mcdst++ = *mcsrc++; \
155
case 3: *mcdst++ = *mcsrc++; \
156
case 2: *mcdst++ = *mcsrc++; \
157
case 1: *mcdst++ = *mcsrc++; if(mcn <= 0) break; mcn--; } \
159
memcpy ((dest), (src), (nbytes)) \
163
# include "bashintl.h"
170
extern void _malloc_block_signals __P((sigset_t *, sigset_t *));
171
extern void _malloc_unblock_signals __P((sigset_t *, sigset_t *));
173
#endif /* _IMALLOC_H */