[Python-checkins] r82438 - in python/branches/py3k: Lib/test/test_descr.py Misc/NEWS Modules/mathmodule.c

benjamin.peterson python-checkins at python.org
Fri Jul 2 15:46:42 CEST 2010


Author: benjamin.peterson
Date: Fri Jul  2 15:46:42 2010
New Revision: 82438

Log:
fix lookup of __ceil__

Modified:
   python/branches/py3k/Lib/test/test_descr.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Modules/mathmodule.c

Modified: python/branches/py3k/Lib/test/test_descr.py
==============================================================================
--- python/branches/py3k/Lib/test/test_descr.py	(original)
+++ python/branches/py3k/Lib/test/test_descr.py	Fri Jul  2 15:46:42 2010
@@ -1581,6 +1581,7 @@
             ("__format__", format, format_impl, set(), {}),
             ("__floor__", math.floor, zero, set(), {}),
             ("__trunc__", math.trunc, zero, set(), {}),
+            ("__ceil__", math.ceil, zero, set(), {}),
             ]
 
         class Checker(object):

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Fri Jul  2 15:46:42 2010
@@ -1374,8 +1374,8 @@
 Extension Modules
 -----------------
 
-- In the math module, correctly lookup __trunc__ and __floor__ as special
-  methods.
+- In the math module, correctly lookup __trunc__, __ceil__, and __floor__ as
+  special methods.
 
 - Issue #9005: Prevent utctimetuple() from producing year 0 or year
   10,000.  Prior to this change, timezone adjustment in utctimetuple()

Modified: python/branches/py3k/Modules/mathmodule.c
==============================================================================
--- python/branches/py3k/Modules/mathmodule.c	(original)
+++ python/branches/py3k/Modules/mathmodule.c	Fri Jul  2 15:46:42 2010
@@ -843,17 +843,17 @@
     static PyObject *ceil_str = NULL;
     PyObject *method;
 
-    if (ceil_str == NULL) {
-        ceil_str = PyUnicode_InternFromString("__ceil__");
-        if (ceil_str == NULL)
+    method = _PyObject_LookupSpecial(number, "__ceil__", &ceil_str);
+    if (method == NULL) {
+        if (PyErr_Occurred())
             return NULL;
-    }
-
-    method = _PyType_Lookup(Py_TYPE(number), ceil_str);
-    if (method == NULL)
         return math_1_to_int(number, ceil, 0);
-    else
-        return PyObject_CallFunction(method, "O", number);
+    }
+    else {
+        PyObject *result = PyObject_CallFunctionObjArgs(method, NULL);
+        Py_DECREF(method);
+        return result;
+    }
 }
 
 PyDoc_STRVAR(math_ceil_doc,


More information about the Python-checkins mailing list