2006-08-17 02:42:55 -03:00
|
|
|
/* Class object implementation (dead now except for methods) */
|
1990-10-14 09:07:46 -03:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
#include "Python.h"
|
2018-11-21 17:27:47 -04:00
|
|
|
#include "pycore_object.h"
|
2018-11-12 11:53:38 -04:00
|
|
|
#include "pycore_pymem.h"
|
|
|
|
#include "pycore_pystate.h"
|
1990-12-20 11:06:42 -04:00
|
|
|
#include "structmember.h"
|
1992-08-12 12:35:34 -03:00
|
|
|
|
2006-07-27 18:53:35 -03:00
|
|
|
#define TP_DESCR_GET(t) ((t)->tp_descr_get)
|
2001-10-17 17:26:38 -03:00
|
|
|
|
2011-10-14 05:20:37 -03:00
|
|
|
_Py_IDENTIFIER(__name__);
|
2014-08-20 20:41:57 -03:00
|
|
|
_Py_IDENTIFIER(__qualname__);
|
2011-10-10 13:11:30 -03:00
|
|
|
|
2001-09-05 19:52:50 -03:00
|
|
|
PyObject *
|
|
|
|
PyMethod_Function(PyObject *im)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!PyMethod_Check(im)) {
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ((PyMethodObject *)im)->im_func;
|
2001-09-05 19:52:50 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
PyMethod_Self(PyObject *im)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!PyMethod_Check(im)) {
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return ((PyMethodObject *)im)->im_self;
|
2001-09-05 19:52:50 -03:00
|
|
|
}
|
|
|
|
|
2019-05-29 15:31:52 -03:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
method_vectorcall(PyObject *method, PyObject *const *args,
|
|
|
|
size_t nargsf, PyObject *kwnames)
|
|
|
|
{
|
|
|
|
assert(Py_TYPE(method) == &PyMethod_Type);
|
|
|
|
PyObject *self, *func, *result;
|
|
|
|
self = PyMethod_GET_SELF(method);
|
|
|
|
func = PyMethod_GET_FUNCTION(method);
|
|
|
|
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
|
|
|
|
|
|
|
|
if (nargsf & PY_VECTORCALL_ARGUMENTS_OFFSET) {
|
|
|
|
/* PY_VECTORCALL_ARGUMENTS_OFFSET is set, so we are allowed to mutate the vector */
|
|
|
|
PyObject **newargs = (PyObject**)args - 1;
|
|
|
|
nargs += 1;
|
|
|
|
PyObject *tmp = newargs[0];
|
|
|
|
newargs[0] = self;
|
|
|
|
result = _PyObject_Vectorcall(func, newargs, nargs, kwnames);
|
|
|
|
newargs[0] = tmp;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Py_ssize_t nkwargs = (kwnames == NULL) ? 0 : PyTuple_GET_SIZE(kwnames);
|
|
|
|
Py_ssize_t totalargs = nargs + nkwargs;
|
2019-07-03 07:54:00 -03:00
|
|
|
if (totalargs == 0) {
|
|
|
|
return _PyObject_Vectorcall(func, &self, 1, NULL);
|
|
|
|
}
|
|
|
|
|
2019-06-18 05:56:53 -03:00
|
|
|
PyObject *newargs_stack[_PY_FASTCALL_SMALL_STACK];
|
2019-07-03 07:54:00 -03:00
|
|
|
PyObject **newargs;
|
2019-06-18 05:56:53 -03:00
|
|
|
if (totalargs <= (Py_ssize_t)Py_ARRAY_LENGTH(newargs_stack) - 1) {
|
|
|
|
newargs = newargs_stack;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
newargs = PyMem_Malloc((totalargs+1) * sizeof(PyObject *));
|
|
|
|
if (newargs == NULL) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-05-29 15:31:52 -03:00
|
|
|
}
|
|
|
|
/* use borrowed references */
|
|
|
|
newargs[0] = self;
|
2019-07-03 07:54:00 -03:00
|
|
|
/* bpo-37138: since totalargs > 0, it's impossible that args is NULL.
|
|
|
|
* We need this, since calling memcpy() with a NULL pointer is
|
|
|
|
* undefined behaviour. */
|
|
|
|
assert(args != NULL);
|
|
|
|
memcpy(newargs + 1, args, totalargs * sizeof(PyObject *));
|
2019-05-29 15:31:52 -03:00
|
|
|
result = _PyObject_Vectorcall(func, newargs, nargs+1, kwnames);
|
2019-06-18 05:56:53 -03:00
|
|
|
if (newargs != newargs_stack) {
|
|
|
|
PyMem_Free(newargs);
|
|
|
|
}
|
2019-05-29 15:31:52 -03:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-27 06:40:20 -04:00
|
|
|
/* Method objects are used for bound instance methods returned by
|
|
|
|
instancename.methodname. ClassName.methodname returns an ordinary
|
|
|
|
function.
|
1993-05-20 11:24:46 -03:00
|
|
|
*/
|
1990-10-14 09:07:46 -03:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
PyObject *
|
2007-11-27 06:40:20 -04:00
|
|
|
PyMethod_New(PyObject *func, PyObject *self)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (self == NULL) {
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
return NULL;
|
|
|
|
}
|
2019-07-26 03:05:50 -03:00
|
|
|
PyMethodObject *im = PyObject_GC_New(PyMethodObject, &PyMethod_Type);
|
|
|
|
if (im == NULL) {
|
|
|
|
return NULL;
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
im->im_weakreflist = NULL;
|
|
|
|
Py_INCREF(func);
|
|
|
|
im->im_func = func;
|
2019-06-16 17:19:19 -03:00
|
|
|
Py_INCREF(self);
|
2010-05-09 12:52:27 -03:00
|
|
|
im->im_self = self;
|
2019-05-29 15:31:52 -03:00
|
|
|
im->vectorcall = method_vectorcall;
|
2010-05-09 12:52:27 -03:00
|
|
|
_PyObject_GC_TRACK(im);
|
|
|
|
return (PyObject *)im;
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
2013-11-23 13:59:12 -04:00
|
|
|
static PyObject *
|
2018-04-29 15:59:33 -03:00
|
|
|
method_reduce(PyMethodObject *im, PyObject *Py_UNUSED(ignored))
|
2013-11-23 13:59:12 -04:00
|
|
|
{
|
|
|
|
PyObject *self = PyMethod_GET_SELF(im);
|
|
|
|
PyObject *func = PyMethod_GET_FUNCTION(im);
|
|
|
|
PyObject *funcname;
|
|
|
|
_Py_IDENTIFIER(getattr);
|
|
|
|
|
|
|
|
funcname = _PyObject_GetAttrId(func, &PyId___name__);
|
|
|
|
if (funcname == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-12-11 02:28:18 -04:00
|
|
|
return Py_BuildValue("N(ON)", _PyEval_GetBuiltinId(&PyId_getattr),
|
|
|
|
self, funcname);
|
2013-11-23 13:59:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyMethodDef method_methods[] = {
|
|
|
|
{"__reduce__", (PyCFunction)method_reduce, METH_NOARGS, NULL},
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
2001-09-18 00:53:24 -03:00
|
|
|
/* Descriptors for PyMethod attributes */
|
|
|
|
|
2007-11-27 06:40:20 -04:00
|
|
|
/* im_func and im_self are stored in the PyMethod object */
|
1990-10-14 09:07:46 -03:00
|
|
|
|
2007-12-11 15:56:40 -04:00
|
|
|
#define MO_OFF(x) offsetof(PyMethodObject, x)
|
1990-12-20 11:06:42 -04:00
|
|
|
|
2006-08-23 21:41:19 -03:00
|
|
|
static PyMemberDef method_memberlist[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
{"__func__", T_OBJECT, MO_OFF(im_func), READONLY|RESTRICTED,
|
|
|
|
"the function (or other callable) implementing a method"},
|
|
|
|
{"__self__", T_OBJECT, MO_OFF(im_self), READONLY|RESTRICTED,
|
|
|
|
"the instance to which a method is bound"},
|
|
|
|
{NULL} /* Sentinel */
|
1990-12-20 11:06:42 -04:00
|
|
|
};
|
|
|
|
|
2003-11-22 19:55:50 -04:00
|
|
|
/* Christian Tismer argued convincingly that method attributes should
|
|
|
|
(nearly) always override function attributes.
|
|
|
|
The one exception is __doc__; there's a default __doc__ which
|
|
|
|
should only be used for the class, not for instances */
|
|
|
|
|
|
|
|
static PyObject *
|
2006-08-23 21:41:19 -03:00
|
|
|
method_get_doc(PyMethodObject *im, void *context)
|
2003-11-22 19:55:50 -04:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
static PyObject *docstr;
|
|
|
|
if (docstr == NULL) {
|
|
|
|
docstr= PyUnicode_InternFromString("__doc__");
|
|
|
|
if (docstr == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyObject_GetAttr(im->im_func, docstr);
|
2003-11-22 19:55:50 -04:00
|
|
|
}
|
|
|
|
|
2006-08-23 21:41:19 -03:00
|
|
|
static PyGetSetDef method_getset[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
{"__doc__", (getter)method_get_doc, NULL, NULL},
|
|
|
|
{0}
|
2003-11-22 19:55:50 -04:00
|
|
|
};
|
2001-01-15 16:40:19 -04:00
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2006-08-23 21:41:19 -03:00
|
|
|
method_getattro(PyObject *obj, PyObject *name)
|
1990-12-20 11:06:42 -04:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyMethodObject *im = (PyMethodObject *)obj;
|
|
|
|
PyTypeObject *tp = obj->ob_type;
|
|
|
|
PyObject *descr = NULL;
|
|
|
|
|
|
|
|
{
|
|
|
|
if (tp->tp_dict == NULL) {
|
|
|
|
if (PyType_Ready(tp) < 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
descr = _PyType_Lookup(tp, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descr != NULL) {
|
|
|
|
descrgetfunc f = TP_DESCR_GET(descr->ob_type);
|
|
|
|
if (f != NULL)
|
|
|
|
return f(descr, obj, (PyObject *)obj->ob_type);
|
|
|
|
else {
|
|
|
|
Py_INCREF(descr);
|
|
|
|
return descr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PyObject_GetAttr(im->im_func, name);
|
1990-12-20 11:06:42 -04:00
|
|
|
}
|
|
|
|
|
2006-08-23 21:41:19 -03:00
|
|
|
PyDoc_STRVAR(method_doc,
|
2007-11-27 06:40:20 -04:00
|
|
|
"method(function, instance)\n\
|
2002-06-14 17:41:17 -03:00
|
|
|
\n\
|
2007-12-11 15:56:40 -04:00
|
|
|
Create a bound instance method object.");
|
2002-06-14 17:41:17 -03:00
|
|
|
|
|
|
|
static PyObject *
|
2006-08-23 21:41:19 -03:00
|
|
|
method_new(PyTypeObject* type, PyObject* args, PyObject *kw)
|
2002-06-14 17:41:17 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyObject *func;
|
|
|
|
PyObject *self;
|
|
|
|
|
|
|
|
if (!_PyArg_NoKeywords("method", kw))
|
|
|
|
return NULL;
|
|
|
|
if (!PyArg_UnpackTuple(args, "method", 2, 2,
|
|
|
|
&func, &self))
|
|
|
|
return NULL;
|
|
|
|
if (!PyCallable_Check(func)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"first argument must be callable");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (self == NULL || self == Py_None) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"self must not be None");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PyMethod_New(func, self);
|
2002-06-14 17:41:17 -03:00
|
|
|
}
|
|
|
|
|
1990-10-14 09:07:46 -03:00
|
|
|
static void
|
2013-08-13 15:18:52 -03:00
|
|
|
method_dealloc(PyMethodObject *im)
|
1990-10-14 09:07:46 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
_PyObject_GC_UNTRACK(im);
|
|
|
|
if (im->im_weakreflist != NULL)
|
|
|
|
PyObject_ClearWeakRefs((PyObject *)im);
|
|
|
|
Py_DECREF(im->im_func);
|
|
|
|
Py_XDECREF(im->im_self);
|
2019-07-26 03:05:50 -03:00
|
|
|
PyObject_GC_Del(im);
|
1990-10-14 09:07:46 -03:00
|
|
|
}
|
|
|
|
|
2006-08-23 21:41:19 -03:00
|
|
|
static PyObject *
|
|
|
|
method_richcompare(PyObject *self, PyObject *other, int op)
|
1992-09-03 17:39:51 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyMethodObject *a, *b;
|
|
|
|
PyObject *res;
|
|
|
|
int eq;
|
|
|
|
|
|
|
|
if ((op != Py_EQ && op != Py_NE) ||
|
|
|
|
!PyMethod_Check(self) ||
|
|
|
|
!PyMethod_Check(other))
|
|
|
|
{
|
2011-08-10 22:28:54 -03:00
|
|
|
Py_RETURN_NOTIMPLEMENTED;
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
a = (PyMethodObject *)self;
|
|
|
|
b = (PyMethodObject *)other;
|
|
|
|
eq = PyObject_RichCompareBool(a->im_func, b->im_func, Py_EQ);
|
|
|
|
if (eq == 1) {
|
2018-07-31 03:18:24 -03:00
|
|
|
eq = (a->im_self == b->im_self);
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
2018-07-31 03:18:24 -03:00
|
|
|
else if (eq < 0)
|
2010-05-09 12:52:27 -03:00
|
|
|
return NULL;
|
|
|
|
if (op == Py_EQ)
|
|
|
|
res = eq ? Py_True : Py_False;
|
|
|
|
else
|
|
|
|
res = eq ? Py_False : Py_True;
|
|
|
|
Py_INCREF(res);
|
|
|
|
return res;
|
1992-09-03 17:39:51 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
static PyObject *
|
2006-08-23 21:41:19 -03:00
|
|
|
method_repr(PyMethodObject *a)
|
1993-05-19 11:50:45 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyObject *self = a->im_self;
|
|
|
|
PyObject *func = a->im_func;
|
2018-01-25 04:49:40 -04:00
|
|
|
PyObject *funcname, *result;
|
2014-08-20 20:41:57 -03:00
|
|
|
const char *defname = "?";
|
2010-05-09 12:52:27 -03:00
|
|
|
|
2018-01-25 04:49:40 -04:00
|
|
|
if (_PyObject_LookupAttrId(func, &PyId___qualname__, &funcname) < 0 ||
|
|
|
|
(funcname == NULL &&
|
|
|
|
_PyObject_LookupAttrId(func, &PyId___name__, &funcname) < 0))
|
|
|
|
{
|
|
|
|
return NULL;
|
2014-08-20 20:41:57 -03:00
|
|
|
}
|
2015-03-18 16:53:15 -03:00
|
|
|
|
2014-08-20 20:41:57 -03:00
|
|
|
if (funcname != NULL && !PyUnicode_Check(funcname)) {
|
|
|
|
Py_DECREF(funcname);
|
|
|
|
funcname = NULL;
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX Shouldn't use repr()/%R here! */
|
2014-08-20 20:41:57 -03:00
|
|
|
result = PyUnicode_FromFormat("<bound method %V of %R>",
|
2010-05-09 12:52:27 -03:00
|
|
|
funcname, defname, self);
|
|
|
|
|
|
|
|
Py_XDECREF(funcname);
|
|
|
|
return result;
|
1993-05-19 11:50:45 -03:00
|
|
|
}
|
|
|
|
|
2010-10-17 17:54:53 -03:00
|
|
|
static Py_hash_t
|
2006-08-23 21:41:19 -03:00
|
|
|
method_hash(PyMethodObject *a)
|
1993-03-29 06:43:31 -04:00
|
|
|
{
|
2010-10-17 17:54:53 -03:00
|
|
|
Py_hash_t x, y;
|
2019-03-05 01:19:34 -04:00
|
|
|
x = _Py_HashPointer(a->im_self);
|
2010-05-09 12:52:27 -03:00
|
|
|
y = PyObject_Hash(a->im_func);
|
|
|
|
if (y == -1)
|
|
|
|
return -1;
|
|
|
|
x = x ^ y;
|
|
|
|
if (x == -1)
|
|
|
|
x = -2;
|
|
|
|
return x;
|
1993-03-29 06:43:31 -04:00
|
|
|
}
|
|
|
|
|
2000-06-23 11:18:11 -03:00
|
|
|
static int
|
2006-08-23 21:41:19 -03:00
|
|
|
method_traverse(PyMethodObject *im, visitproc visit, void *arg)
|
2000-06-23 11:18:11 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_VISIT(im->im_func);
|
|
|
|
Py_VISIT(im->im_self);
|
|
|
|
return 0;
|
2000-06-23 11:18:11 -03:00
|
|
|
}
|
|
|
|
|
2001-08-15 14:52:31 -03:00
|
|
|
static PyObject *
|
2006-08-23 21:41:19 -03:00
|
|
|
method_descr_get(PyObject *meth, PyObject *obj, PyObject *cls)
|
2001-08-15 14:52:31 -03:00
|
|
|
{
|
2019-03-05 01:19:34 -04:00
|
|
|
Py_INCREF(meth);
|
|
|
|
return meth;
|
2001-08-15 14:52:31 -03:00
|
|
|
}
|
|
|
|
|
1997-05-02 00:12:38 -03:00
|
|
|
PyTypeObject PyMethod_Type = {
|
2010-05-09 12:52:27 -03:00
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
"method",
|
|
|
|
sizeof(PyMethodObject),
|
|
|
|
0,
|
|
|
|
(destructor)method_dealloc, /* tp_dealloc */
|
2019-05-29 15:31:52 -03:00
|
|
|
offsetof(PyMethodObject, vectorcall), /* tp_vectorcall_offset */
|
2010-05-09 12:52:27 -03:00
|
|
|
0, /* tp_getattr */
|
|
|
|
0, /* tp_setattr */
|
2019-05-30 23:13:39 -03:00
|
|
|
0, /* tp_as_async */
|
2010-05-09 12:52:27 -03:00
|
|
|
(reprfunc)method_repr, /* tp_repr */
|
|
|
|
0, /* tp_as_number */
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
(hashfunc)method_hash, /* tp_hash */
|
2019-06-18 05:50:28 -03:00
|
|
|
PyVectorcall_Call, /* tp_call */
|
2010-05-09 12:52:27 -03:00
|
|
|
0, /* tp_str */
|
|
|
|
method_getattro, /* tp_getattro */
|
|
|
|
PyObject_GenericSetAttr, /* tp_setattro */
|
|
|
|
0, /* tp_as_buffer */
|
2019-05-29 15:31:52 -03:00
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC |
|
|
|
|
_Py_TPFLAGS_HAVE_VECTORCALL, /* tp_flags */
|
2010-05-09 12:52:27 -03:00
|
|
|
method_doc, /* tp_doc */
|
|
|
|
(traverseproc)method_traverse, /* tp_traverse */
|
|
|
|
0, /* tp_clear */
|
|
|
|
method_richcompare, /* tp_richcompare */
|
|
|
|
offsetof(PyMethodObject, im_weakreflist), /* tp_weaklistoffset */
|
|
|
|
0, /* tp_iter */
|
|
|
|
0, /* tp_iternext */
|
2013-11-23 13:59:12 -04:00
|
|
|
method_methods, /* tp_methods */
|
2010-05-09 12:52:27 -03:00
|
|
|
method_memberlist, /* tp_members */
|
|
|
|
method_getset, /* tp_getset */
|
|
|
|
0, /* tp_base */
|
|
|
|
0, /* tp_dict */
|
|
|
|
method_descr_get, /* tp_descr_get */
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
0, /* tp_init */
|
|
|
|
0, /* tp_alloc */
|
|
|
|
method_new, /* tp_new */
|
1990-10-14 09:07:46 -03:00
|
|
|
};
|
1997-08-04 23:06:53 -03:00
|
|
|
|
|
|
|
/* Clear out the free list */
|
|
|
|
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60790 | raymond.hettinger | 2008-02-14 10:32:45 +0100 (Thu, 14 Feb 2008) | 4 lines
Add diagnostic message to help figure-out why SocketServer tests occasionally crash
when trying to remove a pid that in not in the activechildren list.
........
r60791 | raymond.hettinger | 2008-02-14 11:46:57 +0100 (Thu, 14 Feb 2008) | 1 line
Add fixed-point examples to the decimal FAQ
........
r60792 | raymond.hettinger | 2008-02-14 12:01:10 +0100 (Thu, 14 Feb 2008) | 1 line
Improve rst markup
........
r60794 | raymond.hettinger | 2008-02-14 12:57:25 +0100 (Thu, 14 Feb 2008) | 1 line
Show how to remove exponents.
........
r60795 | raymond.hettinger | 2008-02-14 13:05:42 +0100 (Thu, 14 Feb 2008) | 1 line
Fix markup.
........
r60797 | christian.heimes | 2008-02-14 13:47:33 +0100 (Thu, 14 Feb 2008) | 1 line
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
........
r60798 | raymond.hettinger | 2008-02-14 13:49:37 +0100 (Thu, 14 Feb 2008) | 1 line
Simplify moneyfmt() recipe.
........
r60810 | raymond.hettinger | 2008-02-14 20:02:39 +0100 (Thu, 14 Feb 2008) | 1 line
Fix markup
........
r60811 | raymond.hettinger | 2008-02-14 20:30:30 +0100 (Thu, 14 Feb 2008) | 1 line
No need to register subclass of ABCs.
........
r60814 | thomas.heller | 2008-02-14 22:00:28 +0100 (Thu, 14 Feb 2008) | 1 line
Try to correct a markup error that does hide the following paragraph.
........
r60822 | christian.heimes | 2008-02-14 23:40:11 +0100 (Thu, 14 Feb 2008) | 1 line
Use a static and interned string for __subclasscheck__ and __instancecheck__ as suggested by Thomas Heller in #2115
........
r60827 | christian.heimes | 2008-02-15 07:57:08 +0100 (Fri, 15 Feb 2008) | 1 line
Fixed repr() and str() of complex numbers. Complex suffered from the same problem as floats but I forgot to test and fix them.
........
r60830 | christian.heimes | 2008-02-15 09:20:11 +0100 (Fri, 15 Feb 2008) | 2 lines
Bug #2111: mmap segfaults when trying to write a block opened with PROT_READ
Thanks to Thomas Herve for the fix.
........
r60835 | eric.smith | 2008-02-15 13:14:32 +0100 (Fri, 15 Feb 2008) | 1 line
In PyNumber_ToBase, changed from an assert to returning an error when PyObject_Index() returns something other than an int or long. It should never be possible to trigger this, as PyObject_Index checks to make sure it returns an int or long.
........
r60837 | skip.montanaro | 2008-02-15 20:03:59 +0100 (Fri, 15 Feb 2008) | 8 lines
Two new functions:
* place_summary_first copies the regrtest summary to the front of the file
making it easier to scan quickly for problems.
* count_failures gets the actual count of the number of failing tests, not
just a 1 (some failures) or 0 (no failures).
........
r60840 | raymond.hettinger | 2008-02-15 22:21:25 +0100 (Fri, 15 Feb 2008) | 1 line
Update example to match the current syntax.
........
r60841 | amaury.forgeotdarc | 2008-02-15 22:22:45 +0100 (Fri, 15 Feb 2008) | 8 lines
Issue #2115: __slot__ attributes setting was 10x slower.
Also correct a possible crash using ABCs.
This change is exactly the same as an optimisation
done 5 years ago, but on slot *access*:
http://svn.python.org/view?view=rev&rev=28297
........
r60842 | amaury.forgeotdarc | 2008-02-15 22:27:44 +0100 (Fri, 15 Feb 2008) | 2 lines
Temporarily let these tests pass
........
r60843 | kurt.kaiser | 2008-02-15 22:56:36 +0100 (Fri, 15 Feb 2008) | 2 lines
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
........
r60844 | kurt.kaiser | 2008-02-15 23:25:09 +0100 (Fri, 15 Feb 2008) | 4 lines
Configured selection highlighting colors were ignored; updating highlighting
in the config dialog would cause non-Python files to be colored as if they
were Python source; improve use of ColorDelagator. Patch 1334. Tal Einat.
........
r60845 | amaury.forgeotdarc | 2008-02-15 23:44:20 +0100 (Fri, 15 Feb 2008) | 9 lines
Re-enable tests, they were failing since gc.collect() clears the various freelists.
They still remain fragile.
For example, a call to assertEqual currently does not make any allocation
(which surprised me at first).
But this can change when gc.collect also deletes the numerous "zombie frames"
attached to each function.
........
2008-02-16 03:38:31 -04:00
|
|
|
int
|
|
|
|
PyMethod_ClearFreeList(void)
|
1997-08-04 23:06:53 -03:00
|
|
|
{
|
2019-07-26 03:05:50 -03:00
|
|
|
return 0;
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60790 | raymond.hettinger | 2008-02-14 10:32:45 +0100 (Thu, 14 Feb 2008) | 4 lines
Add diagnostic message to help figure-out why SocketServer tests occasionally crash
when trying to remove a pid that in not in the activechildren list.
........
r60791 | raymond.hettinger | 2008-02-14 11:46:57 +0100 (Thu, 14 Feb 2008) | 1 line
Add fixed-point examples to the decimal FAQ
........
r60792 | raymond.hettinger | 2008-02-14 12:01:10 +0100 (Thu, 14 Feb 2008) | 1 line
Improve rst markup
........
r60794 | raymond.hettinger | 2008-02-14 12:57:25 +0100 (Thu, 14 Feb 2008) | 1 line
Show how to remove exponents.
........
r60795 | raymond.hettinger | 2008-02-14 13:05:42 +0100 (Thu, 14 Feb 2008) | 1 line
Fix markup.
........
r60797 | christian.heimes | 2008-02-14 13:47:33 +0100 (Thu, 14 Feb 2008) | 1 line
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
........
r60798 | raymond.hettinger | 2008-02-14 13:49:37 +0100 (Thu, 14 Feb 2008) | 1 line
Simplify moneyfmt() recipe.
........
r60810 | raymond.hettinger | 2008-02-14 20:02:39 +0100 (Thu, 14 Feb 2008) | 1 line
Fix markup
........
r60811 | raymond.hettinger | 2008-02-14 20:30:30 +0100 (Thu, 14 Feb 2008) | 1 line
No need to register subclass of ABCs.
........
r60814 | thomas.heller | 2008-02-14 22:00:28 +0100 (Thu, 14 Feb 2008) | 1 line
Try to correct a markup error that does hide the following paragraph.
........
r60822 | christian.heimes | 2008-02-14 23:40:11 +0100 (Thu, 14 Feb 2008) | 1 line
Use a static and interned string for __subclasscheck__ and __instancecheck__ as suggested by Thomas Heller in #2115
........
r60827 | christian.heimes | 2008-02-15 07:57:08 +0100 (Fri, 15 Feb 2008) | 1 line
Fixed repr() and str() of complex numbers. Complex suffered from the same problem as floats but I forgot to test and fix them.
........
r60830 | christian.heimes | 2008-02-15 09:20:11 +0100 (Fri, 15 Feb 2008) | 2 lines
Bug #2111: mmap segfaults when trying to write a block opened with PROT_READ
Thanks to Thomas Herve for the fix.
........
r60835 | eric.smith | 2008-02-15 13:14:32 +0100 (Fri, 15 Feb 2008) | 1 line
In PyNumber_ToBase, changed from an assert to returning an error when PyObject_Index() returns something other than an int or long. It should never be possible to trigger this, as PyObject_Index checks to make sure it returns an int or long.
........
r60837 | skip.montanaro | 2008-02-15 20:03:59 +0100 (Fri, 15 Feb 2008) | 8 lines
Two new functions:
* place_summary_first copies the regrtest summary to the front of the file
making it easier to scan quickly for problems.
* count_failures gets the actual count of the number of failing tests, not
just a 1 (some failures) or 0 (no failures).
........
r60840 | raymond.hettinger | 2008-02-15 22:21:25 +0100 (Fri, 15 Feb 2008) | 1 line
Update example to match the current syntax.
........
r60841 | amaury.forgeotdarc | 2008-02-15 22:22:45 +0100 (Fri, 15 Feb 2008) | 8 lines
Issue #2115: __slot__ attributes setting was 10x slower.
Also correct a possible crash using ABCs.
This change is exactly the same as an optimisation
done 5 years ago, but on slot *access*:
http://svn.python.org/view?view=rev&rev=28297
........
r60842 | amaury.forgeotdarc | 2008-02-15 22:27:44 +0100 (Fri, 15 Feb 2008) | 2 lines
Temporarily let these tests pass
........
r60843 | kurt.kaiser | 2008-02-15 22:56:36 +0100 (Fri, 15 Feb 2008) | 2 lines
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
........
r60844 | kurt.kaiser | 2008-02-15 23:25:09 +0100 (Fri, 15 Feb 2008) | 4 lines
Configured selection highlighting colors were ignored; updating highlighting
in the config dialog would cause non-Python files to be colored as if they
were Python source; improve use of ColorDelagator. Patch 1334. Tal Einat.
........
r60845 | amaury.forgeotdarc | 2008-02-15 23:44:20 +0100 (Fri, 15 Feb 2008) | 9 lines
Re-enable tests, they were failing since gc.collect() clears the various freelists.
They still remain fragile.
For example, a call to assertEqual currently does not make any allocation
(which surprised me at first).
But this can change when gc.collect also deletes the numerous "zombie frames"
attached to each function.
........
2008-02-16 03:38:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2019-08-26 19:12:32 -03:00
|
|
|
_PyMethod_Fini(void)
|
Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678,60680-60683,60685-60686,60688,60690,60692-60694,60697-60700,60705-60706,60708,60711,60714,60720,60724-60730,60732,60736,60742,60744,60746,60748,60750-60751,60753,60756-60757,60759-60761,60763-60764,60766,60769-60770,60774-60784,60787-60845 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60790 | raymond.hettinger | 2008-02-14 10:32:45 +0100 (Thu, 14 Feb 2008) | 4 lines
Add diagnostic message to help figure-out why SocketServer tests occasionally crash
when trying to remove a pid that in not in the activechildren list.
........
r60791 | raymond.hettinger | 2008-02-14 11:46:57 +0100 (Thu, 14 Feb 2008) | 1 line
Add fixed-point examples to the decimal FAQ
........
r60792 | raymond.hettinger | 2008-02-14 12:01:10 +0100 (Thu, 14 Feb 2008) | 1 line
Improve rst markup
........
r60794 | raymond.hettinger | 2008-02-14 12:57:25 +0100 (Thu, 14 Feb 2008) | 1 line
Show how to remove exponents.
........
r60795 | raymond.hettinger | 2008-02-14 13:05:42 +0100 (Thu, 14 Feb 2008) | 1 line
Fix markup.
........
r60797 | christian.heimes | 2008-02-14 13:47:33 +0100 (Thu, 14 Feb 2008) | 1 line
Implemented Martin's suggestion to clear the free lists during the garbage collection of the highest generation.
........
r60798 | raymond.hettinger | 2008-02-14 13:49:37 +0100 (Thu, 14 Feb 2008) | 1 line
Simplify moneyfmt() recipe.
........
r60810 | raymond.hettinger | 2008-02-14 20:02:39 +0100 (Thu, 14 Feb 2008) | 1 line
Fix markup
........
r60811 | raymond.hettinger | 2008-02-14 20:30:30 +0100 (Thu, 14 Feb 2008) | 1 line
No need to register subclass of ABCs.
........
r60814 | thomas.heller | 2008-02-14 22:00:28 +0100 (Thu, 14 Feb 2008) | 1 line
Try to correct a markup error that does hide the following paragraph.
........
r60822 | christian.heimes | 2008-02-14 23:40:11 +0100 (Thu, 14 Feb 2008) | 1 line
Use a static and interned string for __subclasscheck__ and __instancecheck__ as suggested by Thomas Heller in #2115
........
r60827 | christian.heimes | 2008-02-15 07:57:08 +0100 (Fri, 15 Feb 2008) | 1 line
Fixed repr() and str() of complex numbers. Complex suffered from the same problem as floats but I forgot to test and fix them.
........
r60830 | christian.heimes | 2008-02-15 09:20:11 +0100 (Fri, 15 Feb 2008) | 2 lines
Bug #2111: mmap segfaults when trying to write a block opened with PROT_READ
Thanks to Thomas Herve for the fix.
........
r60835 | eric.smith | 2008-02-15 13:14:32 +0100 (Fri, 15 Feb 2008) | 1 line
In PyNumber_ToBase, changed from an assert to returning an error when PyObject_Index() returns something other than an int or long. It should never be possible to trigger this, as PyObject_Index checks to make sure it returns an int or long.
........
r60837 | skip.montanaro | 2008-02-15 20:03:59 +0100 (Fri, 15 Feb 2008) | 8 lines
Two new functions:
* place_summary_first copies the regrtest summary to the front of the file
making it easier to scan quickly for problems.
* count_failures gets the actual count of the number of failing tests, not
just a 1 (some failures) or 0 (no failures).
........
r60840 | raymond.hettinger | 2008-02-15 22:21:25 +0100 (Fri, 15 Feb 2008) | 1 line
Update example to match the current syntax.
........
r60841 | amaury.forgeotdarc | 2008-02-15 22:22:45 +0100 (Fri, 15 Feb 2008) | 8 lines
Issue #2115: __slot__ attributes setting was 10x slower.
Also correct a possible crash using ABCs.
This change is exactly the same as an optimisation
done 5 years ago, but on slot *access*:
http://svn.python.org/view?view=rev&rev=28297
........
r60842 | amaury.forgeotdarc | 2008-02-15 22:27:44 +0100 (Fri, 15 Feb 2008) | 2 lines
Temporarily let these tests pass
........
r60843 | kurt.kaiser | 2008-02-15 22:56:36 +0100 (Fri, 15 Feb 2008) | 2 lines
ScriptBinding event handlers weren't returning 'break'. Patch 2050, Tal Einat.
........
r60844 | kurt.kaiser | 2008-02-15 23:25:09 +0100 (Fri, 15 Feb 2008) | 4 lines
Configured selection highlighting colors were ignored; updating highlighting
in the config dialog would cause non-Python files to be colored as if they
were Python source; improve use of ColorDelagator. Patch 1334. Tal Einat.
........
r60845 | amaury.forgeotdarc | 2008-02-15 23:44:20 +0100 (Fri, 15 Feb 2008) | 9 lines
Re-enable tests, they were failing since gc.collect() clears the various freelists.
They still remain fragile.
For example, a call to assertEqual currently does not make any allocation
(which surprised me at first).
But this can change when gc.collect also deletes the numerous "zombie frames"
attached to each function.
........
2008-02-16 03:38:31 -04:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
(void)PyMethod_ClearFreeList();
|
1997-08-04 23:06:53 -03:00
|
|
|
}
|
2007-12-11 15:56:40 -04:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------
|
|
|
|
* instance method
|
|
|
|
*/
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
PyInstanceMethod_New(PyObject *func) {
|
2010-05-09 12:52:27 -03:00
|
|
|
PyInstanceMethodObject *method;
|
|
|
|
method = PyObject_GC_New(PyInstanceMethodObject,
|
|
|
|
&PyInstanceMethod_Type);
|
|
|
|
if (method == NULL) return NULL;
|
|
|
|
Py_INCREF(func);
|
|
|
|
method->func = func;
|
|
|
|
_PyObject_GC_TRACK(method);
|
|
|
|
return (PyObject *)method;
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PyObject *
|
|
|
|
PyInstanceMethod_Function(PyObject *im)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
if (!PyInstanceMethod_Check(im)) {
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyInstanceMethod_GET_FUNCTION(im);
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define IMO_OFF(x) offsetof(PyInstanceMethodObject, x)
|
|
|
|
|
|
|
|
static PyMemberDef instancemethod_memberlist[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
{"__func__", T_OBJECT, IMO_OFF(func), READONLY|RESTRICTED,
|
|
|
|
"the function (or other callable) implementing a method"},
|
|
|
|
{NULL} /* Sentinel */
|
2007-12-11 15:56:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
instancemethod_get_doc(PyObject *self, void *context)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
static PyObject *docstr;
|
|
|
|
if (docstr == NULL) {
|
|
|
|
docstr = PyUnicode_InternFromString("__doc__");
|
|
|
|
if (docstr == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), docstr);
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyGetSetDef instancemethod_getset[] = {
|
2010-05-09 12:52:27 -03:00
|
|
|
{"__doc__", (getter)instancemethod_get_doc, NULL, NULL},
|
|
|
|
{0}
|
2007-12-11 15:56:40 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
instancemethod_getattro(PyObject *self, PyObject *name)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyTypeObject *tp = self->ob_type;
|
|
|
|
PyObject *descr = NULL;
|
|
|
|
|
|
|
|
if (tp->tp_dict == NULL) {
|
|
|
|
if (PyType_Ready(tp) < 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
descr = _PyType_Lookup(tp, name);
|
|
|
|
|
|
|
|
if (descr != NULL) {
|
|
|
|
descrgetfunc f = TP_DESCR_GET(descr->ob_type);
|
|
|
|
if (f != NULL)
|
|
|
|
return f(descr, self, (PyObject *)self->ob_type);
|
|
|
|
else {
|
|
|
|
Py_INCREF(descr);
|
|
|
|
return descr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PyObject_GetAttr(PyInstanceMethod_GET_FUNCTION(self), name);
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
instancemethod_dealloc(PyObject *self) {
|
2010-05-09 12:52:27 -03:00
|
|
|
_PyObject_GC_UNTRACK(self);
|
|
|
|
Py_DECREF(PyInstanceMethod_GET_FUNCTION(self));
|
|
|
|
PyObject_GC_Del(self);
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
instancemethod_traverse(PyObject *self, visitproc visit, void *arg) {
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_VISIT(PyInstanceMethod_GET_FUNCTION(self));
|
|
|
|
return 0;
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
instancemethod_call(PyObject *self, PyObject *arg, PyObject *kw)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
return PyObject_Call(PyMethod_GET_FUNCTION(self), arg, kw);
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
instancemethod_descr_get(PyObject *descr, PyObject *obj, PyObject *type) {
|
2013-08-13 15:18:52 -03:00
|
|
|
PyObject *func = PyInstanceMethod_GET_FUNCTION(descr);
|
2010-05-09 12:52:27 -03:00
|
|
|
if (obj == NULL) {
|
|
|
|
Py_INCREF(func);
|
|
|
|
return func;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return PyMethod_New(func, obj);
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
instancemethod_richcompare(PyObject *self, PyObject *other, int op)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyInstanceMethodObject *a, *b;
|
|
|
|
PyObject *res;
|
|
|
|
int eq;
|
|
|
|
|
|
|
|
if ((op != Py_EQ && op != Py_NE) ||
|
|
|
|
!PyInstanceMethod_Check(self) ||
|
|
|
|
!PyInstanceMethod_Check(other))
|
|
|
|
{
|
2011-08-10 22:28:54 -03:00
|
|
|
Py_RETURN_NOTIMPLEMENTED;
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
|
|
|
a = (PyInstanceMethodObject *)self;
|
|
|
|
b = (PyInstanceMethodObject *)other;
|
|
|
|
eq = PyObject_RichCompareBool(a->func, b->func, Py_EQ);
|
|
|
|
if (eq < 0)
|
|
|
|
return NULL;
|
|
|
|
if (op == Py_EQ)
|
|
|
|
res = eq ? Py_True : Py_False;
|
|
|
|
else
|
|
|
|
res = eq ? Py_False : Py_True;
|
|
|
|
Py_INCREF(res);
|
|
|
|
return res;
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
instancemethod_repr(PyObject *self)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyObject *func = PyInstanceMethod_Function(self);
|
2018-01-25 04:49:40 -04:00
|
|
|
PyObject *funcname, *result;
|
2017-11-11 07:06:26 -04:00
|
|
|
const char *defname = "?";
|
2010-05-09 12:52:27 -03:00
|
|
|
|
|
|
|
if (func == NULL) {
|
|
|
|
PyErr_BadInternalCall();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-01-25 04:49:40 -04:00
|
|
|
if (_PyObject_LookupAttrId(func, &PyId___name__, &funcname) < 0) {
|
|
|
|
return NULL;
|
2010-05-09 12:52:27 -03:00
|
|
|
}
|
2018-01-25 04:49:40 -04:00
|
|
|
if (funcname != NULL && !PyUnicode_Check(funcname)) {
|
2010-05-09 12:52:27 -03:00
|
|
|
Py_DECREF(funcname);
|
|
|
|
funcname = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = PyUnicode_FromFormat("<instancemethod %V at %p>",
|
|
|
|
funcname, defname, self);
|
|
|
|
|
|
|
|
Py_XDECREF(funcname);
|
|
|
|
return result;
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
static long
|
|
|
|
instancemethod_hash(PyObject *self)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
long x, y;
|
|
|
|
x = (long)self;
|
|
|
|
y = PyObject_Hash(PyInstanceMethod_GET_FUNCTION(self));
|
|
|
|
if (y == -1)
|
|
|
|
return -1;
|
|
|
|
x = x ^ y;
|
|
|
|
if (x == -1)
|
|
|
|
x = -2;
|
|
|
|
return x;
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
PyDoc_STRVAR(instancemethod_doc,
|
|
|
|
"instancemethod(function)\n\
|
|
|
|
\n\
|
|
|
|
Bind a function to a class.");
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
instancemethod_new(PyTypeObject* type, PyObject* args, PyObject *kw)
|
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
PyObject *func;
|
|
|
|
|
|
|
|
if (!_PyArg_NoKeywords("instancemethod", kw))
|
|
|
|
return NULL;
|
|
|
|
if (!PyArg_UnpackTuple(args, "instancemethod", 1, 1, &func))
|
|
|
|
return NULL;
|
|
|
|
if (!PyCallable_Check(func)) {
|
|
|
|
PyErr_SetString(PyExc_TypeError,
|
|
|
|
"first argument must be callable");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PyInstanceMethod_New(func);
|
2007-12-11 15:56:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PyTypeObject PyInstanceMethod_Type = {
|
2010-05-09 12:52:27 -03:00
|
|
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
|
|
|
"instancemethod", /* tp_name */
|
|
|
|
sizeof(PyInstanceMethodObject), /* tp_basicsize */
|
|
|
|
0, /* tp_itemsize */
|
|
|
|
instancemethod_dealloc, /* tp_dealloc */
|
2019-05-30 23:13:39 -03:00
|
|
|
0, /* tp_vectorcall_offset */
|
2010-05-09 12:52:27 -03:00
|
|
|
0, /* tp_getattr */
|
|
|
|
0, /* tp_setattr */
|
2019-05-30 23:13:39 -03:00
|
|
|
0, /* tp_as_async */
|
2010-05-09 12:52:27 -03:00
|
|
|
(reprfunc)instancemethod_repr, /* tp_repr */
|
|
|
|
0, /* tp_as_number */
|
|
|
|
0, /* tp_as_sequence */
|
|
|
|
0, /* tp_as_mapping */
|
|
|
|
0, /*(hashfunc)instancemethod_hash, tp_hash */
|
|
|
|
instancemethod_call, /* tp_call */
|
|
|
|
0, /* tp_str */
|
|
|
|
instancemethod_getattro, /* tp_getattro */
|
|
|
|
PyObject_GenericSetAttr, /* tp_setattro */
|
|
|
|
0, /* tp_as_buffer */
|
|
|
|
Py_TPFLAGS_DEFAULT
|
|
|
|
| Py_TPFLAGS_HAVE_GC, /* tp_flags */
|
|
|
|
instancemethod_doc, /* tp_doc */
|
|
|
|
instancemethod_traverse, /* tp_traverse */
|
|
|
|
0, /* tp_clear */
|
|
|
|
instancemethod_richcompare, /* tp_richcompare */
|
|
|
|
0, /* tp_weaklistoffset */
|
|
|
|
0, /* tp_iter */
|
|
|
|
0, /* tp_iternext */
|
|
|
|
0, /* tp_methods */
|
|
|
|
instancemethod_memberlist, /* tp_members */
|
|
|
|
instancemethod_getset, /* tp_getset */
|
|
|
|
0, /* tp_base */
|
|
|
|
0, /* tp_dict */
|
|
|
|
instancemethod_descr_get, /* tp_descr_get */
|
|
|
|
0, /* tp_descr_set */
|
|
|
|
0, /* tp_dictoffset */
|
|
|
|
0, /* tp_init */
|
|
|
|
0, /* tp_alloc */
|
|
|
|
instancemethod_new, /* tp_new */
|
2007-12-11 15:56:40 -04:00
|
|
|
};
|