power of explicit self?
Fire Crow
me at firecrow.com
Sat Dec 12 15:20:06 EST 2009
> It's not implemented in the compiler. There's a place in the runtime
> for invoking a method where the object is inserted at the beginning
> of the parameter list. IIRC, that's done by wrapping the function
> object.
This is the source of Objects/methodobject.c it look like this is
where
self is added to the argument list, but I'll have to do some more
digging.
thanks for the tip.
50 PyObject *
51 PyCFunction_GetSelf(PyObject *op)
52 {
53 if (!PyCFunction_Check(op)) {
54 PyErr_BadInternalCall();
55 return NULL;
56 }
57 return ((PyCFunctionObject *)op) -> m_self;
58 }
....
69
70 PyObject *
71 PyCFunction_Call(PyObject *func, PyObject *arg, PyObject *kw)
72 {
...
75 PyObject *self = PyCFunction_GET_SELF(func);
...
78 switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS |
METH_STATIC |
METH_COEXIST)) {
79 case METH_VARARGS:
80 if (kw == NULL || PyDict_Size(kw) == 0)
81 return (*meth)(self, arg);
82 break;
83 case METH_VARARGS | METH_KEYWORDS:
...
126 }
More information about the Python-list
mailing list