]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Use PyObject_IsInstance() to check whether the first argument to an
authorGuido van Rossum <guido@python.org>
Wed, 21 Mar 2001 19:17:22 +0000 (19:17 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 21 Mar 2001 19:17:22 +0000 (19:17 +0000)
unbound method is of the right type.  Hopefully this solves SF patch
#409355 (Meta-class inheritance problem); I have no easy way to test.

Python/ceval.c

index 22b3ea0e0ae72b88b6496a98809e0e51a95f4dba..156866f0bc2fa10e4cdc57632e11ff8dbdfb6add 100644 (file)
@@ -1402,7 +1402,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
                case BREAK_LOOP:
                        why = WHY_BREAK;
                        break;
-               
+
                case CONTINUE_LOOP:
                        retval = PyInt_FromLong(oparg);
                        why = WHY_CONTINUE;
@@ -2181,7 +2181,7 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
                        if (b->b_type == SETUP_LOOP && why == WHY_CONTINUE) {
                                /* For a continue inside a try block,
                                   don't pop the block for the loop. */
-                               PyFrame_BlockSetup(f, b->b_type, b->b_level, 
+                               PyFrame_BlockSetup(f, b->b_type, b->b_level,
                                                   b->b_handler);
                                why = WHY_NOT;
                                JUMPTO(PyInt_AS_LONG(retval));
@@ -2825,22 +2825,28 @@ call_method(PyObject *func, PyObject *arg, PyObject *kw)
        if (self == NULL) {
                /* Unbound methods must be called with an instance of
                   the class (or a derived class) as first argument */
+               int ok;
                if (PyTuple_Size(arg) >= 1)
                        self = PyTuple_GET_ITEM(arg, 0);
-               if (!(self != NULL && PyInstance_Check(self)
-                   && PyClass_IsSubclass((PyObject *)
-                                 (((PyInstanceObject *)self)->in_class),
-                                         class))) {
-                PyObject* fn = ((PyFunctionObject*) func)->func_name;
-               PyErr_Format(PyExc_TypeError,
-                             "unbound method %s%smust be "
-                             "called with instance as first argument",
-                             fn ? PyString_AsString(fn) : "",
-                             fn ? "() " : "");
+               if (self == NULL)
+                       ok = 0;
+               else {
+                       ok = PyObject_IsInstance(self, class);
+                       if (ok < 0)
+                               return NULL;
+               }
+               if (!ok) {
+                       PyObject* fn = ((PyFunctionObject*) func)->func_name;
+                       PyErr_Format(PyExc_TypeError,
+                                    "unbound method %s%smust be "
+                                    "called with instance as first argument",
+                                    fn ? PyString_AsString(fn) : "",
+                                    fn ? "() " : "");
                        return NULL;
                }
                Py_INCREF(arg);
-       } else {
+       }
+       else {
                int argcount = PyTuple_Size(arg);
                PyObject *newarg = PyTuple_New(argcount + 1);
                int i;