Skip to content

Commit 7ced683

Browse files
committed
Add byteorder
1 parent 6887d6c commit 7ced683

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

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
@@ -3680,6 +3680,20 @@ make_abi_info(void)
36803680
goto error;
36813681
}
36823682

3683+
#if PY_BIG_ENDIAN
3684+
value = PyUnicode_FromString("big");
3685+
#else
3686+
value = PyUnicode_FromString("little");
3687+
#endif
3688+
if (value == NULL) {
3689+
goto error;
3690+
}
3691+
res = PyDict_SetItemString(abi_info, "byteorder", value);
3692+
if (res < 0) {
3693+
goto error;
3694+
}
3695+
Py_DECREF(value);
3696+
36833697
ns = _PyNamespace_New(abi_info);
36843698
Py_DECREF(abi_info);
36853699
return ns;

0 commit comments

Comments
 (0)