From 75920f5ba278b55e90126b4d73cf355c8b025bb2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Sun, 28 Dec 1997 01:30:05 -0800
Subject: [PATCH] now works better with NT _and_ Unix :)

Rev: src/configure.in:1.144
Rev: src/fd_control.c:1.10
Rev: src/gc.c:1.23
Rev: src/global.h:1.12
Rev: src/main.c:1.28
Rev: src/modules/Image/blit_layer_include.h:1.5
Rev: src/modules/Image/configure.in:1.5
Rev: src/modules/Image/font.c:1.23
Rev: src/modules/files/configure.in:1.36
Rev: src/modules/files/efuns.c:1.41
Rev: src/modules/system/configure.in:1.14
Rev: src/modules/system/system.c:1.33
Rev: src/pike_memory.c:1.3
Rev: src/signal_handler.c:1.16
Rev: src/stralloc.c:1.19
Rev: src/stuff.c:1.3
Rev: src/stuff.h:1.3
---
 src/configure.in                       | 64 ++++++++++++++++----------
 src/fd_control.c                       | 16 ++++++-
 src/gc.c                               | 37 ---------------
 src/global.h                           | 11 +++++
 src/main.c                             |  4 +-
 src/modules/Image/blit_layer_include.h | 22 ++++-----
 src/modules/Image/configure.in         |  2 +-
 src/modules/Image/font.c               |  9 +++-
 src/modules/files/configure.in         |  2 +-
 src/modules/files/efuns.c              | 16 +++++--
 src/modules/system/configure.in        |  2 +-
 src/modules/system/system.c            |  8 +++-
 src/pike_memory.c                      | 30 ++++++++++--
 src/signal_handler.c                   |  8 ++++
 src/stralloc.c                         |  7 ++-
 src/stuff.c                            | 37 +++++++++++++++
 src/stuff.h                            |  2 +
 17 files changed, 185 insertions(+), 92 deletions(-)

diff --git a/src/configure.in b/src/configure.in
index 1de0a9d0e8..9cbfd81114 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -1,4 +1,4 @@
-AC_REVISION("$Id: configure.in,v 1.143 1997/12/23 06:26:05 hubbe Exp $")
+AC_REVISION("$Id: configure.in,v 1.144 1997/12/28 09:29:08 hubbe Exp $")
 AC_INIT(interpret.c)
 AC_CONFIG_HEADER(machine.h)
 
@@ -174,7 +174,7 @@ AC_DEFUN(AC_SYS_COMPILER_FLAG,
   AC_CACHE_VAL(pike_cv_option_$2,
   [
     CFLAGS="[$]OLD_CFLAGS $1"
-    AC_TRY_RUN([int main(){exit(0);}],pike_cv_option_$2=yes,pike_cv_option_$2=no)
+    AC_TRY_RUN([int main(){exit(0);}],pike_cv_option_$2=yes,pike_cv_option_$2=no,pike_cv_option_$2=no)
   ])
   
   CFLAGS="[$]OLD_CFLAGS"
@@ -531,7 +531,7 @@ EOF
     if $YACC -d conftest.y 1>&5 2>&5; then
       AC_TRY_RUN([
 #include "y.tab.c"
-],pure_parser_works=yes,pure_parser_works=no)
+],pure_parser_works=yes,pure_parser_works=no,pure_parser_works=no)
       if test "$pure_parser_works" = "yes"; then
         break
       fi
@@ -619,14 +619,14 @@ AC_CHECK_HEADERS(sys/rusage.h time.h sys/time.h sys/types.h unistd.h stdlib.h \
 memory.h values.h string.h strings.h fcntl.h sys/filio.h sys/sockio.h crypt.h \
 locale.h sys/resource.h sys/select.h sys/mman.h setjmp.h limits.h pthread.h \
 thread.h dlfcn.h dld.h sys/times.h sched.h sys/procfs.h sys/param.h winsock.h \
-sys/ioct.h sys/socket.h)
+sys/ioct.h sys/socket.h malloc.h netinet/in.h sys/wait.h)
 
-AC_SIZEOF_TYPE(char *)
-AC_SIZEOF_TYPE(long)
-AC_SIZEOF_TYPE(int)
-AC_SIZEOF_TYPE(short)
-AC_SIZEOF_TYPE(float)
-AC_SIZEOF_TYPE(double)
+AC_CHECK_SIZEOF(char *,4)
+AC_CHECK_SIZEOF(long,4)
+AC_CHECK_SIZEOF(int,4)
+AC_CHECK_SIZEOF(short,2)
+AC_CHECK_SIZEOF(float,4)
+AC_CHECK_SIZEOF(double,8)
 
 AC_TYPE_SIZE_T
 AC_TYPE_PID_T
