Skip to content

Commit be96e9e

Browse files
committed
Make Py_T_* and Py_ASNATIVEBYTES_* tables more compact
- Use a shared Stable ABI note - Convert the Py_T_* table to list-table for maintainability
1 parent 9312578 commit be96e9e

2 files changed

Lines changed: 89 additions & 34 deletions

File tree

‎Doc/c-api/long.rst‎

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -535,17 +535,24 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
535535
536536
.. c:namespace:: NULL
537537
538-
============================================= ======
539-
Flag Value
540-
============================================= ======
541-
.. c:macro:: Py_ASNATIVEBYTES_DEFAULTS ``-1``
542-
.. c:macro:: Py_ASNATIVEBYTES_BIG_ENDIAN ``0``
543-
.. c:macro:: Py_ASNATIVEBYTES_LITTLE_ENDIAN ``1``
544-
.. c:macro:: Py_ASNATIVEBYTES_NATIVE_ENDIAN ``3``
545-
.. c:macro:: Py_ASNATIVEBYTES_UNSIGNED_BUFFER ``4``
546-
.. c:macro:: Py_ASNATIVEBYTES_REJECT_NEGATIVE ``8``
547-
.. c:macro:: Py_ASNATIVEBYTES_ALLOW_INDEX ``16``
548-
============================================= ======
538+
.. stable-abi-note::
539+
540+
These values are available when compiling for the
541+
:ref:`Stable ABI <stable>` since version 3.14.
542+
543+
.. omit-stable-abi-notes::
544+
545+
============================================= ======
546+
Flag Value
547+
============================================= ======
548+
.. c:macro:: Py_ASNATIVEBYTES_DEFAULTS ``-1``
549+
.. c:macro:: Py_ASNATIVEBYTES_BIG_ENDIAN ``0``
550+
.. c:macro:: Py_ASNATIVEBYTES_LITTLE_ENDIAN ``1``
551+
.. c:macro:: Py_ASNATIVEBYTES_NATIVE_ENDIAN ``3``
552+
.. c:macro:: Py_ASNATIVEBYTES_UNSIGNED_BUFFER ``4``
553+
.. c:macro:: Py_ASNATIVEBYTES_REJECT_NEGATIVE ``8``
554+
.. c:macro:: Py_ASNATIVEBYTES_ALLOW_INDEX ``16``
555+
============================================= ======
549556
550557
Specifying ``Py_ASNATIVEBYTES_NATIVE_ENDIAN`` will override any other endian
551558
flags. Passing ``2`` is reserved.

