@@ -198,3 +198,64 @@ definition with the same method name.
198198 object and will co-exist with the slot. This is helpful because calls to
199199 PyCFunctions are optimized more than wrapper object calls.
200200
201+
202+ .. ctype :: PyMemberDef
203+
204+ Structure which describes an attribute of a type which corresponds to a C
205+ struct member. Its fields are:
206+
207+ +------------------+-------------+-------------------------------+
208+ | Field | C Type | Meaning |
209+ +==================+=============+===============================+
210+ | :attr: `name ` | char \* | name of the member |
211+ +------------------+-------------+-------------------------------+
212+ | :attr: `type ` | int | the type of the member in the |
213+ | | | C struct |
214+ +------------------+-------------+-------------------------------+
215+ | :attr: `offset ` | Py_ssize_t | the offset in bytes that the |
216+ | | | member is located on the |
217+ | | | type's object struct |
218+ +------------------+-------------+-------------------------------+
219+ | :attr: `flags ` | int | flag bits indicating if the |
220+ | | | field should be read-only or |
221+ | | | writable |
222+ +------------------+-------------+-------------------------------+
223+ | :attr: `doc ` | char \* | points to the contents of the |
224+ | | | docstring |
225+ +------------------+-------------+-------------------------------+
226+
227+ :attr: `type ` can be one of many ``T_ `` macros corresponding to various C
228+ types. When the member is accessed in Python, it will be converted to the
229+ equivalent Python type.
230+
231+ =============== ==================
232+ Macro name C type
233+ =============== ==================
234+ T_SHORT short
235+ T_INT int
236+ T_LONG long
237+ T_FLOAT float
238+ T_DOUBLE double
239+ T_STRING char \*
240+ T_OBJECT PyObject \*
241+ T_OBJECT_EX PyObject \*
242+ T_CHAR char
243+ T_BYTE char
244+ T_UNBYTE unsigned char
245+ T_UINT unsigned int
246+ T_USHORT unsigned short
247+ T_ULONG unsigned long
248+ T_BOOL char
249+ T_LONGLONG long long
250+ T_ULONGLONG unsigned long long
251+ T_PYSSIZET Py_ssize_t
252+ =============== ==================
253+
254+ :cmacro: `T_OBJECT ` and :cmacro: `T_OBJECT_EX ` differ in that
255+ :cmacro: `T_OBJECT ` returns ``None `` if the member is *NULL * and
256+ :cmacro: `T_OBJECT_EX ` raises an :exc: `AttributeError `.
257+
258+ :attr: `flags ` can be 0 for write and read access or :cmacro: `READONLY ` for
259+ read-only access. Using :cmacro: `T_STRING ` for :attr: `type ` implies
260+ :cmacro: `READONLY `. Only :cmacro: `T_OBJECT ` and :cmacro: `T_OBJECT_EX `
261+ members can be deleted. (They are set to *NULL *).
0 commit comments