Back to index

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

Go to the source code of this file.

Classes

struct  classmethod
struct  staticmethod

Defines

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

Functions

PyObjectPyFunction_New (PyObject *code, PyObject *globals)
PyObjectPyFunction_GetCode (PyObject *op)
PyObjectPyFunction_GetGlobals (PyObject *op)
PyObjectPyFunction_GetModule (PyObject *op)
PyObjectPyFunction_GetDefaults (PyObject *op)
int PyFunction_SetDefaults (PyObject *op, PyObject *defaults)
PyObjectPyFunction_GetKwDefaults (PyObject *op)
int PyFunction_SetKwDefaults (PyObject *op, PyObject *defaults)
PyObjectPyFunction_GetClosure (PyObject *op)
int PyFunction_SetClosure (PyObject *op, PyObject *closure)
PyObjectPyFunction_GetAnnotations (PyObject *op)
int PyFunction_SetAnnotations (PyObject *op, PyObject *annotations)
static PyObjectfunc_get_dict (PyFunctionObject *op)
static int func_set_dict (PyFunctionObject *op, PyObject *value)
static PyObjectfunc_get_code (PyFunctionObject *op)
static int func_set_code (PyFunctionObject *op, PyObject *value)
static PyObjectfunc_get_name (PyFunctionObject *op)
static int func_set_name (PyFunctionObject *op, PyObject *value)
static PyObjectfunc_get_defaults (PyFunctionObject *op)
static int func_set_defaults (PyFunctionObject *op, PyObject *value)
static PyObjectfunc_get_kwdefaults (PyFunctionObject *op)
static int func_set_kwdefaults (PyFunctionObject *op, PyObject *value)
static PyObjectfunc_get_annotations (PyFunctionObject *op)
static int func_set_annotations (PyFunctionObject *op, PyObject *value)
 PyDoc_STRVAR (func_doc,"function(code, globals[, name[, argdefs[, closure]]])\n\ \n\ Create a function object from a code object and a dictionary.\n\ The optional name string overrides the name from the code object.\n\ The optional argdefs tuple specifies the default argument values.\n\ The optional closure tuple supplies the bindings for free variables.")