‎Doc/c-api/structures.rst‎

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -812,29 +812,77 @@ If that is not possible, an exception such as :exc:`TypeError` or
812812
Unless marked (D), attributes defined this way cannot be deleted
813813
using e.g. :keyword:`del` or :py:func:`delattr`.
814814
815-
================================ ============================= ======================
816-
Macro name C type Python type
817-
================================ ============================= ======================
818-
.. c:macro:: Py_T_BYTE :c:expr:`char` :py:class:`int`
819-
.. c:macro:: Py_T_SHORT :c:expr:`short` :py:class:`int`
820-
.. c:macro:: Py_T_INT :c:expr:`int` :py:class:`int`
821-
.. c:macro:: Py_T_LONG :c:expr:`long` :py:class:`int`
822-
.. c:macro:: Py_T_LONGLONG :c:expr:`long long` :py:class:`int`
823-
.. c:macro:: Py_T_UBYTE :c:expr:`unsigned char` :py:class:`int`
824-
.. c:macro:: Py_T_UINT :c:expr:`unsigned int` :py:class:`int`
825-
.. c:macro:: Py_T_USHORT :c:expr:`unsigned short` :py:class:`int`
826-
.. c:macro:: Py_T_ULONG :c:expr:`unsigned long` :py:class:`int`
827-
.. c:macro:: Py_T_ULONGLONG :c:expr:`unsigned long long` :py:class:`int`
828-
.. c:macro:: Py_T_PYSSIZET :c:expr:`Py_ssize_t` :py:class:`int`
829-
.. c:macro:: Py_T_FLOAT :c:expr:`float` :py:class:`float`
830-
.. c:macro:: Py_T_DOUBLE :c:expr:`double` :py:class:`float`
831-
.. c:macro:: Py_T_BOOL :c:expr:`char` :py:class:`bool`
832-
(written as 0 or 1)
833-
.. c:macro:: Py_T_STRING :c:expr:`const char *` (*) :py:class:`str` (RO)
834-
.. c:macro:: Py_T_STRING_INPLACE :c:expr:`const char[]` (*) :py:class:`str` (RO)
835-
.. c:macro:: Py_T_CHAR :c:expr:`char` (0-127) :py:class:`str` (**)
836-
.. c:macro:: Py_T_OBJECT_EX :c:expr:`PyObject *` :py:class:`object` (D)
837-
================================ ============================= ======================
815+
.. stable-abi-note::
816+
817+
These values are available when compiling for the
818+
:ref:`Stable ABI <stable>` since version 3.12.
819+
820+
.. omit-stable-abi-notes::
821+
822+
.. list-table::
823+
:align: left
824+
:widths: auto
825+
:header-rows: 1
826+
827+
* - Macro name
828+
- C type
829+
- Python type
830+
* - .. c:macro:: Py_T_BYTE
831+
- :c:expr:`char`
832+
- :py:class:`int`
833+
* - .. c:macro:: Py_T_SHORT
834+
- :c:expr:`short`
835+
- :py:class:`int`
836+
* - .. c:macro:: Py_T_INT
837+
- :c:expr:`int`
838+
- :py:class:`int`
839+
* - .. c:macro:: Py_T_LONG
840+
- :c:expr:`long`
841+
- :py:class:`int`
842+
* - .. c:macro:: Py_T_LONGLONG
843+
- :c:expr:`long long`
844+
- :py:class:`int`
845+
* - .. c:macro:: Py_T_UBYTE
846+
- :c:expr:`unsigned char`
847+
- :py:class:`int`
848+
* - .. c:macro:: Py_T_UINT
849+
- :c:expr:`unsigned int`
850+
- :py:class:`int`
851+
* - .. c:macro:: Py_T_USHORT
852+
- :c:expr:`unsigned short`
853+
- :py:class:`int`
854+
* - .. c:macro:: Py_T_ULONG
855+
- :c:expr:`unsigned long`
856+
- :py:class:`int`
857+
* - .. c:macro:: Py_T_ULONGLONG
858+
- :c:expr:`unsigned long long`
859+
- :py:class:`int`
860+
* - .. c:macro:: Py_T_PYSSIZET
861+
- :c:expr:`Py_ssize_t`
862+
- :py:class:`int`
863+
* - .. c:macro:: Py_T_FLOAT
864+
- :c:expr:`float`
865+
- :py:class:`float`
866+
* - .. c:macro:: Py_T_DOUBLE
867+
- :c:expr:`double`
868+
- :py:class:`float`
869+
* - .. c:macro:: Py_T_BOOL
870+
- :c:expr:`char` (written as 0 or 1)
871+
- :py:class:`bool`
872+
* - .. c:macro:: Py_T_STRING
873+
- :c:expr:`const char *` (*)
874+
- :py:class:`str` (RO)
875+
* - .. c:macro:: Py_T_STRING_INPLACE
876+
- :c:expr:`const char[]` (*)
877+
- :py:class:`str` (RO)
878+
* - .. c:macro:: Py_T_CHAR
879+
- :c:expr:`char` (0-127)
880+
- :py:class:`str` (**)
881+
* - .. c:macro:: Py_T_OBJECT_EX
882+
- :c:expr:`PyObject *`
883+
- :py:class:`object` (D)
884+
885+
..
838886
839887
(*): Zero-terminated, UTF8-encoded C string.
840888
With :c:macro:`!Py_T_STRING` the C representation is a pointer;

0 commit comments

Comments
 (0)