Merged the int/long unification branch, by very crude means (sorry Thomas!).
I banged on the code (beyond what's in that branch) to make fewer tests fail;
the only tests that fail now are:
  test_descr -- can't pickle ints?!
  test_pickletools -- ???
  test_socket -- See python.org/sf/1619659
  test_sqlite -- ???
I'll deal with those later.
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index f2aeb9d..8ebb482 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -2136,7 +2136,7 @@
 		if (v == NULL)
 			PyErr_Clear();
 		else {
-			if (PyInt_Check(v))
+			if (PyInt_CheckExact(v))
 				oldflag = PyInt_AsLong(v);
 			assert(oldflag < INT_MAX);
 			Py_DECREF(v);
@@ -2301,6 +2301,8 @@
 		return -1;
 	}
 
+	if (fd == -1 && PyErr_Occurred())
+		return -1;
 	if (fd < 0) {
 		PyErr_Format(PyExc_ValueError,
 			     "file descriptor cannot be a negative integer (%i)",