]> granicus.if.org Git - python/commitdiff
As per Armin Rigo's suggestion, remove special handing from intobject.c to deal with...
authorKristján Valur Jónsson <kristjan@ccpgames.com>
Mon, 7 May 2007 16:46:54 +0000 (16:46 +0000)
committerKristján Valur Jónsson <kristjan@ccpgames.com>
Mon, 7 May 2007 16:46:54 +0000 (16:46 +0000)
Objects/classobject.c
Objects/intobject.c

index 8560b6842cec2213488ee0c1796ce9a1c1785069..89cca5969df506d713f5b47d0e8496c76e535210 100644 (file)
@@ -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__")
index a82b3c889e53c1466cbeb0f693606f6592bf202e..9333a55873aaf5181628a560feb06f95f0cc7c93 100644 (file)
@@ -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)) {