static PyObjectfunc_new (PyTypeObject *type, PyObject *args, PyObject *kw)
static void func_dealloc (PyFunctionObject *op)
static PyObjectfunc_repr (PyFunctionObject *op)
static int func_traverse (PyFunctionObject *f, visitproc visit, void *arg)
static PyObjectfunction_call (PyObject *func, PyObject *arg, PyObject *kw)
static PyObjectfunc_descr_get (PyObject *func, PyObject *obj, PyObject *type)
static void cm_dealloc (classmethod *cm)
static int cm_traverse (classmethod *cm, visitproc visit, void *arg)
static int cm_clear (classmethod *cm)
static PyObjectcm_descr_get (PyObject *self, PyObject *obj, PyObject *type)
static int cm_init (PyObject *self, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR (classmethod_doc,"classmethod(function) -> method\n\ \n\ Convert a function to be a class method.\n\ \n\ A class method receives the class as implicit first argument,\n\ just like an instance method receives the instance.\n\ To declare a class method, use this idiom:\n\ \n\ class C:\n\ def f(cls, arg1, arg2, ...): ...\n\ f = classmethod(f)\n\ \n\ It can be called either on the class (e.g. C.f()) or on an instance\n\ (e.g. C().f()). The instance is ignored except for its class.\n\ If a class method is called for a derived class, the derived class\n\ object is passed as the implied first argument.\n\ \n\ Class methods are different than C++ or Java static methods.\n\ If you want those, see the staticmethod builtin.")
PyObjectPyClassMethod_New (PyObject *callable)
static void sm_dealloc (staticmethod *sm)
static int sm_traverse (staticmethod *sm, visitproc visit, void *arg)
static int sm_clear (staticmethod *sm)
static PyObjectsm_descr_get (PyObject *self, PyObject *obj, PyObject *type)
static int sm_init (PyObject *self, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR (staticmethod_doc,"staticmethod(function) -> method\n\ \n\ Convert a function to be a static method.\n\ \n\ A static method does not receive an implicit first argument.\n\ To declare a static method, use this idiom:\n\ \n\ class C:\n\ def f(arg1, arg2, ...): ...\n\ f = staticmethod(f)\n\ \n\ It can be called either on the class (e.g. C.f()) or on an instance\n\ (e.g. C().f()). The instance is ignored except for its class.\n\ \n\ Static methods in Python are similar to those found in Java or C++.\n\ For a more advanced concept, see the classmethod builtin.")
PyObjectPyStaticMethod_New (PyObject *callable)

Variables

static PyMemberDef func_memberlist []
static PyGetSetDef func_getsetlist []
PyTypeObject PyFunction_Type
static PyMemberDef cm_memberlist []
PyTypeObject PyClassMethod_Type
static PyMemberDef sm_memberlist []
PyTypeObject PyStaticMethod_Type

Define Documentation

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

Definition at line 224 of file funcobject.c.


Function Documentation

static int cm_clear ( classmethod cm) [static]

Definition at line 735 of file funcobject.c.

{
    Py_CLEAR(cm->cm_callable);
    return 0;
}
static void cm_dealloc ( classmethod cm) [static]

Definition at line 720 of file funcobject.c.

{
    _PyObject_GC_UNTRACK((PyObject *)cm);
    Py_XDECREF(cm->cm_callable);
    Py_TYPE(cm)->tp_free((PyObject *)cm);
}
static PyObject* cm_descr_get ( PyObject self,
PyObject obj,
PyObject type 
) [static]

Definition at line 743 of file funcobject.c.

{
    classmethod *cm = (classmethod *)self;

    if (cm->cm_callable == NULL) {
        PyErr_SetString(PyExc_RuntimeError,
                        "uninitialized classmethod object");
        return NULL;
    }
    if (type == NULL)
        type = (PyObject *)(Py_TYPE(obj));
    return PyMethod_New(cm->cm_callable, type);
}

Here is the call graph for this function:

static int cm_init ( PyObject self,
PyObject args,
PyObject kwds 
) [static]

Definition at line 758 of file funcobject.c.

{
    classmethod *cm = (classmethod *)self;
    PyObject *callable;

    if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable))
        return -1;
    if (!_PyArg_NoKeywords("classmethod", kwds))
        return -1;
    Py_INCREF(callable);
    cm->cm_callable = callable;
    return 0;
}

Here is the call graph for this function:

static int cm_traverse ( classmethod cm,
visitproc  visit,
void arg 
) [static]

Definition at line 728 of file funcobject.c.

{
    Py_VISIT(cm->cm_callable);
    return 0;
}
static void func_dealloc ( PyFunctionObject op) [static]
static PyObject* func_descr_get ( PyObject func,
PyObject obj,
PyObject type 
) [static]

Definition at line 644 of file funcobject.c.

{
    if (obj == Py_None || obj == NULL) {
        Py_INCREF(func);
        return func;
    }
    return PyMethod_New(func, obj);
}

Here is the call graph for this function:

static PyObject* func_get_annotations ( PyFunctionObject op) [static]

Definition at line 401 of file funcobject.c.

{
    if (op->func_annotations == NULL) {
        op->func_annotations = PyDict_New();
        if (op->func_annotations == NULL)
            return NULL;
    }
    Py_INCREF(op->func_annotations);
    return op->func_annotations;
}

Here is the call graph for this function:

static PyObject* func_get_code ( PyFunctionObject op) [static]

Definition at line 273 of file funcobject.c.

{
    Py_INCREF(op->func_code);
    return op->func_code;
}
static PyObject* func_get_defaults ( PyFunctionObject op) [static]

Definition at line 337 of file funcobject.c.

