summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-07-02 13:35:17 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-07-02 13:35:17 (GMT)
commitb0125892e6fcdbb2c726322e702e5513ac42ba39 (patch)
tree9f7bc78e35acce9dc62bf786c3e29ff757e39d6a
parent8971f74c55112c848d2edaa584304066235ffd44 (diff)
downloadcpython-b0125892e6fcdbb2c726322e702e5513ac42ba39.zip
cpython-b0125892e6fcdbb2c726322e702e5513ac42ba39.tar.gz
cpython-b0125892e6fcdbb2c726322e702e5513ac42ba39.tar.bz2
account for different ref counting semantics of _PyObject_LookupSpecial
-rw-r--r--Modules/mathmodule.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 2f656bb..64738f0 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -881,7 +881,7 @@ FUNC1(fabs, fabs, 0,
static PyObject * math_floor(PyObject *self, PyObject *number) {
static PyObject *floor_str = NULL;
- PyObject *method;
+ PyObject *method, *result;
method = _PyObject_LookupSpecial(number, "__floor__", &floor_str);
if (method == NULL) {
@@ -889,7 +889,9 @@ static PyObject * math_floor(PyObject *self, PyObject *number) {
return NULL;
return math_1_to_int(number, floor, 0);
}
- return PyObject_CallFunctionObjArgs(method, NULL);
+ result = PyObject_CallFunctionObjArgs(method, NULL);
+ Py_DECREF(method);
+ return result;
}
PyDoc_STRVAR(math_floor_doc,
@@ -1416,7 +1418,7 @@ static PyObject *
math_trunc(PyObject *self, PyObject *number)
{
static PyObject *trunc_str = NULL;
- PyObject *trunc;
+ PyObject *trunc, *result;
if (Py_TYPE(number)->tp_dict == NULL) {
if (PyType_Ready(Py_TYPE(number)) < 0)
@@ -1431,7 +1433,9 @@ math_trunc(PyObject *self, PyObject *number)
Py_TYPE(number)->tp_name);
return NULL;
}
- return PyObject_CallFunctionObjArgs(trunc, NULL);
+ result = PyObject_CallFunctionObjArgs(trunc, NULL);
+ Py_DECREF(trunc);
+ return result;
}
PyDoc_STRVAR(math_trunc_doc,