Merge alpha100 branch back to main trunk
diff --git a/Objects/Makefile.in b/Objects/Makefile.in
index 42671d9..d0c086f 100644
--- a/Objects/Makefile.in
+++ b/Objects/Makefile.in
@@ -9,17 +9,17 @@
 
 CC=		@CC@
 RANLIB=		@RANLIB@
+AR=		@AR@
+
 DEFS=		@DEFS@
 
 
 # === Other things that are customizable but not by configure ===
 
-TOP=		..
-INCLDIR=	$(TOP)/Py
-OPT=		-g
-CFLAGS=		$(OPT) -I$(INCLDIR) $(DEFS)
+INCLDIR=	$(srcdir)/../Include
+OPT=		-O
+CFLAGS=		$(OPT) -I$(INCLDIR) -I.. $(DEFS)
 
-AR=		ar
 MKDEP=		mkdep
 SHELL=		/bin/sh
 
@@ -57,11 +57,33 @@
 clobber:	clean
 		-rm -f *.a tags TAGS
 
-Makefile:	Makefile.in $(TOP)/config.status
-		CONFIG_FILES=Makefile $(SHELL) $(TOP)/config.status
+Makefile:	$(srcdir)/Makefile.in ../config.status
+		(cd ..; CONFIG_FILES=Objects/Makefile CONFIG_HEADERS= \
+		$(SHELL) config.status)
 
-depend:		$(SRCS)
-		$(MKDEP) $(CFLAGS) $(SRCS) $(PGENSRCS)
+depend:
+		$(MKDEP) $(CFLAGS) `echo $(OBJS) | tr ' ' '\012' | \
+					sed 's|\(.*\)\.o|$(srcdir)/\1.c|'`
+
+.PRECIOUS:	Makefile
+
+accessobject.o: accessobject.c
+classobject.o: classobject.c
+fileobject.o: fileobject.c
+floatobject.o: floatobject.c
+frameobject.o: frameobject.c
+funcobject.o: funcobject.c
+intobject.o: intobject.c
+listobject.o: listobject.c
+longobject.o: longobject.c
+mappingobject.o: mappingobject.c
+methodobject.o: methodobject.c
+moduleobject.o: moduleobject.c
+object.o: object.c
+rangeobject.o: rangeobject.c
+stringobject.o: stringobject.c
+tupleobject.o: tupleobject.c
+typeobject.o: typeobject.c
 
 # DO NOT DELETE THIS LINE -- mkdep uses it.
 # DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/Objects/accessobject.c b/Objects/accessobject.c
index b2cd4ad..d516e67 100644
--- a/Objects/accessobject.c
+++ b/Objects/accessobject.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
@@ -26,7 +26,7 @@
 
 /* XXX TO DO LIST
    - __init__ and __del__ (and all other similar methods)
-     should be usable even when private, not ignored (???)
+     should be usable even when private, not ignored
 */
 
 #include "allobjects.h"
@@ -321,12 +321,12 @@
 	sizeof(accessobject),	/*tp_size*/
 	0,			/*tp_itemsize*/
 	/* methods */
-	access_dealloc,		/*tp_dealloc*/
+	(destructor)access_dealloc, /*tp_dealloc*/
 	0,			/*tp_print*/
-	access_getattr,		/*tp_getattr*/
+	(getattrfunc)access_getattr, /*tp_getattr*/
 	0,			/*tp_setattr*/
 	0,			/*tp_compare*/