{
    if (op->func_defaults == NULL) {
        Py_INCREF(Py_None);
        return Py_None;
    }
    Py_INCREF(op->func_defaults);
    return op->func_defaults;
}
static PyObject* func_get_dict ( PyFunctionObject op) [static]

Definition at line 237 of file funcobject.c.

{
    if (op->func_dict == NULL) {
        op->func_dict = PyDict_New();
        if (op->func_dict == NULL)
            return NULL;
    }
    Py_INCREF(op->func_dict);
    return op->func_dict;
}

Here is the call graph for this function:

static PyObject* func_get_kwdefaults ( PyFunctionObject op) [static]

Definition at line 369 of file funcobject.c.

{
    if (op->func_kwdefaults == NULL) {
        Py_INCREF(Py_None);
        return Py_None;
    }
    Py_INCREF(op->func_kwdefaults);
    return op->func_kwdefaults;
}
static PyObject* func_get_name ( PyFunctionObject op) [static]

Definition at line 311 of file funcobject.c.

{
    Py_INCREF(op->func_name);
    return op->func_name;
}
static PyObject* func_new ( PyTypeObject type,
PyObject args,
PyObject kw 
) [static]

Definition at line 466 of file funcobject.c.

{
    PyCodeObject *code;
    PyObject *globals;
    PyObject *name = Py_None;
    PyObject *defaults = Py_None;
    PyObject *closure = Py_None;
    PyFunctionObject *newfunc;
    Py_ssize_t nfree, nclosure;
    static char *kwlist[] = {"code", "globals", "name",
                             "argdefs", "closure", 0};

    if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!|OOO:function",
                          kwlist,
                          &PyCode_Type, &code,
                          &PyDict_Type, &globals,
                          &name, &defaults, &closure))
        return NULL;
    if (name != Py_None && !PyUnicode_Check(name)) {
        PyErr_SetString(PyExc_TypeError,
                        "arg 3 (name) must be None or string");
        return NULL;
    }
    if (defaults != Py_None && !PyTuple_Check(defaults)) {
        PyErr_SetString(PyExc_TypeError,
                        "arg 4 (defaults) must be None or tuple");
        return NULL;
    }
    nfree = PyTuple_GET_SIZE(code->co_freevars);
    if (!PyTuple_Check(closure)) {
        if (nfree && closure == Py_None) {
            PyErr_SetString(PyExc_TypeError,
                            "arg 5 (closure) must be tuple");
            return NULL;
        }
        else if (closure != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "arg 5 (closure) must be None or tuple");
            return NULL;
        }
    }

    /* check that the closure is well-formed */
    nclosure = closure == Py_None ? 0 : PyTuple_GET_SIZE(closure);
    if (nfree != nclosure)
        return PyErr_Format(PyExc_ValueError,
                            "%U requires closure of length %zd, not %zd",
                            code->co_name, nfree, nclosure);
    if (nclosure) {
        Py_ssize_t i;
        for (i = 0; i < nclosure; i++) {
            PyObject *o = PyTuple_GET_ITEM(closure, i);
            if (!PyCell_Check(o)) {
                return PyErr_Format(PyExc_TypeError,
                    "arg 5 (closure) expected cell, found %s",
                                    o->ob_type->tp_name);
            }
        }
    }

    newfunc = (PyFunctionObject *)PyFunction_New((PyObject *)code,
                                                 globals);
    if (newfunc == NULL)
        return NULL;

    if (name != Py_None) {
        Py_INCREF(name);
        Py_DECREF(newfunc->func_name);
        newfunc->func_name = name;
    }
    if (defaults != Py_None) {
        Py_INCREF(defaults);
        newfunc->func_defaults  = defaults;
    }
    if (closure != Py_None) {
        Py_INCREF(closure);
        newfunc->func_closure = closure;
    }

    return (PyObject *)newfunc;
}

Here is the call graph for this function:

static PyObject* func_repr ( PyFunctionObject op) [static]

Definition at line 568 of file funcobject.c.

