From f90e54df65b1b7fa38a1e1bfd9fae3850a4bd56d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Thu, 17 Aug 1995 11:35:27 +0200
Subject: [PATCH] 64 bittar och b{ttre bsd fd tjafs..

Rev: lib/simulate.lpc:1.2
Rev: src/BUGS:1.2
Rev: src/Makefile.in:1.3
Rev: src/array.c:1.2
Rev: src/backend.c:1.2
Rev: src/configure.in:1.3
Rev: src/docode.c:1.2
Rev: src/interpret.c:1.2
Rev: src/language.y:1.2
Rev: src/las.h:1.2
Rev: src/lex.c:1.2
Rev: src/list.c:1.2
Rev: src/macros.h:1.2
Rev: src/main.c:1.4
Rev: src/mapping.c:1.2
Rev: src/modules/files/file.c:1.2
Rev: src/modules/files/socket.c:1.2
Rev: src/modules/regexp/regexp.c:1.2
Rev: src/opcodes.c:1.2
Rev: src/port.c:1.3
Rev: src/port.h:1.3
Rev: src/program.c:1.2
Rev: src/rusage.c:1.2
Rev: src/stralloc.c:1.2
Rev: src/stralloc.h:1.2
Rev: src/svalue.c:1.2
---
 lib/simulate.lpc            |   7 ++-
 src/BUGS                    |  11 ++++
 src/Makefile.in             |   6 +-
 src/array.c                 |  11 +---
 src/backend.c               |   6 +-
 src/configure.in            |  30 +++++++---
 src/docode.c                | 113 +++++++++++++++++++-----------------
 src/interpret.c             |  48 +++++++--------
 src/language.y              |  48 ++++++---------
 src/las.h                   |   1 +
 src/lex.c                   |  12 +++-
 src/list.c                  |   2 +-
 src/macros.h                |   4 +-
 src/main.c                  |   7 +--
 src/mapping.c               |   4 +-
 src/modules/files/file.c    |   4 +-
 src/modules/files/socket.c  |   5 +-
 src/modules/regexp/regexp.c |   4 +-
 src/opcodes.c               |   4 +-
 src/port.c                  |  15 ++---
 src/port.h                  |  13 ++---
 src/program.c               |  49 ++++++++--------
 src/rusage.c                |   1 +
 src/stralloc.c              |   6 +-
 src/stralloc.h              |   2 +-
 src/svalue.c                |   2 +-
 26 files changed, 220 insertions(+), 195 deletions(-)

diff --git a/lib/simulate.lpc b/lib/simulate.lpc
index 61391e403e..067e578453 100644
--- a/lib/simulate.lpc
+++ b/lib/simulate.lpc
@@ -49,6 +49,11 @@ int write_file(string filename,string what)
   return write(what);
 }
 
+mixed call_other(mixed ob, string func, mixed ... arg)
+{
+  return ob[func](@arg);
+}
+
 mixed *map_array(mixed *arr, mixed fun, mixed ... args)
 {
   int e;
@@ -335,7 +340,7 @@ void create()
   add_efun("strstr",search);
   add_efun("sum_arrays",sum_arrays);
   add_efun("this_function",this_function);
-  add_efun("version",lambda() { return "uLPC v1.0E-30"; }); /* for now */
+  add_efun("version",lambda() { return "uLPC v1.0E-20"; }); /* for now */
   add_efun("write_file",write_file);
   add_efun("get_function",get_function);
   add_efun("regexp",regexp);
diff --git a/src/BUGS b/src/BUGS
index 00fb58ed54..e4360198e3 100644
--- a/src/BUGS
+++ b/src/BUGS
@@ -262,6 +262,17 @@
 * sscanf("foo-%-bar"%s-%%-%s",a,b); didn't work
 	fixed
 
+* machines with strange byteorders that didn't handle unaligned reads/write
+  jumped into space because EXTRACT_INT didn't work
+	fixed
+
+* Didn't work on 64-bit-machines (alpha for instance)
+	fixed
+
+* the macro ALIGN interfered with some standard include files on
+  some systems
+	fixed
+
 * setup_fake_program is called too often, I should keep fake_program updated instead
 
 * foreach somtimes says 'bad argument 1 to foreach' after a completed loop
diff --git a/src/Makefile.in b/src/Makefile.in
index 02256a3840..22b69aaefa 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -75,7 +75,7 @@ MODULE_OBJS=@MODULE_OBJS@
 all: ulpc
 
 module_objects:
-	for a in $(MODULES) ; do ( cd $$a ; make $(MAKE_FLAGS) ) ; done
+	for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) ) ; done
 
 ulpc: $(OBJ) module_objects
 	-mv ulpc ulpc.old
@@ -123,7 +123,7 @@ tidy:
 	-rm -f $(TMP_BINDIR)/core *.o *.i *.i~
 
 clean: tidy
-	-for a in $(MODULES) ; do ( cd $$a ; make $(MAKE_FLAGS) clean ) ; done
+	-for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) clean ) ; done
 	-for a in $(MODULES) ; do rm -f $$a/*.o ; done
 	-rm -f language.h language.c efun_protos.h opc_cost.h
 	-rm -f TAGS tags
@@ -164,6 +164,6 @@ verbose_verify: $(TMP_LIBDIR)/testsuite.lpc
 
 depend: language.c
 	gcc -MM $(PREFLAGS) *.c $(SRCDIR)/*.c | sed 's;$(SRCDIR)/;;g' | sed 's;\./;;g' >$(SRCDIR)/dependencies
-	for a in $(MODULES) ; do ( cd $$a ; make $(MAKE_FLAGS) depend ) ; done
+	for a in $(MODULES) ; do ( cd $$a ; ${MAKE} $(MAKE_FLAGS) depend ) ; done
 
 include @srcdir@/dependencies
diff --git a/src/array.c b/src/array.c
index 71d24c0125..2dfc39f992 100644
--- a/src/array.c
+++ b/src/array.c
@@ -1667,13 +1667,13 @@ void describe_array(struct array *a,struct processing *p,int indent)
   {
     if(p->pointer_a == (void *)a)
     {
-      sprintf(buf,"@%ld",e);
+      sprintf(buf,"@%ld",(long)e);
       my_strcat(buf);
       return;
     }
   }
   
-  sprintf(buf,"({ /* %ld elements */\n",a->size);
+  sprintf(buf,"({ /* %ld elements */\n",(long)a->size);
   my_strcat(buf);
   describe_array_low(a,&doing,indent);
   my_putchar('\n');
@@ -1856,8 +1856,6 @@ void apply_array(struct array *a, INT32 args)
   struct svalue *argp;
   INT32 e;
   struct array *ret;