-	access_repr,		/*tp_repr*/
+	(reprfunc)access_repr, /*tp_repr*/
 	0,			/*tp_as_number*/
 	0,			/*tp_as_sequence*/
 	0,			/*tp_as_mapping*/
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 268cf1a..35ce0b1 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.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
@@ -103,7 +103,7 @@
 	register char *name;
 {
 	register object *v;
-	object *class;
+	classobject *class;
 	if (strcmp(name, "__dict__") == 0) {
 		INCREF(op->cl_dict);
 		return op->cl_dict;
@@ -189,12 +189,12 @@
 	"class",
 	sizeof(classobject),
 	0,
-	class_dealloc,	/*tp_dealloc*/
+	(destructor)class_dealloc, /*tp_dealloc*/
 	0,		/*tp_print*/
-	class_getattr,	/*tp_getattr*/
-	class_setattr,	/*tp_setattr*/
+	(getattrfunc)class_getattr, /*tp_getattr*/
+	(setattrfunc)class_setattr, /*tp_setattr*/
 	0,		/*tp_compare*/
-	class_repr,	/*tp_repr*/
+	(reprfunc)class_repr, /*tp_repr*/
 	0,		/*tp_as_number*/
 	0,		/*tp_as_sequence*/
 	0,		/*tp_as_mapping*/
@@ -235,7 +235,7 @@
 	
 	n = gettuplesize(class->cl_bases);
 	for (i = 0; i < n; i++) {
-		if (addaccess(gettupleitem(class->cl_bases, i), inst) < 0)
+		if (addaccess((classobject *)gettupleitem(class->cl_bases, i), inst) < 0)
 			return -1;
 	}
 	
@@ -613,9 +613,9 @@
 }
 
 static mapping_methods instance_as_mapping = {
-	instance_length,	/*mp_length*/
-	instance_subscript,	/*mp_subscript*/
-	instance_ass_subscript,	/*mp_ass_subscript*/
+	(inquiry)instance_length, /*mp_length*/
+	(binaryfunc)instance_subscript, /*mp_subscript*/
+	(objobjargproc)instance_ass_subscript, /*mp_ass_subscript*/
 };
 
 static object *
@@ -764,13 +764,13 @@
 }
 
 static sequence_methods instance_as_sequence = {
-	instance_length,	/*sq_length*/
-	instance_concat,	/*sq_concat*/
-	instance_repeat,	/*sq_repeat*/
-	instance_item,		/*sq_item*/
-	instance_slice,		/*sq_slice*/
-	instance_ass_item,	/*sq_ass_item*/
-	instance_ass_slice,	/*sq_ass_slice*/
+	(inquiry)instance_length, /*sq_length*/
+	(binaryfunc)instance_concat, /*sq_concat*/
+	(intargfunc)instance_repeat, /*sq_repeat*/
+	(intargfunc)instance_item, /*sq_item*/
+	(intintargfunc)instance_slice, /*sq_slice*/
+	(intobjargproc)instance_ass_item, /*sq_ass_item*/
+	(intintobjargproc)instance_ass_slice, /*sq_ass_slice*/
 };
 
 static object *
@@ -916,29 +916,29 @@
 UNARY(instance_hex, "__hex__")
 
 static number_methods instance_as_number = {
-	instance_add,		/*nb_add*/
-	instance_sub,		/*nb_subtract*/
-	instance_mul,		/*nb_multiply*/
-	instance_div,		/*nb_divide*/
-	instance_mod,		/*nb_remainder*/
-	instance_divmod,	/*nb_divmod*/
-	instance_pow,		/*nb_power*/
-	instance_neg,		/*nb_negative*/
-	instance_pos,		/*nb_positive*/
-	instance_abs,		/*nb_absolute*/
-	instance_nonzero,	/*nb_nonzero*/
-	instance_invert,	/*nb_invert*/
-	instance_lshift,	/*nb_lshift*/
-	instance_rshift,	/*nb_rshift*/
-	instance_and,		/*nb_and*/
-	instance_xor,		/*nb_xor*/
-	instance_or,		/*nb_or*/
-	instance_coerce,	/*nb_coerce*/
-	instance_int,		/*nb_int*/
-	instance_long,		/*nb_long*/
-	instance_float,		/*nb_float*/
-	instance_oct,		/*nb_oct*/
-	instance_hex,		/*nb_hex*/
+	(binaryfunc)instance_add, /*nb_add*/
+	(binaryfunc)instance_sub, /*nb_subtract*/
+	(binaryfunc)instance_mul, /*nb_multiply*/
+	(binaryfunc)instance_div, /*nb_divide*/
+	(binaryfunc)instance_mod, /*nb_remainder*/
+	(binaryfunc)instance_divmod, /*nb_divmod*/
+	(binaryfunc)instance_pow, /*nb_power*/
+	(unaryfunc)instance_neg, /*nb_negative*/
+	(unaryfunc)instance_pos, /*nb_positive*/
+	(unaryfunc)instance_abs, /*nb_absolute*/
+	(inquiry)instance_nonzero, /*nb_nonzero*/
+	(unaryfunc)instance_invert, /*nb_invert*/
+	(binaryfunc)instance_lshift, /*nb_lshift*/
+	(binaryfunc)instance_rshift, /*nb_rshift*/
+	(binaryfunc)instance_and, /*nb_and*/
+	(binaryfunc)instance_xor, /*nb_xor*/
+	(binaryfunc)instance_or, /*nb_or*/
+	(coercion)instance_coerce, /*nb_coerce*/
+	(unaryfunc)instance_int, /*nb_int*/
+	(unaryfunc)instance_long, /*nb_long*/
+	(unaryfunc)instance_float, /*nb_float*/
+	(unaryfunc)instance_oct, /*nb_oct*/
+	(unaryfunc)instance_hex, /*nb_hex*/
 };
 
 typeobject Instancetype = {
@@ -947,17 +947,17 @@
 	"instance",
 	sizeof(instanceobject),
 	0,
-	instance_dealloc,	/*tp_dealloc*/
+	(destructor)instance_dealloc, /*tp_dealloc*/
 	0,			/*tp_print*/
 	(object * (*) FPROTO((object *, char *)))
-	instance_getattr,	/*tp_getattr*/
-	instance_setattr,	/*tp_setattr*/
-	instance_compare,	/*tp_compare*/
-	instance_repr,		/*tp_repr*/
+	(getattrfunc)instance_getattr, /*tp_getattr*/
+	(setattrfunc)instance_setattr, /*tp_setattr*/
+	(cmpfunc)instance_compare, /*tp_compare*/
+	(reprfunc)instance_repr, /*tp_repr*/
 	&instance_as_number,	/*tp_as_number*/
 	&instance_as_sequence,	/*tp_as_sequence*/
 	&instance_as_mapping,	/*tp_as_mapping*/
-	instance_hash,		/*tp_hash*/
+	(hashfunc)instance_hash, /*tp_hash*/
 };
 
 