{
    return PyUnicode_FromFormat("<function %U at %p>",
                               op->func_name, op);
}
static int func_set_annotations ( PyFunctionObject op,
PyObject value 
) [static]

Definition at line 413 of file funcobject.c.

{
    PyObject *tmp;

    if (value == Py_None)
        value = NULL;
    /* Legal to del f.func_annotations.
     * Can only set func_annotations to NULL (through C api)
     * or a dict. */
    if (value != NULL && !PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
            "__annotations__ must be set to a dict object");
        return -1;
    }
    tmp = op->func_annotations;
    Py_XINCREF(value);
    op->func_annotations = value;
    Py_XDECREF(tmp);
    return 0;
}

Here is the call graph for this function:

static int func_set_code ( PyFunctionObject op,
PyObject value 
) [static]

Definition at line 280 of file funcobject.c.

{
    PyObject *tmp;
    Py_ssize_t nfree, nclosure;

    /* Not legal to del f.func_code or to set it to anything
     * other than a code object. */
    if (value == NULL || !PyCode_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__code__ must be set to a code object");
        return -1;
    }
    nfree = PyCode_GetNumFree((PyCodeObject *)value);
    nclosure = (op->func_closure == NULL ? 0 :
            PyTuple_GET_SIZE(op->func_closure));
    if (nclosure != nfree) {
        PyErr_Format(PyExc_ValueError,
                     "%U() requires a code object with %zd free vars,"
                     " not %zd",
                     op->func_name,
                     nclosure, nfree);
        return -1;
    }
    tmp = op->func_code;
    Py_INCREF(value);
    op->func_code = value;
    Py_DECREF(tmp);
    return 0;
}

Here is the call graph for this function:

static int func_set_defaults ( PyFunctionObject op,
PyObject value 
) [static]

Definition at line 348 of file funcobject.c.

{
    PyObject *tmp;

    /* Legal to del f.func_defaults.
     * Can only set func_defaults to NULL or a tuple. */
    if (value == Py_None)
        value = NULL;
    if (value != NULL && !PyTuple_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__defaults__ must be set to a tuple object");
        return -1;
    }
    tmp = op->func_defaults;
    Py_XINCREF(value);
    op->func_defaults = value;
    Py_XDECREF(tmp);
    return 0;
}

Here is the call graph for this function:

static int func_set_dict ( PyFunctionObject op,
PyObject value 
) [static]

Definition at line 249 of file funcobject.c.

{
    PyObject *tmp;

    /* It is illegal to del f.func_dict */
    if (value == NULL) {
        PyErr_SetString(PyExc_TypeError,
                        "function's dictionary may not be deleted");
        return -1;
    }
    /* Can only set func_dict to a dictionary */
    if (!PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "setting function's dictionary to a non-dict");
        return -1;
    }
    tmp = op->func_dict;
    Py_INCREF(value);
    op->func_dict = value;
    Py_XDECREF(tmp);
    return 0;
}

Here is the call graph for this function:

static int func_set_kwdefaults ( PyFunctionObject op,
PyObject value 
) [static]

Definition at line 380 of file funcobject.c.

{
    PyObject *tmp;

    if (value == Py_None)
        value = NULL;
    /* Legal to del f.func_kwdefaults.
     * Can only set func_kwdefaults to NULL or a dict. */
    if (value != NULL && !PyDict_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
            "__kwdefaults__ must be set to a dict object");
        return -1;
    }
    tmp = op->func_kwdefaults;
    Py_XINCREF(value);
    op->func_kwdefaults = value;
    Py_XDECREF(tmp);
    return 0;
}

Here is the call graph for this function:

static int func_set_name ( PyFunctionObject op,
PyObject value 
) [static]

Definition at line 318 of file funcobject.c.

{
    PyObject *tmp;

    /* Not legal to del f.func_name or to set it to anything
     * other than a string object. */
    if (value == NULL || !PyUnicode_Check(value)) {
        PyErr_SetString(PyExc_TypeError,
                        "__name__ must be set to a string object");
        return -1;
    }
    tmp = op->func_name;
    Py_INCREF(value);
    op->func_name = value;
    Py_DECREF(tmp);
    return 0;
}

