@@ -353,25 +353,57 @@ The following functions and structs are used to create
353
353
354
354
Structure defining a type's behavior.
355
355
356
- .. c :member :: const char * PyType_Spec. name
356
+ .. c :member :: const char * name
357
357
358
358
Name of the type, used to set :c:member: `PyTypeObject.tp_name `.
359
359
360
- .. c :member :: int PyType_Spec.basicsize
361
- .. c :member :: int PyType_Spec.itemsize
360
+ .. c :member :: int basicsize
362
361
363
- Size of the instance in bytes, used to set
364
- :c:member: `PyTypeObject.tp_basicsize ` and
365
- :c:member: `PyTypeObject.tp_itemsize `.
362
+ If positive, specifies the size of the instance in bytes.
363
+ It is used to set :c:member: `PyTypeObject.tp_basicsize `.
366
364
367
- .. c :member :: int PyType_Spec.flags
365
+ If zero, specifies that :c:member: `~PyTypeObject.tp_basicsize `
366
+ should be inherited.
367
+
368
+ If negative, the absolute value specifies how much space instances of the
369
+ class need *in addition * to the superclass.
370
+ Use :c:func: `PyObject_GetTypeData ` to get a pointer to subclass-specific
371
+ memory reserved this way.
372
+
373
+ .. versionchanged :: 3.12
374
+
375
+ Previously, this field could not be negative.
376
+
377
+ .. c :member :: int itemsize
378
+
379
+ Size of one element of a variable-size type, in bytes.
380
+ Used to set :c:member: `PyTypeObject.tp_itemsize `.
381
+ See ``tp_itemsize `` documentation for caveats.
382
+
383
+ If zero, :c:member: `~PyTypeObject.tp_itemsize ` is inherited.
384
+ Extending arbitrary variable-sized classes is dangerous,
385
+ since some types use a fixed offset for variable-sized memory,
386
+ which can then overlap fixed-sized memory used by a subclass.
387
+ To help prevent mistakes, inheriting ``itemsize `` is only possible
388
+ in the following situations:
389
+
390
+ - The base is not variable-sized (its
391
+ :c:member: `~PyTypeObject.tp_itemsize `).
392
+ - The requested :c:member:`PyType_Spec.basicsize` is positive,
393
+ suggesting that the memory layout of the base class is known.
394
+ - The requested :c:member:`PyType_Spec.basicsize` is zero,
395
+ suggesting that the subclass does not access the instance's memory
396
+ directly.
397
+ - With the :const :`Py_TPFLAGS_ITEMS_AT_END` flag.
398
+
399
+ .. c:member:: unsigned int flags
368
400
369
401
Type flags, used to set :c:member:`PyTypeObject.tp_flags`.
370
402
371
403
If the ``Py_TPFLAGS_HEAPTYPE`` flag is not set,
372
404
:c:func:`PyType_FromSpecWithBases` sets it automatically.
373
405
374
- .. c :member :: PyType_Slot *PyType_Spec. slots
406
+ .. c:member:: PyType_Slot *slots
375
407
376
408
Array of :c:type:`PyType_Slot` structures.
377
409
Terminated by the special slot value ``{0, NULL}``.
0 commit comments