diff --git a/src/block_alloc.h b/src/block_alloc.h index f1d5488f948e0d2a4d2fe09833267273c9e953ad..6f069064878c7f93c24e05f1f773f5a6262e1804 100644 --- a/src/block_alloc.h +++ b/src/block_alloc.h @@ -1,4 +1,4 @@ -/* $Id: block_alloc.h,v 1.12 1999/10/19 15:29:51 hubbe Exp $ */ +/* $Id: block_alloc.h,v 1.13 1999/10/23 06:51:22 hubbe Exp $ */ #undef PRE_INIT_BLOCK #undef INIT_BLOCK #undef EXIT_BLOCK @@ -39,15 +39,15 @@ struct DATA *PIKE_CONCAT(alloc_,DATA)(void) \ \ for(e=0;e<BSIZE;e++) \ { \ - n->x[e].next=PIKE_CONCAT3(free_,DATA,s); \ + n->x[e].BLOCK_ALLOC_NEXT=PIKE_CONCAT3(free_,DATA,s); \ PRE_INIT_BLOCK( (n->x+e) ); \ PIKE_CONCAT3(free_,DATA,s)=n->x+e; \ } \ } \ \ tmp=PIKE_CONCAT3(free_,DATA,s); \ - PIKE_CONCAT3(free_,DATA,s)=tmp->next; \ - DO_IF_DMALLOC( dmalloc_register(tmp,0, __FILE__, __LINE__); ) \ + PIKE_CONCAT3(free_,DATA,s)=tmp->BLOCK_ALLOC_NEXT; \ + DO_IF_DMALLOC( dmalloc_register(tmp,0, __FILE__, __LINE__); ) \ INIT_BLOCK(tmp); \ return tmp; \ } \ @@ -55,8 +55,8 @@ struct DATA *PIKE_CONCAT(alloc_,DATA)(void) \ void PIKE_CONCAT(really_free_,DATA)(struct DATA *d) \ { \ EXIT_BLOCK(d); \ - DO_IF_DMALLOC( dmalloc_unregister(d, 1); ) \ - d->next=PIKE_CONCAT3(free_,DATA,s); \ + DO_IF_DMALLOC( dmalloc_unregister(d, 1); ) \ + d->BLOCK_ALLOC_NEXT=PIKE_CONCAT3(free_,DATA,s); \ PRE_INIT_BLOCK(d); \ PIKE_CONCAT3(free_,DATA,s)=d; \ } \ @@ -84,7 +84,8 @@ void PIKE_CONCAT3(count_memory_in_,DATA,s)(INT32 *num_, INT32 *size_) \ num+=BSIZE; \ size+=sizeof(struct PIKE_CONCAT(DATA,_block)); \ } \ - for(tmp2=PIKE_CONCAT3(free_,DATA,s);tmp2;tmp2=tmp2->next) num--; \ + for(tmp2=PIKE_CONCAT3(free_,DATA,s);tmp2; \ + tmp2=tmp2->BLOCK_ALLOC_NEXT) num--; \ *num_=num; \ *size_=size; \ } @@ -92,159 +93,161 @@ void PIKE_CONCAT3(count_memory_in_,DATA,s)(INT32 *num_, INT32 *size_) \ -#define PTR_HASH_ALLOC(DATA,BSIZE) \ - \ -BLOCK_ALLOC(DATA,BSIZE) \ - \ -static struct DATA **PIKE_CONCAT(DATA,_hash_table)=0; \ -static int PIKE_CONCAT(DATA,_hash_table_size)=0; \ -static int PIKE_CONCAT(num_,DATA)=0; \ - \ -inline struct DATA * \ - PIKE_CONCAT(really_low_find_,DATA)(void *ptr, int hval) \ -{ \ - struct DATA *p,**pp; \ - for(pp=PIKE_CONCAT(DATA,_hash_table)+hval;(p=*pp);pp=&p->next) \ - { \ - if(p->data==ptr) \ - { \ - *pp=p->next; \ - p->next=PIKE_CONCAT(DATA,_hash_table)[hval]; \ - PIKE_CONCAT(DATA,_hash_table)[hval]=p; \ - return p; \ - } \ - } \ - return 0; \ -} \ - \ - \ -struct DATA *PIKE_CONCAT(find_,DATA)(void *ptr) \ -{ \ - unsigned int hval=(long)ptr; \ - hval%=PIKE_CONCAT(DATA,_hash_table_size); \ - return PIKE_CONCAT(really_low_find_,DATA)(ptr, hval); \ -} \ - \ - \ -static void PIKE_CONCAT(DATA,_rehash)() \ -{ \ - /* Time to re-hash */ \ - struct DATA **old_hash= PIKE_CONCAT(DATA,_hash_table); \ - struct DATA *p; \ - int hval; \ - int e=PIKE_CONCAT(DATA,_hash_table_size); \ - \ - PIKE_CONCAT(DATA,_hash_table_size)*=2; \ - PIKE_CONCAT(DATA,_hash_table_size)++; \ - if((PIKE_CONCAT(DATA,_hash_table)=(struct DATA **) \ - malloc(PIKE_CONCAT(DATA,_hash_table_size)* \ - sizeof(struct DATA *)))) \ - { \ - MEMSET(PIKE_CONCAT(DATA,_hash_table),0, \ - sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \ - while(--e >=0) \ - { \ - while((p=old_hash[e])) \ - { \ - old_hash[e]=p->next; \ - hval=(long)(p-> data); \ - hval%=PIKE_CONCAT(DATA,_hash_table_size); \ - p->next=PIKE_CONCAT(DATA,_hash_table)[hval]; \ - PIKE_CONCAT(DATA,_hash_table)[hval]=p; \ - } \ - } \ - free((char *)old_hash); \ - }else{ \ - PIKE_CONCAT(DATA,_hash_table)=old_hash; \ - PIKE_CONCAT(DATA,_hash_table_size)=e; \ - } \ -} \ - \ - \ -struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr, int hval) \ -{ \ - struct DATA *p; \ - \ - DO_IF_DEBUG( if(!PIKE_CONCAT(DATA,_hash_table)) \ - fatal("Hash table error!\n"); ) \ - PIKE_CONCAT(num_,DATA)++; \ - \ - if(( PIKE_CONCAT(num_,DATA)>>2 ) >= \ - PIKE_CONCAT(DATA,_hash_table_size)) \ - { \ - PIKE_CONCAT(DATA,_rehash)(); \ - hval=(long)ptr; \ - hval%=PIKE_CONCAT(DATA,_hash_table_size); \ - } \ - \ - p=PIKE_CONCAT(alloc_,DATA)(); \ - p->data=ptr; \ - p->next=PIKE_CONCAT(DATA,_hash_table)[hval]; \ - PIKE_CONCAT(DATA,_hash_table)[hval]=p; \ - return p; \ -} \ - \ -inline struct DATA *PIKE_CONCAT(get_,DATA)(void *ptr) \ -{ \ - struct DATA *p; \ - int hval=(long)ptr; \ - hval%=PIKE_CONCAT(DATA,_hash_table_size); \ - if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ - return p; \ - \ - return PIKE_CONCAT(make_,DATA)(ptr, hval); \ -} \ - \ -int PIKE_CONCAT3(check_,DATA,_semafore)(void *ptr) \ -{ \ - struct DATA *p; \ - int hval=(long)ptr; \ - hval%=PIKE_CONCAT(DATA,_hash_table_size); \ - if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ - return 0; \ - \ - PIKE_CONCAT(make_,DATA)(ptr, hval); \ - return 1; \ -} \ - \ -int PIKE_CONCAT(remove_,DATA)(void *ptr) \ -{ \ - struct DATA *p; \ - int hval=(long)ptr; \ - if(!PIKE_CONCAT(DATA,_hash_table)) return 0; \ - hval%=PIKE_CONCAT(DATA,_hash_table_size); \ - if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ - { \ - PIKE_CONCAT(num_,DATA)--; \ - if(PIKE_CONCAT(DATA,_hash_table)[hval]!=p) fatal("GAOssdf\n"); \ - PIKE_CONCAT(DATA,_hash_table)[hval]=p->next; \ - PIKE_CONCAT(really_free_,DATA)(p); \ - return 1; \ - } \ - return 0; \ -} \ - \ -void PIKE_CONCAT3(init_,DATA,_hash)(void) \ -{ \ - extern INT32 hashprimes[32]; \ - extern int my_log2(unsigned INT32 x); \ - PIKE_CONCAT(DATA,_hash_table_size)=hashprimes[my_log2(BSIZE)]; \ - \ - PIKE_CONCAT(DATA,_hash_table)=(struct DATA **) \ - malloc(sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \ - if(!PIKE_CONCAT(DATA,_hash_table)) \ - { \ - fprintf(stderr,"Fatal: out of memory.\n"); \ - exit(17); \ - } \ - MEMSET(PIKE_CONCAT(DATA,_hash_table),0, \ - sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \ -} \ - \ -void PIKE_CONCAT3(exit_,DATA,_hash)(void) \ -{ \ - PIKE_CONCAT3(free_all_,DATA,_blocks)(); \ - free(PIKE_CONCAT(DATA,_hash_table)); \ - PIKE_CONCAT(DATA,_hash_table)=0; \ +#define PTR_HASH_ALLOC(DATA,BSIZE) \ + \ +BLOCK_ALLOC(DATA,BSIZE) \ + \ +static struct DATA **PIKE_CONCAT(DATA,_hash_table)=0; \ +static int PIKE_CONCAT(DATA,_hash_table_size)=0; \ +static int PIKE_CONCAT(num_,DATA)=0; \ + \ +inline struct DATA * \ + PIKE_CONCAT(really_low_find_,DATA)(void *ptr, int hval) \ +{ \ + struct DATA *p,**pp; \ + for(pp=PIKE_CONCAT(DATA,_hash_table)+hval;(p=*pp);pp=&p->BLOCK_ALLOC_NEXT) \ + { \ + if(p->data==ptr) \ + { \ + *pp=p->BLOCK_ALLOC_NEXT; \ + p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \ + PIKE_CONCAT(DATA,_hash_table)[hval]=p; \ + return p; \ + } \ + } \ + return 0; \ +} \ + \ + \ +struct DATA *PIKE_CONCAT(find_,DATA)(void *ptr) \ +{ \ + unsigned int hval=(long)ptr; \ + hval%=PIKE_CONCAT(DATA,_hash_table_size); \ + return PIKE_CONCAT(really_low_find_,DATA)(ptr, hval); \ +} \ + \ + \ +static void PIKE_CONCAT(DATA,_rehash)() \ +{ \ + /* Time to re-hash */ \ + struct DATA **old_hash= PIKE_CONCAT(DATA,_hash_table); \ + struct DATA *p; \ + int hval; \ + int e=PIKE_CONCAT(DATA,_hash_table_size); \ + \ + PIKE_CONCAT(DATA,_hash_table_size)*=2; \ + PIKE_CONCAT(DATA,_hash_table_size)++; \ + if((PIKE_CONCAT(DATA,_hash_table)=(struct DATA **) \ + malloc(PIKE_CONCAT(DATA,_hash_table_size)* \ + sizeof(struct DATA *)))) \ + { \ + MEMSET(PIKE_CONCAT(DATA,_hash_table),0, \ + sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \ + while(--e >=0) \ + { \ + while((p=old_hash[e])) \ + { \ + old_hash[e]=p->BLOCK_ALLOC_NEXT; \ + hval=(long)(p-> data); \ + hval%=PIKE_CONCAT(DATA,_hash_table_size); \ + p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \ + PIKE_CONCAT(DATA,_hash_table)[hval]=p; \ + } \ + } \ + free((char *)old_hash); \ + }else{ \ + PIKE_CONCAT(DATA,_hash_table)=old_hash; \ + PIKE_CONCAT(DATA,_hash_table_size)=e; \ + } \ +} \ + \ + \ +struct DATA *PIKE_CONCAT(make_,DATA)(void *ptr, int hval) \ +{ \ + struct DATA *p; \ + \ + DO_IF_DEBUG( if(!PIKE_CONCAT(DATA,_hash_table)) \ + fatal("Hash table error!\n"); ) \ + PIKE_CONCAT(num_,DATA)++; \ + \ + if(( PIKE_CONCAT(num_,DATA)>>2 ) >= \ + PIKE_CONCAT(DATA,_hash_table_size)) \ + { \ + PIKE_CONCAT(DATA,_rehash)(); \ + hval=(long)ptr; \ + hval%=PIKE_CONCAT(DATA,_hash_table_size); \ + } \ + \ + p=PIKE_CONCAT(alloc_,DATA)(); \ + p->data=ptr; \ + p->BLOCK_ALLOC_NEXT=PIKE_CONCAT(DATA,_hash_table)[hval]; \ + PIKE_CONCAT(DATA,_hash_table)[hval]=p; \ + return p; \ +} \ + \ +inline struct DATA *PIKE_CONCAT(get_,DATA)(void *ptr) \ +{ \ + struct DATA *p; \ + int hval=(long)ptr; \ + hval%=PIKE_CONCAT(DATA,_hash_table_size); \ + if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ + return p; \ + \ + return PIKE_CONCAT(make_,DATA)(ptr, hval); \ +} \ + \ +int PIKE_CONCAT3(check_,DATA,_semafore)(void *ptr) \ +{ \ + struct DATA *p; \ + int hval=(long)ptr; \ + hval%=PIKE_CONCAT(DATA,_hash_table_size); \ + if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ + return 0; \ + \ + PIKE_CONCAT(make_,DATA)(ptr, hval); \ + return 1; \ +} \ + \ +int PIKE_CONCAT(remove_,DATA)(void *ptr) \ +{ \ + struct DATA *p; \ + int hval=(long)ptr; \ + if(!PIKE_CONCAT(DATA,_hash_table)) return 0; \ + hval%=PIKE_CONCAT(DATA,_hash_table_size); \ + if((p=PIKE_CONCAT(really_low_find_,DATA)(ptr, hval))) \ + { \ + PIKE_CONCAT(num_,DATA)--; \ + if(PIKE_CONCAT(DATA,_hash_table)[hval]!=p) fatal("GAOssdf\n"); \ + PIKE_CONCAT(DATA,_hash_table)[hval]=p->BLOCK_ALLOC_NEXT; \ + PIKE_CONCAT(really_free_,DATA)(p); \ + return 1; \ + } \ + return 0; \ +} \ + \ +void PIKE_CONCAT3(init_,DATA,_hash)(void) \ +{ \ + extern INT32 hashprimes[32]; \ + extern int my_log2(unsigned INT32 x); \ + PIKE_CONCAT(DATA,_hash_table_size)=hashprimes[my_log2(BSIZE)]; \ + \ + PIKE_CONCAT(DATA,_hash_table)=(struct DATA **) \ + malloc(sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \ + if(!PIKE_CONCAT(DATA,_hash_table)) \ + { \ + fprintf(stderr,"Fatal: out of memory.\n"); \ + exit(17); \ + } \ + MEMSET(PIKE_CONCAT(DATA,_hash_table),0, \ + sizeof(struct DATA *)*PIKE_CONCAT(DATA,_hash_table_size)); \ +} \ + \ +void PIKE_CONCAT3(exit_,DATA,_hash)(void) \ +{ \ + PIKE_CONCAT3(free_all_,DATA,_blocks)(); \ + free(PIKE_CONCAT(DATA,_hash_table)); \ + PIKE_CONCAT(DATA,_hash_table)=0; \ } +#define BLOCK_ALLOC_NEXT next + diff --git a/src/configure.in b/src/configure.in index ee2302f5bb32d4cd125548711eeb8512f31390ff..1f30198a2115cff0d01139fc750cce1b4b4db868 100644 --- a/src/configure.in +++ b/src/configure.in @@ -1,4 +1,4 @@ -AC_REVISION("$Id: configure.in,v 1.324 1999/10/19 01:11:30 grubba Exp $") +AC_REVISION("$Id: configure.in,v 1.325 1999/10/23 06:51:23 hubbe Exp $") AC_INIT(interpret.c) AC_CONFIG_HEADER(machine.h) @@ -440,7 +440,17 @@ AC_ARG_WITH(oob, [ --with-oob enable out-of-band data handling],[A AC_ARG_WITH(thread-trace,[ --with-trace-threads enable individual tracing of threads],[AC_DEFINE(TRACE_THREADS)],[]) AC_ARG_WITH(compiler-trace,[ --with-compiler-trace enable tracing of the compiler],[AC_DEFINE(YYDEBUG)],[]) AC_ARG_WITH(security, [ --with-security enable internal pike security system],[AC_DEFINE(PIKE_SECURITY)],[]) -AC_ARG_WITH(bignums, [ --with-bignums enable internal conversion to bignums],[AC_DEFINE(AUTO_BIGNUM)],[]) +AC_ARG_WITH(bignums, [ --with-bignums enable internal conversion to bignums],[],[]) + +if test "x$with_bignums" = xyes; then + AC_DEFINE(AUTO_BIGNUM) + if test "x$with_gmp" == xno; then + AC_MSG_ERROR([Cannot compile --with-bignums without the GMP library +Either install GMP on your system or run configure with +the option --without-bignums. +]) + else :; fi +else :; fi if test "x$with_poll" = "xyes"; then AC_DEFINE(HAVE_AND_USE_POLL) diff --git a/src/language.yacc b/src/language.yacc index 305a11d3a94c74e45200ec6f6a97fc40b8252bd7..a1cd0cc2f5e13d25f20f06f07b073c7eadee2139 100644 --- a/src/language.yacc +++ b/src/language.yacc @@ -182,7 +182,7 @@ /* This is the grammar definition of Pike. */ #include "global.h" -RCSID("$Id: language.yacc,v 1.127 1999/10/19 15:31:20 hubbe Exp $"); +RCSID("$Id: language.yacc,v 1.128 1999/10/23 06:51:25 hubbe Exp $"); #ifdef HAVE_MEMORY_H #include <memory.h> #endif @@ -278,7 +278,6 @@ int yylex(YYSTYPE *yylval); %type <number> F_MIXED_ID %type <number> F_MULTISET_ID %type <number> F_NO_MASK -%type <number> F_NUMBER %type <number> F_OBJECT_ID %type <number> F_PREDEF %type <number> F_PRIVATE @@ -299,13 +298,13 @@ int yylex(YYSTYPE *yylval); %type <number> modifier %type <number> modifier_list %type <number> modifiers -%type <number> number_or_maxint -%type <number> number_or_minint %type <number> optional_dot_dot_dot %type <number> optional_stars /* The following symbols return type information */ +%type <n> number_or_minint +%type <n> number_or_maxint %type <n> cast %type <n> simple_type %type <n> simple_type2 @@ -313,6 +312,7 @@ int yylex(YYSTYPE *yylval); %type <n> string_constant %type <n> string %type <n> F_STRING +%type <n> F_NUMBER %type <n> optional_rename_inherit %type <n> optional_identifier %type <n> F_IDENTIFIER @@ -849,14 +849,14 @@ type3: F_INT_ID opt_int_range { push_type(T_INT); } number_or_maxint: /* Empty */ { - $$ = MAX_INT32; + $$ = mkintnode(MAX_INT32); } | F_NUMBER ; number_or_minint: /* Empty */ { - $$ = MIN_INT32; + $$ = mkintnode(MIN_INT32); } | F_NUMBER ; @@ -869,8 +869,22 @@ opt_int_range: /* Empty */ | '(' number_or_minint F_DOT_DOT number_or_maxint ')' { /* FIXME: Check that $4 is >= $2. */ - push_type_int($4); - push_type_int($2); + if($2->token == F_CONSTANT && $2->u.sval.type == T_INT) + { + push_type_int($4->u.sval.u.integer); + }else{ + push_type_int(MAX_INT32); + } + + if($4->token == F_CONSTANT && $4->u.sval.type == T_INT) + { + push_type_int($4->u.sval.u.integer); + }else{ + push_type_int(MIN_INT32); + } + + free_node($2); + free_node($4); } ; @@ -1621,7 +1635,7 @@ expr3: expr4 ; expr4: string - | F_NUMBER { $$=mkintnode($1); } + | F_NUMBER | F_FLOAT { $$=mkfloatnode((FLOAT_TYPE)$1); } | catch | gauge diff --git a/src/las.c b/src/las.c index 4fd5625d43e66aea308954e033008b7093321c49..e55cdad807b24146a8a728861a2548664ec0078a 100644 --- a/src/las.c +++ b/src/las.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: las.c,v 1.92 1999/09/22 18:39:10 grubba Exp $"); +RCSID("$Id: las.c,v 1.93 1999/10/23 06:51:26 hubbe Exp $"); #include "language.h" #include "interpret.h" @@ -29,6 +29,7 @@ RCSID("$Id: las.c,v 1.92 1999/09/22 18:39:10 grubba Exp $"); #include "peep.h" #include "builtin_functions.h" #include "cyclic.h" +#include "block_alloc.h" #define LASDEBUG @@ -196,21 +197,20 @@ struct pike_string *find_return_type(node *n) #define NODES 256 -struct node_chunk -{ - struct node_chunk *next; - node nodes[NODES]; -}; +#undef BLOCK_ALLOC_NEXT +#define BLOCK_ALLOC_NEXT u.node.a + +BLOCK_ALLOC(node_s, NODES); -static struct node_chunk *node_chunks=0; -static node *free_nodes=0; +#undef BLOCK_ALLOC_NEXT +#define BLOCK_ALLOC_NEXT next void free_all_nodes(void) { if(!compiler_frame) { node *tmp; - struct node_chunk *tmp2; + struct node_s_block *tmp2; int e=0; #ifndef PIKE_DEBUG @@ -218,26 +218,29 @@ void free_all_nodes(void) { #endif - for(tmp2=node_chunks;tmp2;tmp2=tmp2->next) e+=NODES; - for(tmp=free_nodes;tmp;tmp=CAR(tmp)) e--; + for(tmp2=node_s_blocks;tmp2;tmp2=tmp2->next) e+=NODES; + for(tmp=free_node_ss;tmp;tmp=CAR(tmp)) e--; if(e) { int e2=e; - for(tmp2=node_chunks;tmp2;tmp2=tmp2->next) + for(tmp2=node_s_blocks;tmp2;tmp2=tmp2->next) { for(e=0;e<NODES;e++) { - for(tmp=free_nodes;tmp;tmp=CAR(tmp)) - if(tmp==tmp2->nodes+e) + for(tmp=free_node_ss;tmp;tmp=CAR(tmp)) + if(tmp==tmp2->x+e) break; if(!tmp) { - tmp=tmp2->nodes+e; + tmp=tmp2->x+e; #ifdef PIKE_DEBUG if(!cumulative_parse_error) { fprintf(stderr,"Free node at %p, (%s:%d) (token=%d).\n",tmp, tmp->current_file->str, tmp->line_number, tmp->token); + + debug_malloc_dump_references(tmp); + if(tmp->token==F_CONSTANT) print_tree(tmp); } @@ -262,13 +265,7 @@ void free_all_nodes(void) #ifndef PIKE_DEBUG } #endif - while(node_chunks) - { - tmp2=node_chunks; - node_chunks=tmp2->next; - free((char *)tmp2); - } - free_nodes=0; + free_all_node_s_blocks(); cumulative_parse_error=0; } } @@ -301,29 +298,14 @@ void free_node(node *n) #ifdef PIKE_DEBUG if(n->current_file) free_string(n->current_file); #endif - CAR(n)=free_nodes; - free_nodes=n; + really_free_node_s(n); } /* here starts routines to make nodes */ static node *mkemptynode(void) { - node *res; - if(!free_nodes) - { - int e; - struct node_chunk *tmp=ALLOC_STRUCT(node_chunk); - tmp->next=node_chunks; - node_chunks=tmp; - - for(e=0;e<NODES-1;e++) - CAR(tmp->nodes+e)=tmp->nodes+e+1; - CAR(tmp->nodes+e)=0; - free_nodes=tmp->nodes; - } - res=free_nodes; - free_nodes=CAR(res); + node *res=alloc_node_s(); res->token=0; res->line_number=lex.current_line; #ifdef PIKE_DEBUG diff --git a/src/las.h b/src/las.h index fc67fd64294ecfafa37577c6ab0c8ca9288c7346..c1d4fd586279f7fd26b0ff8a10ef5146d8530e9b 100644 --- a/src/las.h +++ b/src/las.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: las.h,v 1.21 1999/09/25 20:11:49 grubba Exp $ + * $Id: las.h,v 1.22 1999/10/23 06:51:27 hubbe Exp $ */ #ifndef LAS_H #define LAS_H @@ -115,8 +115,8 @@ int dooptcode(struct pike_string *name, void resolv_program(node *n); /* Prototypes end here */ -#define CAR(n) ((n)->u.node.a) -#define CDR(n) ((n)->u.node.b) +#define CAR(n) (dmalloc_touch(node *,(n))->u.node.a) +#define CDR(n) (dmalloc_touch(node *,(n))->u.node.b) #define CAAR(n) CAR(CAR(n)) #define CADR(n) CAR(CDR(n)) #define CDAR(n) CDR(CAR(n)) diff --git a/src/lexer.h b/src/lexer.h index a3520beb50509092f008a95a28fd2fc60ad58f24..ec20723eeb0c4c07e11c387e1db1be07ce8fc146 100644 --- a/src/lexer.h +++ b/src/lexer.h @@ -1,5 +1,5 @@ /* - * $Id: lexer.h,v 1.7 1999/09/19 20:36:47 grubba Exp $ + * $Id: lexer.h,v 1.8 1999/10/23 06:51:28 hubbe Exp $ * * Lexical analyzer template. * Based on lex.c 1.62 @@ -389,7 +389,7 @@ static int low_yylex(YYSTYPE *yylval) } if(!GOBBLE('\'')) yyerror("Unterminated character constant."); - yylval->number=c; + debug_malloc_pass( yylval->n=mkintnode(c) ); return F_NUMBER; case '"': @@ -415,7 +415,15 @@ static int low_yylex(YYSTYPE *yylval) case '0': if(GOBBLE('x') || GOBBLE('X')) { - yylval->number=lex_strtol(lex.pos, &lex.pos, 16); + debug_malloc_pass( yylval->n=mkintnode(0) ); + wide_string_to_svalue_inumber(&yylval->n->u.sval, + lex.pos, + (void **)&lex.pos, + 16, + 0, + SHIFT); + free_string(yylval->n->type); + yylval->n->type=get_type_of_svalue(&yylval->n->u.sval); return F_NUMBER; } @@ -433,16 +441,28 @@ static int low_yylex(YYSTYPE *yylval) yyerror("Illegal octal number."); f=lex_strtod(lex.pos, &p1); - l=lex_strtol(lex.pos, &p2, 0); + + debug_malloc_pass( yylval->n=mkintnode(0) ); + wide_string_to_svalue_inumber(&yylval->n->u.sval, + lex.pos, + (void **)&p2, + 0, + 0, + SHIFT); + + free_string(yylval->n->type); + yylval->n->type=get_type_of_svalue(&yylval->n->u.sval); if(p1>p2) { + debug_malloc_touch(yylval->n); + free_node(yylval->n); lex.pos=p1; yylval->fnum=(FLOAT_TYPE)f; return F_FLOAT; }else{ + debug_malloc_touch(yylval->n); lex.pos=p2; - yylval->number=l; return F_NUMBER; } diff --git a/src/modules/Gmp/configure.in b/src/modules/Gmp/configure.in index c5cb1360e538d4cc6bdfd0277cc302b9f7466040..869cbc187f31bc81da34d640113ae511c4b4b928 100644 --- a/src/modules/Gmp/configure.in +++ b/src/modules/Gmp/configure.in @@ -1,7 +1,8 @@ -# $Id: configure.in,v 1.7 1999/10/05 06:23:19 hubbe Exp $ +# $Id: configure.in,v 1.8 1999/10/23 06:52:07 hubbe Exp $ AC_INIT(mpz_glue.c) AC_CONFIG_HEADER(gmp_machine.h) AC_ARG_WITH(gmp, [ --with(out)-gmp Support bignums],[],[with_gmp=yes]) +AC_ARG_WITH(gmp, [ --with(out)-bignums Support automatic bignum conversion],[],[with_bignums=yes]) AC_MODULE_INIT() @@ -53,7 +54,14 @@ fi if test x$with_gmp = xyes ; then AC_CHECK_GMP(gmp2,gmp2/gmp.h,[ - AC_CHECK_GMP(gmp,gmp.h) + AC_CHECK_GMP(gmp,gmp.h,[ + if test "x$with_bignums" = xyes ; then + AC_MSG_ERROR([Cannot compile --with-bignums without the GMP library +Either install GMP on your system or run configure with +the option --without-bignums. +]) + fi + ]) ]) fi diff --git a/src/opcodes.c b/src/opcodes.c index 00b233a50b9222db80a59bff915659d34b4041e9..ff873ddd5fc3543b15979db6f6b6710e1869d23c 100644 --- a/src/opcodes.c +++ b/src/opcodes.c @@ -24,7 +24,7 @@ #include "security.h" #include "bignum.h" -RCSID("$Id: opcodes.c,v 1.47 1999/10/22 18:16:15 noring Exp $"); +RCSID("$Id: opcodes.c,v 1.48 1999/10/23 06:51:29 hubbe Exp $"); void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind) { @@ -906,25 +906,7 @@ static INT32 really_low_sscanf(char *input, return matches; } - /* This can be here independently of AUTO_BIGNUM. Besides, - we really want to reduce the number of number parsers - around here. :) /Noring */ -#ifdef AUTO_BIGNUM string_to_svalue_inumber(&sval, input+eye, &t, 10, field_length); -#else - if(field_length != -1 && eye+field_length < input_len) - { - char save=input[eye+field_length]; - input[eye+field_length]=0; /* DANGEROUS */ - sval.u.integer=STRTOL(input+eye,&t,10); - input[eye+field_length]=save; - } - else - sval.u.integer=STRTOL(input+eye,&t,10); - - sval.type=T_INT; - sval.subtype=NUMBER_NUMBER; -#endif /* AUTO_BIGNUM */ if(input + eye == t) { @@ -945,25 +927,7 @@ static INT32 really_low_sscanf(char *input, return matches; } - /* This can be here independently of AUTO_BIGNUM. Besides, - we really want to reduce the number of number parsers - around here. :) /Noring */ -#ifdef AUTO_BIGNUM string_to_svalue_inumber(&sval, input+eye, &t, 16, field_length); -#else - if(field_length != -1 && eye+field_length < input_len) - { - char save=input[eye+field_length]; - input[eye+field_length]=0; /* DANGEROUS */ - sval.u.integer=STRTOL(input+eye,&t,16); - input[eye+field_length]=save; - } - else - sval.u.integer=STRTOL(input+eye,&t,16); - - sval.type=T_INT; - sval.subtype=NUMBER_NUMBER; -#endif /* AUTO_BIGNUM */ if(input + eye == t) { @@ -984,25 +948,7 @@ static INT32 really_low_sscanf(char *input, return matches; } - /* This can be here independently of AUTO_BIGNUM. Besides, - we really want to reduce the number of number parsers - around here. :) /Noring */ -#ifdef AUTO_BIGNUM string_to_svalue_inumber(&sval, input+eye, &t, 8, field_length); -#else - if(field_length != -1 && eye+field_length < input_len) - { - char save=input[eye+field_length]; - input[eye+field_length]=0; /* DANGEROUS */ - sval.u.integer=STRTOL(input+eye,&t,8); - input[eye+field_length]=save; - } - else - sval.u.integer=STRTOL(input+eye,&t,8); - - sval.type=T_INT; - sval.subtype=NUMBER_NUMBER; -#endif /* AUTO_BIGNUM */ if(input + eye == t) { @@ -1024,25 +970,7 @@ static INT32 really_low_sscanf(char *input, return matches; } - /* This can be here independently of AUTO_BIGNUM. Besides, - we really want to reduce the number of number parsers - around here. :) /Noring */ -#ifdef AUTO_BIGNUM string_to_svalue_inumber(&sval, input+eye, &t, 0, field_length); -#else - if(field_length != -1 && eye+field_length < input_len) - { - char save=input[eye+field_length]; - input[eye+field_length]=0; /* DANGEROUS */ - sval.u.integer=STRTOL(input+eye,&t,0); - input[eye+field_length]=save; - } - else - sval.u.integer=STRTOL(input+eye,&t,0); - - sval.type=T_INT; - sval.subtype=NUMBER_NUMBER; -#endif /* AUTO_BIGNUM */ if(input + eye == t) { diff --git a/src/pike_memory.c b/src/pike_memory.c index 5fbc786fb1176cb4043200c25531eb54c48e80f9..fc9ac127c64fd046173a96e3cb854fe49f0a7774 100644 --- a/src/pike_memory.c +++ b/src/pike_memory.c @@ -10,7 +10,7 @@ #include "pike_macros.h" #include "gc.h" -RCSID("$Id: pike_memory.c,v 1.48 1999/10/22 02:35:57 hubbe Exp $"); +RCSID("$Id: pike_memory.c,v 1.49 1999/10/23 06:51:30 hubbe Exp $"); /* strdup() is used by several modules, so let's provide it */ #ifndef HAVE_STRDUP @@ -33,6 +33,13 @@ int pcharp_memcmp(PCHARP a, PCHARP b, int sz) b.ptr, sz, b.shift); } +long pcharp_strlen(PCHARP a) +{ + long len; + for(len=0;INDEX_PCHARP(a,len);len++); + return len; +} + INLINE p_wchar1 *MEMCHR1(p_wchar1 *p,p_wchar1 c,INT32 e) { while(--e >= 0) if(*(p++)==c) return p-1; diff --git a/src/pike_memory.h b/src/pike_memory.h index c12077c7841b2e0e6cb8bc12b8b016579177ce5d..16a89bda4eb0d4fcec3cc9d3a332ca618cadf364 100644 --- a/src/pike_memory.h +++ b/src/pike_memory.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: pike_memory.h,v 1.11 1999/03/11 13:44:36 hubbe Exp $ + * $Id: pike_memory.h,v 1.12 1999/10/23 06:51:31 hubbe Exp $ */ #ifndef MEMORY_H #define MEMORY_H @@ -59,8 +59,9 @@ struct generic_mem_searcher #include "block_alloc_h.h" #define MEMCHR0 MEMCHR -/* Prototypes begin here */ +/* Note to self: Protoptypes must be updated manually /Hubbe */ int pcharp_memcmp(PCHARP a, PCHARP b, int sz); +long pcharp_strlen(PCHARP a); INLINE p_wchar1 *MEMCHR1(p_wchar1 *p,p_wchar1 c,INT32 e); INLINE p_wchar2 *MEMCHR2(p_wchar2 *p,p_wchar2 c,INT32 e); void swap(char *a, char *b, INT32 size); @@ -95,8 +96,7 @@ void memfill(char *to, char *from, INT32 fromlen, INT32 offset); - -/* Prototypes end here */ +char *debug_xalloc(long size); #undef BLOCK_ALLOC diff --git a/src/stralloc.c b/src/stralloc.c index e91967a72903f1cfa6d0ce99be1b7a07df4e8aec..3c2871638b857ced80a6d434b2d2fcad93db3467 100644 --- a/src/stralloc.c +++ b/src/stralloc.c @@ -25,7 +25,7 @@ #define HUGE HUGE_VAL #endif /*!HUGE*/ -RCSID("$Id: stralloc.c,v 1.69 1999/10/23 00:43:44 noring Exp $"); +RCSID("$Id: stralloc.c,v 1.70 1999/10/23 06:51:32 hubbe Exp $"); #define BEGIN_HASH_SIZE 997 #define MAX_AVG_LINK_LENGTH 3 @@ -582,6 +582,26 @@ struct pike_string * debug_make_shared_binary_string(const char *str,int len) return s; } +struct pike_string * debug_make_shared_binary_pcharp(const PCHARP str,int len) +{ + switch(str.shift) + { + case 0: + return make_shared_binary_string((p_wchar0 *)(str.ptr), len); + case 1: + return make_shared_binary_string1((p_wchar1 *)(str.ptr), len); + case 2: + return make_shared_binary_string2((p_wchar2 *)(str.ptr), len); + default: + fatal("Unknown string width!\n"); + } +} + +struct pike_string * debug_make_shared_pcharp(const PCHARP str) +{ + return debug_make_shared_binary_pcharp(str, pcharp_strlen(str)); +} + struct pike_string * debug_make_shared_binary_string1(const p_wchar1 *str,int len) { struct pike_string *s; @@ -1783,10 +1803,46 @@ long STRTOL_PCHARP(PCHARP str, PCHARP *ptr, int base) return (neg ? val : -val); } -int string_to_svalue_inumber(struct svalue *r, char *str, char **ptr, int base, +int string_to_svalue_inumber(struct svalue *r, + char * str, + char **ptr, + int base, + int maxlength) +{ + PCHARP tmp; + int ret=pcharp_to_svalue_inumber(r, + MKPCHARP(str,0), + &tmp, + base, + maxlength); + if(ptr) *ptr=(char *)tmp.ptr; + return ret; +} + +int wide_string_to_svalue_inumber(struct svalue *r, + void * str, + void **ptr, + int base, + int maxlength, + int shift) +{ + PCHARP tmp; + int ret=pcharp_to_svalue_inumber(r, + MKPCHARP(str,shift), + &tmp, + base, + maxlength); + if(ptr) *ptr=(char *)tmp.ptr; + return ret; +} + +int pcharp_to_svalue_inumber(struct svalue *r, + PCHARP str, + PCHARP *ptr, + int base, int maxlength) { - char *str_start; + PCHARP str_start; INT_TYPE xx, neg = 0, is_bignum = 0; INT_TYPE val; @@ -1805,10 +1861,13 @@ int string_to_svalue_inumber(struct svalue *r, char *str, char **ptr, int base, if(base < 0 || MBASE < base) return 0; - if(!isalnum(c = *str)) + if(!isalnum(c = EXTRACT_PCHARP(str))) { while(ISSPACE(c)) - c = *++str; + { + INC_PCHARP(str,1); + c = EXTRACT_PCHARP(str); + } switch (c) { @@ -1816,7 +1875,8 @@ int string_to_svalue_inumber(struct svalue *r, char *str, char **ptr, int base, neg++; /* Fall-through. */ case '+': - c = *++str; + INC_PCHARP(str,1); + c = EXTRACT_PCHARP(str); } } @@ -1824,7 +1884,7 @@ int string_to_svalue_inumber(struct svalue *r, char *str, char **ptr, int base, { if(c != '0') base = 10; - else if(str[1] == 'x' || str[1] == 'X') + else if(INDEX_PCHARP(str,1) == 'x' || INDEX_PCHARP(str,1) == 'X') base = 16; else base = 8; @@ -1837,13 +1897,20 @@ int string_to_svalue_inumber(struct svalue *r, char *str, char **ptr, int base, if(!isalnum(c) || (xx = DIGIT(c)) >= base) return 0; /* No number formed. */ - if(base == 16 && c == '0' && isxdigit(((unsigned char *)str)[2]) && - (str[1] == 'x' || str[1] == 'X')) - c = *(str += 2); /* Skip over leading "0x" or "0X". */ + if(base == 16 && c == '0' && + INDEX_PCHARP(str,2) < 256 && /* Don't trust isxdigit... */ + isxdigit(INDEX_PCHARP(str,2)) && + (INDEX_PCHARP(str,1) == 'x' || INDEX_PCHARP(str,1) == 'X')) + { + /* Skip over leading "0x" or "0X". */ + INC_PCHARP(str,2); + c=EXTRACT_PCHARP(str); + } - for(val = -DIGIT(c); isalnum(c = *++str) && - (xx = DIGIT(c)) < base && - 0 != maxlength--; ) + for(val = -DIGIT(c); + isalnum(c = ( INC_PCHARP(str,1),EXTRACT_PCHARP(str) )) && + (xx = DIGIT(c)) < base && + 0 != maxlength--; ) { #ifdef AUTO_BIGNUM if(INT_TYPE_MUL_OVERFLOW(val, base)) @@ -1861,14 +1928,15 @@ int string_to_svalue_inumber(struct svalue *r, char *str, char **ptr, int base, #ifdef AUTO_BIGNUM if(is_bignum || (!neg && r->u.integer < 0)) { - struct pike_string *s; - - s = begin_shared_string(str - str_start); - MEMCPY(s->str, str_start, str - str_start); - s = end_shared_string(s); - - push_string(s); + push_string(make_shared_binary_pcharp(str_start, + SUBTRACT_PCHARP(str,str_start))); push_int(base); + + /* Note that this can concievably throw errors() + * in some situations that might not be desirable... + * take care. + * /Hubbe + */ convert_stack_top_with_base_to_bignum(); *r = *--sp; @@ -1886,7 +1954,7 @@ int convert_stack_top_string_to_inumber(int base) if(sp[-1].type != T_STRING) error("Cannot convert stack top to integer number.\n"); - i = string_to_svalue_inumber(&r, sp[-1].u.string->str, 0, base, 0); + i=pcharp_to_svalue_inumber(&r, MKPCHARP_STR(sp[-1].u.string), 0, base, 0); free_string(sp[-1].u.string); sp[-1] = r; diff --git a/src/stralloc.h b/src/stralloc.h index 259fd6808414afcf64f5c3134fa94dd6ea3f46ed..10817461fbbaf5c748b0231c8cb0e92859ef213f 100644 --- a/src/stralloc.h +++ b/src/stralloc.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: stralloc.h,v 1.36 1999/10/22 18:16:16 noring Exp $ + * $Id: stralloc.h,v 1.37 1999/10/23 06:51:34 hubbe Exp $ */ #ifndef STRALLOC_H #define STRALLOC_H @@ -80,6 +80,8 @@ struct pike_string *debug_findstring(const struct pike_string *foo); #define COMPARE_PCHARP(X,CMP,Y) LOW_COMPARE_PCHARP((X),CMP,(Y)) #endif + + static INLINE PCHARP MKPCHARP(void *ptr, int shift) { PCHARP tmp; @@ -94,6 +96,7 @@ static INLINE PCHARP MKPCHARP(void *ptr, int shift) MKPCHARP((STR)->str + ((OFF)<<(STR)->size_shift), (STR)->size_shift) #define ADD_PCHARP(PTR,I) MKPCHARP_OFF((PTR).ptr,(PTR).shift,(I)) + #ifdef DEBUG_MALLOC #define reference_shared_string(s) do { struct pike_string *S_=(s); debug_malloc_touch(S_); S_->refs++; }while(0) #define copy_shared_string(to,s) do { struct pike_string *S_=(to)=(s); debug_malloc_touch(S_); S_->refs++; }while(0) @@ -144,9 +147,6 @@ INLINE INT32 PIKE_CONCAT4(compare_,FROM,_to_,TO)(const PIKE_CONCAT(p_wchar,TO) * /* Prototypes begin here */ -int string_to_svalue_inumber(struct svalue *r, char *str, char **ptr, int base, - int maxlength); -int convert_stack_top_string_to_inumber(int base); INLINE unsigned INT32 index_shared_string(struct pike_string *s, int pos); INLINE void low_set_index(struct pike_string *s, int pos, int value); INLINE struct pike_string *debug_check_size_shift(struct pike_string *a,int shift); @@ -170,6 +170,8 @@ struct pike_string *debug_begin_wide_shared_string(int len, int shift); struct pike_string *low_end_shared_string(struct pike_string *s); struct pike_string *end_shared_string(struct pike_string *s); struct pike_string * debug_make_shared_binary_string(const char *str,int len); +struct pike_string * debug_make_shared_binary_pcharp(const PCHARP str,int len); +struct pike_string * debug_make_shared_pcharp(const PCHARP str); struct pike_string * debug_make_shared_binary_string1(const p_wchar1 *str,int len); struct pike_string * debug_make_shared_binary_string2(const p_wchar2 *str,int len); struct pike_string *debug_make_shared_string(const char *str); @@ -234,6 +236,23 @@ void free_string_builder(struct string_builder *s); struct pike_string *finish_string_builder(struct string_builder *s); PCHARP MEMCHR_PCHARP(PCHARP ptr, int chr, int len); long STRTOL_PCHARP(PCHARP str, PCHARP *ptr, int base); +int string_to_svalue_inumber(struct svalue *r, + char * str, + char **ptr, + int base, + int maxlength); +int wide_string_to_svalue_inumber(struct svalue *r, + void * str, + void **ptr, + int base, + int maxlength, + int shift); +int pcharp_to_svalue_inumber(struct svalue *r, + PCHARP str, + PCHARP *ptr, + int base, + int maxlength); +int convert_stack_top_string_to_inumber(int base); double STRTOD_PCHARP(PCHARP nptr, PCHARP *endptr); p_wchar0 *require_wstring0(struct pike_string *s, char **to_free); @@ -265,6 +284,12 @@ p_wchar2 *require_wstring2(struct pike_string *s, ((struct pike_string *)debug_malloc_update_location(debug_begin_shared_string(X),__FILE__,__LINE__)) #define begin_wide_shared_string(X,Y) \ ((struct pike_string *)debug_malloc_update_location(debug_begin_wide_shared_string((X),(Y)),__FILE__,__LINE__)) + +#define make_shared_pcharp(X) \ + ((struct pike_string *)debug_malloc_update_location(debug_make_shared_pcharp(X),__FILE__,__LINE__)) +#define make_shared_binary_pcharp(X,Y) \ + ((struct pike_string *)debug_malloc_update_location(debug_make_shared_binary_pcharp((X),(Y)),__FILE__,__LINE__)) + #else #define make_shared_string debug_make_shared_string #define make_shared_binary_string debug_make_shared_binary_string @@ -277,6 +302,10 @@ p_wchar2 *require_wstring2(struct pike_string *s, #define begin_shared_string debug_begin_shared_string #define begin_wide_shared_string debug_begin_wide_shared_string + +#define make_shared_pcharp debug_make_shared_pcharp +#define make_shared_binary_pcharp debug_make_shared_binary_pcharp + #endif #undef CONVERT