* cpphash.h (struct cpp_pool): Remove locks and locked.
(struct cpp_context): Add member buff.
(struct cpp_reader): Remove member argument_pool.
(_cpp_lock_pool, _cpp_unlock_pool): Remove.
* cppinit.c (cpp_create_reader, cpp_destroy): Argument_pool is dead.
* cpplex.c (chunk_suitable): Remove pool argument.
(MIN_BUFF_SIZE, BUFF_SIZE_UPPER_BOUND, EXTENDED_BUFF_SIZE): New.
(new_buff, _cpp_extend_buff): Update.
(_cpp_get_buff): Fix silly pointer bug. Be more selective about
which buffer is returned.
(_cpp_next_chunk, _cpp_init_pool): Pool locking removed.
(_cpp_lock_pool, _cpp_unlock_pool): Remove.
* cppmacro.c (lock_pools, unlock_pools): Remove.
(push_ptoken_context): Take a _cpp_buff.
(enter_macro_context): Pool locking removed.
(replace_args): Use a _cpp_buff for the replacement list with
arguments replaced.
(push_token_context): Clear buff.
(expand_arg): Use _cpp_pop_context.
(_cpp_pop_context): Free a context's buffer, if any.
From-SVN: r45833
+2001-09-26 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * cpphash.h (struct cpp_pool): Remove locks and locked.
+ (struct cpp_context): Add member buff.
+ (struct cpp_reader): Remove member argument_pool.
+ (_cpp_lock_pool, _cpp_unlock_pool): Remove.
+ * cppinit.c (cpp_create_reader, cpp_destroy): Argument_pool is dead.
+ * cpplex.c (chunk_suitable): Remove pool argument.
+ (MIN_BUFF_SIZE, BUFF_SIZE_UPPER_BOUND, EXTENDED_BUFF_SIZE): New.
+ (new_buff, _cpp_extend_buff): Update.
+ (_cpp_get_buff): Fix silly pointer bug. Be more selective about
+ which buffer is returned.
+ (_cpp_next_chunk, _cpp_init_pool): Pool locking removed.
+ (_cpp_lock_pool, _cpp_unlock_pool): Remove.
+ * cppmacro.c (lock_pools, unlock_pools): Remove.
+ (push_ptoken_context): Take a _cpp_buff.
+ (enter_macro_context): Pool locking removed.
+ (replace_args): Use a _cpp_buff for the replacement list with
+ arguments replaced.
+ (push_token_context): Clear buff.
+ (expand_arg): Use _cpp_pop_context.
+ (_cpp_pop_context): Free a context's buffer, if any.
+
2001-09-26 DJ Delorie <dj@redhat.com>
* c-typeck.c (digest_init): Check for sizeless arrays.
typedef struct cpp_pool cpp_pool;
struct cpp_pool
{
- struct cpp_chunk *cur, *locked, *first;
+ struct cpp_chunk *cur, *first;
unsigned char *pos; /* Current position. */
unsigned int align;
- unsigned int locks;
};
/* A generic memory buffer. */
union utoken first;
union utoken last;
+ /* If non-NULL, a buffer used for storage related to this context.
+ When the context is popped, the buffer is freed. */
+ _cpp_buff *buff;
+
/* For a macro context, these are the macro and its arguments. */
cpp_macro *macro;
cpp_pool ident_pool; /* For all identifiers, and permanent
numbers and strings. */
cpp_pool macro_pool; /* For macro definitions. Permanent. */
- cpp_pool argument_pool; /* For macro arguments. Temporary. */
/* Memory buffers. */
_cpp_buff *free_buffs;
extern unsigned char *_cpp_pool_alloc PARAMS ((cpp_pool *, unsigned int));
extern unsigned char *_cpp_next_chunk PARAMS ((cpp_pool *, unsigned int,
unsigned char **));
-extern void _cpp_lock_pool PARAMS ((cpp_pool *));
-extern void _cpp_unlock_pool PARAMS ((cpp_pool *));
/* In cppinit.c. */
extern bool _cpp_push_next_buffer PARAMS ((cpp_reader *));
/* Identifier pool initially 8K. Unaligned, permanent pool. */
_cpp_init_pool (&pfile->ident_pool, 8 * 1024, 1, 0);
- /* Argument pool initially 8K. Aligned, temporary pool. */
- _cpp_init_pool (&pfile->argument_pool, 8 * 1024, 0, 1);
-
/* Macro pool initially 8K. Aligned, permanent pool. */
_cpp_init_pool (&pfile->macro_pool, 8 * 1024, 0, 0);
_cpp_free_pool (&pfile->ident_pool);
_cpp_free_pool (&pfile->macro_pool);
- _cpp_free_pool (&pfile->argument_pool);
_cpp_free_buff (pfile->free_buffs);
for (run = &pfile->base_run; run; run = runn)
static tokenrun *next_tokenrun PARAMS ((tokenrun *));
static cpp_chunk *new_chunk PARAMS ((unsigned int));
-static int chunk_suitable PARAMS ((cpp_pool *, cpp_chunk *, unsigned int));
+static int chunk_suitable PARAMS ((cpp_chunk *, unsigned int));
static unsigned int hex_digit_value PARAMS ((unsigned int));
static _cpp_buff *new_buff PARAMS ((unsigned int));
return result;
}
-/* Memory buffers. */
+/* Memory buffers. Changing these three constants can have a dramatic
+ effect on performance. The values here are reasonable defaults,
+ but might be tuned. If you adjust them, be sure to test across a
+ range of uses of cpplib, including heavy nested function-like macro
+ expansion. Also check the change in peak memory usage (NJAMD is a
+ good tool for this). */
+#define MIN_BUFF_SIZE 8000
+#define BUFF_SIZE_UPPER_BOUND(MIN_SIZE) (8000 + (MIN_SIZE) * 3 / 2)
+#define EXTENDED_BUFF_SIZE(BUFF, MIN_EXTRA) \
+ (MIN_EXTRA + ((BUFF)->limit - (BUFF)->cur) * 2)
struct dummy
{
_cpp_buff *result;
char *base;
- if (len < 4000)
- len = 4000;
+ if (len < MIN_BUFF_SIZE)
+ len = MIN_BUFF_SIZE;
len = CPP_ALIGN (len, DEFAULT_ALIGNMENT);
base = xmalloc (len + sizeof (_cpp_buff));
for (p = &pfile->free_buffs;; p = &(*p)->next)
{
- if (*p == NULL || (*p)->next == NULL)
+ unsigned int size;
+
+ if (*p == NULL)
return new_buff (min_size);
- result = (*p)->next;
- if ((unsigned int) (result->limit - result->base) > min_size)
+ result = *p;
+ size = result->limit - result->base;
+ /* Return a buffer that's big enough, but don't waste one that's
+ way too big. */
+ if (size >= min_size && size < BUFF_SIZE_UPPER_BOUND (min_size))
break;
}
_cpp_buff *buff;
unsigned int min_extra;
{
- unsigned int size = min_extra + (buff->limit - buff->cur) * 2;
+ unsigned int size = EXTENDED_BUFF_SIZE (buff, min_extra);
buff->next = _cpp_get_buff (pfile, size);
memcpy (buff->next->base, buff->cur, buff->limit - buff->cur);
}
static int
-chunk_suitable (pool, chunk, size)
- cpp_pool *pool;
+chunk_suitable (chunk, size)
cpp_chunk *chunk;
unsigned int size;
{
/* Being at least twice SIZE means we can use memcpy in
_cpp_next_chunk rather than memmove. Besides, it's a good idea
anyway. */
- return (chunk && pool->locked != chunk
- && (unsigned int) (chunk->limit - chunk->base) >= size * 2);
+ return (chunk && (unsigned int) (chunk->limit - chunk->base) >= size * 2);
}
/* Returns the end of the new pool. PTR points to a char in the old
/* LEN is the minimum size we want in the new pool. */
len += POOL_ROOM (pool);
- if (! chunk_suitable (pool, chunk, len))
+ if (! chunk_suitable (chunk, len))
{
chunk = new_chunk (POOL_SIZE (pool) * 2 + len);
pool->align = align;
pool->first = new_chunk (size);
pool->cur = pool->first;
- pool->locked = 0;
- pool->locks = 0;
if (temp)
pool->cur->next = pool->cur;
}
-void
-_cpp_lock_pool (pool)
- cpp_pool *pool;
-{
- if (pool->locks++ == 0)
- pool->locked = pool->cur;
-}
-
-void
-_cpp_unlock_pool (pool)
- cpp_pool *pool;
-{
- if (--pool->locks == 0)
- pool->locked = 0;
-}
-
void
_cpp_free_pool (pool)
cpp_pool *pool;
/* Macro expansion. */
-static void lock_pools PARAMS ((cpp_reader *));
-static void unlock_pools PARAMS ((cpp_reader *));
static int enter_macro_context PARAMS ((cpp_reader *, cpp_hashnode *));
static const cpp_token *builtin_macro PARAMS ((cpp_reader *, cpp_hashnode *));
static void push_token_context
PARAMS ((cpp_reader *, cpp_macro *, const cpp_token *, unsigned int));
static void push_ptoken_context
- PARAMS ((cpp_reader *, cpp_macro *, const cpp_token **, unsigned int));
+ PARAMS ((cpp_reader *, cpp_macro *, _cpp_buff *,
+ const cpp_token **, unsigned int));
static _cpp_buff *collect_args PARAMS ((cpp_reader *, const cpp_hashnode *));
static cpp_context *next_context PARAMS ((cpp_reader *));
static const cpp_token *padding_token
}
}
-static void
-lock_pools (pfile)
- cpp_reader *pfile;
-{
- _cpp_lock_pool (&pfile->argument_pool);
-}
-
-static void
-unlock_pools (pfile)
- cpp_reader *pfile;
-{
- _cpp_unlock_pool (&pfile->argument_pool);
-}
-
/* Adds backslashes before all backslashes and double quotes appearing
in strings. Non-printable characters are converted to octal. */
static U_CHAR *
{
cpp_macro *macro = node->value.macro;
- if (!pfile->context->prev)
- lock_pools (pfile);
-
if (macro->fun_like && !funlike_invocation_p (pfile, node))
- {
- if (!pfile->context->prev)
- unlock_pools (pfile);
- return 0;
- }
+ return 0;
/* Disable the macro within its expansion. */
macro->disabled = 1;
const cpp_token *src, *limit;
const cpp_token **dest, **first;
macro_arg *arg;
+ _cpp_buff *buff;
/* First, fully macro-expand arguments, calculating the number of
- tokens in the final expansion as we go. This ensures that the
- possible recursive use of argument_pool is fine. The ordering of
- the if statements below is subtle; we must handle stringification
- before pasting. */
+ tokens in the final expansion as we go. The ordering of the if
+ statements below is subtle; we must handle stringification before
+ pasting. */
total = macro->count;
limit = macro->expansion + macro->count;
/* Now allocate space for the expansion, copy the tokens and replace
the arguments. */
- first = (const cpp_token **) _cpp_pool_alloc (&pfile->argument_pool,
- total * sizeof (cpp_token *));
+ buff = _cpp_get_buff (pfile, total * sizeof (cpp_token *));
+ first = (const cpp_token **) buff->base;
dest = first;
for (src = macro->expansion; src < limit; src++)
if (args[i].expanded)
free (args[i].expanded);
- push_ptoken_context (pfile, macro, first, dest - first);
+ push_ptoken_context (pfile, macro, buff, first, dest - first);
}
/* Return a special padding token, with padding inherited from SOURCE. */
/* Push a list of pointers to tokens. */
static void
-push_ptoken_context (pfile, macro, first, count)
+push_ptoken_context (pfile, macro, buff, first, count)
cpp_reader *pfile;
cpp_macro *macro;
+ _cpp_buff *buff;
const cpp_token **first;
unsigned int count;
{
context->direct_p = false;
context->macro = macro;
+ context->buff = buff;
context->first.ptoken = first;
context->last.ptoken = first + count;
}
context->direct_p = true;
context->macro = macro;
+ context->buff = NULL;
context->first.token = first;
context->last.token = first + count;
}
arg->expanded = (const cpp_token **)
xmalloc (capacity * sizeof (cpp_token *));
- push_ptoken_context (pfile, NULL, arg->first, arg->count + 1);
+ push_ptoken_context (pfile, NULL, NULL, arg->first, arg->count + 1);
for (;;)
{
const cpp_token *token;
arg->expanded[arg->expanded_count++] = token;
}
- /* Avoid the unlock_pools test of _cpp_pop_context. Change this to
- call _cpp_pop_context once we remove pool locking. */
- pfile->context = pfile->context->prev;
+ _cpp_pop_context (pfile);
}
void
_cpp_pop_context (pfile)
cpp_reader *pfile;
{
+ cpp_context *context = pfile->context;
+
/* Re-enable a macro when leaving its expansion. */
- if (pfile->context->macro)
- pfile->context->macro->disabled = 0;
+ if (context->macro)
+ context->macro->disabled = 0;
+
+ if (context->buff)
+ _cpp_release_buff (pfile, context->buff);
- pfile->context = pfile->context->prev;
- if (!pfile->context->prev && !pfile->state.parsing_args)
- unlock_pools (pfile);
+ pfile->context = context->prev;
}
/* Eternal routine to get a token. Also used nearly everywhere