@@ -644,8 +644,6 @@ AC_CHECK_LIB(nsl, gethostbyname)
 AC_CHECK_LIB(dl, dlopen)
 AC_CHECK_LIB(dld, dld_link)
 
-AC_HAVE_FUNCS(strdup)
-
 
 if test "${pike_cv_sys_os}" = "Linux"; then
   if test "${ac_cv_lib_m_floor}" = "no"; then
@@ -708,7 +706,7 @@ int main()
   thr_join(gazonk,0,&sune);
   exit(0);
 }
-    ],pike_cv_unix_threads=yes,pike_cv_unix_threads=no)
+    ],pike_cv_unix_threads=yes,pike_cv_unix_threads=no,pike_cv_unix_threads=no)
   ])
 
   if test x$pike_cv_unix_threads = xyes ; then
@@ -761,7 +759,7 @@ int main()
   pthread_join(gazonk,&sune);
   exit(0);
 }
-      ],pike_cv_posix_threads=yes,pike_cv_posix_threads=no)
+      ],pike_cv_posix_threads=yes,pike_cv_posix_threads=no,pike_cv_posix_threads=no)
     ])
 
     if test $pike_cv_posix_threads = yes ; then
@@ -879,7 +877,7 @@ LIBOBJS="${OLD_LIBOBJS}"
 
 AC_FUNC_MMAP
 
-AC_CHECK_FUNCS(
+AC_CHECK_FUNCS( \
  _crypt \
  bcopy \
  bzero \
@@ -921,6 +919,9 @@ AC_CHECK_FUNCS(
  dld_link \
  dld_get_func \
  pipe \
+ strdup \
+ kill \
+ alarm \
 )
 
 if test $ac_cv_func_crypt$ac_cv_func__crypt = nono ; then
@@ -947,7 +948,7 @@ int main()
        strcoll("*^#", "*^#") != 0 ||
        strcoll("123", "456") >= 0);
 }
-],pike_cv_func_strcoll=yes,pike_cv_func_strcoll=no)
+],pike_cv_func_strcoll=yes,pike_cv_func_strcoll=no,pike_cv_func_strcoll=no)
 ])
 
 if test $pike_cv_func_strcoll = yes; then
@@ -1014,6 +1015,7 @@ int main() {
 }
 ],
 pike_cv_func_gettimeofday_has_two_args=yes,
+pike_cv_func_gettimeofday_has_two_args=no,
 pike_cv_func_gettimeofday_has_two_args=no)])
 
 if test $pike_cv_func_gettimeofday_has_two_args = yes; then
@@ -1183,6 +1185,8 @@ int main()
 pike_cv_hardware_byteorder=`cat conftest.out.2`
 ,
 pike_cv_hardware_byteorder=0
+,
+pike_cv_hardware_byteorder=0
 )])
 
 AC_MSG_RESULT($pike_cv_hardware_byteorder)
@@ -1193,7 +1197,7 @@ dnl#####################################################################
 define(MY_CHECK_FUNCTION,[
 AC_MSG_CHECKING(for working $1)
 AC_CACHE_VAL(pike_cv_func_$1,[
-AC_TRY_RUN([$2],pike_cv_func_$1=yes,pike_cv_func_$1=no)
+AC_TRY_RUN([$2],pike_cv_func_$1=yes,pike_cv_func_$1=no,pike_cv_func_$1=no)
 ])
 AC_MSG_RESULT([$]pike_cv_func_$1)
 if test [$]pike_cv_func_$1 = yes; then
@@ -1318,6 +1322,7 @@ int main()
   exit(0);
 }
 ],pike_cv_method_extract_uchar=by_cast,
+pike_cv_method_extract_uchar=not_by_cast,
 pike_cv_method_extract_uchar=not_by_cast)])
 
 if test "$pike_cv_method_extract_uchar" = by_cast; then
@@ -1342,6 +1347,7 @@ int main()
   exit(0);
 }
 ],pike_cv_method_extract_char=by_cast,
+pike_cv_method_extract_char=not_by_cast,
 pike_cv_method_extract_char=not_by_cast)])
 
 if test "$pike_cv_method_extract_char" = by_cast; then
@@ -1399,7 +1405,7 @@ int main()
   sigrun=0;
   exit(0);
 }
-],pike_cv_sys_signal_oneshot=no,pike_cv_sys_signal_oneshot=yes)])
+],pike_cv_sys_signal_oneshot=no,pike_cv_sys_signal_oneshot=yes,pike_cv_sys_signal_oneshot=yes)])
 
 if test "$pike_cv_sys_signal_oneshot" = yes; then
   AC_MSG_RESULT(yes)
