diff options
author | Michael Seifert <michaelseifert04@yahoo.de> | 2017-09-16 11:29:33 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-16 11:29:33 (GMT) |
commit | 51ea80697b023595cdd79c7696589a04cc581693 (patch) | |
tree | f69703d14c4708c06bbed092c8a393271308a75e /Doc/c-api/structures.rst | |
parent | 77b52e463ab9f8bea7703ff9c03c06b3ec889db7 (diff) | |
download | cpython-51ea80697b023595cdd79c7696589a04cc581693.zip cpython-51ea80697b023595cdd79c7696589a04cc581693.tar.gz cpython-51ea80697b023595cdd79c7696589a04cc581693.tar.bz2 |
bpo-29916: Include PyGetSetDef in C API extension documentation. (#831) (#3607)
(cherry picked from commit da67e0d644bd3185efdaa4d15cc2ac0828ca83f9)
Diffstat (limited to 'Doc/c-api/structures.rst')
-rw-r--r-- | Doc/c-api/structures.rst | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Doc/c-api/structures.rst b/Doc/c-api/structures.rst index c080f31..675f6f2 100644 --- a/Doc/c-api/structures.rst +++ b/Doc/c-api/structures.rst @@ -294,3 +294,43 @@ definition with the same method name. read-only access. Using :c:macro:`T_STRING` for :attr:`type` implies :c:macro:`READONLY`. Only :c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX` members can be deleted. (They are set to *NULL*). + + +.. c:type:: PyGetSetDef + + Structure to define property-like access for a type. See also description of + the :c:member:`PyTypeObject.tp_getset` slot. + + +-------------+------------------+-----------------------------------+ + | Field | C Type | Meaning | + +=============+==================+===================================+ + | name | char \* | attribute name | + +-------------+------------------+-----------------------------------+ + | get | getter | C Function to get the attribute | + +-------------+------------------+-----------------------------------+ + | set | setter | optional C function to set or | + | | | delete the attribute, if omitted | + | | | the attribute is readonly | + +-------------+------------------+-----------------------------------+ + | doc | char \* | optional docstring | + +-------------+------------------+-----------------------------------+ + | closure | void \* | optional function pointer, | + | | | providing additional data for | + | | | getter and setter | + +-------------+------------------+-----------------------------------+ + + The ``get`` function takes one :c:type:`PyObject\*` parameter (the + instance) and a function pointer (the associated ``closure``):: + + typedef PyObject *(*getter)(PyObject *, void *); + + It should return a new reference on success or *NULL* with a set exception + on failure. + + ``set`` functions take two :c:type:`PyObject\*` parameters (the instance and + the value to be set) and a function pointer (the associated ``closure``):: + + typedef int (*setter)(PyObject *, PyObject *, void *); + + In case the attribute should be deleted the second parameter is *NULL*. + Should return ``0`` on success or ``-1`` with a set exception on failure. |