diff --git a/src/array.c b/src/array.c
index 9cf7ed14d02401a7b02ff1840641d75403c41acd..5d3fa80adfeca6a21d30ab185137c704b3e28eb6 100644
--- a/src/array.c
+++ b/src/array.c
@@ -457,7 +457,8 @@ void check_array_for_destruct(struct array *v)
     for(e=0; e<v->size; e++)
     {
       if((ITEM(v)[e].type == T_OBJECT ||
-	  (ITEM(v)[e].type == T_FUNCTION && ITEM(v)[e].subtype!=-1)) &&
+	  (ITEM(v)[e].type == T_FUNCTION &&
+	   ITEM(v)[e].subtype!=FUNCTION_BUILTIN)) &&
 	 (!ITEM(v)[e].u.object->prog))
       {
 	free_svalue(ITEM(v)+e);
@@ -492,7 +493,8 @@ INT32 array_find_destructed_object(struct array *v)
     for(e=0; e<v->size; e++)
     {
       if((ITEM(v)[e].type == T_OBJECT ||
-	  (ITEM(v)[e].type == T_FUNCTION && ITEM(v)[e].subtype!=-1)) &&
+	  (ITEM(v)[e].type == T_FUNCTION &&
+	   ITEM(v)[e].subtype!=FUNCTION_BUILTIN)) &&
 	 (!ITEM(v)[e].u.object->prog))
 	return e;
       types |= 1<<ITEM(v)[e].type;
diff --git a/src/builtin_functions.c b/src/builtin_functions.c
index 0f6afcd82686238067ea78d4b932faf82915f0cf..1d0d210c770ca42bb344210575c0a0d63e26c7f4 100644
--- a/src/builtin_functions.c
+++ b/src/builtin_functions.c
@@ -484,7 +484,7 @@ void f_function_object(INT32 args)
   if(sp[-args].type != T_FUNCTION)
     error("Bad argument 1 to function_object.\n");
 
-  if(sp[-args].subtype == -1)
+  if(sp[-args].subtype == FUNCTION_BUILTIN)
   {
     pop_n_elems(args);
     push_int(0);
@@ -502,7 +502,7 @@ void f_function_name(INT32 args)
   if(sp[-args].type != T_FUNCTION)
     error("Bad argument 1 to function_object.\n");
 
-  if(sp[-args].subtype == -1)
+  if(sp[-args].subtype == FUNCTION_BUILTIN)
   {
     pop_n_elems(args);
     push_int(0);
@@ -1124,7 +1124,7 @@ void f_functionp(INT32 args)
 {
   if(args<1) error("Too few arguments to functionp.\n");
   if(sp[-args].type != T_FUNCTION ||
-     (sp[-args].subtype != -1 && !sp[-args].u.object->prog))
+     (sp[-args].subtype != FUNCTION_BUILTIN && !sp[-args].u.object->prog))
   {
     pop_n_elems(args);
     push_int(0);
diff --git a/src/configure.in b/src/configure.in
index 1999ac61b9372d5509db0caf592dcc67c1f3ce83..e53db5721a1b2af952f58d4931172e50f7f4a11f 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -245,7 +245,7 @@ AC_HEADER_TIME
 AC_HEADER_STDC
 AC_CHECK_HEADERS(sys/rusage.h time.h sys/time.h sys/types.h unistd.h stdlib.h \
 memory.h values.h string.h fcntl.h sys/filio.h sys/sockio.h crypt.h locale.h \
-sys/resource.h sys/select.h sys/mman.h setjmp.h)
+sys/resource.h sys/select.h sys/mman.h setjmp.h limits.h)
 
 AC_SIZEOF_TYPE(char *)
 AC_SIZEOF_TYPE(long)
@@ -859,6 +859,29 @@ else
   AC_MSG_RESULT(no)
 fi
 
+
+AC_MSG_CHECKING(for isspace)
+AC_CACHE_VAL(pike_cv_have_func_isspace,
+[
+AC_TRY_LINK([
+#include <ctype.h>
+],[
+  if(isspace(' ')) exit(0);
+],
+  pike_cv_have_func_isspace=yes
+,
+  pike_cv_have_func_isspace=no
+)])
+
+if test "$pike_cv_have_func_isspace" = yes; then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(HAVE_FUNC_ISSPACE)
+else
+  AC_MSG_RESULT(no)
+fi
+
+
+
 AC_MSG_CHECKING(checking for volatile)
 AC_CACHE_VAL(pike_cv_volatile,
 [
diff --git a/src/constants.c b/src/constants.c
index 7ab4d31501e51a6b6771dec762a23712f23d5d32..de0976b88b52cb44bca4aecf210aa7afee9f3f48 100644
--- a/src/constants.c
+++ b/src/constants.c
@@ -91,7 +91,7 @@ void add_efun2(char *name,
 
   n=make_shared_string(name);
   s.type=T_FUNCTION;
-  s.subtype=-1;
+  s.subtype=FUNCTION_BUILTIN;
   s.u.efun=make_callable(fun, name, type, flags, optimize, docode);
   low_add_efun(n, &s);
   free_svalue(&s);
diff --git a/src/docode.c b/src/docode.c
index 7827943fce4b8c49f0afe02354fcee176c8a6694..cc83acaf0f4f214ae24330d74113ab8e09cb893c 100644
--- a/src/docode.c
+++ b/src/docode.c
@@ -644,7 +644,7 @@ static int do_docode2(node *n,int flags)
     {
       if(CAR(n)->u.sval.type == T_FUNCTION)
       {
-	if(CAR(n)->u.sval.subtype == -1) /* driver fun? */
+	if(CAR(n)->u.sval.subtype == FUNCTION_BUILTIN) /* driver fun? */
 	{
 	  if(!CAR(n)->u.sval.u.efun->docode || 
 	     !CAR(n)->u.sval.u.efun->docode(n))
@@ -954,7 +954,7 @@ static int do_docode2(node *n,int flags)
       return 1;
 
     case T_FUNCTION:
-      if(n->u.sval.subtype!=-1)
+      if(n->u.sval.subtype!=FUNCTION_BUILTIN)
       {
 	if(n->u.sval.u.object == &fake_object)
 	{
diff --git a/src/interpret.c b/src/interpret.c
index e34aa133cf91b344a17faa7c36cae544c5837f4c..21e8fc6a94fdf43d1d6342f4ae6acb808ea7e425 100644
--- a/src/interpret.c
+++ b/src/interpret.c
@@ -875,7 +875,6 @@ static void eval_instruction(unsigned char *pc)
 
       CASE(F_RETURN_0);
       pop_n_elems(sp-fp->locals);
-      check_threads_etc();
       return;
 
       CASE(F_RETURN);
@@ -887,7 +886,6 @@ static void eval_instruction(unsigned char *pc)
       /* fall through */
 
       CASE(F_DUMB_RETURN);
-      check_threads_etc();
       return;
 
       CASE(F_NEGATE); 
@@ -1428,7 +1426,7 @@ void strict_apply_svalue(struct svalue *s, INT32 args)
   switch(s->type)
   {
   case T_FUNCTION:
-    if(s->subtype == -1)
+    if(s->subtype == FUNCTION_BUILTIN)
     {
       (*(s->u.efun->function))(args);
     }else{
diff --git a/src/las.c b/src/las.c
index 895c3aca8aebbaae102fa6e052ffb9e1b499d664..e821d295791c0e85ef6fec7f1ad84aee5307f195 100644
--- a/src/las.c
+++ b/src/las.c
@@ -166,7 +166,7 @@ node *mknode(short token,node *a,node *b)
   case F_APPLY:
     if(a && a->token == F_CONSTANT &&
        a->u.sval.type == T_FUNCTION &&
-       (short)a->u.sval.subtype == -1)
+       a->u.sval.subtype == FUNCTION_BUILTIN)
     {
       res->node_info |= a->u.sval.u.efun->flags;
     }else{
@@ -414,7 +414,7 @@ node *mksvaluenode(struct svalue *s)
 
   case T_FUNCTION:
   {
-    if((short)s->subtype != -1)
+    if(s->subtype != FUNCTION_BUILTIN)
     {
       if(s->u.object == &fake_object)
 	return mkidentifiernode(s->subtype);
@@ -1167,7 +1167,7 @@ static void optimize(node *n)
     case F_APPLY:
       if(CAR(n)->token == F_CONSTANT &&
 	 CAR(n)->u.sval.type == T_FUNCTION &&
-	 (short)CAR(n)->u.sval.subtype == -1 && /* driver fun? */
+	 CAR(n)->u.sval.subtype == FUNCTION_BUILTIN && /* driver fun? */
 	 CAR(n)->u.sval.u.efun->optimize)
       {
 	if(tmp1=CAR(n)->u.sval.u.efun->optimize(n))
@@ -1372,7 +1372,7 @@ static void optimize(node *n)
 	   CAR(opnode) &&
 	   CAR(opnode)->token == F_CONSTANT &&
 	   CAR(opnode)->u.sval.type == T_FUNCTION &&
-	   (short)CAR(opnode)->u.sval.subtype == -1)
+	   CAR(opnode)->u.sval.subtype == FUNCTION_BUILTIN)
 	{
 	  if(CAR(opnode)->u.sval.u.efun->function == f_gt)
 	    oper=F_GT;
diff --git a/src/lex.c b/src/lex.c
index c1494c0235b91fc8fa157643b40d88f153513edb..97266f0d42436f25ab2210873f3f56d5fd90066f 100644
--- a/src/lex.c
+++ b/src/lex.c
@@ -319,7 +319,7 @@ char *low_get_f_name(int n,struct program *p)
     if(p &&
        (int)p->num_constants > (int)(n-F_MAX_OPCODE) &&
        p->constants[n-F_MAX_OPCODE].type==T_FUNCTION &&
-       (p->constants[n-F_MAX_OPCODE].subtype == -1) &&
+       (p->constants[n-F_MAX_OPCODE].subtype == FUNCTION_BUILTIN) &&
        p->constants[n-F_MAX_OPCODE].u.efun)
     {
       return p->constants[n-F_MAX_OPCODE].u.efun->name->str;
@@ -343,7 +343,7 @@ char *get_f_name(int n)
     if(fp && fp->context.prog &&
        (int)fp->context.prog->num_constants > (int)(n-F_MAX_OPCODE) &&
        fp->context.prog->constants[n-F_MAX_OPCODE].type==T_FUNCTION &&
-       (short)fp->context.prog->constants[n-F_MAX_OPCODE].subtype == -1 &&
+       fp->context.prog->constants[n-F_MAX_OPCODE].subtype == FUNCTION_BUILTIN &&
        fp->context.prog->constants[n-F_MAX_OPCODE].u.efun)
     {
       return fp->context.prog->constants[n-F_MAX_OPCODE].u.efun->name->str;
@@ -677,7 +677,7 @@ static int GOBBLE(char c)
 }
 
 #define LOOK() (istate->look())
-#define SKIPWHITE() { int c; while(isspace(c=GETC())); UNGETC(c); }
+#define SKIPWHITE() { int c; while(ISSPACE(c=GETC())); UNGETC(c); }
 #define SKIPTO(X) { int c; while((c=GETC())!=(X) && (c!=MY_EOF)); }
 #define SKIPUPTO(X) { int c; while((c=GETC())!=(X) && (c!=MY_EOF)); UNGETC(c); }
 #define READBUF(X) { \
@@ -903,7 +903,7 @@ static int expand_define(struct pike_string *s, int save_newline)
     {
       SKIPWHITE();
     }else{
-      do { e=GETC(); }while(isspace(e) && e!='\n');
+      do { e=GETC(); }while(ISSPACE(e) && e!='\n');
       UNGETC(e);
     }
 
@@ -1113,7 +1113,7 @@ static void do_skip(int to)
 	  READBUF(C!='\n');
 	  if(buf[0]=='"' &&
 	     buf[strlen(buf)-1]=='2' &&
-	     isspace(buf[strlen(buf)-2]))
+	     ISSPACE(buf[strlen(buf)-2]))
 	  {
 	    if(lvl)
 	    {
diff --git a/src/machine.h.in b/src/machine.h.in
index 97518b9e1ddb7a936651b50ff46053ce190d4f57..3c8610dcee3e7b3011a3abbef2ef08009595561c 100644
--- a/src/machine.h.in
+++ b/src/machine.h.in
@@ -61,6 +61,9 @@
 /* Define if you have the <setjmp.h> header file.  */
 #undef HAVE_SETJMP_H
 
+/* Define if you have the <limits.h> header file.  */
+#undef HAVE_LIMITS_H
+
 /* more header files */
 #undef HAVE_FCNTL_H
 #undef HAVE_SYS_FILIO_H
@@ -146,6 +149,9 @@
 /* Define if you have strcasecmp */
 #undef HAVE_STRCASECMP
 
+/* Define if you have isspace */
+#undef HAVE_ISSPACE
+
 /* Define if you have strtod */
 #undef HAVE_STRTOD
 
diff --git a/src/pike_types.c b/src/pike_types.c
index f6c1bfe55857c75b0e1375fafc1b81aab9060ceb..37e6c2fe298cc5e764727c663d6027e5550512a1 100644
--- a/src/pike_types.c
+++ b/src/pike_types.c
@@ -203,7 +203,7 @@ static void internal_parse_typeA(char **s)
   char buf[80];
   unsigned int len;
 
-  while(isspace(**s)) ++*s;
+  while(ISSPACE(**s)) ++*s;
 
   len=0;
   for(len=0;isidchar(s[0][len]);len++)
@@ -224,11 +224,11 @@ static void internal_parse_typeA(char **s)
   else if(!strcmp(buf,"unknown")) push_type(T_UNKNOWN);
   else if(!strcmp(buf,"function"))
   {
-    while(isspace(**s)) ++*s;
+    while(ISSPACE(**s)) ++*s;
     if(**s == '(')
     {
       ++*s;
-      while(isspace(**s)) ++*s;
+      while(ISSPACE(**s)) ++*s;
       type_stack_mark();
       while(1)
       {
@@ -247,7 +247,7 @@ static void internal_parse_typeA(char **s)
 	if(**s==',')
 	{
 	  ++*s;
-	  while(isspace(**s)) ++*s;
+	  while(ISSPACE(**s)) ++*s;
 	}
 	else if(s[0][0]=='.' && s[0][1]=='.' && s[0][2]=='.')
 	{
@@ -255,7 +255,7 @@ static void internal_parse_typeA(char **s)
 	  push_type(T_MANY);
 	  type_stack_reverse();
 	  *s+=3;
-	  while(isspace(**s)) ++*s;
+	  while(ISSPACE(**s)) ++*s;
 	  if(**s != ':') error("Missing ':' after ... in function type.\n");
 	  break;
 	}
@@ -278,7 +278,7 @@ static void internal_parse_typeA(char **s)
   }
   else if(!strcmp(buf,"mapping"))
   {
-    while(isspace(**s)) ++*s;
+    while(ISSPACE(**s)) ++*s;
     if(**s == '(')
     {
       type_stack_mark();
@@ -302,7 +302,7 @@ static void internal_parse_typeA(char **s)
   }
   else if(!strcmp(buf,"array"))
   {
-    while(isspace(**s)) ++*s;
+    while(ISSPACE(**s)) ++*s;
     if(**s == '(')
     {
       ++*s;
@@ -316,7 +316,7 @@ static void internal_parse_typeA(char **s)
   }
   else if(!strcmp(buf,"multiset"))
   {
-    while(isspace(**s)) ++*s;
+    while(ISSPACE(**s)) ++*s;
     if(**s == '(')
     {
       ++*s;
@@ -331,13 +331,13 @@ static void internal_parse_typeA(char **s)
   else
     error("Couldn't parse type. (%s)\n",buf);
 
-  while(isspace(**s)) ++*s;
+  while(ISSPACE(**s)) ++*s;
 }
 
 
 static void internal_parse_typeB(char **s)
 {
-  while(isspace(**s)) ++*s;
+  while(ISSPACE(**s)) ++*s;
   switch(**s)
   {
   case '!':
@@ -349,7 +349,7 @@ static void internal_parse_typeB(char **s)
   case '(':
     ++*s;
     internal_parse_typeB(s);
-    while(isspace(**s)) ++*s;
+    while(ISSPACE(**s)) ++*s;
     if(**s != ')') error("Expecting ')'.\n");
     break;
     
@@ -363,12 +363,12 @@ static void internal_parse_typeCC(char **s)
 {
   internal_parse_typeB(s);
 
-  while(isspace(**s)) ++*s;
+  while(ISSPACE(**s)) ++*s;
   
   while(**s == '*')
   {
     ++*s;
-    while(isspace(**s)) ++*s;
+    while(ISSPACE(**s)) ++*s;
     push_type(T_ARRAY);
   }
 }
@@ -381,7 +381,7 @@ static void internal_parse_typeC(char **s)
   internal_parse_typeCC(s);
   type_stack_reverse();
 
-  while(isspace(**s)) ++*s;
+  while(ISSPACE(**s)) ++*s;
   
   if(**s == '&')
   {
@@ -400,7 +400,7 @@ static void internal_parse_type(char **s)
 {
   internal_parse_typeC(s);
 
-  while(isspace(**s)) ++*s;
+  while(ISSPACE(**s)) ++*s;
   
   while(**s == '|')
   {
@@ -950,7 +950,7 @@ struct pike_string *get_type_of_svalue(struct svalue *s)
   switch(s->type)
   {
   case T_FUNCTION:
-    if(s->subtype == -1)
+    if(s->subtype == FUNCTION_BUILTIN)
     {
       ret=s->u.efun->type;
     }else{
diff --git a/src/port.c b/src/port.c
index 2a5cf63e36b1e217cc25bda000c7573df44574aa..2f65d3ae18bd778d9d08ab367fad692b31193167 100644
--- a/src/port.c
+++ b/src/port.c
@@ -79,7 +79,7 @@ long STRTOL(char *str,char **ptr,int base)
   if (base < 0 || base > MBASE)
     return (0);			/* base is invalid -- should be a fatal error */
   if (!isalnum(c = *str)) {
-    while (isspace(c))
+    while (ISSPACE(c))
       c = *++str;
     switch (c) {
     case '-':
@@ -125,7 +125,7 @@ int STRCASECMP(const char *a,const char *b)
 
     if(ac && isupper(ac)) ac=tolower(ac);
     if(bc && isupper(bc)) bc=tolower(bc);
-    if(ac != bc) return 1;
+    if(ac - bc) return ac-bc;
     if(!ac) return 0;
   }
 }
@@ -265,7 +265,7 @@ double STRTOD(char * nptr, char **endptr)
   s = nptr;
 
   /* Eat whitespace.  */
-  while (isspace(*s)) ++s;
+  while (ISSPACE(*s)) ++s;
 
   /* Get the sign.  */
   sign = *s == '-' ? -1 : 1;
diff --git a/src/port.h b/src/port.h
index 66beab0b6383ccf0a9818dd0bfc76ad4ad315fe6..d301b191ee0491fa9c153af65d20e75b5767322c 100644
--- a/src/port.h
+++ b/src/port.h
@@ -9,6 +9,11 @@
 #include "types.h"
 
 struct timeval;
+#ifdef HAVE_ISSPACE
+#define ISSPACE(X) isspace(X)
+#else
+#define ISSPACE(X) ("0012345678SSSSS456789012345678901S3456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789000000"[(X)+1] == 'S')
+#endif
 
 #ifndef HAVE_GETTIMEOFDAY
 void GETTIMEOFDAY(struct timeval *t);
@@ -47,7 +52,7 @@ int STRCSPN(const char *s,const char * set);
 #ifndef HAVE_STRCASECMP
 int STRCASECMP(const char *a,const char *b);
 #else
-#  define STRCSPN strcspn
+#  define STRCASECMP strcasecmp
 #endif
 
 #ifndef HAVE_MEMSET
diff --git a/src/signal_handler.c b/src/signal_handler.c
index 2991e9f878e73a2e4b964c11a18a005003d03736..c09da9fde55772257a7d6adc0a40f5620d0cdace 100644
--- a/src/signal_handler.c
+++ b/src/signal_handler.c
@@ -281,8 +281,8 @@ static int signum(char *name)
   int e;
   for(e=0;e<(int)NELEM(signal_desc)-1;e++)
   {
-    if(!strcasecmp(name,signal_desc[e].signame) ||
-       !strcasecmp(name,signal_desc[e].signame+3) )
+    if(!STRCASECMP(name,signal_desc[e].signame) ||
+       !STRCASECMP(name,signal_desc[e].signame+3) )
       return signal_desc[e].signum;
   }
   return -1;
diff --git a/src/svalue.c b/src/svalue.c
index 7a701d99eb6326295f2aca2ea3e748ffc4d12618..d0ed4e12ab51754667345a7531189c1b8ea3d238 100644
--- a/src/svalue.c
+++ b/src/svalue.c
@@ -107,7 +107,7 @@ void free_svalue(struct svalue *s)
 	break;
 
       case T_FUNCTION:
-	if(s->subtype == -1)
+	if(s->subtype == FUNCTION_BUILTIN)
 	{
 	  really_free_callable(s->u.efun);
 	  break;
@@ -168,7 +168,7 @@ void free_svalues(struct svalue *s,INT32 num, INT32 type_hint)
     {
       if(s->u.refs[0]--==0)
       {
-	if(s->subtype == -1)
+	if(s->subtype == FUNCTION_BUILTIN)
 	  really_free_callable(s->u.efun);
 	else
 	  really_free_object(s->u.object);
@@ -691,7 +691,7 @@ void describe_svalue(struct svalue *s,int indent,struct processing *p)
 
 
     case T_FUNCTION:
-      if(s->subtype == -1)
+      if(s->subtype == FUNCTION_BUILTIN)
       {
 	my_binary_strcat(s->u.efun->name->str,s->u.efun->name->len);
       }else{
@@ -838,7 +838,7 @@ TYPE_FIELD gc_check_svalues(struct svalue *s, int num)
     switch(s->type)
     {
     case T_FUNCTION:
-      if(s->subtype == -1) break;
+      if(s->subtype == FUNCTION_BUILTIN) break;
 
     case T_OBJECT:
       if(s->u.object->prog)
@@ -901,7 +901,7 @@ void gc_mark_svalues(struct svalue *s, int num)
     case T_PROGRAM: gc_mark_program_as_referenced(s->u.program); break;
 
     case T_FUNCTION:
-      if(s->subtype == -1) break;
+      if(s->subtype == FUNCTION_BUILTIN) break;
 
     case T_OBJECT:
       if(s->u.object->prog)
diff --git a/src/svalue.h b/src/svalue.h
index 2824c56793ec39682141b595fefbb0f53b98f988..cbbbac02cbf7c0c2916e2957ac01f83226a15b0f 100644
--- a/src/svalue.h
+++ b/src/svalue.h
@@ -41,7 +41,7 @@ union anything
 struct svalue
 {
   unsigned INT16 type;
-  INT16 subtype;
+  unsigned INT16 subtype;
   union anything u;
 };
 
@@ -94,6 +94,8 @@ struct svalue
 #define NUMBER_UNDEFINED 1
 #define NUMBER_DESTRUCTED 2
 
+#define FUNCTION_BUILTIN USHRT_MAX
+
 #define is_gt(a,b) is_lt(b,a)
 #define IS_ZERO(X) ((X)->type==T_INT?(X)->u.integer==0:(1<<(X)->type)&(BIT_OBJECT|BIT_FUNCTION)?!svalue_is_true(X):0)
 
diff --git a/src/types.h b/src/types.h
index 511d470f0fafbb99884e5aff0152d521c0fddc89..eb38876b3bbd9f02302a9fb88a37af60b7292ec8 100644
--- a/src/types.h
+++ b/src/types.h
@@ -9,6 +9,15 @@
 #include "machine.h"
 /* we here define a few types with more defined values */
 
+#ifdef HAVE_LIMITS_H
+#include <limits.h>
+#undef HAVE_LIMITS_H
+#endif
+
+#ifndef USHRT_MAX
+#define USHRT_MAX 65535
+#endif
+
 #define INT64 long long
 
 #if SIZEOF_SHORT >= 4