[Python-3000-checkins] r53651 - python/branches/p3yk/Objects/longobject.c

martin.v.loewis python-3000-checkins at python.org
Tue Feb 6 22:05:31 CET 2007


Author: martin.v.loewis
Date: Tue Feb  6 22:05:30 2007
New Revision: 53651

Modified:
   python/branches/p3yk/Objects/longobject.c
Log:
Fix refcounting bugs related to CONVERT_BINOP.


Modified: python/branches/p3yk/Objects/longobject.c
==============================================================================
--- python/branches/p3yk/Objects/longobject.c	(original)
+++ python/branches/p3yk/Objects/longobject.c	Tue Feb  6 22:05:30 2007
@@ -2147,8 +2147,12 @@
 long_richcompare(PyObject *self, PyObject *other, int op)
 {
 	PyLongObject *a, *b;
+	PyObject *result;
 	CONVERT_BINOP((PyObject *)self, (PyObject *)other, &a, &b);
-	return Py_CmpToRich(op, long_compare(a, b));
+	result = Py_CmpToRich(op, long_compare(a, b));
+	Py_DECREF(a);
+	Py_DECREF(b);
+	return result;
 }
 
 static long
@@ -2283,9 +2287,13 @@
 
 	CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
 
-	if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1)
-		return PyInt_FromLong(MEDIUM_VALUE(a) +
-				      MEDIUM_VALUE(b));
+	if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1) {
+		PyObject *result = PyInt_FromLong(MEDIUM_VALUE(a) +
+						  MEDIUM_VALUE(b));
+		Py_DECREF(a);
+		Py_DECREF(b);
+		return result;
+	}
 	if (a->ob_size < 0) {
 		if (b->ob_size < 0) {
 			z = x_add(a, b);
@@ -2313,8 +2321,13 @@
 
 	CONVERT_BINOP((PyObject *)v, (PyObject *)w, &a, &b);
 
-	if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1)
-		return PyLong_FromLong(MEDIUM_VALUE(a)-MEDIUM_VALUE(b));
+	if (ABS(a->ob_size) <= 1 && ABS(b->ob_size) <= 1) {
+		PyObject* r;
+		r = PyLong_FromLong(MEDIUM_VALUE(a)-MEDIUM_VALUE(b));
+		Py_DECREF(a);
+		Py_DECREF(b);
+		return r;
+	}
 	if (a->ob_size < 0) {
 		if (b->ob_size < 0)
 			z = x_sub(a, b);
@@ -2744,8 +2757,13 @@
 		return Py_NotImplemented;
 	}
 
-	if (ABS(v->ob_size) <= 1 && ABS(w->ob_size) <= 1)
-		return PyLong_FromLong(MEDIUM_VALUE(v)*MEDIUM_VALUE(w));
+	if (ABS(v->ob_size) <= 1 && ABS(w->ob_size) <= 1) {
+		PyObject *r;
+		r = PyLong_FromLong(MEDIUM_VALUE(v)*MEDIUM_VALUE(w));
+		Py_DECREF(a);
+		Py_DECREF(b);
+		return r;
+	}
 
 	z = k_mul(a, b);
 	/* Negate if exactly one of the inputs is negative. */


More information about the Python-3000-checkins mailing list