Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 099325e

Browse files
committed
Add a byte_order value to the sys module. The value is "big" for
big-endian machines and "little" for little-endian machines.
1 parent 107b967 commit 099325e

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Python/sysmodule.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,19 @@ _PySys_Init(void)
456456
PyDict_SetItemString(sysdict, "builtin_module_names",
457457
v = list_builtin_module_names());
458458
Py_XDECREF(v);
459+
{
460+
/* Assumes that longs are at least 2 bytes long.
461+
Should be safe! */
462+
unsigned long number = 1;
463+
464+
s = (char *) &number;
465+
if (s[0] == 0)
466+
PyDict_SetItemString(sysdict, "byte_order",
467+
PyString_FromString("big"));
468+
else
469+
PyDict_SetItemString(sysdict, "byte_order",
470+
PyString_FromString("little"));
471+
}
459472
#ifdef MS_COREDLL
460473
PyDict_SetItemString(sysdict, "dllhandle",
461474
v = PyLong_FromVoidPtr(PyWin_DLLhModule));

0 commit comments

Comments
 (0)