diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-03-21 18:38:11 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-03-21 18:38:11 (GMT) |
commit | d614e707caafc87bd644c1da51ea817c3df54d7b (patch) | |
tree | 38870422794aaa91f4a63a4a87d8c80d09b1c968 /Objects/abstract.c | |
parent | 65e32d1f1a78aef527afe65011a44e2e873f38c8 (diff) | |
download | cpython-d614e707caafc87bd644c1da51ea817c3df54d7b.zip cpython-d614e707caafc87bd644c1da51ea817c3df54d7b.tar.gz cpython-d614e707caafc87bd644c1da51ea817c3df54d7b.tar.bz2 |
rewrite this function, which was still accounting for classic classes
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r-- | Objects/abstract.c | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index 924ccd1..345b96a 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1271,34 +1271,22 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err) PyObject * _PyNumber_ConvertIntegralToInt(PyObject *integral, const char* error_format) { - static PyObject *int_name = NULL; - if (int_name == NULL) { - int_name = PyUnicode_InternFromString("__int__"); - if (int_name == NULL) - return NULL; - } - - if (integral && !PyLong_Check(integral)) { - /* Don't go through tp_as_number->nb_int to avoid - hitting the classic class fallback to __trunc__. */ - PyObject *int_func = PyObject_GetAttr(integral, int_name); - if (int_func == NULL) { - PyErr_Clear(); /* Raise a different error. */ - goto non_integral_error; - } + PyNumberMethods *nb; + if (PyLong_Check(integral)) + return integral; + nb = Py_TYPE(integral)->tp_as_number; + if (nb->nb_int) { + PyObject *as_int = nb->nb_int(integral); Py_DECREF(integral); - integral = PyEval_CallObject(int_func, NULL); - Py_DECREF(int_func); - if (integral && !PyLong_Check(integral)) { - goto non_integral_error; - } + if (!as_int) + return NULL; + if (PyLong_Check(as_int)) + return as_int; + Py_DECREF(as_int); } - return integral; - -non_integral_error: PyErr_Format(PyExc_TypeError, error_format, Py_TYPE(integral)->tp_name); Py_DECREF(integral); - return NULL; + return NULL; } |