Skip to content

Commit f80bcdd

Browse files
committed
Add byteorder
1 parent 86f2a01 commit f80bcdd

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

Doc/library/sys.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ always available. Unless explicitly noted otherwise, all variables are read-only
3838
*debug* is a boolean indicating whether the interpreter was built in
3939
:ref:`debug mode <debug-build>`, i.e. with the :option:`--with-pydebug` option.
4040

41+
*byteorder* is a string indicating the native byte order, either ``'big'`` or
42+
``'little'``. This is the same as the :data:`byteorder` attribute.
43+
4144
.. versionadded:: next
4245

4346

Lib/test/test_sys.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ def test_abi_info(self):
744744
self.assertEqual(len(info.__dict__), 3)
745745
pointer_bits = 64 if sys.maxsize > 2**32 else 32
746746
self.assertEqual(info.pointer_bits, pointer_bits)
747+
self.assertEqual(info.byteorder, sys.byteorder)
747748
for attr, flag in [
748749
("free_threaded", "Py_GIL_DISABLED"),
749750
("debug", "Py_REF_DEBUG"),

Python/sysmodule.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3672,6 +3672,20 @@ make_abi_info(void)
36723672
goto error;
36733673
}
36743674

3675+
#if PY_BIG_ENDIAN
3676+
value = PyUnicode_FromString("big");
3677+
#else
3678+
value = PyUnicode_FromString("little");
3679+
#endif
3680+
if (value == NULL) {
3681+
goto error;
3682+
}
3683+
res = PyDict_SetItemString(abi_info, "byteorder", value);
3684+
if (res < 0) {
3685+
goto error;
3686+
}
3687+
Py_DECREF(value);
3688+
36753689
ns = _PyNamespace_New(abi_info);
36763690
Py_DECREF(abi_info);
36773691
return ns;

0 commit comments

Comments
 (0)