@@ -1464,6 +1470,8 @@ int main()
 pike_cv_max_open_fd=`cat conftest.out.2`
 ,
 pike_cv_max_open_fd=256
+,
+pike_cv_max_open_fd=256
 )])
 AC_MSG_RESULT($pike_cv_max_open_fd)
 AC_DEFINE_UNQUOTED(MAX_OPEN_FILEDESCRIPTORS,$pike_cv_max_open_fd)
@@ -1579,7 +1587,7 @@ void fatal(char *foo,...)
 }
 main() {  exit(0); }
 
-], pike_cv_gcc_attributes=yes, pike_cv_gcc_attributes=no)])
+], pike_cv_gcc_attributes=yes, pike_cv_gcc_attributes=no, pike_cv_gcc_attributes=no)])
 
 AC_MSG_RESULT($pike_cv_gcc_attributes)
 if test "$pike_cv_gcc_attributes" = yes; then
@@ -1648,8 +1656,12 @@ AC_CACHE_VAL(pike_cv_sys_nonblock,
 #define USE_IOCTLSOCKET_FIONBIO
 #include "$srcdir/fd_control.c"
 ], pike_cv_sys_nonblock=USE_IOCTLSOCKET_FIONBIO,
-unset pike_cv_sys_nonblock
-    )))))
+unset pike_cv_sys_nonblock,
+unset pike_cv_sys_nonblock),
+unset pike_cv_sys_nonblock),
+unset pike_cv_sys_nonblock),
+unset pike_cv_sys_nonblock),
+unset pike_cv_sys_nonblock)
   fi
 ])
 
@@ -1715,8 +1727,8 @@ then
            LDSHARED="ld -expect_unresolved '*' -shared -msym -O3"
         ;;
 	DYNIX/ptx*) LDSHARED="ld -G";;
-	next) LDSHARED='$(CC) $(CFLAGS) -nostdlib -r';;
-	Linux*) LDSHARED="gcc -shared";;
+	next) LDSHARED="$CC $CFLAGS -nostdlib -r";;
+	Linux*) LDSHARED="$CC -shared";;
         GNU*) LDSHARED="ld -Bshareable";;
 	FreeBSD*) LDSHARED="ld -Bshareable";;
 	NetBSD) LDSHARED="ld -Bshareable";;
@@ -1777,7 +1789,7 @@ fi
    OLD_CFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS $LINKFORSHARED"
    AC_TRY_RUN([int main() { exit(0); }],
- pike_cv_sys_linkforshared="$LINKFORSHARED", pike_cv_sys_linkforshared='')
+ pike_cv_sys_linkforshared="$LINKFORSHARED", pike_cv_sys_linkforshared='', pike_cv_sys_linkforshared='')
    CFLAGS="$OLD_CFLAGS"
 ])
 
@@ -1815,8 +1827,10 @@ AC_CACHE_VAL(pike_cv_sys_dynamic_loading,
 #define TESTING
 #include "$srcdir/dynamic_load.c"
 void testfunc2(void) { exit(0); }
-], pike_cv_sys_dynamic_loading=yes, pike_cv_sys_dynamic_loading=no)
+], pike_cv_sys_dynamic_loading=yes, pike_cv_sys_dynamic_loading=no, pike_cv_sys_dynamic_loading=no)
     CFLAGS="$OLD_CFLAGS"
+  else
+    pike_cv_sys_dynamic_loading=no
   fi
   rm -f myconftest.so >/dev/null 2>/dev/null
 ])
diff --git a/src/fd_control.c b/src/fd_control.c
index 967318743c..1183cb424d 100644
--- a/src/fd_control.c
+++ b/src/fd_control.c
@@ -22,6 +22,10 @@
 #include <sys/socket.h>
 #endif
 
+#ifdef HAVE_SYS_ERRNO_H
+#include <sys/socket.h>
+#endif
+
 #ifdef HAVE_WINSOCK_H
 #include <winsock.h>
 #endif
@@ -36,7 +40,7 @@
 #include <sys/sockio.h>
 #endif
 
