summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorKristján Valur Jónsson <kristjan@ccpgames.com>2007-05-07 16:46:54 (GMT)
committerKristján Valur Jónsson <kristjan@ccpgames.com>2007-05-07 16:46:54 (GMT)
commitabe1d48d2068ef0fea36a9b370a8b159ab267430 (patch)
tree18126c32358db7927b5fc5c59d9bb6ba110d17c5 /Objects
parent58e123d75ef5858fcae7c52cd0b2dc412f4dd316 (diff)
downloadcpython-abe1d48d2068ef0fea36a9b370a8b159ab267430.zip
cpython-abe1d48d2068ef0fea36a9b370a8b159ab267430.tar.gz
cpython-abe1d48d2068ef0fea36a9b370a8b159ab267430.tar.bz2
As per Armin Rigo's suggestion, remove special handing from intobject.c to deal with the peculiarities of classobject's implementation of the number protocol. The nb_long method of classobject now falls back to nb_int if there is no __long__ attribute present.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/classobject.c14
-rw-r--r--Objects/intobject.c9
2 files changed, 15 insertions, 8 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 8560b68..89cca59 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -1539,6 +1539,18 @@ static PyObject *funcname(PyInstanceObject *self) { \
return generic_unary_op(self, o); \
}
+/* unary function with a fallback */
+#define UNARY_FB(funcname, methodname, funcname_fb) \
+static PyObject *funcname(PyInstanceObject *self) { \
+ static PyObject *o; \
+ if (o == NULL) { o = PyString_InternFromString(methodname); \
+ if (o == NULL) return NULL; } \
+ if (PyObject_HasAttr((PyObject*)self, o)) \
+ return generic_unary_op(self, o); \
+ else \
+ return funcname_fb(self); \
+}
+
#define BINARY(f, m, n) \
static PyObject *f(PyObject *v, PyObject *w) { \
return do_binop(v, w, "__" m "__", "__r" m "__", n); \
@@ -1777,7 +1789,7 @@ instance_index(PyInstanceObject *self)
UNARY(instance_invert, "__invert__")
UNARY(instance_int, "__int__")
-UNARY(instance_long, "__long__")
+UNARY_FB(instance_long, "__long__", instance_int)
UNARY(instance_float, "__float__")
UNARY(instance_oct, "__oct__")
UNARY(instance_hex, "__hex__")
diff --git a/Objects/intobject.c b/Objects/intobject.c
index a82b3c8..9333a55 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -213,15 +213,10 @@ PyInt_AsSsize_t(register PyObject *op)
return -1;
}
- if (nb->nb_long != 0) {
+ if (nb->nb_long != 0)
io = (PyIntObject*) (*nb->nb_long) (op);
- if (io == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
- PyErr_Clear();
- io = (PyIntObject*) (*nb->nb_int) (op);
- }
- } else {
+ else
io = (PyIntObject*) (*nb->nb_int) (op);
- }
if (io == NULL)
return -1;
if (!PyInt_Check(io)) {