Availability: 2.*
_
_
ssize_t-based buffer interface Availability: 2.*
Availability: 2.*
Availability: 2.*
_
_
_
_
_
_
Availability: >= 2.6
int-based buffer interface Availability: 2.4
_
int-based buffer interface Availability: 2.4
_
_
_
Availability: 2.4
Availability: 2.4
Availability: 2.4
Availability: 2.4
_
_
_
_
_
_
ssize_t-based buffer interface Availability: 2.*
Availability: >= 2.6
_
_
ssize_t-based buffer interface Availability: 2.*
_
_
_
_
_
_
_
_
_
_
ssize_t-based buffer interface Availability: 2.*
_
Availability: 2.*
Availability: 2.*
Availability: 3.*
Availability: 3.*
_
Availability: 2.*
PyObject_Dir(obj) acts like Python __builtin__.dir(obj), returning a list of strings. PyObject_Dir(NULL) is like __builtin__.dir(), returning the names of the current locals. In this case, if there are no current locals, NULL is returned, and PyErr_Occurred() is false.
_
_
_
_
_
_
_
Availability: >= 2.6
_
_
_
_
_
_
_
_
_
_
_
_
Availability: 2.*
_
_
Availability: >= 2.6
Availability: 3.*
_
_
Availability: >= 3.2
_
Generic type check
Availability: >= 2.6
_
Used to decrement reference counts. Calls the object's deallocator function when the refcount falls to 0; for objects that don't contain references to other objects or heap memory this can be the standard function free(). Can be used wherever a void expression is allowed. The argument must not be a NULL pointer. If it may be NULL, use Py_XDECREF instead.
These are provided as conveniences to Python runtime embedders, so that they can have object code that is not dependent on Python compilation flags.
Increment reference counts. Can be used wherever a void expression is allowed. The argument must not be a NULL pointer. If it may be NULL, use Py_XINCREF instead.
These are provided as conveniences to Python runtime embedders, so that they can have object code that is not dependent on Python compilation flags.
_
Helpers for printing recursive container types
Not part of the python api, but annoying to do without.
_
_
Same as Py_DECREF, except is a no-op if op is null.
Increment reference counts. Can be used wherever a void expression is allowed. The argument may be a NULL pointer.
Availability: >= 2.7
Availability: 2.5, 2.6, 2.7
Availability: 3.*
_
Availability: 3.*
Availability: 3.*
_
_
Initializes reference counts to 1, and in special builds (Py_REF_DEBUG, Py_TRACE_REFS) performs additional bookkeeping appropriate to the special build.
Convert a python reference to borrowed reference. (Not part of Python api)
Flags for getting buffers Availability: >= 2.6
Flags for getting buffers Availability: >= 2.6
Rich comparison opcodes
Rich comparison opcodes
These flags are used to determine if a type is a subclass. Availability: >= 2.6
_
_
These flags are used to determine if a type is a subclass. Availability: >= 2.6
Objects support nb_index in PyNumberMethods Availability: 2.*
Has the new buffer protocol Availability: 2.6,2.7
Objects support type attribute cache Availability: >= 2.6
These flags are used to determine if a type is a subclass. Availability: >= 2.6
Type is abstract and cannot be instantiated Availability: >= 2.6
These flags are used to determine if a type is a subclass. Availability: >= 2.6
These flags are used to determine if a type is a subclass. Availability: >= 2.6
Objects support type attribute cache Availability: >= 2.6
_
_
PyObject_VAR_HEAD defines the initial segment of all variable-size container objects. These end with a declaration of an array with 1 element, but enough space is malloc'ed so that the array actually has room for ob_size elements. Note that ob_size is an element count, not necessarily a byte count.
_
Denotes a borrowed reference. (Not part of Python api)
_
_
The *real* layout of a type object when allocated on the heap
_
For numbers without flag bit Py_TPFLAGS_CHECKTYPES set, all arguments are guaranteed to be of the object's type (modulo coercion hacks -- i.e. if the type's coercion function returns other types, then these are allowed as well). Numbers that have the Py_TPFLAGS_CHECKTYPES flag bit set should check *both* arguments for proper type and implement the necessary conversions in the slot functions themselves.
Nothing is actually declared to be a PyObject, but every pointer to a Python object can be cast to a PyObject*. This is inheritance built by hand. Similarly every pointer to a variable-size Python object can, in addition, be cast to PyVarObject*.
_
Type objects contain a string containing the type name (to help somewhat in debugging), the allocation parameters (see PyObject_New() and PyObject_NewVar()), and methods for accessing objects of the type. Methods are optional, a nil pointer meaning that particular kind of access is not available for this type. The Py_DECREF() macro uses the tp_dealloc method without checking for a nil pointer; it should always be implemented except if the implementation can guarantee that the reference count will never reach zero (e.g., for statically allocated type objects).
Availability: 3.*
Availability: 3.*
_
Py3k buffer interface Availability: >= 2.6
Availability: 2.7, >= 3.1
_
_
Set if the type allows subclassing
PyNumberMethods do their own coercion Availability: 2.*
_
This is here for backwards compatibility. Extensions that use the old GC Availability: 2.* API will still compile but the objects will not be tracked by the GC.
New members introduced by Python 2.2 exist Availability: 2.*
Objects support garbage collection (see objimp.h)
PyBufferProcs contains bf_getcharbuffer Availability: 2.*
PySequenceMethods and PyNumberMethods contain in-place operators Availability: 2.*
tp_iter is defined Availability: 2.*
tp_richcompare is defined Availability: 2.*
PySequenceMethods contains sq_contains Availability: 2.*
_
Objects which are weakly referencable if their tp_weaklistoffset is >0 Availability: 2.*
Set if the type object is dynamically allocated
Set if the type is 'ready' -- fully initialized
Set while the type is being 'readied', to prevent recursive ready calls
Mirror object.h
Object and type object interface
Objects are structures allocated on the heap. Special rules apply to the use of objects to ensure they are properly garbage-collected. Objects are never allocated statically or on the stack; they must be accessed through special macros and functions only. (Type objects are exceptions to the first rule; the standard types are represented by statically initialized type objects, although work on type/class unification for Python 2.2 made it possible to have heap-allocated type objects too).
An object has a 'reference count' that is increased or decreased when a pointer to the object is copied or deleted; when the reference count reaches zero there are no references to the object left and it can be removed from the heap.
An object has a 'type' that determines what it represents and what kind of data it contains. An object's type is fixed when it is created. Types themselves are represented as objects; an object contains a pointer to the corresponding type object. The type itself has a type pointer pointing to the object representing the type 'type', which contains a pointer to itself!).
Objects do not float around in memory; once allocated an object keeps the same size and address. Objects that must hold variable-size data can contain pointers to variable-size parts of the object. Not all objects of the same type have the same size; but the size cannot change after allocation. (These restrictions are made so a reference to an object can be simply a pointer -- moving an object would require updating all the pointers, and changing an object's size would require moving it if there was another object right next to it.)
Objects are always accessed through pointers of the type 'PyObject *'. The type 'PyObject' is a structure that only contains the reference count and the type pointer. The actual memory allocated for an object contains other data that can only be accessed after casting the pointer to a pointer to a longer structure type. This longer type must start with the reference count and type fields; the macro PyObject_HEAD should be used for this (to accommodate for future changes). The implementation of a particular object type can cast the object pointer to the proper type and back.
A standard interface exists for objects that contain an array of items whose size is determined when the object is allocated.