-  ret=allocate_array_no_init(a->size,0,T_MIXED);
-  ret->type_field=BIT_MIXED;
   argp=sp-args;
   if(a->array_type == T_MIXED)
   {
@@ -1866,8 +1864,6 @@ void apply_array(struct array *a, INT32 args)
       assign_svalues_no_free(sp,argp,args);
       sp+=args;
       apply_svalue(ITEM(a)+e,args);
-      ITEM(ret)[e]=sp[-1];
-      sp--;
     }
   }else{
     for(e=0;e<a->size;e++)
@@ -1876,10 +1872,9 @@ void apply_array(struct array *a, INT32 args)
       assign_svalues_no_free(sp,argp,args);
       sp+=args;
       f_call_function(args+1);
-      ITEM(ret)[e]=sp[-1];
-      sp--;
     }
   }
+  ret=aggregate_array(a->size,T_MIXED);
   pop_n_elems(args);
   push_array(ret);
 }
diff --git a/src/backend.c b/src/backend.c
index 90fd4a3c80..463f3683f1 100644
--- a/src/backend.c
+++ b/src/backend.c
@@ -160,9 +160,10 @@ void do_debug(int check_refs)
   extern void verify_shared_strings_tables(int);
   extern void slow_check_stack(int);
 
+#if 0
   if(d_flag>1)
     init_checked();
-
+#endif
   slow_check_stack(0);
   check_all_arrays(0);
   check_all_mappings(0);
@@ -171,6 +172,7 @@ void do_debug(int check_refs)
   verify_shared_strings_tables(0);
   verify_all_call_outs();
 
+#if 0
   if(d_flag>1)
   {
     check_all_arrays(1);
@@ -180,7 +182,7 @@ void do_debug(int check_refs)
     verify_shared_strings_tables(1);
     exit_checked();
   }
-
+#endif
 }
 #endif
 
diff --git a/src/configure.in b/src/configure.in
index 4dff0237c8..0c15ce7fa1 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -44,6 +44,11 @@ CFLAGS="$OLD_CFLAGS"
 AC_CONFIG_HEADER(machine.h)
 AC_PROG_INSTALL
 AC_PROG_YACC
+if test "$ac_cv_prog_YACC" != "bison -y"; then
+  echo PANIC! Bison not found! Exiting...
+  exit 1
+fi
+
 AC_PROG_CPP
 AC_PROG_RANLIB
 AC_SET_MAKE
