Back to index

python3.2  3.2.2
Classes | Defines | Typedefs | Functions | Variables
typeobject.c File Reference
#include "Python.h"
#include "frameobject.h"
#include "structmember.h"
#include <ctype.h>
#include "typeslots.inc"

Go to the source code of this file.

Classes

struct  method_cache_entry
struct  superobject

Defines

#define MCACHE_MAX_ATTR_SIZE   100
#define MCACHE_SIZE_EXP   10
#define MCACHE_HASH(version, name_hash)
#define MCACHE_HASH_METHOD(type, name)
#define MCACHE_CACHEABLE_NAME(name)
#define COPYVAL(SLOT)   if (type->SLOT == 0) type->SLOT = base->SLOT
#define SLOTDEFINED(SLOT)
#define COPYSLOT(SLOT)   if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
#define COPYNUM(SLOT)   COPYSLOT(tp_as_number->SLOT)
#define COPYSEQ(SLOT)   COPYSLOT(tp_as_sequence->SLOT)
#define COPYMAP(SLOT)   COPYSLOT(tp_as_mapping->SLOT)
#define COPYBUF(SLOT)   COPYSLOT(tp_as_buffer->SLOT)
#define RICHCMP_WRAPPER(NAME, OP)
#define SLOT0(FUNCNAME, OPSTR)
#define SLOT1(FUNCNAME, OPSTR, ARG1TYPE, ARGCODES)
#define SLOT1BINFULL(FUNCNAME, TESTFUNC, SLOTNAME, OPSTR, ROPSTR)
#define SLOT1BIN(FUNCNAME, SLOTNAME, OPSTR, ROPSTR)   SLOT1BINFULL(FUNCNAME, FUNCNAME, SLOTNAME, OPSTR, ROPSTR)
#define SLOT2(FUNCNAME, OPSTR, ARG1TYPE, ARG2TYPE, ARGCODES)
#define slot_mp_length   slot_sq_length
#define TPSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC)
#define FLSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC, FLAGS)
#define ETSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC)
#define SQSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC)   ETSLOT(NAME, as_sequence.SLOT, FUNCTION, WRAPPER, DOC)
#define MPSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC)   ETSLOT(NAME, as_mapping.SLOT, FUNCTION, WRAPPER, DOC)
#define NBSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC)   ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, DOC)
#define UNSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC)
#define IBSLOT(NAME, SLOT, FUNCTION, WRAPPER, DOC)
#define BINSLOT(NAME, SLOT, FUNCTION, DOC)
#define RBINSLOT(NAME, SLOT, FUNCTION, DOC)
#define BINSLOTNOTINFIX(NAME, SLOT, FUNCTION, DOC)
#define RBINSLOTNOTINFIX(NAME, SLOT, FUNCTION, DOC)
#define MAX_EQUIV   10

Typedefs

typedef int(* update_callback )(PyTypeObject *, void *)
typedef struct wrapperbase

Functions

unsigned int PyType_ClearCache (void)
void PyType_Modified (PyTypeObject *type)
static void type_mro_modified (PyTypeObject *type, PyObject *bases)
static int assign_version_tag (PyTypeObject *type)
static PyObjecttype_name (PyTypeObject *type, void *context)
static int type_set_name (PyTypeObject *type, PyObject *value, void *context)
static PyObjecttype_module (PyTypeObject *type, void *context)
static int type_set_module (PyTypeObject *type, PyObject *value, void *context)
static PyObjecttype_abstractmethods (PyTypeObject *type, void *context)
static int type_set_abstractmethods (PyTypeObject *type, PyObject *value, void *context)
static PyObjecttype_get_bases (PyTypeObject *type, void *context)
static PyTypeObjectbest_base (PyObject *)
static int mro_internal (PyTypeObject *)
static int compatible_for_assignment (PyTypeObject *, PyTypeObject *, char *)
static int add_subclass (PyTypeObject *, PyTypeObject *)
static void remove_subclass (PyTypeObject *, PyTypeObject *)
static void update_all_slots (PyTypeObject *)
static int update_subclasses (PyTypeObject *type, PyObject *name, update_callback callback, void *data)
static int recurse_down_subclasses (PyTypeObject *type, PyObject *name, update_callback callback, void *data)
static int mro_subclasses (PyTypeObject *type, PyObject *temp)
static int type_set_bases (PyTypeObject *type, PyObject *value, void *context)
static PyObjecttype_dict (PyTypeObject *type, void *context)
static PyObjecttype_get_doc (PyTypeObject *type, void *context)
static PyObjecttype___instancecheck__ (PyObject *type, PyObject *inst)
static PyObjecttype___subclasscheck__ (PyObject *type, PyObject *inst)
static PyObjecttype_repr (PyTypeObject *type)
static PyObjecttype_call (PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObjectPyType_GenericAlloc (PyTypeObject *type, Py_ssize_t nitems)
PyObjectPyType_GenericNew (PyTypeObject *type, PyObject *args, PyObject *kwds)
static int traverse_slots (PyTypeObject *type, PyObject *self, visitproc visit, void *arg)
static int subtype_traverse (PyObject *self, visitproc visit, void *arg)
static void clear_slots (PyTypeObject *type, PyObject *self)
static int subtype_clear (PyObject *self)
static void subtype_dealloc (PyObject *self)
static PyTypeObjectsolid_base (PyTypeObject *type)
int PyType_IsSubtype (PyTypeObject *a, PyTypeObject *b)
static PyObjectlookup_maybe (PyObject *self, char *attrstr, PyObject **attrobj)
static PyObjectlookup_method (PyObject *self, char *attrstr, PyObject **attrobj)
PyObject_PyObject_LookupSpecial (PyObject *self, char *attrstr, PyObject **attrobj)
static PyObjectcall_method (PyObject *o, char *name, PyObject **nameobj, char *format,...)
static PyObjectcall_maybe (PyObject *o, char *name, PyObject **nameobj, char *format,...)
static int tail_contains (PyObject *list, int whence, PyObject *o)
static PyObjectclass_name (PyObject *cls)
static int check_duplicates (PyObject *list)
static void set_mro_error (PyObject *to_merge, int *remain)
static int pmerge (PyObject *acc, PyObject *to_merge)
static PyObjectmro_implementation (PyTypeObject *type)
static PyObjectmro_external (PyObject *self)
static int extra_ivars (PyTypeObject *type, PyTypeObject *base)
static void object_dealloc (PyObject *)
static int object_init (PyObject *, PyObject *, PyObject *)
static int update_slot (PyTypeObject *, PyObject *)
static void fixup_slot_dispatchers (PyTypeObject *)
static PyTypeObjectget_builtin_base_with_dict (PyTypeObject *type)
static PyObjectget_dict_descriptor (PyTypeObject *type)
static void raise_dict_descr_error (PyObject *obj)
static PyObjectsubtype_dict (PyObject *obj, void *context)
static int subtype_setdict (PyObject *obj, PyObject *value, void *context)
static PyObjectsubtype_getweakref (PyObject *obj, void *context)
static int valid_identifier (PyObject *s)
static int type_init (PyObject *cls, PyObject *args, PyObject *kwds)
long PyType_GetFlags (PyTypeObject *type)
static PyObjecttype_new (PyTypeObject *metatype, PyObject *args, PyObject *kwds)
PyObjectPyType_FromSpec (PyType_Spec *spec)
PyObject_PyType_Lookup (PyTypeObject *type, PyObject *name)
static PyObjecttype_getattro (PyTypeObject *type, PyObject *name)
static int type_setattro (PyTypeObject *type, PyObject *name, PyObject *value)
static void type_dealloc (PyTypeObject *type)
static PyObjecttype_subclasses (PyTypeObject *type, PyObject *args_ignored)
static PyObjecttype_prepare (PyObject *self, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR (type_doc,"type(object) -> the object's type\n""type(name, bases, dict) -> a new type")
static int type_traverse (PyTypeObject *type, visitproc visit, void *arg)
static int type_clear (PyTypeObject *type)
static int type_is_gc (PyTypeObject *type)
static PyObjectobject_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
static int excess_args (PyObject *args, PyObject *kwds)
static PyObjectobject_repr (PyObject *self)
static PyObjectobject_str (PyObject *self)
static PyObjectobject_richcompare (PyObject *self, PyObject *other, int op)
static PyObjectobject_get_class (PyObject *self, void *closure)
static int equiv_structs (PyTypeObject *a, PyTypeObject *b)
static int same_slots_added (PyTypeObject *a, PyTypeObject *b)
static int object_set_class (PyObject *self, PyObject *value, void *closure)
static PyObjectimport_copyreg (void)
static PyObjectslotnames (PyObject *cls)
static PyObjectreduce_2 (PyObject *obj)
static PyObject_common_reduce (PyObject *self, int proto)
static PyObjectobject_reduce (PyObject *self, PyObject *args)
static PyObjectobject_reduce_ex (PyObject *self, PyObject *args)
static PyObjectobject_subclasshook (PyObject *cls, PyObject *args)
 PyDoc_STRVAR (object_subclasshook_doc,"Abstract classes can override this to customize issubclass().\n""\n""This is invoked early on by abc.ABCMeta.__subclasscheck__().\n""It should return True, False or NotImplemented. If it returns\n""NotImplemented, the normal algorithm is used. Otherwise, it\n""overrides the normal algorithm (and the outcome is cached).\n")
static PyObjectobject_format (PyObject *self, PyObject *args)
static PyObjectobject_sizeof (PyObject *self, PyObject *args)
static int add_methods (PyTypeObject *type, PyMethodDef *meth)
static int add_members (PyTypeObject *type, PyMemberDef *memb)
static int add_getset (PyTypeObject *type, PyGetSetDef *gsp)
static void inherit_special (PyTypeObject *type, PyTypeObject *base)
static int overrides_hash (PyTypeObject *type)
static void inherit_slots (PyTypeObject *type, PyTypeObject *base)
static int add_operators (PyTypeObject *)
int PyType_Ready (PyTypeObject *type)
static int check_num_args (PyObject *ob, int n)
static PyObjectwrap_lenfunc (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_inquirypred (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_binaryfunc (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_binaryfunc_l (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_binaryfunc_r (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_ternaryfunc (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_ternaryfunc_r (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_unaryfunc (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_indexargfunc (PyObject *self, PyObject *args, void *wrapped)
static Py_ssize_t getindex (PyObject *self, PyObject *arg)
static PyObjectwrap_sq_item (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_sq_setitem (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_sq_delitem (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_objobjproc (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_objobjargproc (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_delitem (PyObject *self, PyObject *args, void *wrapped)
static int hackcheck (PyObject *self, setattrofunc func, char *what)
static PyObjectwrap_setattr (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_delattr (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_hashfunc (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_call (PyObject *self, PyObject *args, void *wrapped, PyObject *kwds)
static PyObjectwrap_richcmpfunc (PyObject *self, PyObject *args, void *wrapped, int op)
static PyObjectwrap_next (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_descr_get (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_descr_set (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_descr_delete (PyObject *self, PyObject *args, void *wrapped)
static PyObjectwrap_init (PyObject *self, PyObject *args, void *wrapped, PyObject *kwds)
static PyObjecttp_new_wrapper (PyObject *self, PyObject *args, PyObject *kwds)
static int add_tp_new_wrapper (PyTypeObject *type)
static int method_is_overloaded (PyObject *left, PyObject *right, char *name)
static Py_ssize_t slot_sq_length (PyObject *self)
static PyObjectslot_sq_item (PyObject *self, Py_ssize_t i)
static int slot_sq_ass_item (PyObject *self, Py_ssize_t index, PyObject *value)
static int slot_sq_contains (PyObject *self, PyObject *value)
static int slot_mp_ass_subscript (PyObject *self, PyObject *key, PyObject *value)
static PyObjectslot_nb_power (PyObject *, PyObject *, PyObject *)
 SLOT1BINFULL (slot_nb_power_binary, slot_nb_power, nb_power,"__pow__","__rpow__")
static int slot_nb_bool (PyObject *self)
static PyObjectslot_nb_index (PyObject *self)
static PyObjectslot_nb_inplace_power (PyObject *self, PyObject *arg1, PyObject *arg2)
 SLOT1BIN (slot_nb_floor_divide, nb_floor_divide,"__floordiv__","__rfloordiv__")
static PyObjectslot_tp_str (PyObject *self)
static Py_hash_t slot_tp_hash (PyObject *self)
static PyObjectslot_tp_call (PyObject *self, PyObject *args, PyObject *kwds)
static PyObjectslot_tp_getattro (PyObject *self, PyObject *name)
static PyObjectcall_attribute (PyObject *self, PyObject *attr, PyObject *name)
static PyObjectslot_tp_getattr_hook (PyObject *self, PyObject *name)
static int slot_tp_setattro (PyObject *self, PyObject *name, PyObject *value)
static PyObjectslot_tp_richcompare (PyObject *self, PyObject *other, int op)
static PyObjectslot_tp_iter (PyObject *self)
static PyObjectslot_tp_iternext (PyObject *self)
static PyObjectslot_tp_descr_get (PyObject *self, PyObject *obj, PyObject *type)
static int slot_tp_descr_set (PyObject *self, PyObject *target, PyObject *value)
static int slot_tp_init (PyObject *self, PyObject *args, PyObject *kwds)
static PyObjectslot_tp_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
static void slot_tp_del (PyObject *self)
static void ** slotptr (PyTypeObject *type, int ioffset)
static void ** resolve_slotdups (PyTypeObject *type, PyObject *name)
static slotdef * update_one_slot (PyTypeObject *type, slotdef *p)
static int update_slots_callback (PyTypeObject *type, void *data)
static int slotdef_cmp (const void *aa, const void *bb)
static void init_slotdefs (void)
static void super_dealloc (PyObject *self)
static PyObjectsuper_repr (PyObject *self)
static PyObjectsuper_getattro (PyObject *self, PyObject *name)
static PyTypeObjectsupercheck (PyTypeObject *type, PyObject *obj)
static PyObjectsuper_descr_get (PyObject *self, PyObject *obj, PyObject *type)
static int super_init (PyObject *self, PyObject *args, PyObject *kwds)
 PyDoc_STRVAR (super_doc,"super() -> same as super(__class__, <first argument>)\n""super(type) -> unbound super object\n""super(type, obj) -> bound super object; requires isinstance(obj, type)\n""super(type, type2) -> bound super object; requires issubclass(type2, type)\n""Typical use to call a cooperative superclass method:\n""class C(B):\n"" def meth(self, arg):\n"" super().meth(arg)\n""This works for class methods too:\n""class C(B):\n"" @classmethod\n"" def cmeth(cls, arg):\n"" super().cmeth(arg)\n")
static int super_traverse (PyObject *self, visitproc visit, void *arg)

Variables

static struct method_cache_entry [1<< MCACHE_SIZE_EXP]
static unsigned int next_version_tag = 0
static PyMemberDef type_members []
static PyGetSetDef type_getsets []
static PyGetSetDef subtype_getsets_full []
static PyGetSetDef subtype_getsets_dict_only []
static PyGetSetDef subtype_getsets_weakref_only []
static short slotoffsets []
static PyMethodDef type_methods []
PyTypeObject PyType_Type
static PyGetSetDef object_getsets []
static PyMethodDef object_methods []
PyTypeObject PyBaseObject_Type
static char * hash_name_op []
static struct PyMethodDef []
static char * name_op []
static slotdef slotdefs []
static PyMemberDef super_members []
PyTypeObject PySuper_Type

Class Documentation

struct method_cache_entry

Definition at line 28 of file typeobject.c.

Collaboration diagram for method_cache_entry:
Class Members
PyObject * name
PyObject * value
unsigned int version
struct superobject

Definition at line 6005 of file typeobject.c.

Collaboration diagram for superobject:
Class Members
PyObject * obj
PyTypeObject * obj_type
PyObject_HEAD PyTypeObject * type

Define Documentation

#define BINSLOT (   NAME,
  SLOT,
  FUNCTION,
  DOC 
)
Value:
ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_l, \
           "x." NAME "(y) <==> x" DOC "y")

Definition at line 5436 of file typeobject.c.

#define BINSLOTNOTINFIX (   NAME,
  SLOT,
  FUNCTION,
  DOC 
)
Value:
ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_l, \
           "x." NAME "(y) <==> " DOC)

Definition at line 5442 of file typeobject.c.

#define COPYBUF (   SLOT)    COPYSLOT(tp_as_buffer->SLOT)
#define COPYMAP (   SLOT)    COPYSLOT(tp_as_mapping->SLOT)
#define COPYNUM (   SLOT)    COPYSLOT(tp_as_number->SLOT)
#define COPYSEQ (   SLOT)    COPYSLOT(tp_as_sequence->SLOT)
#define COPYSLOT (   SLOT)    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT
#define COPYVAL (   SLOT)    if (type->SLOT == 0) type->SLOT = base->SLOT
#define ETSLOT (   NAME,
  SLOT,
  FUNCTION,
  WRAPPER,
  DOC 
)
Value:
{NAME, offsetof(PyHeapTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \
     PyDoc_STR(DOC)}

Definition at line 5421 of file typeobject.c.

#define FLSLOT (   NAME,
  SLOT,
  FUNCTION,
  WRAPPER,
  DOC,
  FLAGS 
)
Value:
{NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \
     PyDoc_STR(DOC), FLAGS}

Definition at line 5418 of file typeobject.c.

#define IBSLOT (   NAME,
  SLOT,
  FUNCTION,
  WRAPPER,
  DOC 
)
Value:
ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, \
           "x." NAME "(y) <==> x" DOC "y")

Definition at line 5433 of file typeobject.c.

#define MAX_EQUIV   10

Definition at line 5652 of file typeobject.c.

#define MCACHE_CACHEABLE_NAME (   name)
Value:
PyUnicode_CheckExact(name) &&                            \
        PyUnicode_GET_SIZE(name) <= MCACHE_MAX_ATTR_SIZE

Definition at line 24 of file typeobject.c.

#define MCACHE_HASH (   version,
  name_hash 
)
Value:
(((unsigned int)(version) * (unsigned int)(name_hash))          \
         >> (8*sizeof(unsigned int) - MCACHE_SIZE_EXP))

Definition at line 18 of file typeobject.c.

#define MCACHE_HASH_METHOD (   type,
  name 
)
Value:
MCACHE_HASH((type)->tp_version_tag,                     \
                    ((PyUnicodeObject *)(name))->hash)

Definition at line 21 of file typeobject.c.

#define MCACHE_MAX_ATTR_SIZE   100

Definition at line 16 of file typeobject.c.

#define MCACHE_SIZE_EXP   10

Definition at line 17 of file typeobject.c.

#define MPSLOT (   NAME,
  SLOT,
  FUNCTION,
  WRAPPER,
  DOC 
)    ETSLOT(NAME, as_mapping.SLOT, FUNCTION, WRAPPER, DOC)

Definition at line 5426 of file typeobject.c.

#define NBSLOT (   NAME,
  SLOT,
  FUNCTION,
  WRAPPER,
  DOC 
)    ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, DOC)

Definition at line 5428 of file typeobject.c.

#define RBINSLOT (   NAME,
  SLOT,
  FUNCTION,
  DOC 
)
Value:
ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_r, \
           "x." NAME "(y) <==> y" DOC "x")

Definition at line 5439 of file typeobject.c.

#define RBINSLOTNOTINFIX (   NAME,
  SLOT,
  FUNCTION,
  DOC 
)
Value:
ETSLOT(NAME, as_number.SLOT, FUNCTION, wrap_binaryfunc_r, \
           "x." NAME "(y) <==> " DOC)

Definition at line 5445 of file typeobject.c.

#define RICHCMP_WRAPPER (   NAME,
  OP 
)
Value:
static PyObject * \
richcmp_##NAME(PyObject *self, PyObject *args, void *wrapped) \
{ \
    return wrap_richcmpfunc(self, args, wrapped, OP); \
}

Definition at line 4413 of file typeobject.c.

#define SLOT0 (   FUNCNAME,
  OPSTR 
)
Value:
static PyObject * \
FUNCNAME(PyObject *self) \
{ \
    static PyObject *cache_str; \
    return call_method(self, OPSTR, &cache_str, "()"); \
}

Definition at line 4593 of file typeobject.c.

#define SLOT1 (   FUNCNAME,
  OPSTR,
  ARG1TYPE,
  ARGCODES 
)
Value:
static PyObject * \
FUNCNAME(PyObject *self, ARG1TYPE arg1) \
{ \
    static PyObject *cache_str; \
    return call_method(self, OPSTR, &cache_str, "(" ARGCODES ")", arg1); \
}

Definition at line 4601 of file typeobject.c.

#define SLOT1BIN (   FUNCNAME,
  SLOTNAME,
  OPSTR,
  ROPSTR 
)    SLOT1BINFULL(FUNCNAME, FUNCNAME, SLOTNAME, OPSTR, ROPSTR)

Definition at line 4680 of file typeobject.c.

#define SLOT1BINFULL (   FUNCNAME,
  TESTFUNC,
  SLOTNAME,
  OPSTR,
  ROPSTR 
)

Definition at line 4644 of file typeobject.c.

#define SLOT2 (   FUNCNAME,
  OPSTR,
  ARG1TYPE,
  ARG2TYPE,
  ARGCODES 
)
Value:
static PyObject * \
FUNCNAME(PyObject *self, ARG1TYPE arg1, ARG2TYPE arg2) \
{ \
    static PyObject *cache_str; \
    return call_method(self, OPSTR, &cache_str, \
                       "(" ARGCODES ")", arg1, arg2); \
}

