Back to index

python3.2  3.2.2
Defines | Functions | Variables
methodobject.c File Reference
#include "Python.h"
#include "structmember.h"

Go to the source code of this file.

Defines

#define PyCFunction_MAXFREELIST   256
#define OFF(x)   offsetof(PyCFunctionObject, x)

Functions

PyObjectPyCFunction_NewEx (PyMethodDef *ml, PyObject *self, PyObject *module)
PyCFunction PyCFunction_GetFunction (PyObject *op)
PyObjectPyCFunction_GetSelf (PyObject *op)
int PyCFunction_GetFlags (PyObject *op)
PyObjectPyCFunction_Call (PyObject *func, PyObject *arg, PyObject *kw)
static void meth_dealloc (PyCFunctionObject *m)
static PyObjectmeth_get__doc__ (PyCFunctionObject *m, void *closure)
static PyObjectmeth_get__name__ (PyCFunctionObject *m, void *closure)
static int meth_traverse (PyCFunctionObject *m, visitproc visit, void *arg)
static PyObjectmeth_get__self__ (PyCFunctionObject *m, void *closure)
static PyObjectmeth_repr (PyCFunctionObject *m)
static PyObjectmeth_richcompare (PyObject *self, PyObject *other, int op)
static Py_hash_t meth_hash (PyCFunctionObject *a)
int PyCFunction_ClearFreeList (void)
void PyCFunction_Fini (void)
 PyAPI_FUNC (PyObject *)

Variables

static PyCFunctionObjectfree_list = NULL
static int numfree = 0
static PyGetSetDef meth_getsets []
static PyMemberDef meth_members []
PyTypeObject PyCFunction_Type

Define Documentation

#define OFF (   x)    offsetof(PyCFunctionObject, x)

Definition at line 181 of file methodobject.c.

#define PyCFunction_MAXFREELIST   256

Definition at line 13 of file methodobject.c.


Function Documentation

static void meth_dealloc ( PyCFunctionObject m) [static]

Definition at line 122 of file methodobject.c.

Here is the call graph for this function:

static PyObject* meth_get__doc__ ( PyCFunctionObject m,
void closure 
) [static]

Definition at line 138 of file methodobject.c.

{
    const char *doc = m->m_ml->ml_doc;

    if (doc != NULL)
        return PyUnicode_FromString(doc);
    Py_INCREF(Py_None);
    return Py_None;
}

Here is the call graph for this function:

static PyObject* meth_get__name__ ( PyCFunctionObject m,
void closure 
) [static]

Definition at line 149 of file methodobject.c.

Here is the call graph for this function:

static PyObject* meth_get__self__ ( PyCFunctionObject m,
void closure 
) [static]

Definition at line 163 of file methodobject.c.

{
    PyObject *self;

    self = m->m_self;
    if (self == NULL)
        self = Py_None;
    Py_INCREF(self);
    return self;
}
static Py_hash_t meth_hash ( PyCFunctionObject a) [static]

Definition at line 228 of file methodobject.c.

{
    Py_hash_t x, y;
    if (a->m_self == NULL)
        x = 0;
    else {
        x = PyObject_Hash(a->m_self);
        if (x == -1)
            return -1;
    }
    y = _Py_HashPointer((void*)(a->m_ml->ml_meth));
    if (y == -1)
        return -1;
    x ^= y;
    if (x == -1)
        x = -2;
    return x;
}

Here is the call graph for this function:

static PyObject* meth_repr ( PyCFunctionObject m) [static]

Definition at line 189 of file methodobject.c.

{
    if (m->m_self == NULL || PyModule_Check(m->m_self))
        return PyUnicode_FromFormat("<built-in function %s>",
                                   m->m_ml->ml_name);
    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 PyObject* meth_richcompare ( PyObject self,
PyObject other,
int  op 
) [static]

Definition at line 201 of file methodobject.c.

{
    PyCFunctionObject *a, *b;
    PyObject *res;
    int eq;

    if ((op != Py_EQ && op != Py_NE) ||
        !PyCFunction_Check(self) ||
        !PyCFunction_Check(other))
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    a = (PyCFunctionObject *)self;
    b = (PyCFunctionObject *)other;
    eq = a->m_self == b->m_self;
    if (eq)
        eq = a->m_ml->ml_meth == b->m_ml->ml_meth;
    if (op == Py_EQ)
        res = eq ? Py_True : Py_False;
    else
        res = eq ? Py_False : Py_True;
    Py_INCREF(res);
    return res;
}
static int meth_traverse ( PyCFunctionObject m,
visitproc  visit,
void arg 
) [static]

Definition at line 155 of file methodobject.c.

{
    Py_VISIT(m->m_self);
    Py_VISIT(m->m_module);
    return 0;
}
PyAPI_FUNC ( PyObject ) [read]

Definition at line 312 of file methodobject.c.

{
    return PyCFunction_NewEx(ml, self, NULL);
}

Here is the call graph for this function:

PyObject* PyCFunction_Call ( PyObject func,
PyObject arg,
PyObject kw 
)

Definition at line 71 of file methodobject.c.

{
    PyCFunctionObject* f = (PyCFunctionObject*)func;
    PyCFunction meth = PyCFunction_GET_FUNCTION(func);
    PyObject *self = PyCFunction_GET_SELF(func);
    Py_ssize_t size;

    switch (PyCFunction_GET_FLAGS(func) & ~(METH_CLASS | METH_STATIC | METH_COEXIST)) {
    case METH_VARARGS:
        if (kw == NULL || PyDict_Size(kw) == 0)
            return (*meth)(self, arg);
        break;
    case METH_VARARGS | METH_KEYWORDS:
        return (*(PyCFunctionWithKeywords)meth)(self, arg, kw);
    case METH_NOARGS:
        if (kw == NULL || PyDict_Size(kw) == 0) {
            size = PyTuple_GET_SIZE(arg);
            if (size == 0)
                return (*meth)(self, NULL);
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes no arguments (%zd given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    case METH_O:
        if (kw == NULL || PyDict_Size(kw) == 0) {
            size = PyTuple_GET_SIZE(arg);
            if (size == 1)
                return (*meth)(self, PyTuple_GET_ITEM(arg, 0));
            PyErr_Format(PyExc_TypeError,
                "%.200s() takes exactly one argument (%zd given)",
                f->m_ml->ml_name, size);
            return NULL;
        }
        break;
    default:
        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",
                 f->m_ml->ml_name);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 286 of file methodobject.c.

{
    int freelist_size = numfree;

    while (free_list) {
        PyCFunctionObject *v = free_list;
        free_list = (PyCFunctionObject *)(v->m_self);
        PyObject_GC_Del(v);
        numfree--;
    }
    assert(numfree == 0);
    return freelist_size;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 301 of file methodobject.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 61 of file methodobject.c.

{
    if (!PyCFunction_Check(op)) {
        PyErr_BadInternalCall();
        return -1;
    }
    return ((PyCFunctionObject *)op) -> m_ml -> ml_flags;
}

Definition at line 41 of file methodobject.c.

{
    if (!PyCFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyCFunctionObject *)op) -> m_ml -> ml_meth;
}

Here is the caller graph for this function:

Definition at line 51 of file methodobject.c.

{
    if (!PyCFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyCFunctionObject *)op) -> m_self;
}
PyObject* PyCFunction_NewEx ( PyMethodDef ml,
PyObject self,
PyObject module 
)

Definition at line 17 of file methodobject.c.

{
    PyCFunctionObject *op;
    op = free_list;
    if (op != NULL) {
        free_list = (PyCFunctionObject *)(op->m_self);
        PyObject_INIT(op, &PyCFunction_Type);
        numfree--;
    }
    else {
        op = PyObject_GC_New(PyCFunctionObject, &PyCFunction_Type);
        if (op == NULL)
            return NULL;
    }
    op->m_ml = ml;
    Py_XINCREF(self);
    op->m_self = self;
    Py_XINCREF(module);
    op->m_module = module;
    _PyObject_GC_TRACK(op);
    return (PyObject *)op;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 10 of file methodobject.c.

Initial value:
 {
    {"__doc__",  (getter)meth_get__doc__,  NULL, NULL},
    {"__name__", (getter)meth_get__name__, NULL, NULL},
    {"__self__", (getter)meth_get__self__, NULL, NULL},
    {0}
}

Definition at line 174 of file methodobject.c.

Initial value:
 {
    {"__module__",    T_OBJECT,     OFF(m_module), PY_WRITE_RESTRICTED},
    {NULL}
}

Definition at line 183 of file methodobject.c.

int numfree = 0 [static]

Definition at line 11 of file methodobject.c.

Definition at line 248 of file methodobject.c.