14.14.2.6 Data types

class _CData
This non-public class is the common base class of all ctypes data types. Among other things, all ctypes type instances contain a memory block that hold C compatible data; the address of the memory block is returned by the addressof() helper function. Another instance variable is exposed as _objects; this contains other Python objects that need to be kept alive in case the memory block contains pointers.

Common methods of ctypes data types, these are all class methods (to be exact, they are methods of the metaclass):

from_address( address)
This method returns a ctypes type instance using the memory specified by address which must be an integer.

from_param( obj)
This method adapts obj to a ctypes type. It is called with the actual object used in a foreign function call, when the type is present in the foreign functions argtypes tuple; it must return an object that can be used as function call parameter.

All ctypes data types have a default implementation of this classmethod, normally it returns obj if that is an instance of the type. Some types accept other objects as well.

in_dll( library, name)
This method returns a ctypes type instance exported by a shared library. name is the name of the symbol that exports the data, library is the loaded shared library.

Common instance variables of ctypes data types:

_b_base_
Sometimes ctypes data instances do not own the memory block they contain, instead they share part of the memory block of a base object. The _b_base_ readonly member is the root ctypes object that owns the memory block.

_b_needsfree_
This readonly variable is true when the ctypes data instance has allocated the memory block itself, false otherwise.

_objects
This member is either None or a dictionary containing Python objects that need to be kept alive so that the memory block contents is kept valid. This object is only exposed for debugging; never modify the contents of this dictionary.

See About this document... for information on suggesting changes.