Here is the call graph for this function:

static int func_traverse ( PyFunctionObject f,
visitproc  visit,
void arg 
) [static]
static PyObject* function_call ( PyObject func,
PyObject arg,
PyObject kw 
) [static]

Definition at line 591 of file funcobject.c.

{
    PyObject *result;
    PyObject *argdefs;
    PyObject *kwtuple = NULL;
    PyObject **d, **k;
    Py_ssize_t nk, nd;

    argdefs = PyFunction_GET_DEFAULTS(func);
    if (argdefs != NULL && PyTuple_Check(argdefs)) {
        d = &PyTuple_GET_ITEM((PyTupleObject *)argdefs, 0);
        nd = PyTuple_GET_SIZE(argdefs);
    }
    else {
        d = NULL;
        nd = 0;
    }

    if (kw != NULL && PyDict_Check(kw)) {
        Py_ssize_t pos, i;
        nk = PyDict_Size(kw);
        kwtuple = PyTuple_New(2*nk);
        if (kwtuple == NULL)
            return NULL;
        k = &PyTuple_GET_ITEM(kwtuple, 0);
        pos = i = 0;
        while (PyDict_Next(kw, &pos, &k[i], &k[i+1])) {
            Py_INCREF(k[i]);
            Py_INCREF(k[i+1]);
            i += 2;
        }
        nk = i/2;
    }
    else {
        k = NULL;
        nk = 0;
    }

    result = PyEval_EvalCodeEx(
        PyFunction_GET_CODE(func),
        PyFunction_GET_GLOBALS(func), (PyObject *)NULL,
        &PyTuple_GET_ITEM(arg, 0), PyTuple_GET_SIZE(arg),
        k, nk, d, nd,
        PyFunction_GET_KW_DEFAULTS(func),
        PyFunction_GET_CLOSURE(func));

    Py_XDECREF(kwtuple);

    return result;
}

Here is the call graph for this function:

Definition at line 841 of file funcobject.c.

{
    classmethod *cm = (classmethod *)
        PyType_GenericAlloc(&PyClassMethod_Type, 0);
    if (cm != NULL) {
        Py_INCREF(callable);
        cm->cm_callable = callable;
    }
    return (PyObject *)cm;
}

Here is the call graph for this function:

PyDoc_STRVAR ( func_doc  ,
"function(code, globals[, name[, argdefs[, closure]]])\n\\n\Create a function object from a code object and a dictionary.\n\The optional name string overrides the name from the code object.\n\The optional argdefs tuple specifies the default argument values.\n\The optional closure tuple supplies the bindings for free variables."   
)
PyDoc_STRVAR ( classmethod_doc  ,
"classmethod(function) -> method\n\\n\Convert a function to be a class method.\n\\n\A class method receives the class as implicit first  argument,
\n\just like an instance method receives the instance.\n\To declare a class  method,
use this idiom:\n\\n\class C:\n\def f(cls, arg1, arg2,...):...\n\  f = classmethod(f)\n\\n\It can be called either on the class (e.g. C.f()) or on an instance\n\(e.g. C().f()).  The instance is ignored except for its class.\n\If a class method is called for a derived class,
the derived class\n\object is passed as the implied first argument.\n\\n\Class methods are different than C++or Java static methods.\n\If you want  those,
see the staticmethod builtin."   
)
PyDoc_STRVAR ( staticmethod_doc  ,
"staticmethod(function) -> method\n\\n\Convert a function to be a static method.\n\\n\A static method does not receive an implicit first argument.\n\To declare a static  method,
use this idiom:\n\\n\class C:\n\def f(arg1, arg2,...):...\n\  f = staticmethod(f)\n\\n\It can be called either on the class (e.g. C.f()) or on an instance\n\(e.g. C().f()).  The instance is ignored except for its class.\n\\n\Static methods in Python are similar to those found in Java or C++.\n\For a more advanced concept,
see the classmethod builtin."   
)