@@ -1126,14 +1126,14 @@
 	"instance method",
 	sizeof(instancemethodobject),
 	0,
-	instancemethod_dealloc,	/*tp_dealloc*/
+	(destructor)instancemethod_dealloc, /*tp_dealloc*/
 	0,			/*tp_print*/
-	instancemethod_getattr,	/*tp_getattr*/
+	(getattrfunc)instancemethod_getattr, /*tp_getattr*/
 	0,			/*tp_setattr*/
-	instancemethod_compare,	/*tp_compare*/
-	instancemethod_repr,	/*tp_repr*/
+	(cmpfunc)instancemethod_compare, /*tp_compare*/
+	(reprfunc)instancemethod_repr, /*tp_repr*/
 	0,			/*tp_as_number*/
 	0,			/*tp_as_sequence*/
 	0,			/*tp_as_mapping*/
-	instancemethod_hash,	/*tp_hash*/
+	(hashfunc)instancemethod_hash, /*tp_hash*/
 };
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 518fe04..eb8f4aa 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.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
@@ -26,6 +26,7 @@
 
 #include "allobjects.h"
 #include "modsupport.h"
+#include "structmember.h"
 #include "ceval.h"
 
 #define BUF(v) GETSTRINGVALUE((stringobject *)v)
@@ -113,6 +114,30 @@
 	return (object *)f;
 }
 
