Skip to content
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,11 @@ def test_implementation(self):
self.assertEqual(sys.implementation.name,
sys.implementation.name.lower())

if hasattr(os, 'uname'):
import platform
self.assertTrue(hasattr(sys.implementation, '_architecture'))
self.assertEqual(sys.implementation._architecture, platform.machine())

@test.support.cpython_only
def test_debugmallocstats(self):
# Test sys._debugmallocstats()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Added ``_architecture`` attribute to :data:`sys.implementation`
to describe the current system platform.
19 changes: 19 additions & 0 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Data members:
# include <unistd.h> // getpid()
#endif

#ifdef HAVE_SYS_UTSNAME_H
# include <sys/utsname.h>
#endif /* HAVE_SYS_UTSNAME_H */
#ifdef MS_WINDOWS
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
Expand Down Expand Up @@ -3322,6 +3325,9 @@ static PyObject *
make_impl_info(PyObject *version_info)
{
int res;
#if !defined(MS_WINDOWS) && defined(HAVE_SYS_UTSNAME_H)
struct utsname u;
#endif /* !MS_WINDOWS */
PyObject *impl_info, *value, *ns;

impl_info = PyDict_New();
Expand Down Expand Up @@ -3358,6 +3364,19 @@ make_impl_info(PyObject *version_info)
if (res < 0)
goto error;

#if !defined(MS_WINDOWS) && defined(HAVE_SYS_UTSNAME_H)
res = uname(&u);
if (res < 0)
goto error;
value = PyUnicode_FromString(u.machine);
if (value == NULL)
goto error;
res = PyDict_SetItemString(impl_info, "_architecture", value);
Py_DECREF(value);
if (res < 0)
goto error;
#endif /* !MS_WINDOWS */

#ifdef MULTIARCH
value = PyUnicode_FromString(MULTIARCH);
if (value == NULL)
Expand Down
Loading