Yurttas/PL/SL/python/docs/core-python-programming/doc/152/api/cObjects.html


7.5.3 CObjects

Refer to Extending and Embedding the Python Interpreter, section 1.12 (``Providing a C API for an Extension Module''), for more information on using these objects.

PyCObject
This subtype of PyObject represents an opaque value, useful for C extension modules who need to pass an opaque value (as a void* pointer) through Python code to other C code. It is often used to make a C function pointer defined in one module available to other modules, so the regular import mechanism can be used to access C APIs defined in dynamically loaded modules.
int PyCObject_Check (PyObject *p)
Returns true if its argument is a PyCObject.
PyObject* PyCObject_FromVoidPtr (void* cobj, void (*destr)(void *))
Return value: New reference.
Creates a PyCObject from the void * cobj. The destr function will be called when the object is reclaimed, unless it is NULL.
PyObject* PyCObject_FromVoidPtrAndDesc (void* cobj, void* desc, void (*destr)(void *, void *) )
Return value: New reference.
Creates a PyCObject from the void *cobj. The destr function will be called when the object is reclaimed. The desc argument can be used to pass extra callback data for the destructor function.
void* PyCObject_AsVoidPtr (PyObject* self)
Returns the object void * that the PyCObject self was created with.
void* PyCObject_GetDesc (PyObject* self)
Returns the description void * that the PyCObject self was created with.

Send comments on this document to python-docs@python.org.

Error if base doesn't support the read-only buffer protocol or doesn't provide exactly one buffer segment, or it raises ValueError if offset is less than zero. The buffer will hold a reference to the base object, and the buffer's contents will refer to the base object's buffer interface, starting as position offset and extending for size bytes. If size is Py_END_OF_BUFFER, then the new buffer's contents extend to the length of the base object's exported buffer data.

PyObject* PyBuffer_FromReadWriteObject (PyObject *base, int offset, int size)
Return value: New reference.
Return a new writable buffer object. Parameters and exceptions are similar to those for PyBuffer_FromObject(). If the base object does not export the writeable buffer protocol, then TypeError is raised.
PyObject* PyBuffer_FromMemory (void *ptr, int size)
Return value: New reference.
Return a new read-only buffer object that reads from a specified location in memory, with a specified size. The caller is responsible for ensuring that the memory buffer, passed in as ptr, is not deallocated while the returned buffer object exists. Raises ValueError if size is less than zero. Note that Py_END_OF_BUFFER may not be passed for the size parameter; ValueError will be raised in that case.
PyObject* PyBuffer_FromReadWriteMemory (void *ptr, int size)
Return value: New reference.
Similar to PyBuffer_FromMemory(), but the returned buffer is writable.
PyObject* PyBuffer_New (int size)
Return value: New reference.
Returns a new writable buffer object that maintains its own memory buffer of size bytes. ValueError is returned if size is not zero or positive.

Send comments on this document to python-docs@python.org.

py*