Definition at line 191 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyFunctionObject *) op) -> func_annotations;
}

Definition at line 158 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyFunctionObject *) op) -> func_closure;
}

Definition at line 65 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyFunctionObject *) op) -> func_code;
}

Definition at line 95 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyFunctionObject *) op) -> func_defaults;
}

Definition at line 75 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyFunctionObject *) op) -> func_globals;
}

Definition at line 126 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyFunctionObject *) op) -> func_kwdefaults;
}

Definition at line 85 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return NULL;
    }
    return ((PyFunctionObject *) op) -> func_module;
}
PyObject* PyFunction_New ( PyObject code,
PyObject globals 
)

Definition at line 9 of file funcobject.c.

{
    PyFunctionObject *op = PyObject_GC_New(PyFunctionObject,
                                        &PyFunction_Type);
    static PyObject *__name__ = 0;
    if (op != NULL) {
        PyObject *doc;
        PyObject *consts;
        PyObject *module;
        op->func_weakreflist = NULL;
        Py_INCREF(code);
        op->func_code = code;
        Py_INCREF(globals);
        op->func_globals = globals;
        op->func_name = ((PyCodeObject *)code)->co_name;
        Py_INCREF(op->func_name);
        op->func_defaults = NULL; /* No default arguments */
        op->func_kwdefaults = NULL; /* No keyword only defaults */
        op->func_closure = NULL;
        consts = ((PyCodeObject *)code)->co_consts;
        if (PyTuple_Size(consts) >= 1) {
            doc = PyTuple_GetItem(consts, 0);
            if (!PyUnicode_Check(doc))
                doc = Py_None;
        }
        else
            doc = Py_None;
        Py_INCREF(doc);
        op->func_doc = doc;
        op->func_dict = NULL;
        op->func_module = NULL;
        op->func_annotations = NULL;

        /* __module__: If module name is in globals, use it.
           Otherwise, use None.
        */
        if (!__name__) {
            __name__ = PyUnicode_InternFromString("__name__");
            if (!__name__) {
                Py_DECREF(op);
                return NULL;
            }
        }
        module = PyDict_GetItem(globals, __name__);
        if (module) {
            Py_INCREF(module);
            op->func_module = module;
        }
    }
    else
        return NULL;
    _PyObject_GC_TRACK(op);
    return (PyObject *)op;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PyFunction_SetAnnotations ( PyObject op,
PyObject annotations 
)

Definition at line 201 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return -1;
    }
    if (annotations == Py_None)
        annotations = NULL;
    else if (annotations && PyDict_Check(annotations)) {
        Py_INCREF(annotations);
    }
    else {
        PyErr_SetString(PyExc_SystemError,
                        "non-dict annotations");
        return -1;
    }
    Py_XDECREF(((PyFunctionObject *)op) -> func_annotations);
    ((PyFunctionObject *) op) -> func_annotations = annotations;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PyFunction_SetClosure ( PyObject op,
PyObject closure 
)

Definition at line 168 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return -1;
    }
    if (closure == Py_None)
        closure = NULL;
    else if (PyTuple_Check(closure)) {
        Py_INCREF(closure);
    }
    else {
        PyErr_Format(PyExc_SystemError,
                     "expected tuple for closure, got '%.100s'",
                     closure->ob_type->tp_name);
        return -1;
    }
    Py_XDECREF(((PyFunctionObject *) op) -> func_closure);
    ((PyFunctionObject *) op) -> func_closure = closure;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PyFunction_SetDefaults ( PyObject op,
PyObject defaults 
)

Definition at line 105 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return -1;
    }
    if (defaults == Py_None)
        defaults = NULL;
    else if (defaults && PyTuple_Check(defaults)) {
        Py_INCREF(defaults);
    }
    else {
        PyErr_SetString(PyExc_SystemError, "non-tuple default args");
        return -1;
    }
    Py_XDECREF(((PyFunctionObject *) op) -> func_defaults);
    ((PyFunctionObject *) op) -> func_defaults = defaults;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int PyFunction_SetKwDefaults ( PyObject op,
PyObject defaults 
)