Definition at line 4683 of file typeobject.c.

Definition at line 4806 of file typeobject.c.

#define SLOTDEFINED (   SLOT)
Value:
(base->SLOT != 0 && \
     (basebase == NULL || base->SLOT != basebase->SLOT))
#define SQSLOT (   NAME,
  SLOT,
  FUNCTION,
  WRAPPER,
  DOC 
)    ETSLOT(NAME, as_sequence.SLOT, FUNCTION, WRAPPER, DOC)

Definition at line 5424 of file typeobject.c.

#define TPSLOT (   NAME,
  SLOT,
  FUNCTION,
  WRAPPER,
  DOC 
)
Value:
{NAME, offsetof(PyTypeObject, SLOT), (void *)(FUNCTION), WRAPPER, \
     PyDoc_STR(DOC)}

Definition at line 5415 of file typeobject.c.

#define UNSLOT (   NAME,
  SLOT,
  FUNCTION,
  WRAPPER,
  DOC 
)
Value:
ETSLOT(NAME, as_number.SLOT, FUNCTION, WRAPPER, \
           "x." NAME "() <==> " DOC)

Definition at line 5430 of file typeobject.c.


Typedef Documentation

Definition at line 380 of file typeobject.c.

typedef struct wrapperbase

Definition at line 5402 of file typeobject.c.


Function Documentation

static PyObject* _common_reduce ( PyObject self,
int  proto 
) [static]

Definition at line 3283 of file typeobject.c.

