diff options
Diffstat (limited to 'Objects/methodobject.c')
| -rw-r--r-- | Objects/methodobject.c | 145 |
1 files changed, 18 insertions, 127 deletions
diff --git a/Objects/methodobject.c b/Objects/methodobject.c index 0b60ca3..f1a9f4b 100644 --- a/Objects/methodobject.c +++ b/Objects/methodobject.c @@ -81,7 +81,6 @@ PyCFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) return (*meth)(self, arg); break; case METH_VARARGS | METH_KEYWORDS: - case METH_OLDARGS | METH_KEYWORDS: return (*(PyCFunctionWithKeywords)meth)(self, arg, kw); case METH_NOARGS: if (kw == NULL || PyDict_Size(kw) == 0) { @@ -105,19 +104,11 @@ PyCFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) return NULL; } break; - case METH_OLDARGS: - /* the really old style */ - if (kw == NULL || PyDict_Size(kw) == 0) { - size = PyTuple_GET_SIZE(arg); - if (size == 1) - arg = PyTuple_GET_ITEM(arg, 0); - else if (size == 0) - arg = NULL; - return (*meth)(self, arg); - } - break; default: - PyErr_BadInternalCall(); + PyErr_SetString(PyExc_SystemError, "Bad call flags in " + "PyCFunction_Call. METH_OLDARGS is no " + "longer supported!"); + return NULL; } PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", @@ -149,7 +140,7 @@ meth_get__doc__(PyCFunctionObject *m, void *closure) const char *doc = m->m_ml->ml_doc; if (doc != NULL) - return PyString_FromString(doc); + return PyUnicode_FromString(doc); Py_INCREF(Py_None); return Py_None; } @@ -157,7 +148,7 @@ meth_get__doc__(PyCFunctionObject *m, void *closure) static PyObject * meth_get__name__(PyCFunctionObject *m, void *closure) { - return PyString_FromString(m->m_ml->ml_name); + return PyUnicode_FromString(m->m_ml->ml_name); } static int @@ -172,11 +163,7 @@ static PyObject * meth_get__self__(PyCFunctionObject *m, void *closure) { PyObject *self; - if (PyEval_GetRestricted()) { - PyErr_SetString(PyExc_RuntimeError, - "method.__self__ not accessible in restricted mode"); - return NULL; - } + self = m->m_self; if (self == NULL) self = Py_None; @@ -201,28 +188,15 @@ static PyMemberDef meth_members[] = { static PyObject * meth_repr(PyCFunctionObject *m) { - if (m->m_self == NULL) - return PyString_FromFormat("<built-in function %s>", + if (m->m_self == NULL || PyModule_Check(m->m_self)) + return PyUnicode_FromFormat("<built-in function %s>", m->m_ml->ml_name); - return PyString_FromFormat("<built-in method %s of %s object at %p>", + return PyUnicode_FromFormat("<built-in method %s of %s object at %p>", m->m_ml->ml_name, m->m_self->ob_type->tp_name, m->m_self); } -static int -meth_compare(PyCFunctionObject *a, PyCFunctionObject *b) -{ - if (a->m_self != b->m_self) - return (a->m_self < b->m_self) ? -1 : 1; - if (a->m_ml->ml_meth == b->m_ml->ml_meth) - return 0; - if (strcmp(a->m_ml->ml_name, b->m_ml->ml_name) < 0) - return -1; - else - return 1; -} - static PyObject * meth_richcompare(PyObject *self, PyObject *other, int op) { @@ -230,17 +204,10 @@ meth_richcompare(PyObject *self, PyObject *other, int op) PyObject *res; int eq; - if (op != Py_EQ && op != Py_NE) { - /* Py3K warning if comparison isn't == or !=. */ - if (PyErr_WarnPy3k("builtin_function_or_method order " - "comparisons not supported in 3.x", 1) < 0) { - return NULL; - } - - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; - } - else if (!PyCFunction_Check(self) || !PyCFunction_Check(other)) { + if ((op != Py_EQ && op != Py_NE) || + !PyCFunction_Check(self) || + !PyCFunction_Check(other)) + { Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } @@ -257,10 +224,10 @@ meth_richcompare(PyObject *self, PyObject *other, int op) return res; } -static long +static Py_hash_t meth_hash(PyCFunctionObject *a) { - long x,y; + Py_hash_t x, y; if (a->m_self == NULL) x = 0; else { @@ -287,7 +254,7 @@ PyTypeObject PyCFunction_Type = { 0, /* tp_print */ 0, /* tp_getattr */ 0, /* tp_setattr */ - (cmpfunc)meth_compare, /* tp_compare */ + 0, /* tp_reserved */ (reprfunc)meth_repr, /* tp_repr */ 0, /* tp_as_number */ 0, /* tp_as_sequence */ @@ -302,7 +269,7 @@ PyTypeObject PyCFunction_Type = { 0, /* tp_doc */ (traverseproc)meth_traverse, /* tp_traverse */ 0, /* tp_clear */ - meth_richcompare, /* tp_richcompare */ + meth_richcompare, /* tp_richcompare */ 0, /* tp_weaklistoffset */ 0, /* tp_iter */ 0, /* tp_iternext */ @@ -313,82 +280,6 @@ PyTypeObject PyCFunction_Type = { 0, /* tp_dict */ }; -/* List all methods in a chain -- helper for findmethodinchain */ - -static PyObject * -listmethodchain(PyMethodChain *chain) -{ - PyMethodChain *c; - PyMethodDef *ml; - int i, n; - PyObject *v; - - n = 0; - for (c = chain; c != NULL; c = c->link) { - for (ml = c->methods; ml->ml_name != NULL; ml++) - n++; - } - v = PyList_New(n); - if (v == NULL) - return NULL; - i = 0; - for (c = chain; c != NULL; c = c->link) { - for (ml = c->methods; ml->ml_name != NULL; ml++) { - PyList_SetItem(v, i, PyString_FromString(ml->ml_name)); - i++; - } - } - if (PyErr_Occurred()) { - Py_DECREF(v); - return NULL; - } - PyList_Sort(v); - return v; -} - -/* Find a method in a method chain */ - -PyObject * -Py_FindMethodInChain(PyMethodChain *chain, PyObject *self, const char *name) -{ - if (name[0] == '_' && name[1] == '_') { - if (strcmp(name, "__methods__") == 0) { - if (PyErr_WarnPy3k("__methods__ not supported in 3.x", - 1) < 0) - return NULL; - return listmethodchain(chain); - } - if (strcmp(name, "__doc__") == 0) { - const char *doc = self->ob_type->tp_doc; - if (doc != NULL) - return PyString_FromString(doc); - } - } - while (chain != NULL) { - PyMethodDef *ml = chain->methods; - for (; ml->ml_name != NULL; ml++) { - if (name[0] == ml->ml_name[0] && - strcmp(name+1, ml->ml_name+1) == 0) - /* XXX */ - return PyCFunction_New(ml, self); - } - chain = chain->link; - } - PyErr_SetString(PyExc_AttributeError, name); - return NULL; -} - -/* Find a method in a single method list */ - -PyObject * -Py_FindMethod(PyMethodDef *methods, PyObject *self, const char *name) -{ - PyMethodChain chain; - chain.methods = methods; - chain.link = NULL; - return Py_FindMethodInChain(&chain, self, name); -} - /* Clear out the free list */ int |