Definition at line 136 of file funcobject.c.

{
    if (!PyFunction_Check(op)) {
        PyErr_BadInternalCall();
        return -1;
    }
    if (defaults == Py_None)
        defaults = NULL;
    else if (defaults && PyDict_Check(defaults)) {
        Py_INCREF(defaults);
    }
    else {
        PyErr_SetString(PyExc_SystemError,
                        "non-dict keyword only default args");
        return -1;
    }
    Py_XDECREF(((PyFunctionObject *)op) -> func_kwdefaults);
    ((PyFunctionObject *) op) -> func_kwdefaults = defaults;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 993 of file funcobject.c.

{
    staticmethod *sm = (staticmethod *)
        PyType_GenericAlloc(&PyStaticMethod_Type, 0);
    if (sm != NULL) {
        Py_INCREF(callable);
        sm->sm_callable = callable;
    }
    return (PyObject *)sm;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int sm_clear ( staticmethod sm) [static]

Definition at line 890 of file funcobject.c.

{
    Py_XDECREF(sm->sm_callable);
    sm->sm_callable = NULL;

    return 0;
}
static void sm_dealloc ( staticmethod sm) [static]

Definition at line 875 of file funcobject.c.

{
    _PyObject_GC_UNTRACK((PyObject *)sm);
    Py_XDECREF(sm->sm_callable);
    Py_TYPE(sm)->tp_free((PyObject *)sm);
}
static PyObject* sm_descr_get ( PyObject self,
PyObject obj,
PyObject type 
) [static]

Definition at line 899 of file funcobject.c.

{
    staticmethod *sm = (staticmethod *)self;

    if (sm->sm_callable == NULL) {
        PyErr_SetString(PyExc_RuntimeError,
                        "uninitialized staticmethod object");
        return NULL;
    }
    Py_INCREF(sm->sm_callable);
    return sm->sm_callable;
}

Here is the call graph for this function:

static int sm_init ( PyObject self,
PyObject args,
PyObject kwds 
) [static]

Definition at line 913 of file funcobject.c.

{
    staticmethod *sm = (staticmethod *)self;
    PyObject *callable;

    if (!PyArg_UnpackTuple(args, "staticmethod", 1, 1, &callable))
        return -1;
    if (!_PyArg_NoKeywords("staticmethod", kwds))
        return -1;
    Py_INCREF(callable);
    sm->sm_callable = callable;
    return 0;
}

Here is the call graph for this function:

static int sm_traverse ( staticmethod sm,
visitproc  visit,
void arg 
) [static]

Definition at line 883 of file funcobject.c.

{
    Py_VISIT(sm->sm_callable);
    return 0;
}

Variable Documentation

Initial value:
 {
    {"__func__", T_OBJECT, offsetof(classmethod, cm_callable), READONLY},
    {NULL}  
}

Definition at line 772 of file funcobject.c.

Initial value:

Definition at line 434 of file funcobject.c.

Initial value:
 {
    {"__closure__",   T_OBJECT,     OFF(func_closure),
     RESTRICTED|READONLY},
    {"__doc__",       T_OBJECT,     OFF(func_doc), PY_WRITE_RESTRICTED},
    {"__globals__",   T_OBJECT,     OFF(func_globals),
     RESTRICTED|READONLY},
    {"__module__",    T_OBJECT,     OFF(func_module), PY_WRITE_RESTRICTED},
    {NULL}  
}

Definition at line 226 of file funcobject.c.

Definition at line 798 of file funcobject.c.

Definition at line 653 of file funcobject.c.

Definition at line 950 of file funcobject.c.

Initial value:
 {
    {"__func__", T_OBJECT, offsetof(staticmethod, sm_callable), READONLY},
    {NULL}  
}

Definition at line 927 of file funcobject.c.