{
    PyObject *copyreg, *res;

    if (proto >= 2)
        return reduce_2(self);

    copyreg = import_copyreg();
    if (!copyreg)
        return NULL;

    res = PyEval_CallMethod(copyreg, "_reduce_ex", "(Oi)", self, proto);
    Py_DECREF(copyreg);

    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PyObject* _PyObject_LookupSpecial ( PyObject self,
char *  attrstr,
PyObject **  attrobj 
)

Definition at line 1160 of file typeobject.c.

{
    return lookup_maybe(self, attrstr, attrobj);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PyObject* _PyType_Lookup ( PyTypeObject type,
PyObject name 
)

Definition at line 2378 of file typeobject.c.

{
    Py_ssize_t i, n;
    PyObject *mro, *res, *base, *dict;
    unsigned int h;

    if (MCACHE_CACHEABLE_NAME(name) &&
        PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG)) {
        /* fast path */
        h = MCACHE_HASH_METHOD(type, name);
        if (method_cache[h].version == type->tp_version_tag &&
            method_cache[h].name == name)
            return method_cache[h].value;
    }

    /* Look in tp_dict of types in MRO */
    mro = type->tp_mro;

    /* If mro is NULL, the type is either not yet initialized
       by PyType_Ready(), or already cleared by type_clear().
       Either way the safest thing to do is to return NULL. */
    if (mro == NULL)
        return NULL;

    res = NULL;
    assert(PyTuple_Check(mro));
    n = PyTuple_GET_SIZE(mro);
    for (i = 0; i < n; i++) {
        base = PyTuple_GET_ITEM(mro, i);
        assert(PyType_Check(base));
        dict = ((PyTypeObject *)base)->tp_dict;
        assert(dict && PyDict_Check(dict));
        res = PyDict_GetItem(dict, name);
        if (res != NULL)
            break;
    }

    if (MCACHE_CACHEABLE_NAME(name) && assign_version_tag(type)) {
        h = MCACHE_HASH_METHOD(type, name);
        method_cache[h].version = type->tp_version_tag;
        method_cache[h].value = res;  /* borrowed */
        Py_INCREF(name);
        Py_DECREF(method_cache[h].name);
        method_cache[h].name = name;
    }
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int add_getset ( PyTypeObject type,
PyGetSetDef gsp 
) [static]

Definition at line 3542 of file typeobject.c.

{
    PyObject *dict = type->tp_dict;

    for (; gsp->name != NULL; gsp++) {
        PyObject *descr;
        if (PyDict_GetItemString(dict, gsp->name))
            continue;
        descr = PyDescr_NewGetSet(type, gsp);

        if (descr == NULL)
            return -1;
        if (PyDict_SetItemString(dict, gsp->name, descr) < 0)
            return -1;
        Py_DECREF(descr);
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int add_members ( PyTypeObject type,
PyMemberDef memb 
) [static]

Definition at line 3523 of file typeobject.c.

{
    PyObject *dict = type->tp_dict;

    for (; memb->name != NULL; memb++) {
        PyObject *descr;
        if (PyDict_GetItemString(dict, memb->name))
            continue;
        descr = PyDescr_NewMember(type, memb);
        if (descr == NULL)
            return -1;
        if (PyDict_SetItemString(dict, memb->name, descr) < 0)
            return -1;
        Py_DECREF(descr);
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int add_methods ( PyTypeObject type,
PyMethodDef meth 
) [static]

Definition at line 3486 of file typeobject.c.

{
    PyObject *dict = type->tp_dict;

    for (; meth->ml_name != NULL; meth++) {
        PyObject *descr;
        if (PyDict_GetItemString(dict, meth->ml_name) &&
            !(meth->ml_flags & METH_COEXIST))
                continue;
        if (meth->ml_flags & METH_CLASS) {
            if (meth->ml_flags & METH_STATIC) {
                PyErr_SetString(PyExc_ValueError,
                     "method cannot be both class and static");
                return -1;
            }
            descr = PyDescr_NewClassMethod(type, meth);
        }
        else if (meth->ml_flags & METH_STATIC) {
            PyObject *cfunc = PyCFunction_New(meth, NULL);
            if (cfunc == NULL)
                return -1;
            descr = PyStaticMethod_New(cfunc);
            Py_DECREF(cfunc);
        }
        else {
            descr = PyDescr_NewMethod(type, meth);
        }
        if (descr == NULL)
            return -1;
        if (PyDict_SetItemString(dict, meth->ml_name, descr) < 0)
            return -1;
        Py_DECREF(descr);
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int add_operators ( PyTypeObject type) [static]

Definition at line 5963 of file typeobject.c.

{
    PyObject *dict = type->tp_dict;
    slotdef *p;
    PyObject *descr;
    void **ptr;

    init_slotdefs();
    for (p = slotdefs; p->name; p++) {
        if (p->wrapper == NULL)
            continue;
        ptr = slotptr(type, p->offset);
        if (!ptr || !*ptr)
            continue;
        if (PyDict_GetItem(dict, p->name_strobj))
            continue;
        if (*ptr == PyObject_HashNotImplemented) {
            /* Classes may prevent the inheritance of the tp_hash
               slot by storing PyObject_HashNotImplemented in it. Make it
               visible as a None value for the __hash__ attribute. */
            if (PyDict_SetItem(dict, p->name_strobj, Py_None) < 0)
                return -1;
        }
        else {
            descr = PyDescr_NewWrapper(type, p, *ptr);
            if (descr == NULL)
                return -1;
            if (PyDict_SetItem(dict, p->name_strobj, descr) < 0)
                return -1;
            Py_DECREF(descr);
        }
    }
    if (type->tp_new != NULL) {
        if (add_tp_new_wrapper(type) < 0)
            return -1;
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int add_subclass ( PyTypeObject base,
PyTypeObject type 
) [static]

Definition at line 4000 of file typeobject.c.

{
    Py_ssize_t i;
    int result;
    PyObject *list, *ref, *newobj;

    list = base->tp_subclasses;
    if (list == NULL) {
        base->tp_subclasses = list = PyList_New(0);
        if (list == NULL)
            return -1;
    }
    assert(PyList_Check(list));
    newobj = PyWeakref_NewRef((PyObject *)type, NULL);
    i = PyList_GET_SIZE(list);
    while (--i >= 0) {
        ref = PyList_GET_ITEM(list, i);
        assert(PyWeakref_CheckRef(ref));
        if (PyWeakref_GET_OBJECT(ref) == Py_None)
            return PyList_SetItem(list, i, newobj);
    }
    result = PyList_Append(list, newobj);
    Py_DECREF(newobj);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int add_tp_new_wrapper ( PyTypeObject type) [static]

Definition at line 4573 of file typeobject.c.

{
    PyObject *func;

    if (PyDict_GetItemString(type->tp_dict, "__new__") != NULL)
        return 0;
    func = PyCFunction_New(tp_new_methoddef, (PyObject *)type);
    if (func == NULL)
        return -1;
    if (PyDict_SetItemString(type->tp_dict, "__new__", func)) {
        Py_DECREF(func);
        return -1;
    }
    Py_DECREF(func);
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int assign_version_tag ( PyTypeObject type) [static]

Definition at line 143 of file typeobject.c.

{
    /* Ensure that the tp_version_tag is valid and set
       Py_TPFLAGS_VALID_VERSION_TAG.  To respect the invariant, this
       must first be done on all super classes.  Return 0 if this
       cannot be done, 1 if Py_TPFLAGS_VALID_VERSION_TAG.
    */
    Py_ssize_t i, n;
    PyObject *bases;

    if (PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG))
        return 1;
    if (!PyType_HasFeature(type, Py_TPFLAGS_HAVE_VERSION_TAG))
        return 0;
    if (!PyType_HasFeature(type, Py_TPFLAGS_READY))
        return 0;

    type->tp_version_tag = next_version_tag++;
    /* for stress-testing: next_version_tag &= 0xFF; */

    if (type->tp_version_tag == 0) {
        /* wrap-around or just starting Python - clear the whole
           cache by filling names with references to Py_None.
           Values are also set to NULL for added protection, as they
           are borrowed reference */
        for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) {
            method_cache[i].value = NULL;
            Py_XDECREF(method_cache[i].name);
            method_cache[i].name = Py_None;
            Py_INCREF(Py_None);
        }
        /* mark all version tags as invalid */
        PyType_Modified(&PyBaseObject_Type);
        return 1;
    }
    bases = type->tp_bases;
    n = PyTuple_GET_SIZE(bases);
    for (i = 0; i < n; i++) {
        PyObject *b = PyTuple_GET_ITEM(bases, i);
        assert(PyType_Check(b));
        if (!assign_version_tag((PyTypeObject *)b))
            return 0;
    }
    type->tp_flags |= Py_TPFLAGS_VALID_VERSION_TAG;
    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyTypeObject * best_base ( PyObject bases) [static]

Definition at line 1599 of file typeobject.c.

{
    Py_ssize_t i, n;
    PyTypeObject *base, *winner, *candidate, *base_i;
    PyObject *base_proto;

    assert(PyTuple_Check(bases));
    n = PyTuple_GET_SIZE(bases);
    assert(n > 0);
    base = NULL;
    winner = NULL;
    for (i = 0; i < n; i++) {
        base_proto = PyTuple_GET_ITEM(bases, i);
        if (!PyType_Check(base_proto)) {
            PyErr_SetString(
                PyExc_TypeError,
                "bases must be types");
            return NULL;
        }
        base_i = (PyTypeObject *)base_proto;
        if (base_i->tp_dict == NULL) {
            if (PyType_Ready(base_i) < 0)
                return NULL;
        }
        candidate = solid_base(base_i);
        if (winner == NULL) {
            winner = candidate;
            base = base_i;
        }
        else if (PyType_IsSubtype(winner, candidate))
            ;
        else if (PyType_IsSubtype(candidate, winner)) {
            winner = candidate;
            base = base_i;
        }
        else {
            PyErr_SetString(
                PyExc_TypeError,
                "multiple bases have "
                "instance lay-out conflict");
            return NULL;
        }
    }
    if (base == NULL)
        PyErr_SetString(PyExc_TypeError,
            "a new-style class can't have only classic bases");
    return base;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* call_attribute ( PyObject self,
PyObject attr,
PyObject name 
) [static]

Definition at line 5070 of file typeobject.c.

{
    PyObject *res, *descr = NULL;
    descrgetfunc f = Py_TYPE(attr)->tp_descr_get;

    if (f != NULL) {
        descr = f(attr, self, (PyObject *)(Py_TYPE(self)));
        if (descr == NULL)
            return NULL;
        else
            attr = descr;
    }
    res = PyObject_CallFunctionObjArgs(attr, name, NULL);
    Py_XDECREF(descr);
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* call_maybe ( PyObject o,
char *  name,
PyObject **  nameobj,
char *  format,
  ... 
) [static]

Definition at line 1206 of file typeobject.c.

{
    va_list va;
    PyObject *args, *func = 0, *retval;
    va_start(va, format);

    func = lookup_maybe(o, name, nameobj);
    if (func == NULL) {
        va_end(va);
        if (!PyErr_Occurred()) {
            Py_INCREF(Py_NotImplemented);
            return Py_NotImplemented;
        }
        return NULL;
    }

    if (format && *format)
        args = Py_VaBuildValue(format, va);
    else
        args = PyTuple_New(0);

    va_end(va);

    if (args == NULL)
        return NULL;

    assert(PyTuple_Check(args));
    retval = PyObject_Call(func, args, NULL);

    Py_DECREF(args);
    Py_DECREF(func);

    return retval;
}

Here is the call graph for this function:

static PyObject* call_method ( PyObject o,
char *  name,
PyObject **  nameobj,
char *  format,
  ... 
) [static]

Definition at line 1170 of file typeobject.c.

{
    va_list va;
    PyObject *args, *func = 0, *retval;
    va_start(va, format);

    func = lookup_maybe(o, name, nameobj);
    if (func == NULL) {
        va_end(va);
        if (!PyErr_Occurred())
            PyErr_SetObject(PyExc_AttributeError, *nameobj);
        return NULL;
    }

    if (format && *format)
        args = Py_VaBuildValue(format, va);
    else
        args = PyTuple_New(0);

    va_end(va);

    if (args == NULL)
        return NULL;

    assert(PyTuple_Check(args));
    retval = PyObject_Call(func, args, NULL);

    Py_DECREF(args);
    Py_DECREF(func);

    return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int check_duplicates ( PyObject list) [static]

Definition at line 1300 of file typeobject.c.

{
    Py_ssize_t i, j, n;
    /* Let's use a quadratic time algorithm,
       assuming that the bases lists is short.
    */
    n = PyList_GET_SIZE(list);
    for (i = 0; i < n; i++) {
        PyObject *o = PyList_GET_ITEM(list, i);
        for (j = i + 1; j < n; j++) {
            if (PyList_GET_ITEM(list, j) == o) {
                o = class_name(o);
                if (o != NULL) {
                    PyErr_Format(PyExc_TypeError,
                                 "duplicate base class %U",
                                 o);
                    Py_DECREF(o);
                } else {
                    PyErr_SetString(PyExc_TypeError,
                                 "duplicate base class");
                }
                return -1;
            }
        }
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int check_num_args ( PyObject ob,
int  n 
) [static]

Definition at line 4050 of file typeobject.c.

{
    if (!PyTuple_CheckExact(ob)) {
        PyErr_SetString(PyExc_SystemError,
            "PyArg_UnpackTuple() argument list is not a tuple");
        return 0;
    }
    if (n == PyTuple_GET_SIZE(ob))
        return 1;
    PyErr_Format(
        PyExc_TypeError,
        "expected %d arguments, got %zd", n, PyTuple_GET_SIZE(ob));
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* class_name ( PyObject cls) [static]

Definition at line 1282 of file typeobject.c.

{
    PyObject *name = PyObject_GetAttrString(cls, "__name__");
    if (name == NULL) {
        PyErr_Clear();
        Py_XDECREF(name);
        name = PyObject_Repr(cls);
    }
    if (name == NULL)
        return NULL;
    if (!PyUnicode_Check(name)) {
        Py_DECREF(name);
        return NULL;
    }
    return name;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void clear_slots ( PyTypeObject type,
PyObject self 
) [static]

Definition at line 797 of file typeobject.c.

{
    Py_ssize_t i, n;
    PyMemberDef *mp;

    n = Py_SIZE(type);
    mp = PyHeapType_GET_MEMBERS((PyHeapTypeObject *)type);
    for (i = 0; i < n; i++, mp++) {
        if (mp->type == T_OBJECT_EX && !(mp->flags & READONLY)) {
            char *addr = (char *)self + mp->offset;
            PyObject *obj = *(PyObject **)addr;
            if (obj != NULL) {
                *(PyObject **)addr = NULL;
                Py_DECREF(obj);
            }
        }
    }
}

Here is the caller graph for this function:

static int compatible_for_assignment ( PyTypeObject oldto,
PyTypeObject newto,
char *  attr 
) [static]

Definition at line 2988 of file typeobject.c.

{
    PyTypeObject *newbase, *oldbase;

    if (newto->tp_dealloc != oldto->tp_dealloc ||
        newto->tp_free != oldto->tp_free)
    {
        PyErr_Format(PyExc_TypeError,
                     "%s assignment: "
                     "'%s' deallocator differs from '%s'",
                     attr,
                     newto->tp_name,
                     oldto->tp_name);
        return 0;
    }
    newbase = newto;
    oldbase = oldto;
    while (equiv_structs(newbase, newbase->tp_base))
        newbase = newbase->tp_base;
    while (equiv_structs(oldbase, oldbase->tp_base))
        oldbase = oldbase->tp_base;
    if (newbase != oldbase &&
        (newbase->tp_base != oldbase->tp_base ||
         !same_slots_added(newbase, oldbase))) {
        PyErr_Format(PyExc_TypeError,
                     "%s assignment: "
                     "'%s' object layout differs from '%s'",
                     attr,
                     newto->tp_name,
                     oldto->tp_name);
        return 0;
    }

    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int equiv_structs ( PyTypeObject a,
PyTypeObject b 
) [static]

Definition at line 2949 of file typeobject.c.

{
    return a == b ||
           (a != NULL &&
        b != NULL &&
        a->tp_basicsize == b->tp_basicsize &&
        a->tp_itemsize == b->tp_itemsize &&
        a->tp_dictoffset == b->tp_dictoffset &&
        a->tp_weaklistoffset == b->tp_weaklistoffset &&
        ((a->tp_flags & Py_TPFLAGS_HAVE_GC) ==
         (b->tp_flags & Py_TPFLAGS_HAVE_GC)));
}

Here is the caller graph for this function:

static int excess_args ( PyObject args,
PyObject kwds 
) [static]

Definition at line 2753 of file typeobject.c.

{
    return PyTuple_GET_SIZE(args) ||
        (kwds && PyDict_Check(kwds) && PyDict_Size(kwds));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int extra_ivars ( PyTypeObject type,
PyTypeObject base 
) [static]

Definition at line 1649 of file typeobject.c.

{
    size_t t_size = type->tp_basicsize;
    size_t b_size = base->tp_basicsize;

    assert(t_size >= b_size); /* Else type smaller than base! */
    if (type->tp_itemsize || base->tp_itemsize) {
        /* If itemsize is involved, stricter rules */
        return t_size != b_size ||
            type->tp_itemsize != base->tp_itemsize;
    }
    if (type->tp_weaklistoffset && base->tp_weaklistoffset == 0 &&
        type->tp_weaklistoffset + sizeof(PyObject *) == t_size &&
        type->tp_flags & Py_TPFLAGS_HEAPTYPE)
        t_size -= sizeof(PyObject *);
    if (type->tp_dictoffset && base->tp_dictoffset == 0 &&
        type->tp_dictoffset + sizeof(PyObject *) == t_size &&
        type->tp_flags & Py_TPFLAGS_HEAPTYPE)
        t_size -= sizeof(PyObject *);

    return t_size != b_size;
}

Here is the caller graph for this function:

static void fixup_slot_dispatchers ( PyTypeObject type) [static]

Definition at line 5866 of file typeobject.c.

{
    slotdef *p;

    init_slotdefs();
    for (p = slotdefs; p->name; )
        p = update_one_slot(type, p);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1698 of file typeobject.c.

{
    while (type->tp_base != NULL) {
        if (type->tp_dictoffset != 0 &&
            !(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
            return type;
        type = type->tp_base;
    }
    return NULL;
}

Here is the caller graph for this function:

static PyObject* get_dict_descriptor ( PyTypeObject type) [static]

Definition at line 1710 of file typeobject.c.

{
    static PyObject *dict_str;
    PyObject *descr;

    if (dict_str == NULL) {
        dict_str = PyUnicode_InternFromString("__dict__");
        if (dict_str == NULL)
            return NULL;
    }
    descr = _PyType_Lookup(type, dict_str);
    if (descr == NULL || !PyDescr_IsData(descr))
        return NULL;

    return descr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Py_ssize_t getindex ( PyObject self,
PyObject arg 
) [static]

Definition at line 4191 of file typeobject.c.

{
    Py_ssize_t i;

    i = PyNumber_AsSsize_t(arg, PyExc_OverflowError);
    if (i == -1 && PyErr_Occurred())
        return -1;
    if (i < 0) {
        PySequenceMethods *sq = Py_TYPE(self)->tp_as_sequence;
        if (sq && sq->sq_length) {
            Py_ssize_t n = (*sq->sq_length)(self);
            if (n < 0)
                return -1;
            i += n;
        }
    }
    return i;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int hackcheck ( PyObject self,
setattrofunc  func,
char *  what 
) [static]

Definition at line 4324 of file typeobject.c.

{
    PyTypeObject *type = Py_TYPE(self);
    while (type && type->tp_flags & Py_TPFLAGS_HEAPTYPE)
        type = type->tp_base;
    /* If type is NULL now, this is a really weird type.
       In the spirit of backwards compatibility (?), just shut up. */
    if (type && type->tp_setattro != func) {
        PyErr_Format(PyExc_TypeError,
                     "can't apply this %s to %s object",
                     what,
                     type->tp_name);
        return 0;
    }
    return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* import_copyreg ( void  ) [static]

Definition at line 3075 of file typeobject.c.

{
    static PyObject *copyreg_str;

    if (!copyreg_str) {
        copyreg_str = PyUnicode_InternFromString("copyreg");
        if (copyreg_str == NULL)
            return NULL;
    }

    return PyImport_Import(copyreg_str);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void inherit_slots ( PyTypeObject type,
PyTypeObject base 
) [static]

Definition at line 3645 of file typeobject.c.

{
    PyTypeObject *basebase;

#undef SLOTDEFINED
#undef COPYSLOT
#undef COPYNUM
#undef COPYSEQ
#undef COPYMAP
#undef COPYBUF

#define SLOTDEFINED(SLOT) \
    (base->SLOT != 0 && \
     (basebase == NULL || base->SLOT != basebase->SLOT))

#define COPYSLOT(SLOT) \
    if (!type->SLOT && SLOTDEFINED(SLOT)) type->SLOT = base->SLOT

#define COPYNUM(SLOT) COPYSLOT(tp_as_number->SLOT)
#define COPYSEQ(SLOT) COPYSLOT(tp_as_sequence->SLOT)
#define COPYMAP(SLOT) COPYSLOT(tp_as_mapping->SLOT)
#define COPYBUF(SLOT) COPYSLOT(tp_as_buffer->SLOT)

    /* This won't inherit indirect slots (from tp_as_number etc.)
       if type doesn't provide the space. */

    if (type->tp_as_number != NULL && base->tp_as_number != NULL) {
        basebase = base->tp_base;
        if (basebase->tp_as_number == NULL)
            basebase = NULL;
        COPYNUM(nb_add);
        COPYNUM(nb_subtract);
        COPYNUM(nb_multiply);
        COPYNUM(nb_remainder);
        COPYNUM(nb_divmod);
        COPYNUM(nb_power);
        COPYNUM(nb_negative);
        COPYNUM(nb_positive);
        COPYNUM(nb_absolute);
        COPYNUM(nb_bool);
        COPYNUM(nb_invert);
        COPYNUM(nb_lshift);
        COPYNUM(nb_rshift);
        COPYNUM(nb_and);
        COPYNUM(nb_xor);
        COPYNUM(nb_or);
        COPYNUM(nb_int);
        COPYNUM(nb_float);
        COPYNUM(nb_inplace_add);
        COPYNUM(nb_inplace_subtract);
        COPYNUM(nb_inplace_multiply);
        COPYNUM(nb_inplace_remainder);
        COPYNUM(nb_inplace_power);
        COPYNUM(nb_inplace_lshift);
        COPYNUM(nb_inplace_rshift);
        COPYNUM(nb_inplace_and);
        COPYNUM(nb_inplace_xor);
        COPYNUM(nb_inplace_or);
        COPYNUM(nb_true_divide);
        COPYNUM(nb_floor_divide);
        COPYNUM(nb_inplace_true_divide);
        COPYNUM(nb_inplace_floor_divide);
        COPYNUM(nb_index);
    }

    if (type->tp_as_sequence != NULL && base->tp_as_sequence != NULL) {
        basebase = base->tp_base;
        if (basebase->tp_as_sequence == NULL)
            basebase = NULL;
        COPYSEQ(sq_length);
        COPYSEQ(sq_concat);
        COPYSEQ(sq_repeat);
        COPYSEQ(sq_item);
        COPYSEQ(sq_ass_item);
        COPYSEQ(sq_contains);
        COPYSEQ(sq_inplace_concat);
        COPYSEQ(sq_inplace_repeat);
    }

    if (type->tp_as_mapping != NULL && base->tp_as_mapping != NULL) {
        basebase = base->tp_base;
        if (basebase->tp_as_mapping == NULL)
            basebase = NULL;
        COPYMAP(mp_length);
        COPYMAP(mp_subscript);
        COPYMAP(mp_ass_subscript);
    }

    if (type->tp_as_buffer != NULL && base->tp_as_buffer != NULL) {
        basebase = base->tp_base;
        if (basebase->tp_as_buffer == NULL)
            basebase = NULL;
        COPYBUF(bf_getbuffer);
        COPYBUF(bf_releasebuffer);
    }

    basebase = base->tp_base;

    COPYSLOT(tp_dealloc);
    if (type->tp_getattr == NULL && type->tp_getattro == NULL) {
        type->tp_getattr = base->tp_getattr;
        type->tp_getattro = base->tp_getattro;
    }
    if (type->tp_setattr == NULL && type->tp_setattro == NULL) {
        type->tp_setattr = base->tp_setattr;
        type->tp_setattro = base->tp_setattro;
    }
    /* tp_reserved is ignored */
    COPYSLOT(tp_repr);
    /* tp_hash see tp_richcompare */
    COPYSLOT(tp_call);
    COPYSLOT(tp_str);
    {
        /* Copy comparison-related slots only when
           not overriding them anywhere */
        if (type->tp_richcompare == NULL &&
            type->tp_hash == NULL &&
            !overrides_hash(type))
        {
            type->tp_richcompare = base->tp_richcompare;
            type->tp_hash = base->tp_hash;
        }
    }
    {
        COPYSLOT(tp_iter);
        COPYSLOT(tp_iternext);
    }
    {
        COPYSLOT(tp_descr_get);
        COPYSLOT(tp_descr_set);
        COPYSLOT(tp_dictoffset);
        COPYSLOT(tp_init);
        COPYSLOT(tp_alloc);
        COPYSLOT(tp_is_gc);
        if ((type->tp_flags & Py_TPFLAGS_HAVE_GC) ==
            (base->tp_flags & Py_TPFLAGS_HAVE_GC)) {
            /* They agree about gc. */
            COPYSLOT(tp_free);
        }
        else if ((type->tp_flags & Py_TPFLAGS_HAVE_GC) &&
                 type->tp_free == NULL &&
                 base->tp_free == PyObject_Free) {
            /* A bit of magic to plug in the correct default
             * tp_free function when a derived class adds gc,
             * didn't define tp_free, and the base uses the
             * default non-gc tp_free.
             */
            type->tp_free = PyObject_GC_Del;
        }
        /* else they didn't agree about gc, and there isn't something
         * obvious to be done -- the type is on its own.
         */
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void inherit_special ( PyTypeObject type,
PyTypeObject base 
) [static]

Definition at line 3562 of file typeobject.c.

{

    /* Copying basicsize is connected to the GC flags */
    if (!(type->tp_flags & Py_TPFLAGS_HAVE_GC) &&
        (base->tp_flags & Py_TPFLAGS_HAVE_GC) &&
        (!type->tp_traverse && !type->tp_clear)) {
        type->tp_flags |= Py_TPFLAGS_HAVE_GC;
        if (type->tp_traverse == NULL)
            type->tp_traverse = base->tp_traverse;
        if (type->tp_clear == NULL)
            type->tp_clear = base->tp_clear;
    }
    {
        /* The condition below could use some explanation.
           It appears that tp_new is not inherited for static types
           whose base class is 'object'; this seems to be a precaution
           so that old extension types don't suddenly become
           callable (object.__new__ wouldn't insure the invariants
           that the extension type's own factory function ensures).
           Heap types, of course, are under our control, so they do
           inherit tp_new; static extension types that specify some
           other built-in type as the default are considered
           new-style-aware so they also inherit object.__new__. */
        if (base != &PyBaseObject_Type ||
            (type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
            if (type->tp_new == NULL)
                type->tp_new = base->tp_new;
        }
    }
    if (type->tp_basicsize == 0)
        type->tp_basicsize = base->tp_basicsize;

    /* Copy other non-function slots */

#undef COPYVAL
#define COPYVAL(SLOT) \
    if (type->SLOT == 0) type->SLOT = base->SLOT

    COPYVAL(tp_itemsize);
    COPYVAL(tp_weaklistoffset);
    COPYVAL(tp_dictoffset);

    /* Setup fast subclass flags */
    if (PyType_IsSubtype(base, (PyTypeObject*)PyExc_BaseException))
        type->tp_flags |= Py_TPFLAGS_BASE_EXC_SUBCLASS;
    else if (PyType_IsSubtype(base, &PyType_Type))
        type->tp_flags |= Py_TPFLAGS_TYPE_SUBCLASS;
    else if (PyType_IsSubtype(base, &PyLong_Type))
        type->tp_flags |= Py_TPFLAGS_LONG_SUBCLASS;
    else if (PyType_IsSubtype(base, &PyBytes_Type))
        type->tp_flags |= Py_TPFLAGS_BYTES_SUBCLASS;
    else if (PyType_IsSubtype(base, &PyUnicode_Type))
        type->tp_flags |= Py_TPFLAGS_UNICODE_SUBCLASS;
    else if (PyType_IsSubtype(base, &PyTuple_Type))
        type->tp_flags |= Py_TPFLAGS_TUPLE_SUBCLASS;
    else if (PyType_IsSubtype(base, &PyList_Type))
        type->tp_flags |= Py_TPFLAGS_LIST_SUBCLASS;
    else if (PyType_IsSubtype(base, &PyDict_Type))
        type->tp_flags |= Py_TPFLAGS_DICT_SUBCLASS;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_slotdefs ( void  ) [static]

Definition at line 5808 of file typeobject.c.

{
    slotdef *p;
    static int initialized = 0;

    if (initialized)
        return;
    for (p = slotdefs; p->name; p++) {
        p->name_strobj = PyUnicode_InternFromString(p->name);
        if (!p->name_strobj)
            Py_FatalError("Out of memory interning slotdef names");
    }
    qsort((void *)slotdefs, (size_t)(p-slotdefs), sizeof(slotdef),
          slotdef_cmp);
    initialized = 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* lookup_maybe ( PyObject self,
char *  attrstr,
PyObject **  attrobj 
) [static]

Definition at line 1130 of file typeobject.c.

{
    PyObject *res;

    if (*attrobj == NULL) {
        *attrobj = PyUnicode_InternFromString(attrstr);
        if (*attrobj == NULL)
            return NULL;
    }
    res = _PyType_Lookup(Py_TYPE(self), *attrobj);
    if (res != NULL) {
        descrgetfunc f;
        if ((f = Py_TYPE(res)->tp_descr_get) == NULL)
            Py_INCREF(res);
        else
            res = f(res, self, (PyObject *)(Py_TYPE(self)));
    }
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* lookup_method ( PyObject self,
char *  attrstr,
PyObject **  attrobj 
) [static]

Definition at line 1151 of file typeobject.c.

{
    PyObject *res = lookup_maybe(self, attrstr, attrobj);
    if (res == NULL && !PyErr_Occurred())
        PyErr_SetObject(PyExc_AttributeError, *attrobj);
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int method_is_overloaded ( PyObject left,
PyObject right,
char *  name 
) [static]

Definition at line 4612 of file typeobject.c.

{
    PyObject *a, *b;
    int ok;

    b = PyObject_GetAttrString((PyObject *)(Py_TYPE(right)), name);
    if (b == NULL) {
        PyErr_Clear();
        /* If right doesn't have it, it's not overloaded */
        return 0;
    }

    a = PyObject_GetAttrString((PyObject *)(Py_TYPE(left)), name);
    if (a == NULL) {
        PyErr_Clear();
        Py_DECREF(b);
        /* If right has it but left doesn't, it's overloaded */
        return 1;
    }

    ok = PyObject_RichCompareBool(a, b, Py_NE);
    Py_DECREF(a);
    Py_DECREF(b);
    if (ok < 0) {
        PyErr_Clear();
        return 0;
    }

    return ok;
}

Here is the call graph for this function:

static PyObject* mro_external ( PyObject self) [static]

Definition at line 1522 of file typeobject.c.

{
    PyTypeObject *type = (PyTypeObject *)self;

    return mro_implementation(type);
}

Here is the call graph for this function:

static PyObject* mro_implementation ( PyTypeObject type) [static]

Definition at line 1452 of file typeobject.c.

{
    Py_ssize_t i, n;
    int ok;
    PyObject *bases, *result;
    PyObject *to_merge, *bases_aslist;

    if (type->tp_dict == NULL) {
        if (PyType_Ready(type) < 0)
            return NULL;
    }

    /* Find a superclass linearization that honors the constraints
       of the explicit lists of bases and the constraints implied by
       each base class.

       to_merge is a list of lists, where each list is a superclass
       linearization implied by a base class.  The last element of
       to_merge is the declared list of bases.
    */

    bases = type->tp_bases;
    n = PyTuple_GET_SIZE(bases);

    to_merge = PyList_New(n+1);
    if (to_merge == NULL)
        return NULL;

    for (i = 0; i < n; i++) {
        PyObject *base = PyTuple_GET_ITEM(bases, i);
        PyObject *parentMRO;
        parentMRO = PySequence_List(((PyTypeObject*)base)->tp_mro);
        if (parentMRO == NULL) {
            Py_DECREF(to_merge);
            return NULL;
        }

        PyList_SET_ITEM(to_merge, i, parentMRO);
    }

    bases_aslist = PySequence_List(bases);
    if (bases_aslist == NULL) {
        Py_DECREF(to_merge);
        return NULL;
    }
    /* This is just a basic sanity check. */
    if (check_duplicates(bases_aslist) < 0) {
        Py_DECREF(to_merge);
        Py_DECREF(bases_aslist);
        return NULL;
    }
    PyList_SET_ITEM(to_merge, n, bases_aslist);

    result = Py_BuildValue("[O]", (PyObject *)type);
    if (result == NULL) {
        Py_DECREF(to_merge);
        return NULL;
    }

    ok = pmerge(result, to_merge);
    Py_DECREF(to_merge);
    if (ok < 0) {
        Py_DECREF(result);
        return NULL;
    }

    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int mro_internal ( PyTypeObject type) [static]

Definition at line 1530 of file typeobject.c.

{
    PyObject *mro, *result, *tuple;
    int checkit = 0;

    if (Py_TYPE(type) == &PyType_Type) {
        result = mro_implementation(type);
    }
    else {
        static PyObject *mro_str;
        checkit = 1;
        mro = lookup_method((PyObject *)type, "mro", &mro_str);
        if (mro == NULL)
            return -1;
        result = PyObject_CallObject(mro, NULL);
        Py_DECREF(mro);
    }
    if (result == NULL)
        return -1;
    tuple = PySequence_Tuple(result);
    Py_DECREF(result);
    if (tuple == NULL)
        return -1;
    if (checkit) {
        Py_ssize_t i, len;
        PyObject *cls;
        PyTypeObject *solid;

        solid = solid_base(type);

        len = PyTuple_GET_SIZE(tuple);

        for (i = 0; i < len; i++) {
            PyTypeObject *t;
            cls = PyTuple_GET_ITEM(tuple, i);
            if (!PyType_Check(cls)) {
                PyErr_Format(PyExc_TypeError,
                 "mro() returned a non-class ('%.500s')",
                                 Py_TYPE(cls)->tp_name);
                Py_DECREF(tuple);
                return -1;
            }
            t = (PyTypeObject*)cls;
            if (!PyType_IsSubtype(solid, solid_base(t))) {
                PyErr_Format(PyExc_TypeError,
             "mro() returned base with unsuitable layout ('%.500s')",
                                     t->tp_name);
                        Py_DECREF(tuple);
                        return -1;
            }
        }
    }
    type->tp_mro = tuple;

    type_mro_modified(type, type->tp_mro);
    /* corner case: the old-style super class might have been hidden
       from the custom MRO */
    type_mro_modified(type, type->tp_bases);

    PyType_Modified(type);

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int mro_subclasses ( PyTypeObject type,
PyObject temp 
) [static]

Definition at line 387 of file typeobject.c.

{
    PyTypeObject *subclass;
    PyObject *ref, *subclasses, *old_mro;
    Py_ssize_t i, n;

    subclasses = type->tp_subclasses;
    if (subclasses == NULL)
        return 0;
    assert(PyList_Check(subclasses));
    n = PyList_GET_SIZE(subclasses);
    for (i = 0; i < n; i++) {
        ref = PyList_GET_ITEM(subclasses, i);
        assert(PyWeakref_CheckRef(ref));
        subclass = (PyTypeObject *)PyWeakref_GET_OBJECT(ref);
        assert(subclass != NULL);
        if ((PyObject *)subclass == Py_None)
            continue;
        assert(PyType_Check(subclass));
        old_mro = subclass->tp_mro;
        if (mro_internal(subclass) < 0) {
            subclass->tp_mro = old_mro;
            return -1;
        }
        else {
            PyObject* tuple;
            tuple = PyTuple_Pack(2, subclass, old_mro);
            Py_DECREF(old_mro);
            if (!tuple)
                return -1;
            if (PyList_Append(temp, tuple) < 0)
                return -1;
            Py_DECREF(tuple);
        }
        if (mro_subclasses(subclass, temp) < 0)
            return -1;
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void object_dealloc ( PyObject self) [static]

Definition at line 2855 of file typeobject.c.

{
    Py_TYPE(self)->tp_free(self);
}
static PyObject* object_format ( PyObject self,
PyObject args 
) [static]

Definition at line 3376 of file typeobject.c.

{
    PyObject *format_spec;
    PyObject *self_as_str = NULL;
    PyObject *result = NULL;

    if (!PyArg_ParseTuple(args, "U:__format__", &format_spec))
        return NULL;

    self_as_str = PyObject_Str(self);
    if (self_as_str != NULL) {
        /* Issue 7994: If we're converting to a string, we
          should reject format specifications */
        if (PyUnicode_GET_SIZE(format_spec) > 0) {
           if (PyErr_WarnEx(PyExc_PendingDeprecationWarning,
                          "object.__format__ with a non-empty format "
                          "string is deprecated", 1) < 0) {
             goto done;
           }
           /* Eventually this will become an error:
              PyErr_Format(PyExc_TypeError,
              "non-empty format string passed to object.__format__");
              goto done;
           */
       }

       result = PyObject_Format(self_as_str, format_spec);
    }

done:
    Py_XDECREF(self_as_str);

    return result;
}

Here is the call graph for this function:

static PyObject* object_get_class ( PyObject self,
void closure 
) [static]

Definition at line 2942 of file typeobject.c.

{
    Py_INCREF(Py_TYPE(self));
    return (PyObject *)(Py_TYPE(self));
}
static int object_init ( PyObject self,
PyObject args,
PyObject kwds 
) [static]

Definition at line 2760 of file typeobject.c.

{
    int err = 0;
    if (excess_args(args, kwds)) {
        PyTypeObject *type = Py_TYPE(self);
        if (type->tp_init != object_init &&
            type->tp_new != object_new)
        {
            err = PyErr_WarnEx(PyExc_DeprecationWarning,
                       "object.__init__() takes no parameters",
                       1);
        }
        else if (type->tp_init != object_init ||
                 type->tp_new == object_new)
        {
            PyErr_SetString(PyExc_TypeError,
                "object.__init__() takes no parameters");
            err = -1;
        }
    }
    return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject * object_new ( PyTypeObject type,
PyObject args,
PyObject kwds 
) [static]

Definition at line 2784 of file typeobject.c.

{
    int err = 0;
    if (excess_args(args, kwds)) {
        if (type->tp_new != object_new &&
            type->tp_init != object_init)
        {
            err = PyErr_WarnEx(PyExc_DeprecationWarning,
                       "object.__new__() takes no parameters",
                       1);
        }
        else if (type->tp_new != object_new ||
                 type->tp_init == object_init)
        {
            PyErr_SetString(PyExc_TypeError,
                "object.__new__() takes no parameters");
            err = -1;
        }
    }
    if (err < 0)
        return NULL;

    if (type->tp_flags & Py_TPFLAGS_IS_ABSTRACT) {
        static PyObject *comma = NULL;
        PyObject *abstract_methods = NULL;
        PyObject *builtins;
        PyObject *sorted;
        PyObject *sorted_methods = NULL;
        PyObject *joined = NULL;

        /* Compute ", ".join(sorted(type.__abstractmethods__))
           into joined. */
        abstract_methods = type_abstractmethods(type, NULL);
        if (abstract_methods == NULL)
            goto error;
        builtins = PyEval_GetBuiltins();
        if (builtins == NULL)
            goto error;
        sorted = PyDict_GetItemString(builtins, "sorted");
        if (sorted == NULL)
            goto error;
        sorted_methods = PyObject_CallFunctionObjArgs(sorted,
                                                      abstract_methods,
                                                      NULL);
        if (sorted_methods == NULL)
            goto error;
        if (comma == NULL) {
            comma = PyUnicode_InternFromString(", ");
            if (comma == NULL)
                goto error;
        }
        joined = PyObject_CallMethod(comma, "join",
                                     "O",  sorted_methods);
        if (joined == NULL)
            goto error;

        PyErr_Format(PyExc_TypeError,
                     "Can't instantiate abstract class %s "
                     "with abstract methods %U",
                     type->tp_name,
                     joined);
    error:
        Py_XDECREF(joined);
        Py_XDECREF(sorted_methods);
        Py_XDECREF(abstract_methods);
        return NULL;
    }
    return type->tp_alloc(type, 0);
}

Here is the call graph for this function:

static PyObject* object_reduce ( PyObject self,
PyObject args 
) [static]

Definition at line 3301 of file typeobject.c.

{
    int proto = 0;

    if (!PyArg_ParseTuple(args, "|i:__reduce__", &proto))
        return NULL;

    return _common_reduce(self, proto);
}

Here is the call graph for this function:

static PyObject* object_reduce_ex ( PyObject self,
PyObject args 
) [static]

Definition at line 3312 of file typeobject.c.

{
    PyObject *reduce, *res;
    int proto = 0;

    if (!PyArg_ParseTuple(args, "|i:__reduce_ex__", &proto))
        return NULL;

    reduce = PyObject_GetAttrString(self, "__reduce__");
    if (reduce == NULL)
        PyErr_Clear();
    else {
        PyObject *cls, *clsreduce, *objreduce;
        int override;
        cls = PyObject_GetAttrString(self, "__class__");
        if (cls == NULL) {
            Py_DECREF(reduce);
            return NULL;
        }
        clsreduce = PyObject_GetAttrString(cls, "__reduce__");
        Py_DECREF(cls);
        if (clsreduce == NULL) {
            Py_DECREF(reduce);
            return NULL;
        }
        objreduce = PyDict_GetItemString(PyBaseObject_Type.tp_dict,
                                         "__reduce__");
        override = (clsreduce != objreduce);
        Py_DECREF(clsreduce);
        if (override) {
            res = PyObject_CallObject(reduce, NULL);
            Py_DECREF(reduce);
            return res;
        }
        else
            Py_DECREF(reduce);
    }

    return _common_reduce(self, proto);
}

Here is the call graph for this function:

static PyObject* object_repr ( PyObject self) [static]

Definition at line 2861 of file typeobject.c.

{
    PyTypeObject *type;
    PyObject *mod, *name, *rtn;

    type = Py_TYPE(self);
    mod = type_module(type, NULL);
    if (mod == NULL)
        PyErr_Clear();
    else if (!PyUnicode_Check(mod)) {
        Py_DECREF(mod);
        mod = NULL;
    }
    name = type_name(type, NULL);
    if (name == NULL)
        return NULL;
    if (mod != NULL && PyUnicode_CompareWithASCIIString(mod, "builtins"))
        rtn = PyUnicode_FromFormat("<%U.%U object at %p>", mod, name, self);
    else
        rtn = PyUnicode_FromFormat("<%s object at %p>",
                                  type->tp_name, self);
    Py_XDECREF(mod);
    Py_DECREF(name);
    return rtn;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* object_richcompare ( PyObject self,
PyObject other,
int  op 
) [static]

Definition at line 2899 of file typeobject.c.

{
    PyObject *res;

    switch (op) {

    case Py_EQ:
        /* Return NotImplemented instead of False, so if two
           objects are compared, both get a chance at the
           comparison.  See issue #1393. */
        res = (self == other) ? Py_True : Py_NotImplemented;
        Py_INCREF(res);
        break;

    case Py_NE:
        /* By default, != returns the opposite of ==,
           unless the latter returns NotImplemented. */
        res = PyObject_RichCompare(self, other, Py_EQ);
        if (res != NULL && res != Py_NotImplemented) {
            int ok = PyObject_IsTrue(res);
            Py_DECREF(res);
            if (ok < 0)
                res = NULL;
            else {
                if (ok)
                    res = Py_False;
                else
                    res = Py_True;
                Py_INCREF(res);
            }
        }
        break;

    default:
        res = Py_NotImplemented;
        Py_INCREF(res);
        break;
    }

    return res;
}

Here is the call graph for this function:

static int object_set_class ( PyObject self,
PyObject value,
void closure 
) [static]

Definition at line 3025 of file typeobject.c.

{
    PyTypeObject *oldto = Py_TYPE(self);
    PyTypeObject *newto;

    if (value == NULL) {
        PyErr_SetString(PyExc_TypeError,
                        "can't delete __class__ attribute");
        return -1;
    }
    if (!PyType_Check(value)) {
        PyErr_Format(PyExc_TypeError,
          "__class__ must be set to new-style class, not '%s' object",
          Py_TYPE(value)->tp_name);
        return -1;
    }
    newto = (PyTypeObject *)value;
    if (!(newto->tp_flags & Py_TPFLAGS_HEAPTYPE) ||
        !(oldto->tp_flags & Py_TPFLAGS_HEAPTYPE))
    {
        PyErr_Format(PyExc_TypeError,
                     "__class__ assignment: only for heap types");
        return -1;
    }
    if (compatible_for_assignment(newto, oldto, "__class__")) {
        Py_INCREF(newto);
        Py_TYPE(self) = newto;
        Py_DECREF(oldto);
        return 0;
    }
    else {
        return -1;
    }
}

Here is the call graph for this function:

static PyObject* object_sizeof ( PyObject self,
PyObject args 
) [static]

Definition at line 3412 of file typeobject.c.

{
    Py_ssize_t res, isize;

    res = 0;
    isize = self->ob_type->tp_itemsize;
    if (isize > 0)
        res = Py_SIZE(self->ob_type) * isize;
    res += self->ob_type->tp_basicsize;

    return PyLong_FromSsize_t(res);
}
static PyObject* object_str ( PyObject self) [static]

Definition at line 2888 of file typeobject.c.

{
    unaryfunc f;

    f = Py_TYPE(self)->tp_repr;
    if (f == NULL || f == object_str)
        f = object_repr;
    return f(self);
}

Here is the call graph for this function:

static PyObject* object_subclasshook ( PyObject cls,
PyObject args 
) [static]

Definition at line 3354 of file typeobject.c.

static int overrides_hash ( PyTypeObject type) [static]

Definition at line 3631 of file typeobject.c.

{
    char **p;
    PyObject *dict = type->tp_dict;

    assert(dict != NULL);
    for (p = hash_name_op; *p; p++) {
        if (PyDict_GetItemString(dict, *p) != NULL)
            return 1;
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int pmerge ( PyObject acc,
PyObject to_merge 
) [static]

Definition at line 1383 of file typeobject.c.

                                          {
    Py_ssize_t i, j, to_merge_size, empty_cnt;
    int *remain;
    int ok;

    to_merge_size = PyList_GET_SIZE(to_merge);

    /* remain stores an index into each sublist of to_merge.
       remain[i] is the index of the next base in to_merge[i]
       that is not included in acc.
    */
    remain = (int *)PyMem_MALLOC(SIZEOF_INT*to_merge_size);
    if (remain == NULL)
        return -1;
    for (i = 0; i < to_merge_size; i++)
        remain[i] = 0;

  again:
    empty_cnt = 0;
    for (i = 0; i < to_merge_size; i++) {
        PyObject *candidate;

        PyObject *cur_list = PyList_GET_ITEM(to_merge, i);

        if (remain[i] >= PyList_GET_SIZE(cur_list)) {
            empty_cnt++;
            continue;
        }

        /* Choose next candidate for MRO.

           The input sequences alone can determine the choice.
           If not, choose the class which appears in the MRO
           of the earliest direct superclass of the new class.
        */

        candidate = PyList_GET_ITEM(cur_list, remain[i]);
        for (j = 0; j < to_merge_size; j++) {
            PyObject *j_lst = PyList_GET_ITEM(to_merge, j);
            if (tail_contains(j_lst, remain[j], candidate)) {
                goto skip; /* continue outer loop */
            }
        }
        ok = PyList_Append(acc, candidate);
        if (ok < 0) {
            PyMem_Free(remain);
            return -1;
        }
        for (j = 0; j < to_merge_size; j++) {
            PyObject *j_lst = PyList_GET_ITEM(to_merge, j);
            if (remain[j] < PyList_GET_SIZE(j_lst) &&
                PyList_GET_ITEM(j_lst, remain[j]) == candidate) {
                remain[j]++;
            }
        }
        goto again;
      skip: ;
    }

    if (empty_cnt == to_merge_size) {
        PyMem_FREE(remain);
        return 0;
    }
    set_mro_error(to_merge, remain);
    PyMem_FREE(remain);
    return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PyDoc_STRVAR ( type_doc  ,
"type(object) -> the object's type\n""type(name, bases, dict) -> a new type  
)
PyDoc_STRVAR ( object_subclasshook_doc  ,
"Abstract classes can override this to customize issubclass().\n""\n""This is invoked early on by abc.ABCMeta.__subclasscheck__().\n""It should return  True,
False or NotImplemented.If it returns\n""  NotImplemented,
the normal algorithm is used.  Otherwise,
it\n""overrides the normal algorithm(and the outcome is cached).\n  
)
PyDoc_STRVAR ( super_doc  ,
"super() -> same as super(__class__, <first argument>)\n""super(type) -> unbound super object\n""super(type, obj) -> bound super object; requires isinstance(obj, type)\n""super(type, type2) -> bound super object; requires issubclass(type2, type)\n""Typical use to call a cooperative superclass method:\n""class C(B):\n"" def meth(self, arg):\n"" super().meth(arg)\n""This works for class methods too:\n""class C(B):\n"" @classmethod\n"" def cmeth(cls, arg):\n"" super().cmeth(arg)\n  
)
unsigned int PyType_ClearCache ( void  )

Definition at line 38 of file typeobject.c.

{
    Py_ssize_t i;
    unsigned int cur_version_tag = next_version_tag - 1;

    for (i = 0; i < (1 << MCACHE_SIZE_EXP); i++) {
        method_cache[i].version = 0;
        Py_CLEAR(method_cache[i].name);
        method_cache[i].value = NULL;
    }
    next_version_tag = 0;
    /* mark all version tags as invalid */
    PyType_Modified(&PyBaseObject_Type);
    return cur_version_tag;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2329 of file typeobject.c.

{
    PyHeapTypeObject *res = (PyHeapTypeObject*)PyType_GenericAlloc(&PyType_Type, 0);
    char *res_start = (char*)res;
    PyType_Slot *slot;

    if (res == NULL)
      return NULL;
    res->ht_name = PyUnicode_FromString(spec->name);
    if (!res->ht_name)
       goto fail;
    res->ht_type.tp_name = _PyUnicode_AsString(res->ht_name);
    if (!res->ht_type.tp_name)
       goto fail;

    res->ht_type.tp_basicsize = spec->basicsize;
    res->ht_type.tp_itemsize = spec->itemsize;
    res->ht_type.tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE;

    for (slot = spec->slots; slot->slot; slot++) {
       if (slot->slot >= sizeof(slotoffsets)/sizeof(slotoffsets[0])) {
           PyErr_SetString(PyExc_RuntimeError, "invalid slot offset");
           goto fail;
       }
       *(void**)(res_start + slotoffsets[slot->slot]) = slot->pfunc;

        /* need to make a copy of the docstring slot, which usually
           points to a static string literal */
        if (slot->slot == Py_tp_doc) {
            ssize_t len = strlen(slot->pfunc)+1;
            char *tp_doc = PyObject_MALLOC(len);
            if (tp_doc == NULL)
              goto fail;
            memcpy(tp_doc, slot->pfunc, len);
            res->ht_type.tp_doc = tp_doc;
        }
    }

    return (PyObject*)res;

 fail:
    Py_DECREF(res);
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 700 of file typeobject.c.

{
    PyObject *obj;
    const size_t size = _PyObject_VAR_SIZE(type, nitems+1);
    /* note that we need to add one, for the sentinel */

    if (PyType_IS_GC(type))
        obj = _PyObject_GC_Malloc(size);
    else
        obj = (PyObject *)PyObject_MALLOC(size);

    if (obj == NULL)
        return PyErr_NoMemory();

    memset(obj, '\0', size);

    if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
        Py_INCREF(type);

    if (type->tp_itemsize == 0)
        PyObject_INIT(obj, type);
    else
        (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);

    if (PyType_IS_GC(type))
        _PyObject_GC_TRACK(obj);
    return obj;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PyObject* PyType_GenericNew ( PyTypeObject type,
PyObject args,
PyObject kwds 
)

Definition at line 730 of file typeobject.c.

{
    return type->tp_alloc(type, 0);
}

Here is the caller graph for this function:

Definition at line 1910 of file typeobject.c.

{
    return type->tp_flags;
}

Definition at line 1084 of file typeobject.c.

{
    PyObject *mro;

    mro = a->tp_mro;
    if (mro != NULL) {
        /* Deal with multiple inheritance without recursion
           by walking the MRO tuple */
        Py_ssize_t i, n;
        assert(PyTuple_Check(mro));
        n = PyTuple_GET_SIZE(mro);
        for (i = 0; i < n; i++) {
            if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b)
                return 1;
        }
        return 0;
    }
    else {
        /* a is not completely initilized yet; follow tp_base */
        do {
            if (a == b)
                return 1;
            a = a->tp_base;
        } while (a != NULL);
        return b == &PyBaseObject_Type;
    }
}

Here is the caller graph for this function:

Definition at line 55 of file typeobject.c.

{
    /* Invalidate any cached data for the specified type and all
       subclasses.  This function is called after the base
       classes, mro, or attributes of the type are altered.

       Invariants:

       - Py_TPFLAGS_VALID_VERSION_TAG is never set if
         Py_TPFLAGS_HAVE_VERSION_TAG is not set (e.g. on type
         objects coming from non-recompiled extension modules)

       - before Py_TPFLAGS_VALID_VERSION_TAG can be set on a type,
         it must first be set on all super types.

       This function clears the Py_TPFLAGS_VALID_VERSION_TAG of a
       type (so it must first clear it on all subclasses).  The
       tp_version_tag value is meaningless unless this flag is set.
       We don't assign new version tags eagerly, but only as
       needed.
     */
    PyObject *raw, *ref;
    Py_ssize_t i, n;

    if (!PyType_HasFeature(type, Py_TPFLAGS_VALID_VERSION_TAG))
        return;

    raw = type->tp_subclasses;
    if (raw != NULL) {
        n = PyList_GET_SIZE(raw);
        for (i = 0; i < n; i++) {
            ref = PyList_GET_ITEM(raw, i);
            ref = PyWeakref_GET_OBJECT(ref);
            if (ref != Py_None) {
                PyType_Modified((PyTypeObject *)ref);
            }
        }
    }
    type->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
}

Here is the caller graph for this function:

Definition at line 3803 of file typeobject.c.

{
    PyObject *dict, *bases;
    PyTypeObject *base;
    Py_ssize_t i, n;

    if (type->tp_flags & Py_TPFLAGS_READY) {
        assert(type->tp_dict != NULL);
        return 0;
    }
    assert((type->tp_flags & Py_TPFLAGS_READYING) == 0);

    type->tp_flags |= Py_TPFLAGS_READYING;

#ifdef Py_TRACE_REFS
    /* PyType_Ready is the closest thing we have to a choke point
     * for type objects, so is the best place I can think of to try
     * to get type objects into the doubly-linked list of all objects.
     * Still, not all type objects go thru PyType_Ready.
     */
    _Py_AddToAllObjects((PyObject *)type, 0);
#endif

    /* Initialize tp_base (defaults to BaseObject unless that's us) */
    base = type->tp_base;
    if (base == NULL && type != &PyBaseObject_Type) {
        base = type->tp_base = &PyBaseObject_Type;
        Py_INCREF(base);
    }

    /* Now the only way base can still be NULL is if type is
     * &PyBaseObject_Type.
     */

    /* Initialize the base class */
    if (base != NULL && base->tp_dict == NULL) {
        if (PyType_Ready(base) < 0)
            goto error;
    }

    /* Initialize ob_type if NULL.      This means extensions that want to be
       compilable separately on Windows can call PyType_Ready() instead of
       initializing the ob_type field of their type objects. */
    /* The test for base != NULL is really unnecessary, since base is only
       NULL when type is &PyBaseObject_Type, and we know its ob_type is
       not NULL (it's initialized to &PyType_Type).      But coverity doesn't
       know that. */
    if (Py_TYPE(type) == NULL && base != NULL)
        Py_TYPE(type) = Py_TYPE(base);

    /* Initialize tp_bases */
    bases = type->tp_bases;
    if (bases == NULL) {
        if (base == NULL)
            bases = PyTuple_New(0);
        else
            bases = PyTuple_Pack(1, base);
        if (bases == NULL)
            goto error;
        type->tp_bases = bases;
    }

    /* Initialize tp_dict */
    dict = type->tp_dict;
    if (dict == NULL) {
        dict = PyDict_New();
        if (dict == NULL)
            goto error;
        type->tp_dict = dict;
    }

    /* Add type-specific descriptors to tp_dict */
    if (add_operators(type) < 0)
        goto error;
    if (type->tp_methods != NULL) {
        if (add_methods(type, type->tp_methods) < 0)
            goto error;
    }
    if (type->tp_members != NULL) {
        if (add_members(type, type->tp_members) < 0)
            goto error;
    }
    if (type->tp_getset != NULL) {
        if (add_getset(type, type->tp_getset) < 0)
            goto error;
    }

    /* Calculate method resolution order */
    if (mro_internal(type) < 0) {
        goto error;
    }

    /* Inherit special flags from dominant base */
    if (type->tp_base != NULL)
        inherit_special(type, type->tp_base);

    /* Initialize tp_dict properly */
    bases = type->tp_mro;
    assert(bases != NULL);
    assert(PyTuple_Check(bases));
    n = PyTuple_GET_SIZE(bases);
    for (i = 1; i < n; i++) {
        PyObject *b = PyTuple_GET_ITEM(bases, i);
        if (PyType_Check(b))
            inherit_slots(type, (PyTypeObject *)b);
    }

    /* Sanity check for tp_free. */
    if (PyType_IS_GC(type) && (type->tp_flags & Py_TPFLAGS_BASETYPE) &&
        (type->tp_free == NULL || type->tp_free == PyObject_Del)) {
        /* This base class needs to call tp_free, but doesn't have
         * one, or its tp_free is for non-gc'ed objects.
         */
        PyErr_Format(PyExc_TypeError, "type '%.100s' participates in "
                     "gc and is a base type but has inappropriate "
                     "tp_free slot",
                     type->tp_name);
        goto error;
    }

    /* if the type dictionary doesn't contain a __doc__, set it from
       the tp_doc slot.
     */
    if (PyDict_GetItemString(type->tp_dict, "__doc__") == NULL) {
        if (type->tp_doc != NULL) {
            PyObject *doc = PyUnicode_FromString(type->tp_doc);
            if (doc == NULL)
                goto error;
            PyDict_SetItemString(type->tp_dict, "__doc__", doc);
            Py_DECREF(doc);
        } else {
            PyDict_SetItemString(type->tp_dict,
                                 "__doc__", Py_None);
        }
    }

    /* Hack for tp_hash and __hash__.
       If after all that, tp_hash is still NULL, and __hash__ is not in
       tp_dict, set tp_hash to PyObject_HashNotImplemented and
       tp_dict['__hash__'] equal to None.
       This signals that __hash__ is not inherited.
     */
    if (type->tp_hash == NULL) {
        if (PyDict_GetItemString(type->tp_dict, "__hash__") == NULL) {
            if (PyDict_SetItemString(type->tp_dict, "__hash__", Py_None) < 0)
                goto error;
            type->tp_hash = PyObject_HashNotImplemented;
        }
    }

    /* Some more special stuff */
    base = type->tp_base;
    if (base != NULL) {
        if (type->tp_as_number == NULL)
            type->tp_as_number = base->tp_as_number;
        if (type->tp_as_sequence == NULL)
            type->tp_as_sequence = base->tp_as_sequence;
        if (type->tp_as_mapping == NULL)
            type->tp_as_mapping = base->tp_as_mapping;
        if (type->tp_as_buffer == NULL)
            type->tp_as_buffer = base->tp_as_buffer;
    }

    /* Link into each base class's list of subclasses */
    bases = type->tp_bases;
    n = PyTuple_GET_SIZE(bases);
    for (i = 0; i < n; i++) {
        PyObject *b = PyTuple_GET_ITEM(bases, i);
        if (PyType_Check(b) &&
            add_subclass((PyTypeObject *)b, type) < 0)
            goto error;
    }

    /* Warn for a type that implements tp_compare (now known as
       tp_reserved) but not tp_richcompare. */
    if (type->tp_reserved && !type->tp_richcompare) {
        int error;
        error = PyErr_WarnFormat(PyExc_DeprecationWarning, 1,
            "Type %.100s defines tp_reserved (formerly tp_compare) "
            "but not tp_richcompare. Comparisons may not behave as intended.",
            type->tp_name);
        if (error == -1)
            goto error;
    }

    /* All done -- set the ready flag */
    assert(type->tp_dict != NULL);
    type->tp_flags =
        (type->tp_flags & ~Py_TPFLAGS_READYING) | Py_TPFLAGS_READY;
    return 0;

  error:
    type->tp_flags &= ~Py_TPFLAGS_READYING;
    return -1;
}

Here is the call graph for this function:

static void raise_dict_descr_error ( PyObject obj) [static]

Definition at line 1728 of file typeobject.c.

{
    PyErr_Format(PyExc_TypeError,
                 "this __dict__ descriptor does not support "
                 "'%.200s' objects", Py_TYPE(obj)->tp_name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int recurse_down_subclasses ( PyTypeObject type,
PyObject name,
update_callback  callback,
void data 
) [static]

Definition at line 5901 of file typeobject.c.

{
    PyTypeObject *subclass;
    PyObject *ref, *subclasses, *dict;
    Py_ssize_t i, n;

    subclasses = type->tp_subclasses;
    if (subclasses == NULL)
        return 0;
    assert(PyList_Check(subclasses));
    n = PyList_GET_SIZE(subclasses);
    for (i = 0; i < n; i++) {
        ref = PyList_GET_ITEM(subclasses, i);
        assert(PyWeakref_CheckRef(ref));
        subclass = (PyTypeObject *)PyWeakref_GET_OBJECT(ref);
        assert(subclass != NULL);
        if ((PyObject *)subclass == Py_None)
            continue;
        assert(PyType_Check(subclass));
        /* Avoid recursing down into unaffected classes */
        dict = subclass->tp_dict;
        if (dict != NULL && PyDict_Check(dict) &&
            PyDict_GetItem(dict, name) != NULL)
            continue;
        if (update_subclasses(subclass, name, callback, data) < 0)
            return -1;
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* reduce_2 ( PyObject obj) [static]

Definition at line 3127 of file typeobject.c.

{
    PyObject *cls, *getnewargs;
    PyObject *args = NULL, *args2 = NULL;
    PyObject *getstate = NULL, *state = NULL, *names = NULL;
    PyObject *slots = NULL, *listitems = NULL, *dictitems = NULL;
    PyObject *copyreg = NULL, *newobj = NULL, *res = NULL;
    Py_ssize_t i, n;

    cls = PyObject_GetAttrString(obj, "__class__");
    if (cls == NULL)
        return NULL;

    getnewargs = PyObject_GetAttrString(obj, "__getnewargs__");
    if (getnewargs != NULL) {
        args = PyObject_CallObject(getnewargs, NULL);
        Py_DECREF(getnewargs);
        if (args != NULL && !PyTuple_Check(args)) {
            PyErr_Format(PyExc_TypeError,
                "__getnewargs__ should return a tuple, "
                "not '%.200s'", Py_TYPE(args)->tp_name);
            goto end;
        }
    }
    else {
        PyErr_Clear();
        args = PyTuple_New(0);
    }
    if (args == NULL)
        goto end;

    getstate = PyObject_GetAttrString(obj, "__getstate__");
    if (getstate != NULL) {
        state = PyObject_CallObject(getstate, NULL);
        Py_DECREF(getstate);
        if (state == NULL)
            goto end;
    }
    else {
        PyErr_Clear();
        state = PyObject_GetAttrString(obj, "__dict__");
        if (state == NULL) {
            PyErr_Clear();
            state = Py_None;
            Py_INCREF(state);
        }
        names = slotnames(cls);
        if (names == NULL)
            goto end;
        if (names != Py_None) {
            assert(PyList_Check(names));
            slots = PyDict_New();
            if (slots == NULL)
                goto end;
            n = 0;
            /* Can't pre-compute the list size; the list
               is stored on the class so accessible to other
               threads, which may be run by DECREF */
            for (i = 0; i < PyList_GET_SIZE(names); i++) {
                PyObject *name, *value;
                name = PyList_GET_ITEM(names, i);
                value = PyObject_GetAttr(obj, name);
                if (value == NULL)
                    PyErr_Clear();
                else {
                    int err = PyDict_SetItem(slots, name,
                                             value);
                    Py_DECREF(value);
                    if (err)
                        goto end;
                    n++;
                }
            }
            if (n) {
                state = Py_BuildValue("(NO)", state, slots);
                if (state == NULL)
                    goto end;
            }
        }
    }

    if (!PyList_Check(obj)) {
        listitems = Py_None;
        Py_INCREF(listitems);
    }
    else {
        listitems = PyObject_GetIter(obj);
        if (listitems == NULL)
            goto end;
    }

    if (!PyDict_Check(obj)) {
        dictitems = Py_None;
        Py_INCREF(dictitems);
    }
    else {
        PyObject *items = PyObject_CallMethod(obj, "items", "");
        if (items == NULL)
            goto end;
        dictitems = PyObject_GetIter(items);
        Py_DECREF(items);
        if (dictitems == NULL)
            goto end;
    }

    copyreg = import_copyreg();
    if (copyreg == NULL)
        goto end;
    newobj = PyObject_GetAttrString(copyreg, "__newobj__");
    if (newobj == NULL)
        goto end;

    n = PyTuple_GET_SIZE(args);
    args2 = PyTuple_New(n+1);
    if (args2 == NULL)
        goto end;
    PyTuple_SET_ITEM(args2, 0, cls);
    cls = NULL;
    for (i = 0; i < n; i++) {
        PyObject *v = PyTuple_GET_ITEM(args, i);
        Py_INCREF(v);
        PyTuple_SET_ITEM(args2, i+1, v);
    }

    res = PyTuple_Pack(5, newobj, args2, state, listitems, dictitems);

  end:
    Py_XDECREF(cls);
    Py_XDECREF(args);
    Py_XDECREF(args2);
    Py_XDECREF(slots);
    Py_XDECREF(state);
    Py_XDECREF(names);
    Py_XDECREF(listitems);
    Py_XDECREF(dictitems);
    Py_XDECREF(copyreg);
    Py_XDECREF(newobj);
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void remove_subclass ( PyTypeObject base,
PyTypeObject type 
) [static]

Definition at line 4027 of file typeobject.c.

{
    Py_ssize_t i;
    PyObject *list, *ref;

    list = base->tp_subclasses;
    if (list == NULL) {
        return;
    }
    assert(PyList_Check(list));
    i = PyList_GET_SIZE(list);
    while (--i >= 0) {
        ref = PyList_GET_ITEM(list, i);
        assert(PyWeakref_CheckRef(ref));
        if (PyWeakref_GET_OBJECT(ref) == (PyObject*)type) {
            /* this can't fail, right? */
            PySequence_DelItem(list, i);
            return;
        }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void** resolve_slotdups ( PyTypeObject type,
PyObject name 
) [static]

Definition at line 5657 of file typeobject.c.

{
    /* XXX Maybe this could be optimized more -- but is it worth it? */

    /* pname and ptrs act as a little cache */
    static PyObject *pname;
    static slotdef *ptrs[MAX_EQUIV];
    slotdef *p, **pp;
    void **res, **ptr;

    if (pname != name) {
        /* Collect all slotdefs that match name into ptrs. */
        pname = name;
        pp = ptrs;
        for (p = slotdefs; p->name_strobj; p++) {
            if (p->name_strobj == name)
                *pp++ = p;
        }
        *pp = NULL;
    }

    /* Look in all matching slots of the type; if exactly one of these has
       a filled-in slot, return its value.      Otherwise return NULL. */
    res = NULL;
    for (pp = ptrs; *pp; pp++) {
        ptr = slotptr(type, (*pp)->offset);
        if (ptr == NULL || *ptr == NULL)
            continue;
        if (res != NULL)
            return NULL;
        res = ptr;
    }
    return res;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int same_slots_added ( PyTypeObject a,
PyTypeObject b 
) [static]

Definition at line 2963 of file typeobject.c.

{
    PyTypeObject *base = a->tp_base;
    Py_ssize_t size;
    PyObject *slots_a, *slots_b;

    assert(base == b->tp_base);
    size = base->tp_basicsize;
    if (a->tp_dictoffset == size && b->tp_dictoffset == size)
        size += sizeof(PyObject *);
    if (a->tp_weaklistoffset == size && b->tp_weaklistoffset == size)
        size += sizeof(PyObject *);

    /* Check slots compliance */
    slots_a = ((PyHeapTypeObject *)a)->ht_slots;
    slots_b = ((PyHeapTypeObject *)b)->ht_slots;
    if (slots_a && slots_b) {
        if (PyObject_RichCompareBool(slots_a, slots_b, Py_EQ) != 1)
            return 0;
        size += sizeof(PyObject *) * PyTuple_GET_SIZE(slots_a);
    }
    return size == a->tp_basicsize && size == b->tp_basicsize;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void set_mro_error ( PyObject to_merge,
int remain 
) [static]

Definition at line 1338 of file typeobject.c.

{
    Py_ssize_t i, n, off, to_merge_size;
    char buf[1000];
    PyObject *k, *v;
    PyObject *set = PyDict_New();
    if (!set) return;

    to_merge_size = PyList_GET_SIZE(to_merge);
    for (i = 0; i < to_merge_size; i++) {
        PyObject *L = PyList_GET_ITEM(to_merge, i);
        if (remain[i] < PyList_GET_SIZE(L)) {
            PyObject *c = PyList_GET_ITEM(L, remain[i]);
            if (PyDict_SetItem(set, c, Py_None) < 0) {
                Py_DECREF(set);
                return;
            }
        }
    }
    n = PyDict_Size(set);

    off = PyOS_snprintf(buf, sizeof(buf), "Cannot create a \
consistent method resolution\norder (MRO) for bases");
    i = 0;
    while (PyDict_Next(set, &i, &k, &v) && (size_t)off < sizeof(buf)) {
        PyObject *name = class_name(k);
        char *name_str;
        if (name != NULL) {
            name_str = _PyUnicode_AsString(name);
            if (name_str == NULL)
                name_str = "?";
        } else
            name_str = "?";
        off += PyOS_snprintf(buf + off, sizeof(buf) - off, " %s", name_str);
        Py_XDECREF(name);
        if (--n && (size_t)(off+1) < sizeof(buf)) {
            buf[off++] = ',';
            buf[off] = '\0';
        }
    }
    PyErr_SetString(PyExc_TypeError, buf);
    Py_DECREF(set);
}

Here is the call graph for this function:

Here is the caller graph for this function:

SLOT1BIN ( slot_nb_floor_divide  ,
nb_floor_divide  ,
"__floordiv__"  ,
"__rfloordiv__"   
)

Definition at line 4939 of file typeobject.c.

{
    PyObject *func, *res;
    static PyObject *repr_str;

    func = lookup_method(self, "__repr__", &repr_str);
    if (func != NULL) {
        res = PyEval_CallObject(func, NULL);
        Py_DECREF(func);
        return res;
    }
    PyErr_Clear();
    return PyUnicode_FromFormat("<%s object at %p>",
                               Py_TYPE(self)->tp_name, self);
}

Here is the call graph for this function:

SLOT1BINFULL ( slot_nb_power_binary  ,
slot_nb_power  ,
nb_power  ,
"__pow__"  ,
"__rpow__"   
)

Definition at line 4836 of file typeobject.c.

{
    static PyObject *pow_str;

    if (modulus == Py_None)
        return slot_nb_power_binary(self, other);
    /* Three-arg power doesn't use __rpow__.  But ternary_op
       can call this when the second argument's type uses
       slot_nb_power, so check before calling self.__pow__. */
    if (Py_TYPE(self)->tp_as_number != NULL &&
        Py_TYPE(self)->tp_as_number->nb_power == slot_nb_power) {
        return call_method(self, "__pow__", &pow_str,
                           "(OO)", other, modulus);
    }
    Py_INCREF(Py_NotImplemented);
    return Py_NotImplemented;
}

Here is the call graph for this function:

static int slot_mp_ass_subscript ( PyObject self,
PyObject key,
PyObject value 
) [static]

Definition at line 4811 of file typeobject.c.

{
    PyObject *res;
    static PyObject *delitem_str, *setitem_str;

    if (value == NULL)
        res = call_method(self, "__delitem__", &delitem_str,
                          "(O)", key);
    else
        res = call_method(self, "__setitem__", &setitem_str,
                         "(OO)", key, value);
    if (res == NULL)
        return -1;
    Py_DECREF(res);
    return 0;
}

Here is the call graph for this function:

static int slot_nb_bool ( PyObject self) [static]

Definition at line 4863 of file typeobject.c.

{
    PyObject *func, *args;
    static PyObject *bool_str, *len_str;
    int result = -1;
    int using_len = 0;

    func = lookup_maybe(self, "__bool__", &bool_str);
    if (func == NULL) {
        if (PyErr_Occurred())
            return -1;
        func = lookup_maybe(self, "__len__", &len_str);
        if (func == NULL)
            return PyErr_Occurred() ? -1 : 1;
        using_len = 1;
    }
    args = PyTuple_New(0);
    if (args != NULL) {
        PyObject *temp = PyObject_Call(func, args, NULL);
        Py_DECREF(args);
        if (temp != NULL) {
            if (using_len) {
                /* enforced by slot_nb_len */
                result = PyObject_IsTrue(temp);
            }
            else if (PyBool_Check(temp)) {
                result = PyObject_IsTrue(temp);
            }
            else {
                PyErr_Format(PyExc_TypeError,
                             "__bool__ should return "
                             "bool, returned %s",
                             Py_TYPE(temp)->tp_name);
                result = -1;
            }
            Py_DECREF(temp);
        }
    }
    Py_DECREF(func);
    return result;
}

Here is the call graph for this function:

static PyObject* slot_nb_index ( PyObject self) [static]

Definition at line 4907 of file typeobject.c.

{
    static PyObject *index_str;
    return call_method(self, "__index__", &index_str, "()");
}

Here is the call graph for this function:

static PyObject* slot_nb_inplace_power ( PyObject self,
PyObject arg1,
PyObject arg2 
) [static]

Definition at line 4929 of file typeobject.c.

{
  static PyObject *cache_str;
  return call_method(self, "__ipow__", &cache_str, "(" "O" ")", arg1);
}

Here is the call graph for this function:

static PyObject* slot_nb_power ( PyObject ,
PyObject ,
PyObject  
) [static]
static int slot_sq_ass_item ( PyObject self,
Py_ssize_t  index,
PyObject value 
) [static]

Definition at line 4758 of file typeobject.c.

{
    PyObject *res;
    static PyObject *delitem_str, *setitem_str;

    if (value == NULL)
        res = call_method(self, "__delitem__", &delitem_str,
                          "(n)", index);
    else
        res = call_method(self, "__setitem__", &setitem_str,
                          "(nO)", index, value);
    if (res == NULL)
        return -1;
    Py_DECREF(res);
    return 0;
}

Here is the call graph for this function:

static int slot_sq_contains ( PyObject self,
PyObject value 
) [static]

Definition at line 4776 of file typeobject.c.

{
    PyObject *func, *res, *args;
    int result = -1;

    static PyObject *contains_str;

    func = lookup_maybe(self, "__contains__", &contains_str);
    if (func != NULL) {
        args = PyTuple_Pack(1, value);
        if (args == NULL)
            res = NULL;
        else {
            res = PyObject_Call(func, args, NULL);
            Py_DECREF(args);
        }
        Py_DECREF(func);
        if (res != NULL) {
            result = PyObject_IsTrue(res);
            Py_DECREF(res);
        }
    }
    else if (! PyErr_Occurred()) {
        /* Possible results: -1 and 1 */
        result = (int)_PySequence_IterSearch(self, value,
                                         PY_ITERSEARCH_CONTAINS);
    }
    return result;
}

Here is the call graph for this function:

static PyObject* slot_sq_item ( PyObject self,
Py_ssize_t  i 
) [static]

Definition at line 4715 of file typeobject.c.

{
    static PyObject *getitem_str;
    PyObject *func, *args = NULL, *ival = NULL, *retval = NULL;
    descrgetfunc f;

    if (getitem_str == NULL) {
        getitem_str = PyUnicode_InternFromString("__getitem__");
        if (getitem_str == NULL)
            return NULL;
    }
    func = _PyType_Lookup(Py_TYPE(self), getitem_str);
    if (func != NULL) {
        if ((f = Py_TYPE(func)->tp_descr_get) == NULL)
            Py_INCREF(func);
        else {
            func = f(func, self, (PyObject *)(Py_TYPE(self)));
            if (func == NULL) {
                return NULL;
            }
        }
        ival = PyLong_FromSsize_t(i);
        if (ival != NULL) {
            args = PyTuple_New(1);
            if (args != NULL) {
                PyTuple_SET_ITEM(args, 0, ival);
                retval = PyObject_Call(func, args, NULL);
                Py_XDECREF(args);
                Py_XDECREF(func);
                return retval;
            }
        }
    }
    else {
        PyErr_SetObject(PyExc_AttributeError, getitem_str);
    }
    Py_XDECREF(args);
    Py_XDECREF(ival);
    Py_XDECREF(func);
    return NULL;
}

Here is the call graph for this function:

static Py_ssize_t slot_sq_length ( PyObject self) [static]

Definition at line 4693 of file typeobject.c.

{
    static PyObject *len_str;
    PyObject *res = call_method(self, "__len__", &len_str, "()");
    Py_ssize_t len;

    if (res == NULL)
        return -1;
    len = PyNumber_AsSsize_t(res, PyExc_OverflowError);
    Py_DECREF(res);
    if (len < 0) {
        if (!PyErr_Occurred())
            PyErr_SetString(PyExc_ValueError,
                            "__len__() should return >= 0");
        return -1;
    }
    return len;
}

Here is the call graph for this function:

static PyObject* slot_tp_call ( PyObject self,
PyObject args,
PyObject kwds 
) [static]

Definition at line 5035 of file typeobject.c.

{
    static PyObject *call_str;
    PyObject *meth = lookup_method(self, "__call__", &call_str);
    PyObject *res;

    if (meth == NULL)
        return NULL;

    res = PyObject_Call(meth, args, kwds);

    Py_DECREF(meth);
    return res;
}

Here is the call graph for this function:

static void slot_tp_del ( PyObject self) [static]

Definition at line 5332 of file typeobject.c.

{
    static PyObject *del_str = NULL;
    PyObject *del, *res;
    PyObject *error_type, *error_value, *error_traceback;

    /* Temporarily resurrect the object. */
    assert(self->ob_refcnt == 0);
    self->ob_refcnt = 1;

    /* Save the current exception, if any. */
    PyErr_Fetch(&error_type, &error_value, &error_traceback);

    /* Execute __del__ method, if any. */
    del = lookup_maybe(self, "__del__", &del_str);
    if (del != NULL) {
        res = PyEval_CallObject(del, NULL);
        if (res == NULL)
            PyErr_WriteUnraisable(del);
        else
            Py_DECREF(res);
        Py_DECREF(del);
    }

    /* Restore the saved exception. */
    PyErr_Restore(error_type, error_value, error_traceback);

    /* Undo the temporary resurrection; can't use DECREF here, it would
     * cause a recursive call.
     */
    assert(self->ob_refcnt > 0);
    if (--self->ob_refcnt == 0)
        return;         /* this is the normal path out */

    /* __del__ resurrected it!  Make it look like the original Py_DECREF
     * never happened.
     */
    {
        Py_ssize_t refcnt = self->ob_refcnt;
        _Py_NewReference(self);
        self->ob_refcnt = refcnt;
    }
    assert(!PyType_IS_GC(Py_TYPE(self)) ||
           _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED);
    /* If Py_REF_DEBUG, _Py_NewReference bumped _Py_RefTotal, so
     * we need to undo that. */
    _Py_DEC_REFTOTAL;
    /* If Py_TRACE_REFS, _Py_NewReference re-added self to the object
     * chain, so no more to do there.
     * If COUNT_ALLOCS, the original decref bumped tp_frees, and
     * _Py_NewReference bumped tp_allocs:  both of those need to be
     * undone.
     */
#ifdef COUNT_ALLOCS
    --Py_TYPE(self)->tp_frees;
    --Py_TYPE(self)->tp_allocs;
#endif
}

Here is the call graph for this function:

static PyObject* slot_tp_descr_get ( PyObject self,
PyObject obj,
PyObject type 
) [static]

Definition at line 5229 of file typeobject.c.

{
    PyTypeObject *tp = Py_TYPE(self);
    PyObject *get;
    static PyObject *get_str = NULL;

    if (get_str == NULL) {
        get_str = PyUnicode_InternFromString("__get__");
        if (get_str == NULL)
            return NULL;
    }
    get = _PyType_Lookup(tp, get_str);
    if (get == NULL) {
        /* Avoid further slowdowns */
        if (tp->tp_descr_get == slot_tp_descr_get)
            tp->tp_descr_get = NULL;
        Py_INCREF(self);
        return self;
    }
    if (obj == NULL)
        obj = Py_None;
    if (type == NULL)
        type = Py_None;
    return PyObject_CallFunctionObjArgs(get, self, obj, type, NULL);
}

Here is the call graph for this function:

static int slot_tp_descr_set ( PyObject self,
PyObject target,
PyObject value 
) [static]

Definition at line 5256 of file typeobject.c.

{
    PyObject *res;
    static PyObject *del_str, *set_str;

    if (value == NULL)
        res = call_method(self, "__delete__", &del_str,
                          "(O)", target);
    else
        res = call_method(self, "__set__", &set_str,
                          "(OO)", target, value);
    if (res == NULL)
        return -1;
    Py_DECREF(res);
    return 0;
}

Here is the call graph for this function:

static PyObject* slot_tp_getattr_hook ( PyObject self,
PyObject name 
) [static]

Definition at line 5088 of file typeobject.c.

{
    PyTypeObject *tp = Py_TYPE(self);
    PyObject *getattr, *getattribute, *res;
    static PyObject *getattribute_str = NULL;
    static PyObject *getattr_str = NULL;

    if (getattr_str == NULL) {
        getattr_str = PyUnicode_InternFromString("__getattr__");
        if (getattr_str == NULL)
            return NULL;
    }
    if (getattribute_str == NULL) {
        getattribute_str =
            PyUnicode_InternFromString("__getattribute__");
        if (getattribute_str == NULL)
            return NULL;
    }
    /* speed hack: we could use lookup_maybe, but that would resolve the
       method fully for each attribute lookup for classes with
       __getattr__, even when the attribute is present. So we use
       _PyType_Lookup and create the method only when needed, with
       call_attribute. */
    getattr = _PyType_Lookup(tp, getattr_str);
    if (getattr == NULL) {
        /* No __getattr__ hook: use a simpler dispatcher */
        tp->tp_getattro = slot_tp_getattro;
        return slot_tp_getattro(self, name);
    }
    Py_INCREF(getattr);
    /* speed hack: we could use lookup_maybe, but that would resolve the
       method fully for each attribute lookup for classes with
       __getattr__, even when self has the default __getattribute__
       method. So we use _PyType_Lookup and create the method only when
       needed, with call_attribute. */
    getattribute = _PyType_Lookup(tp, getattribute_str);
    if (getattribute == NULL ||
        (Py_TYPE(getattribute) == &PyWrapperDescr_Type &&
         ((PyWrapperDescrObject *)getattribute)->d_wrapped ==
         (void *)PyObject_GenericGetAttr))
        res = PyObject_GenericGetAttr(self, name);
    else {
        Py_INCREF(getattribute);
        res = call_attribute(self, getattribute, name);
        Py_DECREF(getattribute);
    }
    if (res == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
        PyErr_Clear();
        res = call_attribute(self, getattr, name);
    }
    Py_DECREF(getattr);
    return res;
}

Here is the call graph for this function:

static PyObject* slot_tp_getattro ( PyObject self,
PyObject name 
) [static]

Definition at line 5062 of file typeobject.c.

{
    static PyObject *getattribute_str = NULL;
    return call_method(self, "__getattribute__", &getattribute_str,
                       "(O)", name);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static Py_hash_t slot_tp_hash ( PyObject self) [static]

Definition at line 4987 of file typeobject.c.

{
    PyObject *func, *res;
    static PyObject *hash_str;
    Py_ssize_t h;

    func = lookup_method(self, "__hash__", &hash_str);

    if (func == Py_None) {
        Py_DECREF(func);
        func = NULL;
    }

    if (func == NULL) {
        return PyObject_HashNotImplemented(self);
    }

    res = PyEval_CallObject(func, NULL);
    Py_DECREF(func);
    if (res == NULL)
        return -1;

    if (!PyLong_Check(res)) {
        PyErr_SetString(PyExc_TypeError,
                        "__hash__ method should return an integer");
        return -1;
    }
    /* Transform the PyLong `res` to a Py_hash_t `h`.  For an existing
       hashable Python object x, hash(x) will always lie within the range of
       Py_hash_t.  Therefore our transformation must preserve values that
       already lie within this range, to ensure that if x.__hash__() returns
       hash(y) then hash(x) == hash(y). */
    h = PyLong_AsSsize_t(res);
    if (h == -1 && PyErr_Occurred()) {
        /* res was not within the range of a Py_hash_t, so we're free to
           use any sufficiently bit-mixing transformation;
           long.__hash__ will do nicely. */
        PyErr_Clear();
        h = PyLong_Type.tp_hash(res);
    }
    /* -1 is reserved for errors. */
    if (h == -1)
        h = -2;
    Py_DECREF(res);
    return h;
}

Here is the call graph for this function:

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

Definition at line 5274 of file typeobject.c.

{
    static PyObject *init_str;
    PyObject *meth = lookup_method(self, "__init__", &init_str);
    PyObject *res;

    if (meth == NULL)
        return -1;
    res = PyObject_Call(meth, args, kwds);
    Py_DECREF(meth);
    if (res == NULL)
        return -1;
    if (res != Py_None) {
        PyErr_Format(PyExc_TypeError,
                     "__init__() should return None, not '%.200s'",
                     Py_TYPE(res)->tp_name);
        Py_DECREF(res);
        return -1;
    }
    Py_DECREF(res);
    return 0;
}

Here is the call graph for this function:

static PyObject* slot_tp_iter ( PyObject self) [static]

Definition at line 5193 of file typeobject.c.

{
    PyObject *func, *res;
    static PyObject *iter_str, *getitem_str;

    func = lookup_method(self, "__iter__", &iter_str);
    if (func != NULL) {
        PyObject *args;
        args = res = PyTuple_New(0);
        if (args != NULL) {
            res = PyObject_Call(func, args, NULL);
            Py_DECREF(args);
        }
        Py_DECREF(func);
        return res;
    }
    PyErr_Clear();
    func = lookup_method(self, "__getitem__", &getitem_str);
    if (func == NULL) {
        PyErr_Format(PyExc_TypeError,
                     "'%.200s' object is not iterable",
                     Py_TYPE(self)->tp_name);
        return NULL;
    }
    Py_DECREF(func);
    return PySeqIter_New(self);
}

Here is the call graph for this function:

static PyObject* slot_tp_iternext ( PyObject self) [static]

Definition at line 5222 of file typeobject.c.

{
    static PyObject *next_str;
    return call_method(self, "__next__", &next_str, "()");
}

Here is the call graph for this function:

static PyObject* slot_tp_new ( PyTypeObject type,
PyObject args,
PyObject kwds 
) [static]

Definition at line 5298 of file typeobject.c.

{
    static PyObject *new_str;
    PyObject *func;
    PyObject *newargs, *x;
    Py_ssize_t i, n;

    if (new_str == NULL) {
        new_str = PyUnicode_InternFromString("__new__");
        if (new_str == NULL)
            return NULL;
    }
    func = PyObject_GetAttr((PyObject *)type, new_str);
    if (func == NULL)
        return NULL;
    assert(PyTuple_Check(args));
    n = PyTuple_GET_SIZE(args);
    newargs = PyTuple_New(n+1);
    if (newargs == NULL)
        return NULL;
    Py_INCREF(type);
    PyTuple_SET_ITEM(newargs, 0, (PyObject *)type);
    for (i = 0; i < n; i++) {
        x = PyTuple_GET_ITEM(args, i);
        Py_INCREF(x);
        PyTuple_SET_ITEM(newargs, i+1, x);
    }
    x = PyObject_Call(func, newargs, kwds);
    Py_DECREF(newargs);
    Py_DECREF(func);
    return x;
}

Here is the call graph for this function:

static PyObject* slot_tp_richcompare ( PyObject self,
PyObject other,
int  op 
) [static]

Definition at line 5170 of file typeobject.c.

{
    PyObject *func, *args, *res;
    static PyObject *op_str[6];

    func = lookup_method(self, name_op[op], &op_str[op]);
    if (func == NULL) {
        PyErr_Clear();
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }
    args = PyTuple_Pack(1, other);
    if (args == NULL)
        res = NULL;
    else {
        res = PyObject_Call(func, args, NULL);
        Py_DECREF(args);
    }
    Py_DECREF(func);
    return res;
}

Here is the call graph for this function:

static int slot_tp_setattro ( PyObject self,
PyObject name,
PyObject value 
) [static]

Definition at line 5143 of file typeobject.c.

{
    PyObject *res;
    static PyObject *delattr_str, *setattr_str;

    if (value == NULL)
        res = call_method(self, "__delattr__", &delattr_str,
                          "(O)", name);
    else
        res = call_method(self, "__setattr__", &setattr_str,
                          "(OO)", name, value);
    if (res == NULL)
        return -1;
    Py_DECREF(res);
    return 0;
}

Here is the call graph for this function:

static PyObject* slot_tp_str ( PyObject self) [static]

Definition at line 4963 of file typeobject.c.

{
    PyObject *func, *res;
    static PyObject *str_str;

    func = lookup_method(self, "__str__", &str_str);
    if (func != NULL) {
        res = PyEval_CallObject(func, NULL);
        Py_DECREF(func);
        return res;
    }
    else {
        PyObject *ress;
        PyErr_Clear();
        res = slot_tp_repr(self);
        if (!res)
            return NULL;
        ress = _PyUnicode_AsDefaultEncodedString(res, NULL);
        Py_DECREF(res);
        return ress;
    }
}

Here is the call graph for this function:

static int slotdef_cmp ( const void aa,
const void bb 
) [static]

Definition at line 5793 of file typeobject.c.

{
    const slotdef *a = (const slotdef *)aa, *b = (const slotdef *)bb;
    int c = a->offset - b->offset;
    if (c != 0)
        return c;
    else
        /* Cannot use a-b, as this gives off_t,
           which may lose precision when converted to int. */
        return (a > b) ? 1 : (a < b) ? -1 : 0;
}

Here is the caller graph for this function:

static PyObject* slotnames ( PyObject cls) [static]

Definition at line 3089 of file typeobject.c.

{
    PyObject *clsdict;
    PyObject *copyreg;
    PyObject *slotnames;

    if (!PyType_Check(cls)) {
        Py_INCREF(Py_None);
        return Py_None;
    }

    clsdict = ((PyTypeObject *)cls)->tp_dict;
    slotnames = PyDict_GetItemString(clsdict, "__slotnames__");
    if (slotnames != NULL && PyList_Check(slotnames)) {
        Py_INCREF(slotnames);
        return slotnames;
    }

    copyreg = import_copyreg();
    if (copyreg == NULL)
        return NULL;

    slotnames = PyObject_CallMethod(copyreg, "_slotnames", "O", cls);
    Py_DECREF(copyreg);
    if (slotnames != NULL &&
        slotnames != Py_None &&
        !PyList_Check(slotnames))
    {
        PyErr_SetString(PyExc_TypeError,
            "copyreg._slotnames didn't return a list or None");
        Py_DECREF(slotnames);
        slotnames = NULL;
    }

    return slotnames;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void** slotptr ( PyTypeObject type,
int  ioffset 
) [static]

Definition at line 5620 of file typeobject.c.

{
    char *ptr;
    long offset = ioffset;

    /* Note: this depends on the order of the members of PyHeapTypeObject! */
    assert(offset >= 0);
    assert((size_t)offset < offsetof(PyHeapTypeObject, as_buffer));
    if ((size_t)offset >= offsetof(PyHeapTypeObject, as_sequence)) {
        ptr = (char *)type->tp_as_sequence;
        offset -= offsetof(PyHeapTypeObject, as_sequence);
    }
    else if ((size_t)offset >= offsetof(PyHeapTypeObject, as_mapping)) {
        ptr = (char *)type->tp_as_mapping;
        offset -= offsetof(PyHeapTypeObject, as_mapping);
    }
    else if ((size_t)offset >= offsetof(PyHeapTypeObject, as_number)) {
        ptr = (char *)type->tp_as_number;
        offset -= offsetof(PyHeapTypeObject, as_number);
    }
    else {
        ptr = (char *)type;
    }
    if (ptr != NULL)
        ptr += offset;
    return (void **)ptr;
}

Here is the caller graph for this function:

static PyTypeObject * solid_base ( PyTypeObject type) [static]

Definition at line 1673 of file typeobject.c.

{
    PyTypeObject *base;

    if (type->tp_base)
        base = solid_base(type->tp_base);
    else
        base = &PyBaseObject_Type;
    if (extra_ivars(type, base))
        return type;
    else
        return base;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int subtype_clear ( PyObject self) [static]

Definition at line 817 of file typeobject.c.

{
    PyTypeObject *type, *base;
    inquiry baseclear;

    /* Find the nearest base with a different tp_clear
       and clear slots while we're at it */
    type = Py_TYPE(self);
    base = type;
    while ((baseclear = base->tp_clear) == subtype_clear) {
        if (Py_SIZE(base))
            clear_slots(base, self);
        base = base->tp_base;
        assert(base);
    }

    /* There's no need to clear the instance dict (if any);
       the collector will call its tp_clear handler. */

    if (baseclear)
        return baseclear(self);
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void subtype_dealloc ( PyObject self) [static]

Definition at line 842 of file typeobject.c.

{
    PyTypeObject *type, *base;
    destructor basedealloc;

    /* Extract the type; we expect it to be a heap type */
    type = Py_TYPE(self);
    assert(type->tp_flags & Py_TPFLAGS_HEAPTYPE);

    /* Test whether the type has GC exactly once */

    if (!PyType_IS_GC(type)) {
        /* It's really rare to find a dynamic type that doesn't have
           GC; it can only happen when deriving from 'object' and not
           adding any slots or instance variables.  This allows
           certain simplifications: there's no need to call
           clear_slots(), or DECREF the dict, or clear weakrefs. */

        /* Maybe call finalizer; exit early if resurrected */
        if (type->tp_del) {
            type->tp_del(self);
            if (self->ob_refcnt > 0)
                return;
        }

        /* Find the nearest base with a different tp_dealloc */
        base = type;
        while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
            assert(Py_SIZE(base) == 0);
            base = base->tp_base;
            assert(base);
        }

        /* Extract the type again; tp_del may have changed it */
        type = Py_TYPE(self);

        /* Call the base tp_dealloc() */
        assert(basedealloc);
        basedealloc(self);

        /* Can't reference self beyond this point */
        Py_DECREF(type);

        /* Done */
        return;
    }

    /* We get here only if the type has GC */

    /* UnTrack and re-Track around the trashcan macro, alas */
    /* See explanation at end of function for full disclosure */
    PyObject_GC_UnTrack(self);
    ++_PyTrash_delete_nesting;
    Py_TRASHCAN_SAFE_BEGIN(self);
    --_PyTrash_delete_nesting;
    /* DO NOT restore GC tracking at this point.  weakref callbacks
     * (if any, and whether directly here or indirectly in something we
     * call) may trigger GC, and if self is tracked at that point, it
     * will look like trash to GC and GC will try to delete self again.
     */

    /* Find the nearest base with a different tp_dealloc */
    base = type;
    while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
        base = base->tp_base;
        assert(base);
    }

    /* If we added a weaklist, we clear it.      Do this *before* calling
       the finalizer (__del__), clearing slots, or clearing the instance
       dict. */

    if (type->tp_weaklistoffset && !base->tp_weaklistoffset)
        PyObject_ClearWeakRefs(self);

    /* Maybe call finalizer; exit early if resurrected */
    if (type->tp_del) {
        _PyObject_GC_TRACK(self);
        type->tp_del(self);
        if (self->ob_refcnt > 0)
            goto endlabel;              /* resurrected */
        else
            _PyObject_GC_UNTRACK(self);
        /* New weakrefs could be created during the finalizer call.
            If this occurs, clear them out without calling their
            finalizers since they might rely on part of the object
            being finalized that has already been destroyed. */
        if (type->tp_weaklistoffset && !base->tp_weaklistoffset) {
            /* Modeled after GET_WEAKREFS_LISTPTR() */
            PyWeakReference **list = (PyWeakReference **) \
                PyObject_GET_WEAKREFS_LISTPTR(self);
            while (*list)
                _PyWeakref_ClearRef(*list);
        }
    }

    /*  Clear slots up to the nearest base with a different tp_dealloc */
    base = type;
    while ((basedealloc = base->tp_dealloc) == subtype_dealloc) {
        if (Py_SIZE(base))
            clear_slots(base, self);
        base = base->tp_base;
        assert(base);
    }

    /* If we added a dict, DECREF it */
    if (type->tp_dictoffset && !base->tp_dictoffset) {
        PyObject **dictptr = _PyObject_GetDictPtr(self);
        if (dictptr != NULL) {
            PyObject *dict = *dictptr;
            if (dict != NULL) {
                Py_DECREF(dict);
                *dictptr = NULL;
            }
        }
    }

    /* Extract the type again; tp_del may have changed it */
    type = Py_TYPE(self);

    /* Call the base tp_dealloc(); first retrack self if
     * basedealloc knows about gc.
     */
    if (PyType_IS_GC(base))
        _PyObject_GC_TRACK(self);
    assert(basedealloc);
    basedealloc(self);

    PyType_Modified(type);

    /* Can't reference self beyond this point */
    Py_DECREF(type);

  endlabel:
    ++_PyTrash_delete_nesting;
    Py_TRASHCAN_SAFE_END(self);
    --_PyTrash_delete_nesting;

    /* Explanation of the weirdness around the trashcan macros:

       Q. What do the trashcan macros do?

       A. Read the comment titled "Trashcan mechanism" in object.h.
          For one, this explains why there must be a call to GC-untrack
          before the trashcan begin macro.      Without understanding the
          trashcan code, the answers to the following questions don't make
          sense.

       Q. Why do we GC-untrack before the trashcan and then immediately
          GC-track again afterward?

       A. In the case that the base class is GC-aware, the base class
          probably GC-untracks the object.      If it does that using the
          UNTRACK macro, this will crash when the object is already
          untracked.  Because we don't know what the base class does, the
          only safe thing is to make sure the object is tracked when we
          call the base class dealloc.  But...  The trashcan begin macro
          requires that the object is *untracked* before it is called.  So
          the dance becomes:

         GC untrack
         trashcan begin
         GC track

       Q. Why did the last question say "immediately GC-track again"?
          It's nowhere near immediately.

       A. Because the code *used* to re-track immediately.      Bad Idea.
          self has a refcount of 0, and if gc ever gets its hands on it
          (which can happen if any weakref callback gets invoked), it
          looks like trash to gc too, and gc also tries to delete self
          then.  But we're already deleting self.  Double deallocation is
          a subtle disaster.

       Q. Why the bizarre (net-zero) manipulation of
          _PyTrash_delete_nesting around the trashcan macros?

       A. Some base classes (e.g. list) also use the trashcan mechanism.
          The following scenario used to be possible:

          - suppose the trashcan level is one below the trashcan limit

          - subtype_dealloc() is called

          - the trashcan limit is not yet reached, so the trashcan level
        is incremented and the code between trashcan begin and end is
        executed

          - this destroys much of the object's contents, including its
        slots and __dict__

          - basedealloc() is called; this is really list_dealloc(), or
        some other type which also uses the trashcan macros

          - the trashcan limit is now reached, so the object is put on the
        trashcan's to-be-deleted-later list

          - basedealloc() returns

          - subtype_dealloc() decrefs the object's type

          - subtype_dealloc() returns

          - later, the trashcan code starts deleting the objects from its
        to-be-deleted-later list

          - subtype_dealloc() is called *AGAIN* for the same object

          - at the very least (if the destroyed slots and __dict__ don't
        cause problems) the object's type gets decref'ed a second
        time, which is *BAD*!!!

          The remedy is to make sure that if the code between trashcan
          begin and end in subtype_dealloc() is called, the code between
          trashcan begin and end in basedealloc() will also be called.
          This is done by decrementing the level after passing into the
          trashcan block, and incrementing it just before leaving the
          block.

          But now it's possible that a chain of objects consisting solely
          of objects whose deallocator is subtype_dealloc() will defeat
          the trashcan mechanism completely: the decremented level means
          that the effective level never reaches the limit.      Therefore, we
          *increment* the level *before* entering the trashcan block, and
          matchingly decrement it after leaving.  This means the trashcan
          code will trigger a little early, but that's no big deal.

       Q. Are there any live examples of code in need of all this
          complexity?

       A. Yes.  See SF bug 668433 for code that crashed (when Python was
          compiled in debug mode) before the trashcan level manipulations
          were added.  For more discussion, see SF patches 581742, 575073
          and bug 574207.
    */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* subtype_dict ( PyObject obj,
void context 
) [static]

Definition at line 1736 of file typeobject.c.

{
    PyObject **dictptr;
    PyObject *dict;
    PyTypeObject *base;

    base = get_builtin_base_with_dict(Py_TYPE(obj));
    if (base != NULL) {
        descrgetfunc func;
        PyObject *descr = get_dict_descriptor(base);
        if (descr == NULL) {
            raise_dict_descr_error(obj);
            return NULL;
        }
        func = Py_TYPE(descr)->tp_descr_get;
        if (func == NULL) {
            raise_dict_descr_error(obj);
            return NULL;
        }
        return func(descr, obj, (PyObject *)(Py_TYPE(obj)));
    }

    dictptr = _PyObject_GetDictPtr(obj);
    if (dictptr == NULL) {
        PyErr_SetString(PyExc_AttributeError,
                        "This object has no __dict__");
        return NULL;
    }
    dict = *dictptr;
    if (dict == NULL)
        *dictptr = dict = PyDict_New();
    Py_XINCREF(dict);
    return dict;
}

Here is the call graph for this function:

static PyObject* subtype_getweakref ( PyObject obj,
void context 
) [static]

Definition at line 1814 of file typeobject.c.

{
    PyObject **weaklistptr;
    PyObject *result;

    if (Py_TYPE(obj)->tp_weaklistoffset == 0) {
        PyErr_SetString(PyExc_AttributeError,
                        "This object has no __weakref__");
        return NULL;
    }
    assert(Py_TYPE(obj)->tp_weaklistoffset > 0);
    assert(Py_TYPE(obj)->tp_weaklistoffset + sizeof(PyObject *) <=
           (size_t)(Py_TYPE(obj)->tp_basicsize));
    weaklistptr = (PyObject **)
        ((char *)obj + Py_TYPE(obj)->tp_weaklistoffset);
    if (*weaklistptr == NULL)
        result = Py_None;
    else
        result = *weaklistptr;
    Py_INCREF(result);
    return result;
}

Here is the call graph for this function:

static int subtype_setdict ( PyObject obj,
PyObject value,
void context 
) [static]

Definition at line 1772 of file typeobject.c.

{
    PyObject **dictptr;
    PyObject *dict;
    PyTypeObject *base;

    base = get_builtin_base_with_dict(Py_TYPE(obj));
    if (base != NULL) {
        descrsetfunc func;
        PyObject *descr = get_dict_descriptor(base);
        if (descr == NULL) {
            raise_dict_descr_error(obj);
            return -1;
        }
        func = Py_TYPE(descr)->tp_descr_set;
        if (func == NULL) {
            raise_dict_descr_error(obj);
            return -1;
        }
        return func(descr, obj, value);
    }

    dictptr = _PyObject_GetDictPtr(obj);
    if (dictptr == NULL) {
        PyErr_SetString(PyExc_AttributeError,
                        "This object has no __dict__");
        return -1;
    }
    if (value != NULL && !PyDict_Check(value)) {
        PyErr_Format(PyExc_TypeError,
                     "__dict__ must be set to a dictionary, "
                     "not a '%.200s'", Py_TYPE(value)->tp_name);
        return -1;
    }
    dict = *dictptr;
    Py_XINCREF(value);
    *dictptr = value;
    Py_XDECREF(dict);
    return 0;
}

Here is the call graph for this function:

static int subtype_traverse ( PyObject self,
visitproc  visit,
void arg 
) [static]

Definition at line 760 of file typeobject.c.

{
    PyTypeObject *type, *base;
    traverseproc basetraverse;

    /* Find the nearest base with a different tp_traverse,
       and traverse slots while we're at it */
    type = Py_TYPE(self);
    base = type;
    while ((basetraverse = base->tp_traverse) == subtype_traverse) {
        if (Py_SIZE(base)) {
            int err = traverse_slots(base, self, visit, arg);
            if (err)
                return err;
        }
        base = base->tp_base;
        assert(base);
    }

    if (type->tp_dictoffset != base->tp_dictoffset) {
        PyObject **dictptr = _PyObject_GetDictPtr(self);
        if (dictptr && *dictptr)
            Py_VISIT(*dictptr);
    }

    if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
        /* For a heaptype, the instances count as references
           to the type.          Traverse the type so the collector
           can find cycles involving this link. */
        Py_VISIT(type);

    if (basetraverse)
        return basetraverse(self, visit, arg);
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void super_dealloc ( PyObject self) [static]

Definition at line 6023 of file typeobject.c.

{
    superobject *su = (superobject *)self;

    _PyObject_GC_UNTRACK(self);
    Py_XDECREF(su->obj);
    Py_XDECREF(su->type);
    Py_XDECREF(su->obj_type);
    Py_TYPE(self)->tp_free(self);
}
static PyObject* super_descr_get ( PyObject self,
PyObject obj,
PyObject type 
) [static]

Definition at line 6181 of file typeobject.c.

{
    superobject *su = (superobject *)self;
    superobject *newobj;

    if (obj == NULL || obj == Py_None || su->obj != NULL) {
        /* Not binding to an object, or already bound */
        Py_INCREF(self);
        return self;
    }
    if (Py_TYPE(su) != &PySuper_Type)
        /* If su is an instance of a (strict) subclass of super,
           call its type */
        return PyObject_CallFunctionObjArgs((PyObject *)Py_TYPE(su),
                                            su->type, obj, NULL);
    else {
        /* Inline the common case */
        PyTypeObject *obj_type = supercheck(su->type, obj);
        if (obj_type == NULL)
            return NULL;
        newobj = (superobject *)PySuper_Type.tp_new(&PySuper_Type,
                                                 NULL, NULL);
        if (newobj == NULL)
            return NULL;
        Py_INCREF(su->type);
        Py_INCREF(obj);
        newobj->type = su->type;
        newobj->obj = obj;
        newobj->obj_type = obj_type;
        return (PyObject *)newobj;
    }
}

Here is the call graph for this function:

static PyObject* super_getattro ( PyObject self,
PyObject name 
) [static]

Definition at line 6051 of file typeobject.c.

{
    superobject *su = (superobject *)self;
    int skip = su->obj_type == NULL;

    if (!skip) {
        /* We want __class__ to return the class of the super object
           (i.e. super, or a subclass), not the class of su->obj. */
        skip = (PyUnicode_Check(name) &&
            PyUnicode_GET_SIZE(name) == 9 &&
            PyUnicode_CompareWithASCIIString(name, "__class__") == 0);
    }

    if (!skip) {
        PyObject *mro, *res, *tmp, *dict;
        PyTypeObject *starttype;
        descrgetfunc f;
        Py_ssize_t i, n;

        starttype = su->obj_type;
        mro = starttype->tp_mro;

        if (mro == NULL)
            n = 0;
        else {
            assert(PyTuple_Check(mro));
            n = PyTuple_GET_SIZE(mro);
        }
        for (i = 0; i < n; i++) {
            if ((PyObject *)(su->type) == PyTuple_GET_ITEM(mro, i))
                break;
        }
        i++;
        res = NULL;
        for (; i < n; i++) {
            tmp = PyTuple_GET_ITEM(mro, i);
            if (PyType_Check(tmp))
                dict = ((PyTypeObject *)tmp)->tp_dict;
            else
                continue;
            res = PyDict_GetItem(dict, name);
            if (res != NULL) {
                Py_INCREF(res);
                f = Py_TYPE(res)->tp_descr_get;
                if (f != NULL) {
                    tmp = f(res,
                        /* Only pass 'obj' param if
                           this is instance-mode super
                           (See SF ID #743627)
                        */
                        (su->obj == (PyObject *)
                                    su->obj_type
                            ? (PyObject *)NULL
                            : su->obj),
                        (PyObject *)starttype);
                    Py_DECREF(res);
                    res = tmp;
                }
                return res;
            }
        }
    }
    return PyObject_GenericGetAttr(self, name);
}

Here is the call graph for this function:

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

Definition at line 6215 of file typeobject.c.

{
    superobject *su = (superobject *)self;
    PyTypeObject *type = NULL;
    PyObject *obj = NULL;
    PyTypeObject *obj_type = NULL;

    if (!_PyArg_NoKeywords("super", kwds))
        return -1;
    if (!PyArg_ParseTuple(args, "|O!O:super", &PyType_Type, &type, &obj))
        return -1;

    if (type == NULL) {
        /* Call super(), without args -- fill in from __class__
           and first local variable on the stack. */
        PyFrameObject *f = PyThreadState_GET()->frame;
        PyCodeObject *co = f->f_code;
        Py_ssize_t i, n;
        if (co == NULL) {
            PyErr_SetString(PyExc_SystemError,
                            "super(): no code object");
            return -1;
        }
        if (co->co_argcount == 0) {
            PyErr_SetString(PyExc_SystemError,
                            "super(): no arguments");
            return -1;
        }
        obj = f->f_localsplus[0];
        if (obj == NULL) {
            PyErr_SetString(PyExc_SystemError,
                            "super(): arg[0] deleted");
            return -1;
        }
        if (co->co_freevars == NULL)
            n = 0;
        else {
            assert(PyTuple_Check(co->co_freevars));
            n = PyTuple_GET_SIZE(co->co_freevars);
        }
        for (i = 0; i < n; i++) {
            PyObject *name = PyTuple_GET_ITEM(co->co_freevars, i);
            assert(PyUnicode_Check(name));
            if (!PyUnicode_CompareWithASCIIString(name,
                                                  "__class__")) {
                Py_ssize_t index = co->co_nlocals +
                    PyTuple_GET_SIZE(co->co_cellvars) + i;
                PyObject *cell = f->f_localsplus[index];
                if (cell == NULL || !PyCell_Check(cell)) {
                    PyErr_SetString(PyExc_SystemError,
                      "super(): bad __class__ cell");
                    return -1;
                }
                type = (PyTypeObject *) PyCell_GET(cell);
                if (type == NULL) {
                    PyErr_SetString(PyExc_SystemError,
                      "super(): empty __class__ cell");
                    return -1;
                }
                if (!PyType_Check(type)) {
                    PyErr_Format(PyExc_SystemError,
                      "super(): __class__ is not a type (%s)",
                      Py_TYPE(type)->tp_name);
                    return -1;
                }
                break;
            }
        }
        if (type == NULL) {
            PyErr_SetString(PyExc_SystemError,
                            "super(): __class__ cell not found");
            return -1;
        }
    }

    if (obj == Py_None)
        obj = NULL;
    if (obj != NULL) {
        obj_type = supercheck(type, obj);
        if (obj_type == NULL)
            return -1;
        Py_INCREF(obj);
    }
    Py_INCREF(type);
    su->type = type;
    su->obj = obj;
    su->obj_type = obj_type;
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PyObject* super_repr ( PyObject self) [static]

Definition at line 6035 of file typeobject.c.

{
    superobject *su = (superobject *)self;

    if (su->obj_type)
        return PyUnicode_FromFormat(
            "<super: <class '%s'>, <%s object>>",
            su->type ? su->type->tp_name : "NULL",
            su->obj_type->tp_name);
    else
        return PyUnicode_FromFormat(
            "<super: <class '%s'>, NULL>",
            su->type ? su->type->tp_name : "NULL");
}
static int super_traverse ( PyObject self,
visitproc  visit,
void arg 
) [static]

Definition at line 6321 of file typeobject.c.

{
    superobject *su = (superobject *)self;

    Py_VISIT(su->obj);
    Py_VISIT(su->type);
    Py_VISIT(su->obj_type);

    return 0;
}
static PyTypeObject* supercheck ( PyTypeObject type,
PyObject obj 
) [static]

Definition at line 6117 of file typeobject.c.

{
    /* Check that a super() call makes sense.  Return a type object.

       obj can be a new-style class, or an instance of one:

       - If it is a class, it must be a subclass of 'type'.      This case is
         used for class methods; the return value is obj.

       - If it is an instance, it must be an instance of 'type'.  This is
         the normal case; the return value is obj.__class__.

       But... when obj is an instance, we want to allow for the case where
       Py_TYPE(obj) is not a subclass of type, but obj.__class__ is!
       This will allow using super() with a proxy for obj.
    */

    /* Check for first bullet above (special case) */
    if (PyType_Check(obj) && PyType_IsSubtype((PyTypeObject *)obj, type)) {
        Py_INCREF(obj);
        return (PyTypeObject *)obj;
    }

    /* Normal case */
    if (PyType_IsSubtype(Py_TYPE(obj), type)) {
        Py_INCREF(Py_TYPE(obj));
        return Py_TYPE(obj);
    }
    else {
        /* Try the slow way */
        static PyObject *class_str = NULL;
        PyObject *class_attr;

        if (class_str == NULL) {
            class_str = PyUnicode_FromString("__class__");
            if (class_str == NULL)
                return NULL;
        }

        class_attr = PyObject_GetAttr(obj, class_str);

        if (class_attr != NULL &&
            PyType_Check(class_attr) &&
            (PyTypeObject *)class_attr != Py_TYPE(obj))
        {
            int ok = PyType_IsSubtype(
                (PyTypeObject *)class_attr, type);
            if (ok)
                return (PyTypeObject *)class_attr;
        }

        if (class_attr == NULL)
            PyErr_Clear();
        else
            Py_DECREF(class_attr);
    }

    PyErr_SetString(PyExc_TypeError,
                    "super(type, obj): "
                    "obj must be an instance or subtype of type");
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int tail_contains ( PyObject list,
int  whence,
PyObject o 
) [static]

Definition at line 1270 of file typeobject.c.

                                                       {
    Py_ssize_t j, size;
    size = PyList_GET_SIZE(list);

    for (j = whence+1; j < size; j++) {
        if (PyList_GET_ITEM(list, j) == o)
            return 1;
    }
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function: