aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>2005-05-13 14:36:51 +0000
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>2005-05-13 14:36:51 +0000
commit34b55f35a75c07a59c7973417fd7ea75cdb78c44 (patch)
treeac1a269b011ef6c74634f9242256c4084da387a7
parent0dee2d158077af7a12a2d7fb17f785e8bad34662 (diff)
downloadxen-34b55f35a75c07a59c7973417fd7ea75cdb78c44.tar.gz
xen-34b55f35a75c07a59c7973417fd7ea75cdb78c44.tar.bz2
xen-34b55f35a75c07a59c7973417fd7ea75cdb78c44.zip
bitkeeper revision 1.1159.281.1 (4284bb83DRFxFAWqa-zevESa69akFA)
sxpr_parser.c, sxpr_parser.h: Revert size of sxpr parser input buffer to original size and make buffer allocated dynamically and increasing in size on demand. Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
-rw-r--r--tools/libxutil/sxpr_parser.c25
-rw-r--r--tools/libxutil/sxpr_parser.h4
2 files changed, 24 insertions, 5 deletions
diff --git a/tools/libxutil/sxpr_parser.c b/tools/libxutil/sxpr_parser.c
index d32ef959b3..ba29c49f9c 100644
--- a/tools/libxutil/sxpr_parser.c
+++ b/tools/libxutil/sxpr_parser.c
@@ -160,6 +160,8 @@ void Parser_free(Parser *z){
if(!z) return;
objfree(z->val);
z->val = ONONE;
+ if (z->buf)
+ deallocate(z->buf);
deallocate(z);
}
@@ -171,6 +173,7 @@ Parser * Parser_new(void){
if(!z) goto exit;
err = 0;
+ z->buf = NULL;
reset(z);
exit:
if(err){
@@ -201,8 +204,16 @@ static int inputchar(Parser *p, char c){
static int savechar(Parser *p, char c){
int err = 0;
if(p->buf_i >= p->buf_n){
- err = -ENOMEM;
- goto exit;
+ char *nbuf;
+ nbuf = allocate(2 * (p->buf_n + 1));
+ if (nbuf == NULL) {
+ err = -ENOMEM;
+ goto exit;
+ }
+ memcpy(nbuf, p->buf, p->buf_i);
+ deallocate(p->buf);
+ p->buf = nbuf;
+ p->buf_n = 2 * (p->buf_n + 1) - 1;
}
p->buf[p->buf_i] = c;
p->buf_i++;
@@ -687,8 +698,16 @@ int end_list(Parser *p){
static void reset(Parser *z){
IOStream *error_out = z->error_out;
int flags = z->flags;
+ int buf_n = z->buf_n;
+ char *buf = z->buf;
memzero(z, sizeof(Parser));
- z->buf_n = sizeof(z->buf) - 1;
+ if (buf) {
+ z->buf = buf;
+ z->buf_n = buf_n;
+ } else {
+ z->buf = (char *)allocate(PARSER_BUF_SIZE);
+ z->buf_n = PARSER_BUF_SIZE - 1;
+ }
z->buf_i = 0;
z->line_no = 1;
z->char_no = 0;
diff --git a/tools/libxutil/sxpr_parser.h b/tools/libxutil/sxpr_parser.h
index 0a3fde55fd..a47554633d 100644
--- a/tools/libxutil/sxpr_parser.h
+++ b/tools/libxutil/sxpr_parser.h
@@ -28,7 +28,7 @@
/** Size of a parser input buffer.
* Tokens read must fit into this size (including trailing null).
*/
-#define PARSER_BUF_SIZE 4096
+#define PARSER_BUF_SIZE 1024
struct Parser;
typedef int ParserStateFn(struct Parser *, char c);
@@ -60,7 +60,7 @@ typedef struct Parser {
/** Lookahead character. */
char c;
/** Buffer for reading tokens. */
- char buf[PARSER_BUF_SIZE];
+ char *buf;
/** Size of token buffer. */
int buf_n;
int buf_i;