diff --git a/.cvsignore b/.cvsignore index bbef49da9c136ab9d6915852758c97f9516484ae..0136d70c2d543abfb7ed7cb88b5de16500686f60 100644 --- a/.cvsignore +++ b/.cvsignore @@ -2,6 +2,7 @@ Pike-v0.3.tar.gz Pike-v0.3.tar.hz Pike-v0.4.tar.gz Pike-v0.4.tar.hz +Pike-v0.5b7.tar.gz Pike_v0.1.tar.gz Pike_v0.2.tar.gz Pike_v0.3.tar.gz diff --git a/.gitignore b/.gitignore index 18f1f53671646fcb09239f266b80511d1c43d363..e1eba67679d0ba222b7903b309e8a4f6c551da29 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,7 @@ core /Pike-v0.3.tar.hz /Pike-v0.4.tar.gz /Pike-v0.4.tar.hz +/Pike-v0.5b7.tar.gz /Pike_v0.1.tar.gz /Pike_v0.2.tar.gz /Pike_v0.3.tar.gz diff --git a/src/Makefile.in b/src/Makefile.in index fb7864d354da29bd7479ec4fa16970e59e0f363e..804f48517a28b4498370b8e5e39bd22022092eb8 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -88,7 +88,7 @@ OBJ= \ pike_types.o \ main.o \ mapping.o \ - memory.o \ + pike_memory.o \ module.o \ module_support.o \ object.o \ diff --git a/src/array.c b/src/array.c index 5ec1df37e6b5c1a5768361647595ce789c952329..756357d5f050870d4cdf5712fb205d49d6568813 100644 --- a/src/array.c +++ b/src/array.c @@ -15,7 +15,7 @@ #include "pike_types.h" #include "fsort.h" #include "builtin_functions.h" -#include "memory.h" +#include "pike_memory.h" #include "gc.h" #include "main.h" diff --git a/src/builtin_functions.c b/src/builtin_functions.c index 2279f3ee24c176fe73f50d674515cf6a94757cca..b5f30fe757c4f12d065c3298bc856321ba213d0b 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: builtin_functions.c,v 1.36 1997/05/07 06:27:32 per Exp $"); +RCSID("$Id: builtin_functions.c,v 1.37 1997/05/19 23:31:00 hubbe Exp $"); #include "interpret.h" #include "svalue.h" #include "pike_macros.h" @@ -25,7 +25,7 @@ RCSID("$Id: builtin_functions.c,v 1.36 1997/05/07 06:27:32 per Exp $"); #include "gc.h" #include "backend.h" #include "main.h" -#include "memory.h" +#include "pike_memory.h" #include "threads.h" #include "time_stuff.h" #include "version.h" diff --git a/src/constants.c b/src/constants.c index 49f697bcf919ac7920e1604e74edeb6b5270e4d8..d960b818f78eaf6ac685a8a10491db046e083608 100644 --- a/src/constants.c +++ b/src/constants.c @@ -9,7 +9,7 @@ #include "program.h" #include "pike_types.h" #include "stralloc.h" -#include "memory.h" +#include "pike_memory.h" #include "interpret.h" #include "mapping.h" #include "error.h" diff --git a/src/docode.c b/src/docode.c index c6a3bcb7a92fc76979b30ad1e87996b17c64a906..e84657b08c1d10ae028c324d7cfceceb5446caf5 100644 --- a/src/docode.c +++ b/src/docode.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: docode.c,v 1.16 1997/04/17 22:47:06 hubbe Exp $"); +RCSID("$Id: docode.c,v 1.17 1997/05/19 23:31:00 hubbe Exp $"); #include "las.h" #include "program.h" #include "language.h" @@ -15,7 +15,7 @@ RCSID("$Id: docode.c,v 1.16 1997/04/17 22:47:06 hubbe Exp $"); #include "array.h" #include "pike_macros.h" #include "error.h" -#include "memory.h" +#include "pike_memory.h" #include "svalue.h" #include "main.h" #include "lex.h" diff --git a/src/dynamic_buffer.c b/src/dynamic_buffer.c index aa833811522fe23317955f96c24f3ebdc2057dfa..aca18c7266c2ede8ba35486dc0ad044d4b5d3e26 100644 --- a/src/dynamic_buffer.c +++ b/src/dynamic_buffer.c @@ -7,7 +7,7 @@ #include "dynamic_buffer.h" #include "stralloc.h" #include "error.h" -#include "memory.h" +#include "pike_memory.h" static dynamic_buffer buff; diff --git a/src/gc.c b/src/gc.c index a3d1f008beb46c7849bceb88b46fa92d0a97e391..6b33fc6d70450f4edfbd49277d4e0f1ca6aa34ee 100644 --- a/src/gc.c +++ b/src/gc.c @@ -18,6 +18,7 @@ struct callback *gc_evaluator_callback=0; #include "stralloc.h" #include "stuff.h" #include "error.h" +#include "pike_memory.h" #include "gc.h" #include "main.h" diff --git a/src/gc.h b/src/gc.h index 74876eec46d8ab3b9817e6cad2635ff2cc2fbdb3..e7ee5766691fb558227bd84cca492ededaa3be8f 100644 --- a/src/gc.h +++ b/src/gc.h @@ -4,6 +4,7 @@ #ifdef GC2 #include "global.h" +#include "callback.h" extern INT32 num_objects; extern INT32 num_allocs; diff --git a/src/global.h b/src/global.h index 21585e30dfd77c913580acb2c729b76c97679ed4..a56bf86208d0dd9121ce58d13c477326b2ea44da 100644 --- a/src/global.h +++ b/src/global.h @@ -84,35 +84,23 @@ char *alloca (); #undef HAVE_STRING_H #endif -#ifdef HAVE_MEMORY_H -#include <memory.h> -#undef HAVE_MEMORY_H +#ifdef HAVE_LIMITS_H +#include <limits.h> +#undef HAVE_LIMITS_H #endif -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) -#define RCSID(X) \ - static char *rcsid __attribute__ ((unused)) =X -#elif __GNUC__ == 2 -#define RCSID(X) \ - static char *rcsid = X; \ - static void *use_rcsid=(&use_rcsid, (void *)&rcsid) -#else -#define RCSID(X) \ - static char *rcsid = X +#ifdef HAVE_SYS_TYPES_H +#include <sys/types.h> +#undef HAVE_SYS_TYPES_H #endif -#if defined(__GNUC__) && !defined(DEBUG) && !defined(lint) -#define INLINE inline -#else -#define INLINE +#ifdef HAVE_MEMORY_H +#include <memory.h> +#undef HAVE_MEMORY_H #endif -/* we here define a few types with more defined values */ -#ifdef HAVE_LIMITS_H -#include <limits.h> -#undef HAVE_LIMITS_H -#endif +/* we here define a few types with more defined values */ #define INT64 long long @@ -137,11 +125,25 @@ char *alloca (); #define FLOAT_TYPE float -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> -#undef HAVE_SYS_TYPES_H + + +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) +#define RCSID(X) \ + static char *rcsid __attribute__ ((unused)) =X +#elif __GNUC__ == 2 +#define RCSID(X) \ + static char *rcsid = X; \ + static void *use_rcsid=(&use_rcsid, (void *)&rcsid) +#else +#define RCSID(X) \ + static char *rcsid = X #endif +#if defined(__GNUC__) && !defined(DEBUG) && !defined(lint) +#define INLINE inline +#else +#define INLINE +#endif #include "port.h" diff --git a/src/las.c b/src/las.c index 23c9066cee738b20a39d1cc9fd3bad6b2c080b8d..f71e13c3b40df6b6c244c2ade1f80102a381ad8e 100644 --- a/src/las.c +++ b/src/las.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: las.c,v 1.32 1997/04/18 01:17:40 hubbe Exp $"); +RCSID("$Id: las.c,v 1.33 1997/05/19 23:31:01 hubbe Exp $"); #include "language.h" #include "interpret.h" @@ -21,7 +21,7 @@ RCSID("$Id: las.c,v 1.32 1997/04/18 01:17:40 hubbe Exp $"); #include "error.h" #include "docode.h" #include "main.h" -#include "memory.h" +#include "pike_memory.h" #include "operators.h" #include "callback.h" #include "pike_macros.h" diff --git a/src/lex.c b/src/lex.c index d5dca0f5ff50059b96f891ee0170275bccec9f32..18c829778a1c1fe84653dc04d57982e43572bdc0 100644 --- a/src/lex.c +++ b/src/lex.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: lex.c,v 1.23 1997/05/19 09:32:39 hubbe Exp $"); +RCSID("$Id: lex.c,v 1.24 1997/05/19 23:31:02 hubbe Exp $"); #include "language.h" #include "array.h" #include "lex.h" @@ -13,7 +13,7 @@ RCSID("$Id: lex.c,v 1.23 1997/05/19 09:32:39 hubbe Exp $"); #include "constants.h" #include "hashtable.h" #include "stuff.h" -#include "memory.h" +#include "pike_memory.h" #include "interpret.h" #include "error.h" #include "object.h" diff --git a/src/mapping.c b/src/mapping.c index 4e23c21d60e0ff1a2b1e831be309ce719c0bb302..6be1344b8105cc9f2447a959834e7c00f347de4f 100644 --- a/src/mapping.c +++ b/src/mapping.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: mapping.c,v 1.19 1997/05/19 22:48:08 hubbe Exp $"); +RCSID("$Id: mapping.c,v 1.20 1997/05/19 23:31:02 hubbe Exp $"); #include "main.h" #include "object.h" #include "mapping.h" @@ -13,7 +13,7 @@ RCSID("$Id: mapping.c,v 1.19 1997/05/19 22:48:08 hubbe Exp $"); #include "pike_macros.h" #include "language.h" #include "error.h" -#include "memory.h" +#include "pike_memory.h" #include "dynamic_buffer.h" #include "interpret.h" #include "las.h" diff --git a/src/modules/Image/quant.c b/src/modules/Image/quant.c index 182dd345e279021b02e8e2f2f85d68733642f633..ef871d87034a181bcbd662f8bcc3c5039553845c 100644 --- a/src/modules/Image/quant.c +++ b/src/modules/Image/quant.c @@ -1,5 +1,5 @@ #include <config.h> -/* $Id: quant.c,v 1.8 1997/05/19 22:50:27 hubbe Exp $ */ +/* $Id: quant.c,v 1.9 1997/05/19 23:32:02 hubbe Exp $ */ /* @@ -21,6 +21,7 @@ David K #include "error.h" #include "global.h" +#include "pike_memory.h" #include "array.h" #include "threads.h" diff --git a/src/modules/Regexp/pike_regexp.c b/src/modules/Regexp/pike_regexp.c index a0ff79a859b6109aa845a8329a2e40deeaf28e3d..6bb86144e6128672c0128236a832a5eed6939749 100644 --- a/src/modules/Regexp/pike_regexp.c +++ b/src/modules/Regexp/pike_regexp.c @@ -61,7 +61,7 @@ #include "global.h" #include <ctype.h> #include "pike_regexp.h" -#include "memory.h" +#include "pike_memory.h" #include "error.h" /* diff --git a/src/modules/call_out/call_out.c b/src/modules/call_out/call_out.c index 4b58191748a7640e30789618afbc2e6570d8309b..74fc1a8cdbe1493c27e460ba6c9ab3558cd2725a 100644 --- a/src/modules/call_out/call_out.c +++ b/src/modules/call_out/call_out.c @@ -4,14 +4,14 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: call_out.c,v 1.11 1997/05/18 22:23:29 grubba Exp $"); +RCSID("$Id: call_out.c,v 1.12 1997/05/19 23:32:56 hubbe Exp $"); #include "array.h" #include "dynamic_buffer.h" #include "object.h" #include "interpret.h" #include "error.h" #include "builtin_functions.h" -#include "memory.h" +#include "pike_memory.h" #include "main.h" #include "backend.h" #include "time_stuff.h" diff --git a/src/modules/sprintf/sprintf.c b/src/modules/sprintf/sprintf.c index 4f13157115add827e81ee3bd07135fb2f06b0c7a..5bca7636873696377fa309fab217ce7deccbaaf9 100644 --- a/src/modules/sprintf/sprintf.c +++ b/src/modules/sprintf/sprintf.c @@ -96,7 +96,7 @@ */ #include "global.h" -RCSID("$Id: sprintf.c,v 1.10 1997/04/16 03:13:41 hubbe Exp $"); +RCSID("$Id: sprintf.c,v 1.11 1997/05/19 23:33:22 hubbe Exp $"); #include "error.h" #include "array.h" #include "svalue.h" @@ -105,7 +105,7 @@ RCSID("$Id: sprintf.c,v 1.10 1997/04/16 03:13:41 hubbe Exp $"); #include "pike_types.h" #include "constants.h" #include "interpret.h" -#include "memory.h" +#include "pike_memory.h" #define FORMAT_INFO_STACK_SIZE 200 #define RETURN_SHARED_STRING diff --git a/src/multiset.c b/src/multiset.c index c7a8f6dd604415ede84b38764141ba1e6995758e..fcc31acb2f94ea22adbb8189d4ff67e5e6f565ff 100644 --- a/src/multiset.c +++ b/src/multiset.c @@ -8,7 +8,7 @@ #include "multiset.h" #include "svalue.h" #include "pike_macros.h" -#include "memory.h" +#include "pike_memory.h" #include "error.h" #include "dynamic_buffer.h" #include "interpret.h" diff --git a/src/object.c b/src/object.c index 93cd6cac8c85b88ce3f332ce0a7dfa0a8d800343..aef6fb78cc39a2346431e198c77ba69f32627488 100644 --- a/src/object.c +++ b/src/object.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: object.c,v 1.17 1997/04/16 03:09:14 hubbe Exp $"); +RCSID("$Id: object.c,v 1.18 1997/05/19 23:31:04 hubbe Exp $"); #include "object.h" #include "dynamic_buffer.h" #include "interpret.h" @@ -12,7 +12,7 @@ RCSID("$Id: object.c,v 1.17 1997/04/16 03:09:14 hubbe Exp $"); #include "stralloc.h" #include "svalue.h" #include "pike_macros.h" -#include "memory.h" +#include "pike_memory.h" #include "error.h" #include "main.h" #include "array.h" diff --git a/src/opcodes.c b/src/opcodes.c index 71698888919e54da0859a41649ec2741045f2e03..254a8c85514eddda4ab88fa0fa1c91752c943626 100644 --- a/src/opcodes.c +++ b/src/opcodes.c @@ -16,7 +16,7 @@ #include "object.h" #include "error.h" #include "pike_types.h" -#include "memory.h" +#include "pike_memory.h" #include "fd_control.h" void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind) diff --git a/src/operators.c b/src/operators.c index 988f76051672c5e9e8a737ce96c3f8041aa8329c..2fea7f42c42dc0a45e229c9d99502674b6eeee79 100644 --- a/src/operators.c +++ b/src/operators.c @@ -5,7 +5,7 @@ \*/ #include <math.h> #include "global.h" -RCSID("$Id: operators.c,v 1.14 1997/04/28 23:48:42 hubbe Exp $"); +RCSID("$Id: operators.c,v 1.15 1997/05/19 23:31:04 hubbe Exp $"); #include "interpret.h" #include "svalue.h" #include "multiset.h" @@ -15,7 +15,7 @@ RCSID("$Id: operators.c,v 1.14 1997/04/28 23:48:42 hubbe Exp $"); #include "opcodes.h" #include "operators.h" #include "language.h" -#include "memory.h" +#include "pike_memory.h" #include "error.h" #include "docode.h" #include "constants.h" diff --git a/src/peep.c b/src/peep.c index 1552fe2dc6ea106a0a8774fb3102f64c36fa7a91..fe70d6329ac662d54340a2cbc7a25ee2bc08bf1a 100644 --- a/src/peep.c +++ b/src/peep.c @@ -8,6 +8,7 @@ #include "main.h" #include "error.h" #include "lex.h" +#include "pike_memory.h" #include "peep.h" struct p_instr_s diff --git a/src/pike_macros.h b/src/pike_macros.h index ff402f5bfeaac4b261334289b1e211a11dcfbd96..812a50fc11b9e462b216ee6a004390ce1168c172 100644 --- a/src/pike_macros.h +++ b/src/pike_macros.h @@ -7,7 +7,7 @@ #define MACROS_H #include <sys/param.h> -#include "memory.h" +#include "pike_memory.h" #define BASEOF(ptr, str_type, field) \ ((struct str_type *)((char*)ptr - (char*)& (((struct str_type *)0)->field))) diff --git a/src/pike_memory.c b/src/pike_memory.c new file mode 100644 index 0000000000000000000000000000000000000000..5a4ef44aa90021573885a645cfc39da28ccba9dd --- /dev/null +++ b/src/pike_memory.c @@ -0,0 +1,367 @@ +/*\ +||| This file a part of Pike, and is copyright by Fredrik Hubinette +||| Pike is distributed as GPL (General Public License) +||| See the files COPYING and DISCLAIMER for more information. +\*/ +#include "global.h" +#include "pike_memory.h" +#include "error.h" +#include "pike_macros.h" + +char *xalloc(SIZE_T size) +{ + char *ret; + if(!size) return 0; + + ret=(char *)malloc(size); + if(ret) return ret; + + error("Out of memory.\n"); + return 0; +} + +void swap(char *a, char *b, INT32 size) +{ + int tmp; + char tmpbuf[1024]; + while(size) + { + tmp=MINIMUM((long)sizeof(tmpbuf), size); + MEMCPY(tmpbuf,a,tmp); + MEMCPY(b,a,tmp); + MEMCPY(b,tmpbuf,tmp); + size-=tmp; + a+=tmp; + b+=tmp; + } +} + +void reverse(char *memory, INT32 nitems, INT32 size) +{ +#define DOSIZE(X,Y) \ + case X: \ + { \ + struct Y { char tt[X]; }; \ + struct Y tmp; \ + struct Y *start=(struct Y *) memory; \ + struct Y *end=start+nitems-1; \ + while(start<end){tmp=*start;*(start++)=*end;*(end--)=tmp;} \ + break; \ + } + + switch(size) + { + DOSIZE(1,TMP1) + DOSIZE(2,TMP2) + DOSIZE(4,TMP4) + DOSIZE(8,TMP8) + default: + { + char *start = (char *) memory; + char *end=start+(nitems-1)*size; + while(start<end) + { + swap(start,end,size); + start+=size; + end-=size; + } + } + } +} + +/* + * This function may NOT change 'order' + * This function is hopefully fast enough... + */ +void reorder(char *memory, INT32 nitems, INT32 size,INT32 *order) +{ + INT32 e; + char *tmp; + tmp=xalloc(size * nitems); +#undef DOSIZE +#define DOSIZE(X,Y) \ + case X: \ + { \ + struct Y { char tt[X]; }; \ + struct Y *from=(struct Y *) memory; \ + struct Y *to=(struct Y *) tmp; \ + for(e=0;e<nitems;e++) to[e]=from[order[e]]; \ + break; \ + } + + + switch(size) + { + DOSIZE(1,TMP1) + DOSIZE(2,TMP2) + DOSIZE(4,TMP4) + DOSIZE(8,TMP8) + DOSIZE(16,TMP16) + + default: + for(e=0;e<nitems;e++) MEMCPY(tmp+e*size, memory+order[e]*size, size); + } + + MEMCPY(memory, tmp, size * nitems); + free(tmp); +} + +unsigned INT32 hashmem(const unsigned char *a,INT32 len,INT32 mlen) +{ + unsigned INT32 ret; + + ret=9248339*len; + if(len<mlen) mlen=len; + switch(mlen&7) + { + case 7: ret^=*(a++); + case 6: ret^=(ret<<4)+*(a++); + case 5: ret^=(ret<<7)+*(a++); + case 4: ret^=(ret<<6)+*(a++); + case 3: ret^=(ret<<3)+*(a++); + case 2: ret^=(ret<<7)+*(a++); + case 1: ret^=(ret<<5)+*(a++); + } + +#ifdef HANDLES_UNALIGNED_MEMORY_ACCESS + { + unsigned int *b; + b=(unsigned int *)a; + + for(mlen>>=3;--mlen>=0;) + { + ret^=(ret<<7)+*(b++); + ret^=(ret>>6)+*(b++); + } + } +#else + for(mlen>>=3;--mlen>=0;) + { + ret^=(ret<<7)+((((((*(a++)<<3)+*(a++))<<4)+*(a++))<<5)+*(a++)); + ret^=(ret>>6)+((((((*(a++)<<3)+*(a++))<<4)+*(a++))<<5)+*(a++)); + } +#endif + return ret; +} + +unsigned INT32 hashstr(const unsigned char *str,INT32 maxn) +{ + unsigned INT32 ret,c; + + ret=str++[0]; + for(; maxn>=0; maxn--) + { + c=str++[0]; + if(!c) break; + ret ^= ( ret << 4 ) + c ; + ret &= 0x7fffffff; + } + + return ret; +} + + +/* + * a quick memory search function. + * Written by Fredrik Hubinette (hubbe@lysator.liu.se) + */ +void init_memsearch(struct mem_searcher *s, + char *needle, + SIZE_T needlelen, + SIZE_T max_haystacklen) +{ + s->needle=needle; + s->needlelen=needlelen; + + switch(needlelen) + { + case 0: s->method=no_search; break; + case 1: s->method=use_memchr; break; + case 2: + case 3: + case 4: + case 5: + case 6: s->method=memchr_and_memcmp; break; + default: + if(max_haystacklen <= needlelen + 64) + { + s->method=memchr_and_memcmp; + }else{ + INT32 tmp, h; + unsigned INT32 hsize, e, max; + unsigned char *q; + struct link *ptr; + + hsize=52+(max_haystacklen >> 7) - (needlelen >> 8); + max =13+(max_haystacklen >> 4) - (needlelen >> 5); + + if(hsize > NELEM(s->set)) + { + hsize=NELEM(s->set); + }else{ + for(e=8;e<hsize;e+=e); + hsize=e; + } + + for(e=0;e<hsize;e++) s->set[e]=0; + hsize--; + + if(max > needlelen) max=needlelen; + max=(max-sizeof(INT32)+1) & -sizeof(INT32); + if(max > MEMSEARCH_LINKS) max=MEMSEARCH_LINKS; + + ptr=& s->links[0]; + + q=(unsigned char *)needle; + +#if BYTEORDER == 4321 + for(tmp=e=0;e<sizeof(INT32)-1;e++) + { + tmp<<=8; + tmp|=*(q++); + } +#endif + + for(e=0;e<max;e++) + { +#if BYTEORDER == 4321 + tmp<<=8; + tmp|=*(q++); +#else + tmp=EXTRACT_INT(q); + q++; +#endif + h=tmp; + h+=h>>7; + h+=h>>17; + h&=hsize; + + ptr->offset=e; + ptr->key=tmp; + ptr->next=s->set[h]; + s->set[h]=ptr; + ptr++; + } + s->hsize=hsize; + s->max=max; + s->method=hubbe_search; + } + } +} + + +char *memory_search(struct mem_searcher *s, + char *haystack, + SIZE_T haystacklen) +{ + if(s->needlelen > haystacklen) return 0; + + switch(s->method) + { + case no_search: + return haystack; + + case use_memchr: + return MEMCHR(haystack,s->needle[0],haystacklen); + + case memchr_and_memcmp: + { + char *end,c,*needle; + SIZE_T needlelen; + + needle=s->needle; + needlelen=s->needlelen; + + end=haystack + haystacklen - needlelen+1; + c=needle[0]; + needle++; + needlelen--; + while((haystack=MEMCHR(haystack,c,end-haystack))) + if(!MEMCMP(++haystack,needle,needlelen)) + return haystack-1; + + return 0; + } + + case hubbe_search: + { + INT32 tmp, h; + char *q, *end; + register struct link *ptr; + + end=haystack+haystacklen; + q=haystack + s->max - sizeof(INT32); + q=(char *)( ((long)q) & -sizeof(INT32)); + for(;q<=end-sizeof(INT32);q+=s->max) + { + h=tmp=*(INT32 *)q; + + h+=h>>7; + h+=h>>17; + h&=s->hsize; + + for(ptr=s->set[h];ptr;ptr=ptr->next) + { + char *where; + + if(ptr->key != tmp) continue; + + where=q-ptr->offset; + if(where<haystack) continue; + if(where+s->needlelen>end) return 0; + + if(!MEMCMP(where,s->needle,s->needlelen)) + return where; + } + } + } + } + return 0; +} + +char *my_memmem(char *needle, + SIZE_T needlelen, + char *haystack, + SIZE_T haystacklen) +{ + struct mem_searcher tmp; + init_memsearch(&tmp, needle, needlelen, haystacklen); + return memory_search(&tmp, haystack, haystacklen); +} + +void memfill(char *to, + INT32 tolen, + char *from, + INT32 fromlen, + INT32 offset) +{ + if(fromlen==1) + { + MEMSET(to, *from, tolen); + } + else if(tolen>0) + { + INT32 tmp=MINIMUM(tolen, fromlen - offset); + MEMCPY(to, from + offset, tmp); + to+=tmp; + tolen-=tmp; + + if(tolen > 0) + { + tmp=MINIMUM(tolen, fromlen); + MEMCPY(to, from, tmp); + from=to; + to+=tmp; + tolen-=tmp; + + while(tolen>0) + { + tmp=MINIMUM(tolen, fromlen); + MEMCPY(to, from, MINIMUM(tolen, fromlen)); + fromlen+=tmp; + tolen-=tmp; + to+=tmp; + } + } + } +} diff --git a/src/pike_memory.h b/src/pike_memory.h new file mode 100644 index 0000000000000000000000000000000000000000..e53a9fe6ef9d676fa3f6634ceed07be7f49ab81f --- /dev/null +++ b/src/pike_memory.h @@ -0,0 +1,61 @@ +/*\ +||| This file a part of Pike, and is copyright by Fredrik Hubinette +||| Pike is distributed as GPL (General Public License) +||| See the files COPYING and DISCLAIMER for more information. +\*/ +#ifndef MEMORY_H +#define MEMORY_H + +#include "global.h" + +#define MEMSEARCH_LINKS 512 + +struct link +{ + struct link *next; + INT32 key, offset; +}; + +enum methods { + no_search, + use_memchr, + memchr_and_memcmp, + hubbe_search +}; + +struct mem_searcher +{ + enum methods method; + char *needle; + SIZE_T needlelen; + unsigned INT32 hsize, max; + struct link links[MEMSEARCH_LINKS]; + struct link *set[MEMSEARCH_LINKS]; +}; + +/* Prototypes begin here */ +char *xalloc(SIZE_T size); +void swap(char *a, char *b, INT32 size); +void reverse(char *memory, INT32 nitems, INT32 size); +void reorder(char *memory, INT32 nitems, INT32 size,INT32 *order); +unsigned INT32 hashmem(const unsigned char *a,INT32 len,INT32 mlen); +unsigned INT32 hashstr(const unsigned char *str,INT32 maxn); +void init_memsearch(struct mem_searcher *s, + char *needle, + SIZE_T needlelen, + SIZE_T max_haystacklen); +char *memory_search(struct mem_searcher *s, + char *haystack, + SIZE_T haystacklen); +char *my_memmem(char *needle, + SIZE_T needlelen, + char *haystack, + SIZE_T haystacklen); +void memfill(char *to, + INT32 tolen, + char *from, + INT32 fromlen, + INT32 offset); +/* Prototypes end here */ + +#endif diff --git a/src/pike_types.c b/src/pike_types.c index 92c102e6bffc616153fcf80684721db1c6d8018b..18ac0ff8e4913c541e21513bc3ca62737e300f2c 100644 --- a/src/pike_types.c +++ b/src/pike_types.c @@ -4,7 +4,7 @@ ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h" -RCSID("$Id: pike_types.c,v 1.21 1997/04/16 03:09:15 hubbe Exp $"); +RCSID("$Id: pike_types.c,v 1.22 1997/05/19 23:31:06 hubbe Exp $"); #include <ctype.h> #include "svalue.h" #include "pike_types.h" @@ -20,7 +20,7 @@ RCSID("$Id: pike_types.c,v 1.21 1997/04/16 03:09:15 hubbe Exp $"); #include "error.h" #include "las.h" #include "language.h" -#include "memory.h" +#include "pike_memory.h" int max_correct_args; diff --git a/src/stralloc.c b/src/stralloc.c index 4cbbeafb885ec6443e8b322898405496dc1dc581..ba03109b9e207f8f07722e035458ef0a48b6af6f 100644 --- a/src/stralloc.c +++ b/src/stralloc.c @@ -8,7 +8,7 @@ #include "pike_macros.h" #include "dynamic_buffer.h" #include "pike_macros.h" -#include "memory.h" +#include "pike_memory.h" #include "error.h" #include "gc.h"