[Python-checkins] r51500 - in python/branches/int_unification: Include/abstract.h Include/intobject.h Objects/abstract.c Objects/longobject.c
martin.v.loewis
python-checkins at python.org
Wed Aug 23 02:08:34 CEST 2006
Author: martin.v.loewis
Date: Wed Aug 23 02:08:32 2006
New Revision: 51500
Modified:
python/branches/int_unification/Include/abstract.h
python/branches/int_unification/Include/intobject.h
python/branches/int_unification/Objects/abstract.c
python/branches/int_unification/Objects/longobject.c
Log:
Make PyNumber_Long invoke nb_int, drop PyNumber_Int.
Also fix PyLong_FitsInLong.
Modified: python/branches/int_unification/Include/abstract.h
==============================================================================
--- python/branches/int_unification/Include/abstract.h (original)
+++ python/branches/int_unification/Include/abstract.h Wed Aug 23 02:08:32 2006
@@ -715,7 +715,7 @@
is cleared and the value is clipped.
*/
- PyAPI_FUNC(PyObject *) PyNumber_Int(PyObject *o);
+ #define PyNumber_Int PyNumber_Long
/*
Returns the o converted to an integer object on success, or
Modified: python/branches/int_unification/Include/intobject.h
==============================================================================
--- python/branches/int_unification/Include/intobject.h (original)
+++ python/branches/int_unification/Include/intobject.h Wed Aug 23 02:08:32 2006
@@ -40,7 +40,7 @@
#define PyInt_AsLong PyLong_AsLong
#define PyInt_AsSsize_t PyLong_AsSsize_t
#define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask
-#define PyInt_AsUnsignedLongLongMask PyInt_AsUnsignedLongM
+#define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask
PyAPI_FUNC(long) PyInt_GetMax(void);
Modified: python/branches/int_unification/Objects/abstract.c
==============================================================================
--- python/branches/int_unification/Objects/abstract.c (original)
+++ python/branches/int_unification/Objects/abstract.c Wed Aug 23 02:08:32 2006
@@ -790,25 +790,6 @@
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.
@@ -890,47 +871,6 @@
}
-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 (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)
@@ -959,7 +899,22 @@
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))) {
Modified: python/branches/int_unification/Objects/longobject.c
==============================================================================
--- python/branches/int_unification/Objects/longobject.c (original)
+++ python/branches/int_unification/Objects/longobject.c Wed Aug 23 02:08:32 2006
@@ -241,12 +241,14 @@
int
_PyLong_FitsInLong(PyObject *vv)
{
+ int size;
if (!PyLong_CheckExact(vv)) {
PyErr_BadInternalCall();
return 0;
}
/* conservative estimate */
- return ((PyLongObject*)vv)->ob_size <= 2;
+ size = ((PyLongObject*)vv)->ob_size;
+ return -2 <= size && size <= 2;
}
/* Get a Py_ssize_t from a long int object.
More information about the Python-checkins
mailing list