Keep PyLong_AsLongAndOverflow documentation and implementation in sync
between py3k and trunk;  merge new tests from trunk to py3k.
(See issue #7528.)
diff --git a/Objects/longobject.c b/Objects/longobject.c
index b46ce4e..8e4093c 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -346,9 +346,10 @@
 
 	if (!PyLong_Check(vv)) {
 		PyNumberMethods *nb;
-		if ((nb = vv->ob_type->tp_as_number) == NULL ||
-		    nb->nb_int == NULL) {
-			PyErr_SetString(PyExc_TypeError, "an integer is required");
+		nb = vv->ob_type->tp_as_number;
+		if (nb == NULL || nb->nb_int == NULL) {
+			PyErr_SetString(PyExc_TypeError,
+					"an integer is required");
 			return -1;
 		}
 		vv = (*nb->nb_int) (vv);
@@ -388,13 +389,13 @@
 			prev = x;
 			x = (x << PyLong_SHIFT) | v->ob_digit[i];
 			if ((x >> PyLong_SHIFT) != prev) {
-				*overflow = Py_SIZE(v) > 0 ? 1 : -1;
+				*overflow = sign;
 				goto exit;
 			}
 		}
-		/* Haven't lost any bits, but casting to long requires extra care
-		 * (see comment above).
-	         */
+		/* Haven't lost any bits, but casting to long requires extra
+		 * care (see comment above).
+		 */
 		if (x <= (unsigned long)LONG_MAX) {
 			res = (long)x * sign;
 		}
@@ -402,9 +403,9 @@
 			res = LONG_MIN;
 		}
 		else {
-			*overflow = Py_SIZE(v) > 0 ? 1 : -1;
+			*overflow = sign;
 			/* res is already set to -1 */
-		}	
+		}
 	}
  exit:
 	if (do_decref) {