Merge alpha100 branch back to main trunk
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 2cae7f4..ef3ec23 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -1,5 +1,5 @@
 /***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
 Amsterdam, The Netherlands.
 
                         All Rights Reserved
@@ -28,7 +28,8 @@
 #include "modsupport.h"
 #include "ceval.h"
 
-#include "myselect.h"
+#include <sys/types.h>
+#include "myselect.h" /* Also includes mytime.h */
 
 static object *SelectError;
 
@@ -63,12 +64,13 @@
 	    err_badarg();
 	    return -1;
 	}
-	if ( v >= FD_SETSIZE ) {
-	    err_setstr(SystemError, "FD_SETSIZE too low in select()");
+	if ( v < 0 || v >= FD_SETSIZE ) {
+	    err_setstr(ValueError, "filedescriptor out of range in select()");
 	    return -1;
 	}
 	if ( v > max ) max = v;
 	FD_SET(v, set);
+	XDECREF(fd2obj[v]);
 	fd2obj[v] = o;
     }
     return max+1;
@@ -91,11 +93,12 @@
     for(i=0; i<max; i++)
       if ( FD_ISSET(i,set) ) {
 	  if ( i > FD_SETSIZE ) {
-	      err_setstr(SystemError, "FD_SETSIZE too low in select()");
+	      err_setstr(SystemError,
+			 "filedescriptor out of range returned in select()");
 	      return NULL;
 	  }
 	  o = fd2obj[i];
-	  if ( o == 0 ) {
+	  if ( o == NULL ) {
 	      err_setstr(SystemError,
 			 "Bad filedescriptor returned from select()");
 	      return NULL;