+void
+setfilebufsize(f, bufsize)
+	object *f;
+	int bufsize;
+{
+	if (bufsize >= 0) {
+#ifdef HAVE_SETVBUF
+		int type;
+		switch (bufsize) {
+		case 0:
+			type = _IONBF;
+			break;
+		case 1:
+			type = _IOLBF;
+			bufsize = BUFSIZ;
+			break;
+		default:
+			type = _IOFBF;
+		}
+		setvbuf(((fileobject *)f)->f_fp, (char *)NULL, type, bufsize);
+#endif /* HAVE_SETVBUF */
+	}
+}
+
 static object *
 err_closed()
 {
@@ -290,16 +315,16 @@
 	
 	if (f->f_fp == NULL)
 		return err_closed();
-	if (args == NULL) {
+	if (args == NULL)
 		n = 0;
+	else {
+		if (!getargs(args, "i", &n))
+			return NULL;
 		if (n < 0) {
 			err_setstr(ValueError, "negative read count");
 			return NULL;
 		}
 	}
-	else if (!getargs(args, "i", &n))
-		return NULL;
-	
 	n2 = n != 0 ? n : BUFSIZ;
 	v = newsizedstringobject((char *)NULL, n2);
 	if (v == NULL)
@@ -358,10 +383,9 @@
 	for (;;) {
 		if ((c = getc(fp)) == EOF) {
 			clearerr(fp);
-			if (intrcheck()) {
+			if (sigcheck()) {
 				RET_SAVE
 				DECREF(v);
-				err_set(KeyboardInterrupt);
 				return NULL;
 			}
 			if (n < 0 && buf == BUF(v)) {
@@ -583,26 +607,58 @@
 }
 
 static struct methodlist file_methods[] = {
-	{"close",	file_close},
-	{"flush",	file_flush},
-	{"fileno",	file_fileno},
-	{"isatty",	file_isatty},
-	{"read",	file_read},
-	{"readline",	file_readline},
-	{"readlines",	file_readlines},
-	{"seek",	file_seek},
-	{"tell",	file_tell},
-	{"write",	file_write},
-	{"writelines",	file_writelines},
+	{"close",	(method)file_close},
+	{"flush",	(method)file_flush},
+	{"fileno",	(method)file_fileno},
+	{"isatty",	(method)file_isatty},
+	{"read",	(method)file_read},
+	{"readline",	(method)file_readline},
+	{"readlines",	(method)file_readlines},
+	{"seek",	(method)file_seek},
+	{"tell",	(method)file_tell},
+	{"write",	(method)file_write},
+	{"writelines",	(method)file_writelines},
 	{NULL,		NULL}		/* sentinel */
 };
 
+#define OFF(x) offsetof(fileobject, x)
+
+static struct memberlist file_memberlist[] = {
+	{"softspace",	T_INT,		OFF(f_softspace)},
+	{"mode",	T_OBJECT,	OFF(f_mode),	RO},
+	{"name",	T_OBJECT,	OFF(f_name),	RO},
+	/* getattr(f, "closed") is implemented without this table */
+	{"closed",	T_INT,		0,		RO},
+	{NULL}	/* Sentinel */
+};
+
 static object *
 file_getattr(f, name)
 	fileobject *f;
 	char *name;
 {
-	return findmethod(file_methods, (object *)f, name);
+	object *res;
+
+	res = findmethod(file_methods, (object *)f, name);
+	if (res != NULL)
+		return res;
+	err_clear();
+	if (strcmp(name, "closed") == 0)
+		return newintobject((long)(f->f_fp == 0));
+	return getmember((char *)f, file_memberlist, name);
+}
+
+static int
+file_setattr(f, name, v)
+	fileobject *f;
+	char *name;
+	object *v;
+{
+	if (v == NULL) {
+		err_setstr(AttributeError, "can't delete file attributes");
+		return -1;
+	}
+	return setmember((char *)f, file_memberlist, name, v);
 }
 
 typeobject Filetype = {
@@ -611,12 +667,12 @@
 	"file",
 	sizeof(fileobject),
 	0,
-	file_dealloc,	/*tp_dealloc*/
+	(destructor)file_dealloc, /*tp_dealloc*/
 	0,		/*tp_print*/
-	file_getattr,	/*tp_getattr*/
-	0,		/*tp_setattr*/
+	(getattrfunc)file_getattr, /*tp_getattr*/
+	(setattrfunc)file_setattr, /*tp_setattr*/
 	0,		/*tp_compare*/
-	file_repr,	/*tp_repr*/
+	(reprfunc)file_repr, /*tp_repr*/
 };
 
 /* Interface for the 'soft space' between print items. */
@@ -710,7 +766,7 @@
 		if (fp != NULL)
 			fputs(s, fp);
 	}
-	else {
+	else if (!err_occurred()) {
 		object *v = newstringobject(s);
 		if (v == NULL) {
 			err_clear();
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index d3a2c77..5ff67db 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.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
@@ -47,7 +47,7 @@
 #define CHECK(x) /* Don't know how to check */
 #endif
 
-#ifndef THINK_C
+#ifndef macintosh
 extern double fmod PROTO((double, double));
 extern double pow PROTO((double, double));
 #endif
@@ -77,12 +77,31 @@
 getfloatvalue(op)
 	object *op;
 {
-	if (!is_floatobject(op)) {
+	number_methods *nb;
+	floatobject *fo;
+	double val;
+	
+	if (op && is_floatobject(op))
+		return GETFLOATVALUE((floatobject*) op);
+	
+	if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
+	    nb->nb_float == NULL) {
 		err_badarg();
 		return -1;
 	}
-	else
-		return ((floatobject *)op) -> ob_fval;
+	
+	fo = (floatobject*) (*nb->nb_float) (op);
+	if (fo == NULL)
+		return -1;
+	if (!is_floatobject(fo)) {
+		err_setstr(TypeError, "nb_float should return float object");
+		return -1;
+	}
+	
+	val = GETFLOATVALUE(fo);
+	DECREF(fo);
+	
+	return val;
 }
 
 /* Methods */
@@ -156,7 +175,17 @@
 	/* This is designed so that Python numbers with the same
 	   value hash to the same value, otherwise comparisons
 	   of mapping keys will turn out weird */
+
+#ifdef MPW /* MPW C modf expects pointer to extended as second argument */
+{
+	extended e;
+	fractpart = modf(v->ob_fval, &e);
+	intpart = e;
+}
+#else
 	fractpart = modf(v->ob_fval, &intpart);
+#endif
+
 	if (fractpart == 0.0) {
 		if (intpart > 0x7fffffffL || -intpart > 0x7fffffffL) {
 			/* Convert to long int and use its hash... */
@@ -372,27 +401,27 @@
 
 
 static number_methods float_as_number = {
-	float_add,	/*nb_add*/
-	float_sub,	/*nb_subtract*/
-	float_mul,	/*nb_multiply*/
-	float_div,	/*nb_divide*/
-	float_rem,	/*nb_remainder*/
-	float_divmod,	/*nb_divmod*/
-	float_pow,	/*nb_power*/
-	float_neg,	/*nb_negative*/
-	float_pos,	/*nb_positive*/
-	float_abs,	/*nb_absolute*/
-	float_nonzero,	/*nb_nonzero*/
+	(binaryfunc)float_add, /*nb_add*/
+	(binaryfunc)float_sub, /*nb_subtract*/
+	(binaryfunc)float_mul, /*nb_multiply*/
+	(binaryfunc)float_div, /*nb_divide*/
+	(binaryfunc)float_rem, /*nb_remainder*/
+	(binaryfunc)float_divmod, /*nb_divmod*/
+	(binaryfunc)float_pow, /*nb_power*/
+	(unaryfunc)float_neg, /*nb_negative*/
+	(unaryfunc)float_pos, /*nb_positive*/
+	(unaryfunc)float_abs, /*nb_absolute*/
+	(inquiry)float_nonzero, /*nb_nonzero*/
 	0,		/*nb_invert*/
 	0,		/*nb_lshift*/
 	0,		/*nb_rshift*/
 	0,		/*nb_and*/
 	0,		/*nb_xor*/
 	0,		/*nb_or*/
-	float_coerce,	/*nb_coerce*/
-	float_int,	/*nb_int*/
-	float_long,	/*nb_long*/
-	float_float,	/*nb_float*/
+	(coercion)float_coerce, /*nb_coerce*/
+	(unaryfunc)float_int, /*nb_int*/
+	(unaryfunc)float_long, /*nb_long*/
+	(unaryfunc)float_float, /*nb_float*/
 	0,		/*nb_oct*/
 	0,		/*nb_hex*/
 };
@@ -403,14 +432,14 @@
 	"float",
 	sizeof(floatobject),
 	0,
-	float_dealloc,		/*tp_dealloc*/
-	float_print,		/*tp_print*/
+	(destructor)float_dealloc, /*tp_dealloc*/
+	(printfunc)float_print, /*tp_print*/
 	0,			/*tp_getattr*/
 	0,			/*tp_setattr*/
-	float_compare,		/*tp_compare*/
-	float_repr,		/*tp_repr*/
+	(cmpfunc)float_compare, /*tp_compare*/
+	(reprfunc)float_repr, /*tp_repr*/
 	&float_as_number,	/*tp_as_number*/
 	0,			/*tp_as_sequence*/
 	0,			/*tp_as_mapping*/
-	float_hash,		/*tp_hash */
+	(hashfunc)float_hash, /*tp_hash*/
 };
diff --git a/Objects/xxobject.c b/Objects/xxobject.c
index 64e0228..e135d3f 100644
--- a/Objects/xxobject.c
+++ b/Objects/xxobject.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
@@ -42,7 +42,7 @@
 	object	*x_attr;	/* Attributes dictionary */
 } xxobject;
 
-extern typeobject Xxtype;	/* Really static, forward */
+staticforward typeobject Xxtype;
 
 #define is_xxobject(v)		((v)->ob_type == &Xxtype)
 
@@ -80,7 +80,7 @@
 }
 
 static struct methodlist xx_methods[] = {
-	{"demo",	xx_demo},
+	{"demo",	(method)xx_demo},
 	{NULL,		NULL}		/* sentinel */
 };
 
@@ -125,13 +125,13 @@
 	OB_HEAD_INIT(&Typetype)
 	0,			/*ob_size*/
 	"xx",			/*tp_name*/
-	sizeof(xxobject),	/*tp_size*/
+	sizeof(xxobject),	/*tp_basicsize*/
 	0,			/*tp_itemsize*/
 	/* methods */
-	xx_dealloc,		/*tp_dealloc*/
+	(destructor)xx_dealloc, /*tp_dealloc*/
 	0,			/*tp_print*/
-	xx_getattr,		/*tp_getattr*/
-	xx_setattr,		/*tp_setattr*/
+	(getattrfunc)xx_getattr, /*tp_getattr*/
+	(setattrfunc)xx_setattr, /*tp_setattr*/
 	0,			/*tp_compare*/
 	0,			/*tp_repr*/
 	0,			/*tp_as_number*/