ia64/xen-unstable
changeset 4903:d83084fd7e85
bitkeeper revision 1.1389.1.59 (4284bbd6CcKrWKYacVwZloM-lo2WtA)
Merge firebug.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xen-2.0-testing.bk
into firebug.cl.cam.ac.uk:/local/scratch/cl349/xen-unstable.bk-clean
Merge firebug.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xen-2.0-testing.bk
into firebug.cl.cam.ac.uk:/local/scratch/cl349/xen-unstable.bk-clean
author | cl349@firebug.cl.cam.ac.uk |
---|---|
date | Fri May 13 14:38:14 2005 +0000 (2005-05-13) |
parents | d3b5e4a7d853 82f072b9e1f1 |
children | 8b3e823884db |
files | tools/libxutil/sxpr_parser.c tools/libxutil/sxpr_parser.h |
line diff
1.1 --- a/tools/libxutil/sxpr_parser.c Fri May 13 12:52:44 2005 +0000 1.2 +++ b/tools/libxutil/sxpr_parser.c Fri May 13 14:38:14 2005 +0000 1.3 @@ -160,6 +160,8 @@ void Parser_free(Parser *z){ 1.4 if(!z) return; 1.5 objfree(z->val); 1.6 z->val = ONONE; 1.7 + if (z->buf) 1.8 + deallocate(z->buf); 1.9 deallocate(z); 1.10 } 1.11 1.12 @@ -171,6 +173,7 @@ Parser * Parser_new(void){ 1.13 1.14 if(!z) goto exit; 1.15 err = 0; 1.16 + z->buf = NULL; 1.17 reset(z); 1.18 exit: 1.19 if(err){ 1.20 @@ -201,8 +204,16 @@ static int inputchar(Parser *p, char c){ 1.21 static int savechar(Parser *p, char c){ 1.22 int err = 0; 1.23 if(p->buf_i >= p->buf_n){ 1.24 - err = -ENOMEM; 1.25 - goto exit; 1.26 + char *nbuf; 1.27 + nbuf = allocate(2 * (p->buf_n + 1)); 1.28 + if (nbuf == NULL) { 1.29 + err = -ENOMEM; 1.30 + goto exit; 1.31 + } 1.32 + memcpy(nbuf, p->buf, p->buf_i); 1.33 + deallocate(p->buf); 1.34 + p->buf = nbuf; 1.35 + p->buf_n = 2 * (p->buf_n + 1) - 1; 1.36 } 1.37 p->buf[p->buf_i] = c; 1.38 p->buf_i++; 1.39 @@ -687,8 +698,16 @@ int end_list(Parser *p){ 1.40 static void reset(Parser *z){ 1.41 IOStream *error_out = z->error_out; 1.42 int flags = z->flags; 1.43 + int buf_n = z->buf_n; 1.44 + char *buf = z->buf; 1.45 memzero(z, sizeof(Parser)); 1.46 - z->buf_n = sizeof(z->buf) - 1; 1.47 + if (buf) { 1.48 + z->buf = buf; 1.49 + z->buf_n = buf_n; 1.50 + } else { 1.51 + z->buf = (char *)allocate(PARSER_BUF_SIZE); 1.52 + z->buf_n = PARSER_BUF_SIZE - 1; 1.53 + } 1.54 z->buf_i = 0; 1.55 z->line_no = 1; 1.56 z->char_no = 0;
2.1 --- a/tools/libxutil/sxpr_parser.h Fri May 13 12:52:44 2005 +0000 2.2 +++ b/tools/libxutil/sxpr_parser.h Fri May 13 14:38:14 2005 +0000 2.3 @@ -28,7 +28,7 @@ 2.4 /** Size of a parser input buffer. 2.5 * Tokens read must fit into this size (including trailing null). 2.6 */ 2.7 -#define PARSER_BUF_SIZE 4096 2.8 +#define PARSER_BUF_SIZE 1024 2.9 2.10 struct Parser; 2.11 typedef int ParserStateFn(struct Parser *, char c); 2.12 @@ -60,7 +60,7 @@ typedef struct Parser { 2.13 /** Lookahead character. */ 2.14 char c; 2.15 /** Buffer for reading tokens. */ 2.16 - char buf[PARSER_BUF_SIZE]; 2.17 + char *buf; 2.18 /** Size of token buffer. */ 2.19 int buf_n; 2.20 int buf_i;