-static void low_set_nonblocking(int fd,int which)
+void set_nonblocking(int fd,int which)
 {
 #ifdef DEBUG
   if(fd<0 || fd >MAX_OPEN_FILEDESCRIPTORS)
@@ -116,6 +120,7 @@ int main()
 #else
 
 #include <signal.h>
+#include <errno.h>
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
@@ -129,6 +134,12 @@ RETSIGTYPE sigalrm_handler1(int tmp) { exit(1); }
 extern int errno;
 #endif /* !errno */
 
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+
+
 int my_socketpair(int family, int type, int protocol, int sv[2])
 {
   static int fd=-1;
@@ -136,7 +147,8 @@ int my_socketpair(int family, int type, int protocol, int sv[2])
   struct sockaddr_in addr,addr2;
   int len;
 
-  MEMSET((char *)&addr,0,sizeof(struct sockaddr_in));
+  for(len=0;len<sizeof(struct sockaddr_in);len++)
+    ((char *)&addr)[len]=0;
 
   /* We lie, we actually create an AF_INET socket... */
   if(family != AF_UNIX || type != SOCK_STREAM)
diff --git a/src/gc.c b/src/gc.c
index 647b25ee4d..9a7f6f5651 100644
--- a/src/gc.c
+++ b/src/gc.c
@@ -405,43 +405,6 @@ int gc_do_free(void *a)
   return !(m->flags & GC_REFERENCED);
 }
 
-/* Not all of these are primes, but they should be adequate */
-static INT32 hashprimes[] =
-{
-  31,        /* ~ 2^0  = 1 */
-  31,        /* ~ 2^1  = 2 */
-  31,        /* ~ 2^2  = 4 */
-  31,        /* ~ 2^3  = 8 */
-  31,        /* ~ 2^4  = 16 */
-  31,        /* ~ 2^5  = 32 */
-  61,        /* ~ 2^6  = 64 */
-  127,       /* ~ 2^7  = 128 */
-  251,       /* ~ 2^8  = 256 */
-  541,       /* ~ 2^9  = 512 */
-  1151,      /* ~ 2^10 = 1024 */
-  2111,      /* ~ 2^11 = 2048 */
-  4327,      /* ~ 2^12 = 4096 */
-  8803,      /* ~ 2^13 = 8192 */
-  17903,     /* ~ 2^14 = 16384 */
-  32321,     /* ~ 2^15 = 32768 */
-  65599,     /* ~ 2^16 = 65536 */
-  133153,    /* ~ 2^17 = 131072 */
-  270001,    /* ~ 2^18 = 264144 */
-  547453,    /* ~ 2^19 = 524288 */
-  1109891,   /* ~ 2^20 = 1048576 */
-  2000143,   /* ~ 2^21 = 2097152 */
-  4561877,   /* ~ 2^22 = 4194304 */
-  9248339,   /* ~ 2^23 = 8388608 */
-  16777215,  /* ~ 2^24 = 16777216 */
-  33554431,  /* ~ 2^25 = 33554432 */
-  67108863,  /* ~ 2^26 = 67108864 */
-  134217727, /* ~ 2^27 = 134217728 */
-  268435455, /* ~ 2^28 = 268435456 */
-  536870911, /* ~ 2^29 = 536870912 */
-  1073741823,/* ~ 2^30 = 1073741824 */
-  2147483647,/* ~ 2^31 = 2147483648 */
-};
-
 void do_gc(void)
 {
   double tmp;
diff --git a/src/global.h b/src/global.h
index 6fa3746c3d..50b9fb5572 100644
--- a/src/global.h
+++ b/src/global.h
@@ -45,6 +45,12 @@ struct svalue;
 #define GC2
 #endif
 
+#if defined(i386)
+#ifndef HANDLES_UNALIGNED_MEMORY_ACCESS
+#define HANDLES_UNALIGNED_MEMORY_ACCESS
+#endif
+#endif
+
 /* AIX requires this to be the first thing in the file.  */
 #ifdef __GNUC__
 # ifdef alloca
@@ -72,6 +78,11 @@ char *alloca ();
 #undef HAVE_STDLIB_H
 #endif
 
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#undef HAVE_MALLOC_H
+#endif
+
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #undef HAVE_UNISTD_H
diff --git a/src/main.c b/src/main.c
index 637eec9d64..aafafd9593 100644
--- a/src/main.c
+++ b/src/main.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: main.c,v 1.27 1997/11/08 01:34:40 hubbe Exp $");
+RCSID("$Id: main.c,v 1.28 1997/12/28 09:29:10 hubbe Exp $");
 #include "backend.h"
 #include "module.h"
 #include "object.h"
@@ -65,12 +65,14 @@ void main(int argc, char **argv, char **env)
 
   ARGV=argv;
 
+#ifndef __NT__
   /* Close extra fds (if any) */
   for (e=3; e < MAX_OPEN_FILEDESCRIPTORS; e++) {
     do {
       num = close(e);
     } while ((num < 0) && (errno == EINTR));
   }
+#endif
 
 #ifdef HAVE_SETLOCALE
 #ifdef LC_NUMERIC
diff --git a/src/modules/Image/blit_layer_include.h b/src/modules/Image/blit_layer_include.h
index 913c91e955..e6f605e383 100644
--- a/src/modules/Image/blit_layer_include.h
+++ b/src/modules/Image/blit_layer_include.h
@@ -1,10 +1,10 @@
-/* $Id: blit_layer_include.h,v 1.4 1997/10/27 22:41:17 mirar Exp $ */
+/* $Id: blit_layer_include.h,v 1.5 1997/12/28 09:29:31 hubbe Exp $ */
 /* included w/ defines in blit.c, image_add_layer() */
 
 /*
 **! module Image
 **! note
-**!	$Id: blit_layer_include.h,v 1.4 1997/10/27 22:41:17 mirar Exp $
+**!	$Id: blit_layer_include.h,v 1.5 1997/12/28 09:29:31 hubbe Exp $
 **! class image
 */
 
@@ -102,19 +102,19 @@
 		  switch (lr->method)
 		  {
 		     case LAYER_MAX:
-		        res.r=max(lr->s->r,rgb.r);
-		        res.g=max(lr->s->g,rgb.g);
-		        res.b=max(lr->s->b,rgb.b);
+		        res.r=MAXIMUM(lr->s->r,rgb.r);
+		        res.g=MAXIMUM(lr->s->g,rgb.g);
+		        res.b=MAXIMUM(lr->s->b,rgb.b);
 			break;
 		     case LAYER_MIN:
-		        res.r=min(lr->s->r,rgb.r);
-		        res.g=min(lr->s->g,rgb.g);
-		        res.b=min(lr->s->b,rgb.b);
+		        res.r=MINIMUM(lr->s->r,rgb.r);
+		        res.g=MINIMUM(lr->s->g,rgb.g);
+		        res.b=MINIMUM(lr->s->b,rgb.b);
 			break;
 		     case LAYER_ADD:
-		        res.r=(unsigned char)max(255,(lr->s->r+rgb.r));
-		        res.g=(unsigned char)max(255,(lr->s->g+rgb.g));
-		        res.b=(unsigned char)max(255,(lr->s->b+rgb.b));
+		        res.r=(unsigned char)MAXIMUM(255,(lr->s->r+rgb.r));
+		        res.g=(unsigned char)MAXIMUM(255,(lr->s->g+rgb.g));
+		        res.b=(unsigned char)MAXIMUM(255,(lr->s->b+rgb.b));
 			break;
 		     case LAYER_MULT:
 		        res.r=(unsigned char)((lr->s->r*rgb.r)*q);
diff --git a/src/modules/Image/configure.in b/src/modules/Image/configure.in
index 10c3fe257a..4b2d3ce58d 100644
--- a/src/modules/Image/configure.in
+++ b/src/modules/Image/configure.in
@@ -7,7 +7,7 @@ sinclude(../module_configure.in)
 
 AC_FUNC_MMAP
 
-AC_CHECK_HEADERS(sys/fcntl.h fcntl.h stdlib.h netinet/in.h)
+AC_CHECK_HEADERS(sys/fcntl.h fcntl.h stdlib.h netinet/in.h winsock.h)
 
 AC_SUBST(RANLIB)
 
diff --git a/src/modules/Image/font.c b/src/modules/Image/font.c
index 1c347d2e6a..4673c869ec 100644
--- a/src/modules/Image/font.c
+++ b/src/modules/Image/font.c
@@ -1,4 +1,4 @@
-/* $Id: font.c,v 1.22 1997/12/22 23:26:46 hubbe Exp $ */
+/* $Id: font.c,v 1.23 1997/12/28 09:29:32 hubbe Exp $ */
 #include <config.h>
 
 #define SPACE_CHAR 'i'
@@ -6,7 +6,7 @@
 /*
 **! module Image
 **! note
-**!	$Id: font.c,v 1.22 1997/12/22 23:26:46 hubbe Exp $
+**!	$Id: font.c,v 1.23 1997/12/28 09:29:32 hubbe Exp $
 **! class font
 **!
 **! note
@@ -110,6 +110,10 @@ Kerningtable types:
 #include <netinet/in.h>
 #endif
 
+#ifdef HAVE_WINSOCK_H
+#include <winsock.h>
+#endif
+
 #include <errno.h>
 
 #include "config.h"
@@ -133,6 +137,7 @@ Kerningtable types:
 static struct program *font_program;
 extern struct program *image_program;
 
+#undef THIS
 #define THIS (*(struct font **)(fp->current_storage))
 #define THISOBJ (fp->current_object)
 
diff --git a/src/modules/files/configure.in b/src/modules/files/configure.in
index 5fe7ea3976..eb6d135205 100644
--- a/src/modules/files/configure.in
+++ b/src/modules/files/configure.in
@@ -11,7 +11,7 @@ AC_HEADER_DIRENT
 AC_CHECK_LIB(bind, __inet_ntoa)
 AC_CHECK_LIB(socket, socket)
 
-AC_HAVE_FUNCS(getwd perror fork1 readdir_r statvfs statfs ustat)
+AC_HAVE_FUNCS(getwd perror fork1 readdir_r statvfs statfs ustat fork lstat)
 
 AC_MSG_CHECKING(if we can declare environ)
 AC_CACHE_VAL(pike_cv_declare_environ,[
diff --git a/src/modules/files/efuns.c b/src/modules/files/efuns.c
index b366fb9159..71e4afe495 100644
--- a/src/modules/files/efuns.c
+++ b/src/modules/files/efuns.c
@@ -96,12 +96,13 @@ void f_file_stat(INT32 args)
   s = sp[-args].u.string->str;
   l = (args>1 && !IS_ZERO(sp-1-args))?1:0;
   THREADS_ALLOW();
+#ifdef HAVE_LSTAT
   if(l)
-  {
     i=lstat(s, &st);
-  }else{
+  else
+#endif
     i=stat(s, &st);
-  }
+
   THREADS_DISALLOW();
   pop_n_elems(args);
   if(i==-1)
@@ -312,7 +313,11 @@ void f_rm(INT32 args)
   s = sp[-args].u.string->str;
   
   THREADS_ALLOW();
+#ifdef HAVE_LSTAT
   i=lstat(s, &st) != -1;
+#else
+  i=stat(s, &st) != -1;
+#endif
   if(i)
   {
     if(S_IFDIR == (S_IFMT & st.st_mode))
@@ -557,6 +562,7 @@ void f_getcwd(INT32 args)
   free(e);
 }
 
+#ifdef HAVE_FORK
 void f_fork(INT32 args)
 {
   int res;
@@ -579,7 +585,7 @@ void f_fork(INT32 args)
   }
 #endif
 }
-
+#endif
 
 void f_exece(INT32 args)
 {
@@ -743,7 +749,9 @@ void init_files_efuns(void)
   add_efun("get_dir",f_get_dir,"function(string:string *)",OPT_EXTERNAL_DEPEND);
   add_efun("cd",f_cd,"function(string:int)",OPT_SIDE_EFFECT);
   add_efun("getcwd",f_getcwd,"function(:string)",OPT_EXTERNAL_DEPEND);
+#ifdef HAVE_FORK
   add_efun("fork",f_fork,"function(:int)",OPT_SIDE_EFFECT);
+#endif
   add_efun("exece",f_exece,"function(string,mixed*,void|mapping(string:string):int)",OPT_SIDE_EFFECT); 
 
 #ifdef HAVE_STRERROR
diff --git a/src/modules/system/configure.in b/src/modules/system/configure.in
index 8c5c3fec83..0023b1a420 100644
--- a/src/modules/system/configure.in
+++ b/src/modules/system/configure.in
@@ -11,7 +11,7 @@ AC_HAVE_HEADERS(syslog.h sys/syslog.h sys/types.h errno.h unistd.h pwd.h \
 	sys/conf.h sys/socket.h netinet/in.h arpa/inet.h netdb.h stdarg.h \
 	sys/utsname.h pwd.h passwd.h shadow.h grp.h sys/stat.h winsock.h)
 
-AC_HAVE_FUNCS(syslog link symlink readlink \
+AC_HAVE_FUNCS(syslog link symlink readlink chown \
 	initgroups setgroups seteuid setresuid setegid setresgid \
         geteuid getpgrp getpgid getppid getuid getgid setuid setgid \
 	getpwnam getspnam getpwent setpwent endpwent \
diff --git a/src/modules/system/system.c b/src/modules/system/system.c
index 15e56a3caf..340a8a67b9 100644
--- a/src/modules/system/system.c
+++ b/src/modules/system/system.c
@@ -1,5 +1,5 @@
 /*
- * $Id: system.c,v 1.32 1997/12/23 06:26:14 hubbe Exp $
+ * $Id: system.c,v 1.33 1997/12/28 09:30:05 hubbe Exp $
  *
  * System-call module for Pike
  *
@@ -14,7 +14,7 @@
 #include "system.h"
 
 #include "global.h"
-RCSID("$Id: system.c,v 1.32 1997/12/23 06:26:14 hubbe Exp $");
+RCSID("$Id: system.c,v 1.33 1997/12/28 09:30:05 hubbe Exp $");
 #include "module_support.h"
 #include "las.h"
 #include "interpret.h"
@@ -255,6 +255,7 @@ void f_chmod(INT32 args)
   pop_n_elems(args);
 }
 
+#ifdef HAVE_CHOWN
 void f_chown(INT32 args)
 {
   char *path;
@@ -273,6 +274,7 @@ void f_chown(INT32 args)
   }
   pop_n_elems(args);
 }
+#endif
 
 #ifdef HAVE_INITGROUPS
 /* void initgroups(string name, int gid) */
@@ -802,7 +804,9 @@ void pike_module_init(void)
   add_efun("readlink", f_readlink, "function(string:string)", OPT_EXTERNAL_DEPEND);
 #endif /* HAVE_READLINK */
   add_efun("chmod", f_chmod, "function(string, int:void)", OPT_SIDE_EFFECT);
+#ifdef HAVE_CHOWN
   add_efun("chown", f_chown, "function(string, int, int:void)", OPT_SIDE_EFFECT);
+#endif
 #ifdef HAVE_INITGROUPS
   add_efun("initgroups", f_initgroups, "function(string, int:void)", OPT_SIDE_EFFECT);
 #endif /* HAVE_INITGROUPS */
diff --git a/src/pike_memory.c b/src/pike_memory.c
index 2b477350e0..e5d158ad15 100644
--- a/src/pike_memory.c
+++ b/src/pike_memory.c
@@ -128,7 +128,22 @@ unsigned INT32 hashmem(const unsigned char *a,INT32 len,INT32 mlen)
   unsigned INT32 ret;
 
   ret=9248339*len;
-  if(len<mlen) mlen=len;
+  if(len<mlen)
+    mlen=len;
+  else
+  {
+    switch(len-mlen)
+    {
+      default: ret^=(ret<<6) + a[len-7];
+      case 7:
+      case 6: ret^=(ret<<7) + a[len-5];
+      case 5:
+      case 4: ret^=(ret<<4) + a[len-4];
+      case 3: ret^=(ret<<3) + a[len-3];
+      case 2: ret^=(ret<<3) + a[len-2];
+      case 1: ret^=(ret<<3) + a[len-1];
+    }
+  }
   switch(mlen&7)
   {
     case 7: ret^=*(a++);
@@ -154,10 +169,19 @@ unsigned INT32 hashmem(const unsigned char *a,INT32 len,INT32 mlen)
 #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++));
+    register unsigned int t1,t2;
+    t1= *(a++);
+    t2= *(a++);
+    t1=(t1<<5) + *(a++);
+    t2=(t2<<4) + *(a++);
+    t1=(t1<<7) + *(a++);
+    t2=(t2<<5) + *(a++);
+    t1=(t1<<3) + *(a++);
+    t2=(t2<<4) + *(a++);
+    ret^=(ret<<7) + (ret>>6) + t1 + (t2<<6);
   }
 #endif
+
   return ret;
 }
 
diff --git a/src/signal_handler.c b/src/signal_handler.c
index 326dd82ee3..a3a4a801d1 100644
--- a/src/signal_handler.c
+++ b/src/signal_handler.c
@@ -410,6 +410,7 @@ static void f_signame(int args)
     push_int(0);
 }
 
+#ifdef HAVE_KILL
 static void f_kill(INT32 args)
 {
   if(args < 2)
@@ -422,6 +423,7 @@ static void f_kill(INT32 args)
   sp[-args].u.integer=!kill(sp[-args].u.integer,sp[1-args].u.integer);
   pop_n_elems(args-1);
 }
+#endif
 
 static void f_getpid(INT32 args)
 {
@@ -429,6 +431,7 @@ static void f_getpid(INT32 args)
   push_int(getpid());
 }
 
+#ifdef HAVE_ALARM
 static void f_alarm(INT32 args)
 {
   long seconds;
@@ -444,6 +447,7 @@ static void f_alarm(INT32 args)
   pop_n_elems(args);
   push_int(alarm(seconds));
 }
+#endif
 
 #ifdef HAVE_UALARM
 static void f_ualarm(INT32 args)
@@ -485,11 +489,15 @@ void init_signals(void)
   firstsig=lastsig=0;
 
   add_efun("signal",f_signal,"function(int,mixed|void:void)",OPT_SIDE_EFFECT);
+#ifdef HAVE_KILL
   add_efun("kill",f_kill,"function(int,int:int)",OPT_SIDE_EFFECT);
+#endif
   add_efun("signame",f_signame,"function(int:string)",0);
   add_efun("signum",f_signum,"function(string:int)",0);
   add_efun("getpid",f_getpid,"function(:int)",0);
+#ifdef HAVE_ALARM
   add_efun("alarm",f_alarm,"function(int:int)",OPT_SIDE_EFFECT);
+#endif
 #ifdef HAVE_UALARM
   add_efun("ualarm",f_ualarm,"function(int:int)",OPT_SIDE_EFFECT);
 #endif
diff --git a/src/stralloc.c b/src/stralloc.c
index 431288ae96..5f4c51d699 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -11,11 +11,13 @@
 #include "pike_memory.h"
 #include "error.h"
 #include "gc.h"
+#include "stuff.h"
 
 #define BEGIN_HASH_SIZE 997
 #define MAX_AVG_LINK_LENGTH 3
 
 unsigned INT32 htable_size=0;
+static unsigned int hashprimes_entry=0;
 static struct pike_string **base_table=0;
 static unsigned INT32 full_hash_value;
 unsigned INT32 num_strings=0;
@@ -108,7 +110,7 @@ static void rehash(void)
   old=htable_size;
   old_base=base_table;
 
-  htable_size=htable_size*2 +1;
+  htable_size=hashprimes[++hashprimes_entry];
   base_table=(struct pike_string **)xalloc(sizeof(struct pike_string *)*htable_size);
   MEMSET((char *)base_table,0,sizeof(struct pike_string *)*htable_size);
 
@@ -574,7 +576,8 @@ struct pike_string *string_replace(struct pike_string *str,
 /*** init/exit memory ***/
 void init_shared_string_table(void)
 {
-  htable_size=BEGIN_HASH_SIZE;
+  for(hashprimes_entry;hashprimes[hashprimes_entry]<BEGIN_HASH_SIZE;hashprimes_entry++);
+  htable_size=hashprimes[hashprimes_entry];
   base_table=(struct pike_string **)xalloc(sizeof(struct pike_string *)*htable_size);
   MEMSET((char *)base_table,0,sizeof(struct pike_string *)*htable_size);
 }
diff --git a/src/stuff.c b/src/stuff.c
index 26ad4a61c8..3f999acabc 100644
--- a/src/stuff.c
+++ b/src/stuff.c
@@ -5,6 +5,43 @@
 \*/
 #include "stuff.h"
 
+/* Not all of these are primes, but they should be adequate */
+INT32 hashprimes[32] =
+{
+  31,        /* ~ 2^0  = 1 */
+  31,        /* ~ 2^1  = 2 */
+  31,        /* ~ 2^2  = 4 */
+  31,        /* ~ 2^3  = 8 */
+  31,        /* ~ 2^4  = 16 */
+  31,        /* ~ 2^5  = 32 */
+  61,        /* ~ 2^6  = 64 */
+  127,       /* ~ 2^7  = 128 */
+  251,       /* ~ 2^8  = 256 */
+  541,       /* ~ 2^9  = 512 */
+  1151,      /* ~ 2^10 = 1024 */
+  2111,      /* ~ 2^11 = 2048 */
+  4327,      /* ~ 2^12 = 4096 */
+  8803,      /* ~ 2^13 = 8192 */
+  17903,     /* ~ 2^14 = 16384 */
+  32321,     /* ~ 2^15 = 32768 */
+  65599,     /* ~ 2^16 = 65536 */
+  133153,    /* ~ 2^17 = 131072 */
+  270001,    /* ~ 2^18 = 264144 */
+  547453,    /* ~ 2^19 = 524288 */
+  1109891,   /* ~ 2^20 = 1048576 */
+  2000143,   /* ~ 2^21 = 2097152 */
+  4561877,   /* ~ 2^22 = 4194304 */
+  9248339,   /* ~ 2^23 = 8388608 */
+  16777215,  /* ~ 2^24 = 16777216 */
+  33554431,  /* ~ 2^25 = 33554432 */
+  67108863,  /* ~ 2^26 = 67108864 */
+  134217727, /* ~ 2^27 = 134217728 */
+  268435455, /* ~ 2^28 = 268435456 */
+  536870911, /* ~ 2^29 = 536870912 */
+  1073741823,/* ~ 2^30 = 1073741824 */
+  2147483647,/* ~ 2^31 = 2147483648 */
+};
+
 /* same thing as (int)floor(log((double)x) / log(2.0)) */
 /* Except a bit quicker :) (hopefully) */
 
diff --git a/src/stuff.h b/src/stuff.h
index ffded4a18c..a277b5aca2 100644
--- a/src/stuff.h
+++ b/src/stuff.h
@@ -14,4 +14,6 @@ int count_bits(unsigned INT32 x);
 int is_more_than_one_bit(unsigned INT32 x);
 /* Prototypes end here */
 
+extern INT32 hashprimes[32];
+
 #endif
-- 
GitLab