@@ -262,7 +267,9 @@ AC_DEFINE_UNQUOTED(BYTEORDER,$lpc_cv_hardware_byteorder)
 AC_MSG_CHECKING(unaligned read/writes)
 AC_CACHE_VAL(lpc_cv_hardware_unalignedRW,
 [
-
+if test -x /usr/bin/uac ; then
+  /usr/bin/uac p sigbus
+fi
 
 AC_TRY_RUN([
 int main()
@@ -415,17 +422,24 @@ AC_TRY_RUN([
 int main()
 {
   FILE *f;
-  int limit;
-#ifdef HAVE_GETRLIMIT
+  long limit;
+#if !defined(RLIMIT_NOLIMIT) && defined(RLIMIT_OFILE)
+#define RLIMIT_NOFILE RLIMIT_OFILE
+#endif
+#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
   struct rlimit lim;
 
   if(getrlimit(RLIMIT_NOFILE,&lim))
   {
     limit = MAX_FD;
   }else{
-    limit = lim.rlim_max;
-    if(limit == RLIM_INFINITY)
+    if(lim.rlim_max == RLIM_INFINITY)
+    {
       limit=16384; /* noone needs more */
+    }else{
+      limit=lim.rlim_max;
+      if(limit > 16384) limit=16384;
+    }
   }
 #else
   limit = MAX_FD;
@@ -433,7 +447,7 @@ int main()
 	
 
   f=fopen("conftest.out.2","w");
-  fprintf(f,"%ld\n",(long)lim.rlim_max);
+  fprintf(f,"%ld\n",(long)limit);
   fclose(f);
 
   return 0;
@@ -599,8 +613,8 @@ MODULE_OBJS=
 module_names=
 for a in `(cd $srcdir/modules ; echo *)`
 do
-  if test "$a" != "CVS" ; then
-    if test -d "$srcdir/modules/$a" ; then
+  if test "$a" != "CVS" -a "$a" != "RCS"; then
+      if test -d "$srcdir/modules/$a" ; then
       dirs="$dirs modules/$a"
       MODULE_OBJS="$MODULE_OBJS modules/$a/$a.a"
       module_names="$module_names $a"
diff --git a/src/docode.c b/src/docode.c
index 58843a9f00..de5fa25d67 100644
--- a/src/docode.c
+++ b/src/docode.c
@@ -1,4 +1,4 @@
-#include "machine.h"
+#include "global.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include "config.h"
@@ -48,8 +48,7 @@ static void upd_short(int offset, INT16 l)
 #ifdef HANDLES_UNALIGNED_MEMORY_ACCESS
   *((INT16 *)(areas[A_PROGRAM].s.str+offset))=l;
 #else
-  areas[A_PROGRAM].s.str[offset + 0] = ((char *)&l)[0];
-  areas[A_PROGRAM].s.str[offset + 1] = ((char *)&l)[1];
+  MEMCPY(areas[A_PROGRAM].s.str+offset, (char *)&l,sizeof(l));
 #endif
 }
 
@@ -58,20 +57,16 @@ static void upd_int(int offset, INT32 tmp)
 #ifdef HANDLES_UNALIGNED_MEMORY_ACCESS
   *((int *)(areas[A_PROGRAM].s.str+offset))=tmp;
 #else
-  areas[A_PROGRAM].s.str[offset + 0] = ((char *)&tmp)[0];
-  areas[A_PROGRAM].s.str[offset + 1] = ((char *)&tmp)[1];
-  areas[A_PROGRAM].s.str[offset + 2] = ((char *)&tmp)[2];
-  areas[A_PROGRAM].s.str[offset + 3] = ((char *)&tmp)[3];
+  MEMCPY(areas[A_PROGRAM].s.str+offset, (char *)&tmp,sizeof(tmp));
 #endif
 }
 
 /*
- * Store a 4 byte number. It is stored in such a way as to be sure
- * that correct byte order is used, regardless of machine architecture.
+ * Store an INT32.
  */
-void ins_long(long l,int area)
+void ins_long(INT32 l,int area)
 {
-  add_to_mem_block(area, (char *)&l+0, sizeof(long));
+  add_to_mem_block(area, (char *)&l+0, sizeof(INT32));
 }
 
 int store_linenumbers=1;
@@ -112,7 +107,7 @@ void ins_f_byte(unsigned int b)
 {
 #ifdef DEBUG
   if(a_flag>2)
-    fprintf(stderr,">%6lx: %s\n",PC,get_f_name(b));
+    fprintf(stderr,">%6lx: %s\n",(long)PC,get_f_name(b));
 #endif
   low_ins_f_byte(b);
 }
@@ -145,7 +140,7 @@ static void ins_f_byte_with_numerical_arg(unsigned int a,unsigned int b)
   ins_f_byte(a);
 #ifdef DEBUG
   if(a_flag>2)
-    fprintf(stderr,">%6lx: argument = %u\n",PC,b);
+    fprintf(stderr,">%6lx: argument = %u\n",(long)PC,b);
 #endif
   ins_byte(b, A_PROGRAM);
 }
@@ -334,46 +329,54 @@ static INT32 do_jump(int token,INT32 whereto)
 
 static void clean_jumptable() { max_jumps=jump_ptr=-1; }
 
-static void push_break_stack()
+struct jump_list
 {
-  push_explicit((int)break_stack);
-  push_explicit(current_break);
-  push_explicit(break_stack_size);
+  int *stack;
+  int current;
+  int size;
+};
+
+static void push_break_stack(struct jump_list *x)
+{
+  x->stack=break_stack;
+  x->current=current_break;
+  x->size=break_stack_size;
   break_stack_size=10;
   break_stack=(int *)xalloc(sizeof(int)*break_stack_size);
   current_break=0;
 }
 
-static void pop_break_stack(int jump)
+static void pop_break_stack(struct jump_list *x,int jump)
 {
   for(current_break--;current_break>=0;current_break--)
     set_branch(break_stack[current_break],jump);
 
   free((char *)break_stack);
-  break_stack_size=pop_address();
-  current_break=pop_address();
-  break_stack=(int *)pop_address();
+  
+  break_stack_size=x->size;
+  current_break=x->current;
+  break_stack=x->stack;
 }
 
-static void push_continue_stack()
+static void push_continue_stack(struct jump_list *x)
 {
-  push_explicit((int)continue_stack);
-  push_explicit(current_continue);
-  push_explicit(continue_stack_size);
+  x->stack=continue_stack;
+  x->current=current_continue;
+  x->size=continue_stack_size;
   continue_stack_size=10;
   continue_stack=(int *)xalloc(sizeof(int)*continue_stack_size);
   current_continue=0;
 }
 
-static void pop_continue_stack(int jump)
+static void pop_continue_stack(struct jump_list *x,int jump)
 {
   for(current_continue--;current_continue>=0;current_continue--)
     set_branch(continue_stack[current_continue],jump);
 
   free((char *)continue_stack);
-  continue_stack_size=pop_address();
-  current_continue=pop_address();
-  continue_stack=(int *)pop_address();
+  continue_stack_size=x->size;
+  current_continue=x->current;
+  continue_stack=x->stack;
 }
 
 static int do_docode2(node *n,int flags);
@@ -760,24 +763,25 @@ static int do_docode2(node *n,int flags)
 
   case F_FOR:
   {
+    struct jump_list brk,cnt;
     INT32 *prev_switch_jumptable = current_switch_jumptable;
     current_switch_jumptable=0;
 
-    push_break_stack();
-    push_continue_stack();
+    push_break_stack(&brk);
+    push_continue_stack(&cnt);
     if(CDR(n))
     {
       tmp1=do_jump(F_BRANCH,-1);
       tmp2=PC;
       if(CDR(n)) DO_CODE_BLOCK(CADR(n));
-      pop_continue_stack(PC);
+      pop_continue_stack(&cnt,PC);
       if(CDR(n)) DO_CODE_BLOCK(CDDR(n));
       set_branch(tmp1,PC);
     }else{
       tmp2=PC;
     }
     do_jump_when_non_zero(CAR(n),tmp2);
-    pop_break_stack(PC);
+    pop_break_stack(&brk,PC);
 
     current_switch_jumptable = prev_switch_jumptable;
     return 0;
@@ -788,6 +792,7 @@ static int do_docode2(node *n,int flags)
 
   case F_FOREACH:
   {
+    struct jump_list cnt,brk;
     INT32 *prev_switch_jumptable = current_switch_jumptable;
     current_switch_jumptable=0;
 
@@ -795,13 +800,13 @@ static int do_docode2(node *n,int flags)
     ins_f_byte(F_CONST0);
     tmp3=do_jump(F_BRANCH,-1);
     tmp1=PC;
-    push_break_stack();
-    push_continue_stack();
+    push_break_stack(&brk);
+    push_continue_stack(&cnt);
     DO_CODE_BLOCK(CDR(n));
-    pop_continue_stack(PC);
+    pop_continue_stack(&cnt,PC);
     set_branch(tmp3,PC);
     do_jump(n->token,tmp1);
-    pop_break_stack(PC);
+    pop_break_stack(&brk,PC);
 
     current_switch_jumptable = prev_switch_jumptable;
     return 0;
@@ -812,19 +817,20 @@ static int do_docode2(node *n,int flags)
   case F_INC_LOOP:
   case F_DEC_LOOP:
   {
+    struct jump_list cnt,brk;
     INT32 *prev_switch_jumptable = current_switch_jumptable;
     current_switch_jumptable=0;
 
     tmp2=do_docode(CAR(n),0);
     tmp3=do_jump(F_BRANCH,-1);
     tmp1=PC;
-    push_break_stack();
-    push_continue_stack();
+    push_break_stack(&brk);
+    push_continue_stack(&cnt);
     DO_CODE_BLOCK(CDR(n));
-    pop_continue_stack(PC);
+    pop_continue_stack(&cnt,PC);
     set_branch(tmp3,PC);
     do_jump(n->token,tmp1);
-    pop_break_stack(PC);
+    pop_break_stack(&brk,PC);
 
     current_switch_jumptable = prev_switch_jumptable;
     return 0;
@@ -832,16 +838,17 @@ static int do_docode2(node *n,int flags)
 
   case F_DO:
   {
+    struct jump_list cnt,brk;
     INT32 *prev_switch_jumptable = current_switch_jumptable;
     current_switch_jumptable=0;
 
     tmp2=PC;
-    push_break_stack();
-    push_continue_stack();
+    push_break_stack(&brk);
+    push_continue_stack(&cnt);
     DO_CODE_BLOCK(CAR(n));
-    pop_continue_stack(PC);
+    pop_continue_stack(&cnt,PC);
     do_jump_when_non_zero(CDR(n),tmp2);
-    pop_break_stack(PC);
+    pop_break_stack(&brk,PC);
 
     current_switch_jumptable = prev_switch_jumptable;
     return 0;
@@ -926,6 +933,7 @@ static int do_docode2(node *n,int flags)
 
   case F_SWITCH:
   {
+    struct jump_list brk;
     INT32 e,cases,*order;
     INT32 *jumptable;
     INT32 prev_switch_values_on_stack = current_switch_values_on_stack;
@@ -936,14 +944,14 @@ static int do_docode2(node *n,int flags)
     if(do_docode(CAR(n),0)!=1)
       fatal("Internal compiler error, time to panic\n");
 
-    push_break_stack();
+    push_break_stack(&brk);
 
     cases=count_cases(CDR(n));
 
     ins_f_byte(F_SWITCH);
     tmp1=PC;
     ins_short(0, A_PROGRAM);
-    while(PC != (unsigned int)ALIGN(PC)) ins_byte(0, A_PROGRAM);
+    while(PC != (unsigned int)MY_ALIGN(PC)) ins_byte(0, A_PROGRAM);
     tmp2=PC;
     current_switch_values_on_stack=0;
     current_switch_case=0;
@@ -1001,7 +1009,7 @@ static int do_docode2(node *n,int flags)
     current_switch_case = prev_switch_case;
     current_switch_values_on_stack = prev_switch_values_on_stack ;
 
-    pop_break_stack(PC);
+    pop_break_stack(&brk,PC);
 
     return 0;
   }
@@ -1113,15 +1121,16 @@ static int do_docode2(node *n,int flags)
 
   case F_CATCH:
   {
+    struct jump_list cnt,brk;
     INT32 *prev_switch_jumptable = current_switch_jumptable;
     current_switch_jumptable=0;
 
     tmp1=do_jump(F_CATCH,-1);
-    push_break_stack();
-    push_continue_stack();
+    push_break_stack(&brk);
+    push_continue_stack(&cnt);
     DO_CODE_BLOCK(CAR(n));
-    pop_continue_stack(PC);
-    pop_break_stack(PC);
+    pop_continue_stack(&cnt,PC);
+    pop_break_stack(&brk,PC);
     ins_f_byte(F_DUMB_RETURN);
     set_branch(tmp1,PC);
 
diff --git a/src/interpret.c b/src/interpret.c
index 6aeb52065b..f75086962b 100644
--- a/src/interpret.c
+++ b/src/interpret.c
@@ -166,7 +166,8 @@ static char trace_buffer[100];
   instr=prefix,\
   prefix=0,\
   instr+=EXTRACT_UCHAR(pc++),\
-  (t_flag>3 ? sprintf(trace_buffer,"-    Arg = %ld\n",instr),write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0),\
+  (t_flag>3 ? sprintf(trace_buffer,"-    Arg = %ld\n",(long)instr),\
+   write_to_stderr(trace_buffer,strlen(trace_buffer)) : 0),\
   instr))
 
 #else
@@ -218,7 +219,7 @@ CASE(ID) \
     pc+=EXTRACT_INT(pc); \
     check_signals(); \
   }else{ \
-    pc+=4; \
+    pc+=sizeof(INT32); \
     pop_n_elems(3); \
   } \
   break; \
@@ -254,7 +255,6 @@ void f_catch(unsigned char *pc)
 
 #ifdef DEBUG
 #define BACKLOG 512
-#define BACKLOG_FILE_LENGTH 48
 struct backlog
 {
   INT32 instruction;
@@ -286,9 +286,9 @@ void dump_backlog()
       file=get_line(backlog[e].pc-1,backlog[e].program, &line);
       fprintf(stderr,"%s:%ld: %s(%ld)\n",
 	      file,
-	      line,
+	      (long)line,
 	      low_get_f_name(backlog[e].instruction + F_OFFSET, backlog[e].program),
-	      backlog[e].arg);
+	      (long)backlog[e].arg);
     }
   }while(e!=backlogp);
 };
@@ -343,12 +343,12 @@ static void eval_instruction(unsigned char *pc)
 
       file=get_line(pc-1,fp->context.prog,&linep);
       while((f=strchr(file,'/'))) file=f+1;
-      fprintf(stderr,"- %s:%4ld:(%x): %-25s %4d %4d\n",
-	      file,linep,
-	      pc-fp->context.prog->program-1,
+      fprintf(stderr,"- %s:%4ld:(%lx): %-25s %4ld %4ld\n",
+	      file,(long)linep,
+	      (long)(pc-fp->context.prog->program-1),
 	      get_f_name(instr + F_OFFSET),
-	      sp-evaluator_stack,
-	      mark_sp-mark_stack);
+	      (long)(sp-evaluator_stack),
+	      (long)(mark_sp-mark_stack));
       if(nonblock)
 	set_nonblocking(2,1);
     }
@@ -361,7 +361,7 @@ static void eval_instruction(unsigned char *pc)
       CASE(F_ADD_512); instr=EXTRACT_UCHAR(pc++)+512; goto again;
       CASE(F_ADD_768); instr=EXTRACT_UCHAR(pc++)+768; goto again;
       CASE(F_ADD_1024);instr=EXTRACT_UCHAR(pc++)+1024;goto again;
-      CASE(F_ADD_256X); instr=EXTRACT_UWORD(pc); pc+=2; goto again;
+      CASE(F_ADD_256X); instr=EXTRACT_UWORD(pc); pc+=sizeof(INT16); goto again;
 
       /* Support to allow large arguments */
       CASE(F_PREFIX_256); prefix+=256; break;
@@ -586,7 +586,7 @@ static void eval_instruction(unsigned char *pc)
       check_destructed(sp-1);
       if(!IS_ZERO(sp-1))
       {
-	pc+=4;
+	pc+=sizeof(INT32);
       }else{
 	check_signals();
 	pc+=EXTRACT_INT(pc);
@@ -597,8 +597,8 @@ static void eval_instruction(unsigned char *pc)
       CASE(F_BRANCH_WHEN_NON_ZERO);
       check_destructed(sp-1);
       if(IS_ZERO(sp-1))
-      {
-	pc+=4;
+      {	
+	pc+=sizeof(INT32);
       }else{
 	check_signals();
 	pc+=EXTRACT_INT(pc);
@@ -610,7 +610,7 @@ static void eval_instruction(unsigned char *pc)
       check_destructed(sp-1);
       if(!IS_ZERO(sp-1))
       {
-	pc+=4;
+	pc+=sizeof(INT32);
 	pop_stack();
       }else{
 	check_signals();
@@ -622,7 +622,7 @@ static void eval_instruction(unsigned char *pc)
       check_destructed(sp-1);
       if(IS_ZERO(sp-1))
       {
-	pc+=4;
+	pc+=sizeof(INT32);
 	pop_stack();
       }else{
 	check_signals();
@@ -631,7 +631,7 @@ static void eval_instruction(unsigned char *pc)
       break;
 
       CASE(F_CATCH);
-      f_catch(pc+4);
+      f_catch(pc+sizeof(INT32));
       pc+=EXTRACT_INT(pc);
       break;
 
@@ -640,8 +640,8 @@ static void eval_instruction(unsigned char *pc)
 	INT32 tmp;
 	tmp=switch_lookup(fp->context.prog->
 			  constants[EXTRACT_UWORD(pc)].u.array,sp-1);
-	pc+=2;
-	pc=(unsigned char *)ALIGN(pc);
+	pc+=sizeof(INT16);
+	pc=(unsigned char *)MY_ALIGN(pc);
 	if(tmp >= 0)
 	  pc+=((INT32 *)pc)[1+tmp*2];
 	else
@@ -667,7 +667,7 @@ static void eval_instruction(unsigned char *pc)
 	  pc+=EXTRACT_INT(pc);
 	  sp[-1].u.integer++;
 	}else{
-	  pc+=4;
+	  pc+=sizeof(INT32);
 	  pop_n_elems(4);
 	}
 	break;
@@ -895,7 +895,7 @@ void apply_low(struct object *o, int fun, int args)
     if((nonblock=query_nonblocking(2)))
       set_nonblocking(2,0);
 
-    if(fp)
+    if(fp && fp->pc)
     {
       file=get_line(fp->pc,fp->context.prog,&linep);
       while((f=strchr(file,'/'))) file=f+1;
@@ -916,7 +916,7 @@ void apply_low(struct object *o, int fun, int args)
     }
     my_strcat(")"); 
     s=simple_free_buf();
-    fprintf(stderr,"- %s:%4ld: %s\n",file,linep,s);
+    fprintf(stderr,"- %s:%4ld: %s\n",file,(long)linep,s);
     free(s);
 
     if(nonblock)
@@ -1093,7 +1093,7 @@ void strict_apply_svalue(struct svalue *s, INT32 args)
     if((nonblock=query_nonblocking(2)))
       set_nonblocking(2,0);
 
-    if(fp)
+    if(fp && fp->pc)
     {
       file=get_line(fp->pc,fp->context.prog,&linep);
       while((f=strchr(file,'/'))) file=f+1;
@@ -1112,7 +1112,7 @@ void strict_apply_svalue(struct svalue *s, INT32 args)
     }
     my_strcat(")"); 
     st=simple_free_buf();
-    fprintf(stderr,"- %s:%4ld: %s\n",file,linep,st);
+    fprintf(stderr,"- %s:%4ld: %s\n",file,(long)linep,st);
     free(st);
 
     if(nonblock)
diff --git a/src/language.y b/src/language.y
index a4bcb7b02b..f24127310a 100644
--- a/src/language.y
+++ b/src/language.y
@@ -62,7 +62,6 @@
 %token F_ARRAY_ID
 %token F_ARROW
 %token F_BREAK
-%token F_CALL_OTHER
 %token F_CASE
 %token F_COLON_COLON
 %token F_COMMA
@@ -168,7 +167,6 @@ void add_local_name(struct lpc_string *,struct lpc_string *);
 struct locals *local_variables;
 
 static int varargs;
-static struct lpc_string *current_type;
 static INT32  current_modifiers;
 
 void fix_comp_stack(int sp)
@@ -208,7 +206,7 @@ void fix_comp_stack(int sp)
 %type <number> F_IF F_INHERIT F_INLINE F_INT_ID F_LAMBDA F_LIST_ID F_MAPPING_ID
 %type <number> F_MIXED_ID F_NO_MASK F_OBJECT_ID F_PRIVATE F_PROGRAM_ID
 %type <number> F_PROTECTED F_PUBLIC F_RETURN F_SSCANF F_STATIC
-%type <number> F_STRING_ID F_SWITCH F_VARARGS F_VOID_ID F_WHILE F_CALL_OTHER
+%type <number> F_STRING_ID F_SWITCH F_VARARGS F_VOID_ID F_WHILE
 
 /* The following symbos return type information */
 
@@ -217,7 +215,7 @@ void fix_comp_stack(int sp)
 %type <n> lambda for_expr block  assoc_pair new_local_name
 %type <n> expr_list2 m_expr_list m_expr_list2 statement gauge sscanf
 %type <n> for do cond optional_else_part while statements
-%type <n> local_name_list call_other expr_list3
+%type <n> local_name_list
 %type <n> unused2 foreach unused switch case return expr_list default
 %type <n> continue break block_or_semi
 %%
@@ -255,8 +253,8 @@ block_or_semi: block { $$ = mknode(F_ARG_LIST,$1,mknode(F_RETURN,mkintnode(0),0)
 
 type_or_error: simple_type
              {
-                if(current_type) free_string(current_type); 
-                current_type=$1;
+                if(local_variables->current_type) free_string(local_variables->current_type); 
+                local_variables->current_type=$1;
              }
              | /* empty */
              {
@@ -269,7 +267,7 @@ def: modifiers type_or_error optional_stars F_IDENTIFIER '(' arguments ')'
    {
      int e;
      /* construct the function type */
-     push_finished_type(current_type);
+     push_finished_type(local_variables->current_type);
      while($3--) push_type(T_ARRAY);
      e=$6-1;
      if(varargs)
@@ -469,7 +467,7 @@ name_list: new_name
 new_name: optional_stars F_IDENTIFIER
 	{
 	  struct lpc_string *type;
-	  push_finished_type(current_type);
+	  push_finished_type(local_variables->current_type);
 	  while($1--) push_type(T_ARRAY);
 	  type=pop_type();
           define_variable($2, type, current_modifiers);
@@ -479,7 +477,7 @@ new_name: optional_stars F_IDENTIFIER
         | optional_stars F_IDENTIFIER '='
         {
 	  struct lpc_string *type;
-	  push_finished_type(current_type);
+	  push_finished_type(local_variables->current_type);
 	  while($1--) push_type(T_ARRAY);
 	  type=pop_type();
           $<number>$=define_variable($2, type, current_modifiers);
@@ -495,7 +493,7 @@ new_name: optional_stars F_IDENTIFIER
 
 new_local_name: optional_stars F_IDENTIFIER
                 {
-		  push_finished_type(current_type);
+		  push_finished_type(local_variables->current_type);
 		  while($1--) push_type(T_ARRAY);
                   add_local_name($2, pop_type());
                   $$=mkcastnode(void_type_string,
@@ -504,7 +502,7 @@ new_local_name: optional_stars F_IDENTIFIER
                 }
               | optional_stars F_IDENTIFIER '=' expr0
                 {
-		  push_finished_type(current_type);
+		  push_finished_type(local_variables->current_type);
 		  while($1--) push_type(T_ARRAY);
                   add_local_name($2, pop_type());
                   $$=mkcastnode(void_type_string,
@@ -551,8 +549,8 @@ statements: { $$=0; }
 statement: unused2 ';' { $$=$1; }
          | simple_type
          {
-	   if(current_type) free_string(current_type);
-	   current_type=$1;
+	   if(local_variables->current_type) free_string(local_variables->current_type);
+	   local_variables->current_type=$1;
 	 } local_name_list ';' { $$=$3; }
          | cond
          | while
@@ -840,7 +838,6 @@ expr4: string
      | catch
      | gauge
      | sscanf
-     | call_other
      | lambda
      | F_IDENTIFIER
      {
@@ -932,17 +929,6 @@ expr4: string
        free_string($2);
      }
      ;
-
-expr_list3: { $$=0; }
-          | ',' expr_list { $$=$2; }
-          ;
-
-call_other: F_CALL_OTHER '(' expr0 ',' expr0 expr_list3 ')'
-          {
-	    $$=mkapplynode(mknode(F_INDEX,
-				  mkcastnode(object_type_string,$3),
-				  $5),$6);
-          }
   
 gauge: F_GAUGE '(' unused ')'
   {
@@ -1011,7 +997,10 @@ void yyerror(char *str)
     SAFE_APPLY_MASTER("compile_error",3);
     pop_stack();
   }else{
-    (void)fprintf(stderr, "%s:%ld: %s\n", current_file->str,current_line,str);
+    (void)fprintf(stderr, "%s:%ld: %s\n",
+		  current_file->str,
+		  (long)current_line,
+		  str);
     fflush(stderr);
   }
 }
@@ -1096,9 +1085,8 @@ void dump_program_desc(struct program *p)
 static void push_locals()
 {
   struct locals *l;
-  push_explicit((int)current_type);
-  current_type=0;
   l=ALLOC_STRUCT(locals);
+  l->current_type=0;
   l->next=local_variables;
   local_variables=l;
   local_variables->current_number_of_locals=0;
@@ -1109,10 +1097,10 @@ static void pop_locals()
   struct locals *l;
   free_all_local_names();
   l=local_variables->next;
+  if(local_variables->current_type)
+    free_string(local_variables->current_type);
   free((char *)local_variables);
 
   local_variables=l;
   /* insert check if ( local->next == parent locals ) here */
-  if(current_type) free_string(current_type);
-  current_type=(struct lpc_string *)pop_address();
 }
diff --git a/src/las.h b/src/las.h
index f8037156ab..9c8209adf1 100644
--- a/src/las.h
+++ b/src/las.h
@@ -18,6 +18,7 @@ struct local_variable
 struct locals
 {
   struct locals *next;
+  struct lpc_string *current_type;
   int current_number_of_locals;
   struct local_variable variable[MAX_LOCAL];
 };
diff --git a/src/lex.c b/src/lex.c
index f0a6158b03..0f315e3da7 100644
--- a/src/lex.c
+++ b/src/lex.c
@@ -58,6 +58,8 @@ void exit_lex()
       free_string(local_variables->variable[e].name);
       free_string(local_variables->variable[e].type);
     }
+    if(local_variables->current_type)
+      free_string(local_variables->current_type);
     l=local_variables->next;
     free((char *)local_variables);
     local_variables=l;
@@ -105,7 +107,6 @@ struct keyword reserved_words[] =
 { "varargs",	F_VARARGS, },
 { "void",	F_VOID_ID, },
 { "while",	F_WHILE, },
-{ "call_other",	F_CALL_OTHER, },
 };
 
 struct keyword instr_names[]=
@@ -935,7 +936,7 @@ static void handle_include(char *name)
 
   UNGETSTR("\" 2",3);
   UNGETSTR(current_file->str,current_file->len);
-  sprintf(buf,"\n# %ld \"",current_line+1);
+  sprintf(buf,"\n# %ld \"",(long)current_line+1);
   UNGETSTR(buf,strlen(buf));
 
   total_lines+=current_line-old_line;
@@ -1869,7 +1870,7 @@ static int calc()
 void insert_current_line()
 {
   char buf[20];
-  sprintf(buf," %ld ",current_line);
+  sprintf(buf," %ld ",(long)current_line);
   UNGETSTR(buf,strlen(buf));
 }
 
@@ -1917,6 +1918,7 @@ static void start_new()
     local_variables=ALLOC_STRUCT(locals);
   local_variables->next=0;
   local_variables->current_number_of_locals=0;
+  local_variables->current_type=0;
   simple_add_define("__uLPC__", "1",0);
   
   for (tmpf=lpc_predefs; tmpf; tmpf=tmpf->next)
@@ -1965,6 +1967,10 @@ void end_new_file()
       free_string(local_variables->variable[e].name);
       free_string(local_variables->variable[e].type);
     }
+  
+    if(local_variables->current_type)
+      free_string(local_variables->current_type);
+
     l=local_variables->next;
     free((char *)local_variables);
     local_variables=l;
diff --git a/src/list.c b/src/list.c
index d1d7621817..11e53ef178 100644
--- a/src/list.c
+++ b/src/list.c
@@ -192,7 +192,7 @@ void describe_list(struct list *l,struct processing *p,int indent)
     }
   }
   
-  sprintf(buf,"(< /* %ld elements */\n",l->ind->size);
+  sprintf(buf,"(< /* %ld elements */\n",(long)l->ind->size);
   my_strcat(buf);
   describe_array_low(l->ind,&doing,indent);
   my_putchar('\n');
diff --git a/src/macros.h b/src/macros.h
index 1536a2d70a..5588351d1e 100644
--- a/src/macros.h
+++ b/src/macros.h
@@ -19,7 +19,7 @@
 #endif
 
 #define isidchar(X) (isalnum(X) || (X)=='_')
-#define ALIGN_BOUND 4
-#define ALIGN(X) (((long)(X)+(ALIGN_BOUND-1)) & ~(ALIGN_BOUND-1))
+#define ALIGN_BOUND sizeof(char *)
+#define MY_ALIGN(X) (((long)(X)+(ALIGN_BOUND-1)) & ~(ALIGN_BOUND-1))
 
 #endif
diff --git a/src/main.c b/src/main.c
index c7bc20e813..e08952ceb0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -137,12 +137,11 @@ void main(int argc, char **argv, char **env)
 #endif
   {
     struct rlimit lim;
-    int tmp;
+    long tmp;
     if(!getrlimit(RLIMIT_NOFILE, &lim))
     {
-      tmp=lim.rlim_max;
-      if(tmp == RLIM_INFINITY) tmp=0x7fffffff;
-      tmp=MINIMUM(tmp, MAX_OPEN_FILEDESCRIPTORS);
+      if(lim.rlim_max == RLIM_INFINITY) tmp=0x7fffffff;
+      tmp=MINIMUM(lim.rlim_max, MAX_OPEN_FILEDESCRIPTORS);
       lim.rlim_cur=tmp;
       setrlimit(RLIMIT_NOFILE, &lim);
     }
diff --git a/src/mapping.c b/src/mapping.c
index aed9429fce..221c67e043 100644
--- a/src/mapping.c
+++ b/src/mapping.c
@@ -272,13 +272,13 @@ void describe_mapping(struct mapping *m,struct processing *p,int indent)
   {
     if(p->pointer_a == (void *)m)
     {
-      sprintf(buf,"@%ld",e);
+      sprintf(buf,"@%ld",(long)e);
       my_strcat(buf);
       return;
     }
   }
   
-  sprintf(buf,"([ /* %ld elements */\n", m->ind->size);
+  sprintf(buf,"([ /* %ld elements */\n", (long) m->ind->size);
   my_strcat(buf);
   for(e=0;e<m->ind->size;e++)
   {
diff --git a/src/modules/files/file.c b/src/modules/files/file.c
index d10cd12767..be52cddb62 100644
--- a/src/modules/files/file.c
+++ b/src/modules/files/file.c
@@ -844,7 +844,7 @@ static void file_dup2(INT32 args)
 
 static void file_open_socket(INT32 args)
 {
-  int fd;
+  int fd, tmp;
 
   do_close(THIS, FILE_READ | FILE_WRITE);
   fd=socket(AF_INET, SOCK_STREAM, 0);
@@ -863,6 +863,8 @@ static void file_open_socket(INT32 args)
     return;
   }
 
+  tmp=1;
+  setsockopt(fd,SOL_SOCKET, SO_KEEPALIVE, (char *)&tmp, sizeof(tmp));
   reference_fd(fd);
   set_close_on_exec(fd,1);
   open_mode[fd]=FILE_READ | FILE_WRITE;
diff --git a/src/modules/files/socket.c b/src/modules/files/socket.c
index 278156de54..51d3e85136 100644
--- a/src/modules/files/socket.c
+++ b/src/modules/files/socket.c
@@ -254,7 +254,7 @@ extern struct program *file_program;
 
 static void port_accept(INT32 args)
 {
-  int fd;
+  int fd, tmp;
   int len=0;
   struct object *o;
 
@@ -277,6 +277,9 @@ static void port_accept(INT32 args)
     close(fd);
     return;
   }
+  
+  tmp=1;
+  setsockopt(fd,SOL_SOCKET, SO_KEEPALIVE, (char *)&tmp, sizeof(tmp));
 
   set_close_on_exec(fd,1);
   o=file_make_object_from_fd(fd,FILE_READ | FILE_WRITE);
diff --git a/src/modules/regexp/regexp.c b/src/modules/regexp/regexp.c
index a8b2fc8f83..a77c770296 100644
--- a/src/modules/regexp/regexp.c
+++ b/src/modules/regexp/regexp.c
@@ -1171,12 +1171,12 @@ regexp         *r;
     s = r->program + 1;
     while (op != END) {		/* While that wasn't END last time... */
 	op = OP(s);
-	printf("%2d%s", s - r->program, regprop(s));	/* Where, what. */
+	printf("%2d%s", (long)(s - r->program), regprop(s));	/* Where, what. */
 	nxt = regnext(s);
 	if (nxt == (char *)NULL)	/* nxt ptr. */
 	    printf("(0)");
 	else
-	    printf("(%d)", (s - r->program) + (nxt - s));
+	  printf("(%ld)", (long)( (s - r->program) + (nxt - s) ));
 	s += 3;
 	if (op == ANYOF || op == ANYBUT || op == EXACTLY) {
 	    /* Literal string, where present. */
diff --git a/src/opcodes.c b/src/opcodes.c
index 26f9b8cd9e..df459febd3 100644
--- a/src/opcodes.c
+++ b/src/opcodes.c
@@ -130,7 +130,7 @@ void f_cast()
       switch(sp[-1].type)
       {
       case T_INT:
-	sprintf(buf,"%ld",sp[-1].u.integer);
+	sprintf(buf,"%ld",(long)sp[-1].u.integer);
 	break;
 
       case T_FLOAT:
@@ -516,7 +516,7 @@ void f_sscanf(INT32 args)
     if((nonblock=query_nonblocking(2)))
       set_nonblocking(2,0);
     
-    fprintf(stderr,"-    Matches: %ld\n",i);
+    fprintf(stderr,"-    Matches: %ld\n",(long)i);
     if(nonblock)
       set_nonblocking(2,1);
   }
diff --git a/src/port.c b/src/port.c
index 4ec365daa6..5d4ae22ddc 100644
--- a/src/port.c
+++ b/src/port.c
@@ -233,7 +233,7 @@ char *MEMMEM(char *needle, SIZE_T needlelen, char *haystack, SIZE_T haystacklen)
       end=haystack+haystacklen+1;
     
       q=haystack+max-sizeof(INT32);
-      q=(char *)( ((INT32)q) & -sizeof(INT32));
+      q=(char *)( ((long)q) & -sizeof(INT32));
       for(;q<end-sizeof(INT32)+1;q+=max)
       {
 	h=tmp=*(INT32 *)q;
@@ -578,26 +578,21 @@ int VFPRINTF(FILE *f,char *s,va_list args)
 unsigned INT16 EXTRACT_UWORD(unsigned char *p)
 {
   unsigned INT16 a;
-  ((unsigned char *)&a)[0]=p[0];
-  ((unsigned char *)&a)[1]=p[1];
+  MEMCPY((char *)&a,p,sizeof(a));
   return a;
 }
 
 INT16 EXTRACT_WORD(unsigned char *p)
 {
   INT16 a;
-  ((unsigned char *)&a)[0]=p[0];
-  ((unsigned char *)&a)[1]=p[1];
+  MEMCPY((char *)&a,p,sizeof(a));
   return a;
 }
 
 INT32 EXTRACT_INT(unsigned char *p)
 {
-  INT16 a;
-  ((unsigned char *)&a)[0]=p[0];
-  ((unsigned char *)&a)[1]=p[1];
-  ((unsigned char *)&a)[2]=p[2];
-  ((unsigned char *)&a)[3]=p[3];
+  INT32 a;
+  MEMCPY((char *)&a,p,sizeof(a));
   return a;
 }
 #endif
diff --git a/src/port.h b/src/port.h
index f00de8a179..0c8afe2980 100644
--- a/src/port.h
+++ b/src/port.h
@@ -143,26 +143,21 @@ INT32 EXTRACT_INT(unsigned char *p);
 static INLINE unsigned INT16 EXTRACT_UWORD(unsigned char *p)
 {
   unsigned INT16 a;
-  ((unsigned char *)&a)[0]=p[0];
-  ((unsigned char *)&a)[1]=p[1];
+  MEMCPY((char *)&a,p,sizeof(a));
   return a;
 }
 
 static INLINE INT16 EXTRACT_WORD(unsigned char *p)
 {
   INT16 a;
-  ((unsigned char *)&a)[0]=p[0];
-  ((unsigned char *)&a)[1]=p[1];
+  MEMCPY((char *)&a,p,sizeof(a));
   return a;
 }
 
 static INLINE INT32 EXTRACT_INT(unsigned char *p)
 {
-  INT16 a;
-  ((unsigned char *)&a)[0]=p[0];
-  ((unsigned char *)&a)[1]=p[1];
-  ((unsigned char *)&a)[2]=p[2];
-  ((unsigned char *)&a)[3]=p[3];
+  INT32 a;
+  MEMCPY((char *)&a,p,sizeof(a));
   return a;
 }
 #endif
diff --git a/src/program.c b/src/program.c
index 0a54f8ec13..b103d1e505 100644
--- a/src/program.c
+++ b/src/program.c
@@ -188,13 +188,11 @@ static int funcmp(const void *a,const void *b)
  */
 
 #define INS_BLOCK(PTR,PTRS,TYPE,AREA) \
+prog->PTR=(TYPE *)p; \
 if((prog->PTRS = areas[AREA].s.len/sizeof(TYPE))) \
 { \
-  prog->PTR = (TYPE *)p; \
   MEMCPY(p,areas[AREA].s.str, areas[AREA].s.len); \
-  p+=ALIGN(areas[AREA].s.len); \
-}else{ \
-  prog->PTR = 0; \
+  p+=MY_ALIGN(areas[AREA].s.len); \
 }
 
 struct program *end_program()
@@ -231,16 +229,16 @@ struct program *end_program()
     prog=0;
   }else{
     setup_fake_program();
-    size = ALIGN(sizeof (struct program));
-    for (i=0; i<NUM_AREAS; i++) size += ALIGN(areas[i].s.len);
-    size+=ALIGN(fake_program.num_identifier_references * sizeof(unsigned short));
+    size = MY_ALIGN(sizeof (struct program));
+    for (i=0; i<NUM_AREAS; i++) size += MY_ALIGN(areas[i].s.len);
+    size+=MY_ALIGN(fake_program.num_identifier_references * sizeof(unsigned short));
 
     p = (char *)xalloc(size);
     prog = (struct program *)p;
     *prog = fake_program;
     prog->total_size = size;
     prog->refs = 1;
-    p += ALIGN(sizeof (struct program));
+    p += MY_ALIGN(sizeof (struct program));
 
     INS_BLOCK(program,program_size,unsigned char,A_PROGRAM);
     INS_BLOCK(linenumbers,num_linenumbers,char,A_LINENUMBERS);
@@ -286,7 +284,7 @@ struct program *end_program()
     prog->num_identifier_indexes=e;
     fsort((void *)prog->identifier_index, e,sizeof(unsigned short),(fsortfun)funcmp);
 
-    p+=ALIGN(prog->num_identifier_indexes*sizeof(unsigned short));
+    p+=MY_ALIGN(prog->num_identifier_indexes*sizeof(unsigned short));
 
     for (i=0; i<NUM_AREAS; i++) toss_buffer(areas+i);
 
@@ -345,7 +343,7 @@ SIZE_T add_storage(SIZE_T size)
 {
   SIZE_T offset;
   offset=fake_program.storage_needed;
-  size=ALIGN(size);
+  size=MY_ALIGN(size);
   fake_program.storage_needed += size;
   return offset;
 }
@@ -824,7 +822,7 @@ int find_shared_string_identifier(struct lpc_string *name,
     unsigned int hashval;
     hashval=my_hash_string(name);
     hashval+=prog->id;
-    hashval^=(unsigned int)prog;
+    hashval^=(unsigned long)prog;
     hashval-=name->str[0];
     hashval%=FIND_FUNCTION_HASHSIZE;
     if(is_same_string(cache[hashval].name,name) &&
@@ -1124,24 +1122,24 @@ void check_program(struct program *p, int pass)
   if(p->storage_needed < 0)
     fatal("Program->storage_needed < 0.\n");
 
-  size=ALIGN(sizeof(struct program));
-  size+=ALIGN(p->num_linenumbers);
-  size+=ALIGN(p->program_size);
-  size+=ALIGN(p->num_constants * sizeof(struct svalue));
-  size+=ALIGN(p->num_strings * sizeof(struct lpc_string *));
-  size+=ALIGN(p->num_identifiers * sizeof(struct identifier));
-  size+=ALIGN(p->num_identifier_references * sizeof(struct reference));
-  size+=ALIGN(p->num_inherits * sizeof(struct inherit));
+  size=MY_ALIGN(sizeof(struct program));
+  size+=MY_ALIGN(p->num_linenumbers);
+  size+=MY_ALIGN(p->program_size);
+  size+=MY_ALIGN(p->num_constants * sizeof(struct svalue));
+  size+=MY_ALIGN(p->num_strings * sizeof(struct lpc_string *));
+  size+=MY_ALIGN(p->num_identifiers * sizeof(struct identifier));
+  size+=MY_ALIGN(p->num_identifier_references * sizeof(struct reference));
+  size+=MY_ALIGN(p->num_inherits * sizeof(struct inherit));
 
-  size+=ALIGN(p->num_identifier_indexes * sizeof(INT16));
+  size+=MY_ALIGN(p->num_identifier_indexes * sizeof(INT16));
 
-  if(size < p->total_size)
+  if(size > p->total_size)
     fatal("Program size is in error.\n");
 
-  size-=ALIGN(p->num_identifier_indexes * sizeof(INT16));
-  size+=ALIGN(p->num_identifier_references * sizeof(INT16));
+  size-=MY_ALIGN(p->num_identifier_indexes * sizeof(INT16));
+  size+=MY_ALIGN(p->num_identifier_references * sizeof(INT16));
 
-  if(size > p->total_size)
+  if(size < p->total_size)
     fatal("Program size is in error.\n");
 
 
@@ -1185,7 +1183,8 @@ void check_program(struct program *p, int pass)
     if(p->identifiers[e].flags & ~7)
       fatal("Unknown flags in identifier flag field.\n");
 
-    check_type(p->identifiers[e].run_time_type);
+    if(p->identifiers[e].run_time_type!=T_MIXED)
+      check_type(p->identifiers[e].run_time_type);
   }
 
   for(e=0;e<p->num_identifier_references;e++)
diff --git a/src/rusage.c b/src/rusage.c
index b633f9d993..dd6dfb29ec 100644
--- a/src/rusage.c
+++ b/src/rusage.c
@@ -1,3 +1,4 @@
+#include <sys/types.h>
 #include <sys/time.h>
 #include <sys/stat.h>
 #include <fcntl.h>
diff --git a/src/stralloc.c b/src/stralloc.c
index f69e171bc4..e861b4088a 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -300,9 +300,9 @@ struct lpc_string *add_string_status(int verbose)
       for(p=base_table[e];p;p=p->next)
       {
 	num_distinct_strings++;
-	bytes_distinct_strings+=ALIGN(p->len);
+	bytes_distinct_strings+=MY_ALIGN(p->len);
 	allocd_strings+=p->refs;
-	allocd_bytes+=p->refs*ALIGN(p->len+3);
+	allocd_bytes+=p->refs*MY_ALIGN(p->len+3);
       }
 
     }
@@ -336,7 +336,7 @@ void dump_stralloc_strings()
   struct lpc_string *p;
   for(e=0;e<HTABLE_SIZE;e++)
     for(p=base_table[e];p;p=p->next)
-      printf("%ld refs \"%s\"\n",p->refs,p->str);
+      printf("%ld refs \"%s\"\n",(long)p->refs,p->str);
 }
 
 struct lpc_string *add_shared_strings(struct lpc_string *a,
diff --git a/src/stralloc.h b/src/stralloc.h
index 06a3463288..33135cdf9c 100644
--- a/src/stralloc.h
+++ b/src/stralloc.h
@@ -19,7 +19,7 @@ struct lpc_string *debug_findstring(const struct lpc_string *foo);
 
 #define free_string(s) do{ struct lpc_string *_=(s); if(!--_->refs) really_free_string(_); }while(0)
 
-#define my_hash_string(X) ((unsigned int)(X))
+#define my_hash_string(X) ((unsigned long)(X))
 #define my_order_strcmp(X,Y) ((char *)(X)-(char *)(Y))
 #define is_same_string(X,Y) ((X)==(Y))
 
diff --git a/src/svalue.c b/src/svalue.c
index 739e9e8f3d..b604501181 100644
--- a/src/svalue.c
+++ b/src/svalue.c
@@ -561,7 +561,7 @@ void describe_svalue(struct svalue *s,int indent,struct processing *p)
       break;
 
     case T_INT:
-      sprintf(buf,"%ld",s->u.integer);
+      sprintf(buf,"%ld",(long)s->u.integer);
       my_strcat(buf);
       break;
 
-- 
GitLab