summaryrefslogtreecommitdiffstats
path: root/Objects/abstract.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-01-14 03:31:43 (GMT)
committerGuido van Rossum <guido@python.org>2007-01-14 03:31:43 (GMT)
commitddefaf31b366ea84250fc5090837c2b764a04102 (patch)
treeab3d7b5172f4e6a064165468fc70beb41bdca1d3 /Objects/abstract.c
parent5b787e8bc2dbda5583eee039cb6a6e47c8d8a034 (diff)
downloadcpython-ddefaf31b366ea84250fc5090837c2b764a04102.zip
cpython-ddefaf31b366ea84250fc5090837c2b764a04102.tar.gz
cpython-ddefaf31b366ea84250fc5090837c2b764a04102.tar.bz2
Merged the int/long unification branch, by very crude means (sorry Thomas!).
I banged on the code (beyond what's in that branch) to make fewer tests fail; the only tests that fail now are: test_descr -- can't pickle ints?! test_pickletools -- ??? test_socket -- See python.org/sf/1619659 test_sqlite -- ??? I'll deal with those later.
Diffstat (limited to 'Objects/abstract.c')
-rw-r--r--Objects/abstract.c85
1 files changed, 18 insertions, 67 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 03883be..8405782 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -790,25 +790,6 @@ PyNumber_Absolute(PyObject *o)
return type_error("bad operand type for abs(): '%.200s'", o);
}
-/* Add a check for embedded NULL-bytes in the argument. */
-static PyObject *
-int_from_string(const char *s, Py_ssize_t len)
-{
- char *end;
- PyObject *x;
-
- x = PyInt_FromString((char*)s, &end, 10);
- if (x == NULL)
- return NULL;
- if (end != s + len) {
- PyErr_SetString(PyExc_ValueError,
- "null byte in argument for int()");
- Py_DECREF(x);
- return NULL;
- }
- return x;
-}
-
/* Return a Python Int or Long from the object item
Raise TypeError if the result is not an int-or-long
or if the object cannot be interpreted as an index.
@@ -828,7 +809,7 @@ PyNumber_Index(PyObject *item)
if (result &&
!PyInt_Check(result) && !PyLong_Check(result)) {
PyErr_Format(PyExc_TypeError,
- "__index__ returned non-(int,long) " \
+ "__index__ returned non-int " \
"(type %.200s)",
result->ob_type->tp_name);
Py_DECREF(result);
@@ -890,51 +871,6 @@ PyNumber_AsSsize_t(PyObject *item, PyObject *err)
}
-PyObject *
-PyNumber_Int(PyObject *o)
-{
- PyNumberMethods *m;
- const char *buffer;
- Py_ssize_t buffer_len;
-
- if (o == NULL)
- return null_error();
- if (PyInt_CheckExact(o)) {
- Py_INCREF(o);
- return o;
- }
- m = o->ob_type->tp_as_number;
- if (m && m->nb_int) { /* This should include subclasses of int */
- PyObject *res = m->nb_int(o);
- if (res && (!PyInt_Check(res) && !PyLong_Check(res))) {
- PyErr_Format(PyExc_TypeError,
- "__int__ returned non-int (type %.200s)",
- res->ob_type->tp_name);
- Py_DECREF(res);
- return NULL;
- }
- return res;
- }
- if (PyInt_Check(o)) { /* A int subclass without nb_int */
- PyIntObject *io = (PyIntObject*)o;
- return PyInt_FromLong(io->ob_ival);
- }
- if (PyString_Check(o))
- return int_from_string(PyString_AS_STRING(o),
- PyString_GET_SIZE(o));
-#ifdef Py_USING_UNICODE
- if (PyUnicode_Check(o))
- return PyInt_FromUnicode(PyUnicode_AS_UNICODE(o),
- PyUnicode_GET_SIZE(o),
- 10);
-#endif
- if (!PyObject_AsCharBuffer(o, &buffer, &buffer_len))
- return int_from_string((char*)buffer, buffer_len);
-
- return type_error("int() argument must be a string or a "
- "number, not '%.200s'", o);
-}
-
/* Add a check for embedded NULL-bytes in the argument. */
static PyObject *
long_from_string(const char *s, Py_ssize_t len)
@@ -947,7 +883,7 @@ long_from_string(const char *s, Py_ssize_t len)
return NULL;
if (end != s + len) {
PyErr_SetString(PyExc_ValueError,
- "null byte in argument for long()");
+ "null byte in argument for int()");
Py_DECREF(x);
return NULL;
}
@@ -963,7 +899,22 @@ PyNumber_Long(PyObject *o)
if (o == NULL)
return null_error();
+ if (PyLong_CheckExact(o)) {
+ Py_INCREF(o);
+ return o;
+ }
m = o->ob_type->tp_as_number;
+ if (m && m->nb_int) { /* This should include subclasses of int */
+ PyObject *res = m->nb_int(o);
+ if (res && !PyLong_Check(res)) {
+ PyErr_Format(PyExc_TypeError,
+ "__int__ returned non-int (type %.200s)",
+ res->ob_type->tp_name);
+ Py_DECREF(res);
+ return NULL;
+ }
+ return res;
+ }
if (m && m->nb_long) { /* This should include subclasses of long */
PyObject *res = m->nb_long(o);
if (res && (!PyInt_Check(res) && !PyLong_Check(res))) {
@@ -994,7 +945,7 @@ PyNumber_Long(PyObject *o)
if (!PyObject_AsCharBuffer(o, &buffer, &buffer_len))
return long_from_string(buffer, buffer_len);
- return type_error("long() argument must be a string or a "
+ return type_error("int() argument must be a string or a "
"number, not '%.200s'", o);
}