From aa251ca62724dc0d45582f81dfeef5c52d8b141b Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 26 Sep 2024 14:46:01 +0800 Subject: [PATCH 01/28] Added _architecture field to sys.implementation --- .../Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst | 1 + Python/sysmodule.c | 6 ++++++ 2 files changed, 7 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst diff --git a/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst b/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst new file mode 100644 index 00000000000000..76db522b814237 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst @@ -0,0 +1 @@ +Add ``_architecture`` field to :data:`sys.implementation` diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 887a916563a2e1..74674662396245 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3358,6 +3358,12 @@ make_impl_info(PyObject *version_info) if (res < 0) goto error; + value = PyUnicode_FromString(Py_GetPlatform()); + res = PyDict_SetItemString(impl_info, "_architecture", value); + Py_DECREF(value); + if (res < 0) + goto error; + #ifdef MULTIARCH value = PyUnicode_FromString(MULTIARCH); if (value == NULL) From 3b140f147a3574b6fb154d20fd565e5eac346187 Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 26 Sep 2024 19:00:21 +0800 Subject: [PATCH 02/28] Add value check --- Python/sysmodule.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 74674662396245..e6a97dc1d2bbed 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3359,6 +3359,8 @@ make_impl_info(PyObject *version_info) goto error; value = PyUnicode_FromString(Py_GetPlatform()); + if (value == NULL) + goto error; res = PyDict_SetItemString(impl_info, "_architecture", value); Py_DECREF(value); if (res < 0) From 0e404a5b7d934fdf774dca6e1cfc8c0ab689e9e9 Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 26 Sep 2024 19:27:37 +0800 Subject: [PATCH 03/28] Add '.' --- .../next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst b/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst index 76db522b814237..e22006a3c2565d 100644 --- a/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst +++ b/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst @@ -1 +1 @@ -Add ``_architecture`` field to :data:`sys.implementation` +Add ``_architecture`` field to :data:`sys.implementation`. From 6a508f9dd9f826923047e85224b2e635e24f0e0b Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 26 Sep 2024 19:31:51 +0800 Subject: [PATCH 04/28] Change desc --- .../Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst b/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst index e22006a3c2565d..eca14c28c22bb4 100644 --- a/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst +++ b/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst @@ -1 +1,2 @@ -Add ``_architecture`` field to :data:`sys.implementation`. +Added ``_architecture`` attribute to :data:`sys.implementation` +to describe the current system platform. From 8fa96f03ac677407c1ce2485c49ee54492b13001 Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 26 Sep 2024 19:42:18 +0800 Subject: [PATCH 05/28] Add _architecture testing --- Lib/test/test_sys.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 42b5a7c94e7700..ec75142b0f3e4c 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1019,6 +1019,7 @@ def test_implementation(self): self.assertTrue(hasattr(sys.implementation, 'version')) self.assertTrue(hasattr(sys.implementation, 'hexversion')) self.assertTrue(hasattr(sys.implementation, 'cache_tag')) + self.assertTrue(hasattr(sys.implementation, '_architecture')) version = sys.implementation.version self.assertEqual(version[:2], (version.major, version.minor)) @@ -1032,6 +1033,8 @@ def test_implementation(self): self.assertEqual(sys.implementation.name, sys.implementation.name.lower()) + self.assertEqual(sys.implementation._architecture, sys.platform) + @test.support.cpython_only def test_debugmallocstats(self): # Test sys._debugmallocstats() From a47814e8a3b9567597e4be2cf5e7d711459470e0 Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 26 Sep 2024 22:03:14 +0800 Subject: [PATCH 06/28] Change _architecture attribute value --- Python/sysmodule.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index e6a97dc1d2bbed..a3bd11176bf1d8 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -43,6 +43,10 @@ Data members: # include // getpid() #endif +#ifdef HAVE_SYS_UTSNAME_H +# include +#endif /* HAVE_SYS_UTSNAME_H */ + #ifdef MS_WINDOWS # define WIN32_LEAN_AND_MEAN # include @@ -3322,6 +3326,9 @@ static PyObject * make_impl_info(PyObject *version_info) { int res; +#ifndef MS_WINDOWS + struct utsname u; +#endif /* !MS_WINDOWS */ PyObject *impl_info, *value, *ns; impl_info = PyDict_New(); @@ -3358,13 +3365,18 @@ make_impl_info(PyObject *version_info) if (res < 0) goto error; - value = PyUnicode_FromString(Py_GetPlatform()); +#ifndef MS_WINDOWS + 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); From 60ca1633bd3e01d33c4e75bf25e09cd0e6edd6f1 Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 26 Sep 2024 22:07:00 +0800 Subject: [PATCH 07/28] Change test --- Lib/test/test_sys.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index ec75142b0f3e4c..83e6e88d94ca14 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1019,7 +1019,6 @@ def test_implementation(self): self.assertTrue(hasattr(sys.implementation, 'version')) self.assertTrue(hasattr(sys.implementation, 'hexversion')) self.assertTrue(hasattr(sys.implementation, 'cache_tag')) - self.assertTrue(hasattr(sys.implementation, '_architecture')) version = sys.implementation.version self.assertEqual(version[:2], (version.major, version.minor)) @@ -1033,7 +1032,9 @@ def test_implementation(self): self.assertEqual(sys.implementation.name, sys.implementation.name.lower()) - self.assertEqual(sys.implementation._architecture, sys.platform) + if hasattr(os, 'uname'): + self.assertTrue(hasattr(sys.implementation, '_architecture')) + self.assertEqual(sys.implementation._architecture, os.uname) @test.support.cpython_only def test_debugmallocstats(self): From a969b9aaefb0acc0a9551e1f461b9272dab74eb5 Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 26 Sep 2024 22:10:03 +0800 Subject: [PATCH 08/28] Change test --- Lib/test/test_sys.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 83e6e88d94ca14..98a1ad5b41f84c 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1033,8 +1033,9 @@ def test_implementation(self): sys.implementation.name.lower()) if hasattr(os, 'uname'): + import platform self.assertTrue(hasattr(sys.implementation, '_architecture')) - self.assertEqual(sys.implementation._architecture, os.uname) + self.assertEqual(sys.implementation._architecture, platform.machine()) @test.support.cpython_only def test_debugmallocstats(self): From facc406b2d5aa501e44dd78f4b4181af20f6b56f Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 26 Sep 2024 22:14:49 +0800 Subject: [PATCH 09/28] Add defined --- Python/sysmodule.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index a3bd11176bf1d8..4d852bf9ffe792 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -46,7 +46,6 @@ Data members: #ifdef HAVE_SYS_UTSNAME_H # include #endif /* HAVE_SYS_UTSNAME_H */ - #ifdef MS_WINDOWS # define WIN32_LEAN_AND_MEAN # include @@ -3326,7 +3325,7 @@ static PyObject * make_impl_info(PyObject *version_info) { int res; -#ifndef MS_WINDOWS +#if !defined(MS_WINDOWS) && defined(HAVE_SYS_UTSNAME_H) struct utsname u; #endif /* !MS_WINDOWS */ PyObject *impl_info, *value, *ns; @@ -3365,7 +3364,7 @@ make_impl_info(PyObject *version_info) if (res < 0) goto error; -#ifndef MS_WINDOWS +#if !defined(MS_WINDOWS) && defined(HAVE_SYS_UTSNAME_H) res = uname(&u); if (res < 0) goto error; From 870ad00e0bbfc321dfa99c2ef404665e45eeb8e3 Mon Sep 17 00:00:00 2001 From: ruang Date: Fri, 27 Sep 2024 15:59:23 +0800 Subject: [PATCH 10/28] Change to only support the win32 --- Python/sysmodule.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 4d852bf9ffe792..0e1c3019fc5126 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3325,8 +3325,8 @@ static PyObject * make_impl_info(PyObject *version_info) { int res; -#if !defined(MS_WINDOWS) && defined(HAVE_SYS_UTSNAME_H) - struct utsname u; +#ifdef MS_WINDOWS + SYSTEM_INFO s; #endif /* !MS_WINDOWS */ PyObject *impl_info, *value, *ns; @@ -3364,11 +3364,16 @@ 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); +#ifdef MS_WINDOWS + GetNativeSystemInfo(&s); + switch (s.wProcessorArchitecture) { + case PROCESSOR_ARCHITECTURE_AMD64: value = PyUnicode_FromString("AMD64"); break; + case PROCESSOR_ARCHITECTURE_ARM: value = PyUnicode_FromString("ARM"); break; + case PROCESSOR_ARCHITECTURE_ARM64: value = PyUnicode_FromString("ARM64"); break; + case PROCESSOR_ARCHITECTURE_IA64: value = PyUnicode_FromString("IA64"); break; + case PROCESSOR_ARCHITECTURE_INTEL: value = PyUnicode_FromString("i386"); break; + default: value = PyUnicode_FromString(""); break; + } if (value == NULL) goto error; res = PyDict_SetItemString(impl_info, "_architecture", value); @@ -3377,6 +3382,7 @@ make_impl_info(PyObject *version_info) goto error; #endif /* !MS_WINDOWS */ + #ifdef MULTIARCH value = PyUnicode_FromString(MULTIARCH); if (value == NULL) From 54f8ff0a818bfc1fab140a6270095c5dbd1af7c8 Mon Sep 17 00:00:00 2001 From: ruang Date: Fri, 27 Sep 2024 16:04:19 +0800 Subject: [PATCH 11/28] Change test --- Lib/test/test_sys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 98a1ad5b41f84c..dfedc283c21a9a 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1032,7 +1032,7 @@ def test_implementation(self): self.assertEqual(sys.implementation.name, sys.implementation.name.lower()) - if hasattr(os, 'uname'): + if sys.platform == 'win32': import platform self.assertTrue(hasattr(sys.implementation, '_architecture')) self.assertEqual(sys.implementation._architecture, platform.machine()) From e90a7be5ab8c43a0290cef9317a6c887ee889faa Mon Sep 17 00:00:00 2001 From: ruang Date: Fri, 27 Sep 2024 16:05:39 +0800 Subject: [PATCH 12/28] Remove utsname --- Python/sysmodule.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 0e1c3019fc5126..29e8a6e3af03c2 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -43,9 +43,6 @@ Data members: # include // getpid() #endif -#ifdef HAVE_SYS_UTSNAME_H -# include -#endif /* HAVE_SYS_UTSNAME_H */ #ifdef MS_WINDOWS # define WIN32_LEAN_AND_MEAN # include From 6f4c9a369e30cd4aceec272ebda6c9fd590a3088 Mon Sep 17 00:00:00 2001 From: ruang Date: Fri, 27 Sep 2024 22:54:54 +0800 Subject: [PATCH 13/28] Change to preprocessor --- Python/sysmodule.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 29e8a6e3af03c2..241922ff4b14d7 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3322,9 +3322,6 @@ static PyObject * make_impl_info(PyObject *version_info) { int res; -#ifdef MS_WINDOWS - SYSTEM_INFO s; -#endif /* !MS_WINDOWS */ PyObject *impl_info, *value, *ns; impl_info = PyDict_New(); @@ -3361,24 +3358,22 @@ make_impl_info(PyObject *version_info) if (res < 0) goto error; -#ifdef MS_WINDOWS - GetNativeSystemInfo(&s); - switch (s.wProcessorArchitecture) { - case PROCESSOR_ARCHITECTURE_AMD64: value = PyUnicode_FromString("AMD64"); break; - case PROCESSOR_ARCHITECTURE_ARM: value = PyUnicode_FromString("ARM"); break; - case PROCESSOR_ARCHITECTURE_ARM64: value = PyUnicode_FromString("ARM64"); break; - case PROCESSOR_ARCHITECTURE_IA64: value = PyUnicode_FromString("IA64"); break; - case PROCESSOR_ARCHITECTURE_INTEL: value = PyUnicode_FromString("i386"); break; - default: value = PyUnicode_FromString(""); break; - } +#ifdef _WIN32 +# define OS_PLATFORM "win32" +#elif _WIN64 +# define OS_PLATFORM "amd64" +#elif _M_ARM +# define OS_PLATFORM "arm32" +#elif _M_ARM64 +# define OS_PLATFORM "arm64" +#endif + value = PyUnicode_FromString(OS_PLATFORM); if (value == NULL) goto error; res = PyDict_SetItemString(impl_info, "_architecture", value); - Py_DECREF(value); +#undef OS_PLATFORM if (res < 0) goto error; -#endif /* !MS_WINDOWS */ - #ifdef MULTIARCH value = PyUnicode_FromString(MULTIARCH); From a955b9dc4298fc52c29b24a221c5ae064450366c Mon Sep 17 00:00:00 2001 From: ruang Date: Fri, 27 Sep 2024 22:56:32 +0800 Subject: [PATCH 14/28] Change test --- Lib/test/test_sys.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index dfedc283c21a9a..794fc62e7bdbea 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1032,10 +1032,9 @@ def test_implementation(self): self.assertEqual(sys.implementation.name, sys.implementation.name.lower()) - if sys.platform == 'win32': - import platform - self.assertTrue(hasattr(sys.implementation, '_architecture')) - self.assertEqual(sys.implementation._architecture, platform.machine()) + + self.assertTrue(hasattr(sys.implementation, '_architecture')) + self.assertIn(sys.implementation._architecture, ['win32', 'amd64', 'arm32', 'arm64']) @test.support.cpython_only def test_debugmallocstats(self): From 1aaec7464f31d189eebf52cedcb8f8d6470eaace Mon Sep 17 00:00:00 2001 From: ruang Date: Fri, 27 Sep 2024 23:08:55 +0800 Subject: [PATCH 15/28] Add defalut defined --- Python/sysmodule.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 241922ff4b14d7..59ced71277ba28 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3366,6 +3366,8 @@ make_impl_info(PyObject *version_info) # define OS_PLATFORM "arm32" #elif _M_ARM64 # define OS_PLATFORM "arm64" +#else +# define OS_PLATFORM "" #endif value = PyUnicode_FromString(OS_PLATFORM); if (value == NULL) From 1b5dd93e564cdea4a0deaad527b6f6de8e676338 Mon Sep 17 00:00:00 2001 From: ruang Date: Fri, 27 Sep 2024 23:13:13 +0800 Subject: [PATCH 16/28] Change test --- Lib/test/test_sys.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 794fc62e7bdbea..464eef7e5733bb 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1034,7 +1034,8 @@ def test_implementation(self): self.assertTrue(hasattr(sys.implementation, '_architecture')) - self.assertIn(sys.implementation._architecture, ['win32', 'amd64', 'arm32', 'arm64']) + self.assertIn(sys.implementation._architecture, + ['win32', 'amd64', 'arm32', 'arm64', '']) @test.support.cpython_only def test_debugmallocstats(self): From 4acaa22e9256290e3680c728152fa30cb8b83029 Mon Sep 17 00:00:00 2001 From: ruang Date: Sat, 28 Sep 2024 10:25:13 +0800 Subject: [PATCH 17/28] Changes to vcxproj preprocessing --- Lib/test/test_sys.py | 7 +++---- PCbuild/pythoncore.vcxproj | 6 +++++- Python/sysmodule.c | 16 +++------------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 464eef7e5733bb..19f395f3a265f4 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1032,10 +1032,9 @@ def test_implementation(self): self.assertEqual(sys.implementation.name, sys.implementation.name.lower()) - - self.assertTrue(hasattr(sys.implementation, '_architecture')) - self.assertIn(sys.implementation._architecture, - ['win32', 'amd64', 'arm32', 'arm64', '']) + if hasattr(sys.implementation, '_architecture'): + self.assertIn(sys.implementation._architecture, + ['win32', 'amd64', 'arm32', 'arm64', '']) @test.support.cpython_only def test_debugmallocstats(self): diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index dbb18ba96d6e50..b2f7ce50dbf62c 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -651,7 +651,11 @@ - VPATH="$(PyVPath)";%(PreprocessorDefinitions) + + VPLATFORM="$(ArchName)"; + VPATH="$(PyVPath)"; + %(PreprocessorDefinitions) + diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 59ced71277ba28..bb313003d461f7 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3358,24 +3358,14 @@ make_impl_info(PyObject *version_info) if (res < 0) goto error; -#ifdef _WIN32 -# define OS_PLATFORM "win32" -#elif _WIN64 -# define OS_PLATFORM "amd64" -#elif _M_ARM -# define OS_PLATFORM "arm32" -#elif _M_ARM64 -# define OS_PLATFORM "arm64" -#else -# define OS_PLATFORM "" -#endif - value = PyUnicode_FromString(OS_PLATFORM); +#ifdef VPLATFORM + value = PyUnicode_FromString(VPLATFORM); if (value == NULL) goto error; res = PyDict_SetItemString(impl_info, "_architecture", value); -#undef OS_PLATFORM if (res < 0) goto error; +#endif #ifdef MULTIARCH value = PyUnicode_FromString(MULTIARCH); From e00b4c34dc0f0883b71e9e4a895da4873ca77abd Mon Sep 17 00:00:00 2001 From: ruang Date: Sat, 28 Sep 2024 11:15:33 +0800 Subject: [PATCH 18/28] Free value --- Python/sysmodule.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index bb313003d461f7..c7f3e7f91bed72 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3363,6 +3363,7 @@ make_impl_info(PyObject *version_info) if (value == NULL) goto error; res = PyDict_SetItemString(impl_info, "_architecture", value); + Py_DECREF(value); if (res < 0) goto error; #endif From faf3898aadc2cb3dae7cb0ffa156e8d2c9dfb483 Mon Sep 17 00:00:00 2001 From: ruang Date: Sat, 28 Sep 2024 19:12:00 +0800 Subject: [PATCH 19/28] Add some space --- Lib/test/test_sys.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 19f395f3a265f4..e5a8e346727df6 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1034,7 +1034,7 @@ def test_implementation(self): if hasattr(sys.implementation, '_architecture'): self.assertIn(sys.implementation._architecture, - ['win32', 'amd64', 'arm32', 'arm64', '']) + ['win32', 'amd64', 'arm32', 'arm64', '']) @test.support.cpython_only def test_debugmallocstats(self): From 8ba0b990b989fad8bb376e2ca1644386529b89c0 Mon Sep 17 00:00:00 2001 From: ruang Date: Sat, 28 Sep 2024 19:18:44 +0800 Subject: [PATCH 20/28] _architecture rename to arch --- Python/sysmodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index c7f3e7f91bed72..35c0f5a4e69310 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3362,7 +3362,7 @@ make_impl_info(PyObject *version_info) value = PyUnicode_FromString(VPLATFORM); if (value == NULL) goto error; - res = PyDict_SetItemString(impl_info, "_architecture", value); + res = PyDict_SetItemString(impl_info, "arch", value); Py_DECREF(value); if (res < 0) goto error; From 29308840aeb2f3f22e7368a44b81cdcd972a8def Mon Sep 17 00:00:00 2001 From: ruang Date: Tue, 15 Oct 2024 17:23:54 +0800 Subject: [PATCH 21/28] VPLATFORM rename to VARCH_NAME --- PCbuild/pythoncore.vcxproj | 2 +- Python/sysmodule.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index b2f7ce50dbf62c..4b665fa9854015 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -652,7 +652,7 @@ - VPLATFORM="$(ArchName)"; + VARCH_NAME="$(ArchName)"; VPATH="$(PyVPath)"; %(PreprocessorDefinitions) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 35c0f5a4e69310..e4d631a085e2a6 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3358,8 +3358,8 @@ make_impl_info(PyObject *version_info) if (res < 0) goto error; -#ifdef VPLATFORM - value = PyUnicode_FromString(VPLATFORM); +#ifdef VARCH_NAME + value = PyUnicode_FromString(VARCH_NAME); if (value == NULL) goto error; res = PyDict_SetItemString(impl_info, "arch", value); From e8cb18b15b7f7a6474723b056f5e17edfac3ae8a Mon Sep 17 00:00:00 2001 From: ruang Date: Tue, 15 Oct 2024 17:35:51 +0800 Subject: [PATCH 22/28] Add braces --- Python/sysmodule.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index e4d631a085e2a6..06611aa16be4dc 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3360,12 +3360,14 @@ make_impl_info(PyObject *version_info) #ifdef VARCH_NAME value = PyUnicode_FromString(VARCH_NAME); - if (value == NULL) + if (value == NULL) { goto error; + } res = PyDict_SetItemString(impl_info, "arch", value); Py_DECREF(value); - if (res < 0) + if (res < 0) { goto error; + } #endif #ifdef MULTIARCH From 0c988f7af425b283a143f7550b79e7344a71b977 Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 17 Oct 2024 08:21:27 +0800 Subject: [PATCH 23/28] Remove V prefix --- PCbuild/pythoncore.vcxproj | 2 +- Python/sysmodule.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 4b665fa9854015..47202ee0450790 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -652,7 +652,7 @@ - VARCH_NAME="$(ArchName)"; + ARCH_NAME="$(ArchName)"; VPATH="$(PyVPath)"; %(PreprocessorDefinitions) diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 06611aa16be4dc..852e7d5361ae12 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -3358,8 +3358,8 @@ make_impl_info(PyObject *version_info) if (res < 0) goto error; -#ifdef VARCH_NAME - value = PyUnicode_FromString(VARCH_NAME); +#ifdef ARCH_NAME + value = PyUnicode_FromString(ARCH_NAME); if (value == NULL) { goto error; } From d7964093e252d6ded36265fc05ddc439fbc77918 Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 17 Oct 2024 08:29:29 +0800 Subject: [PATCH 24/28] Change test --- Lib/test/test_sys.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index e5a8e346727df6..38a47f821484c9 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1032,8 +1032,8 @@ def test_implementation(self): self.assertEqual(sys.implementation.name, sys.implementation.name.lower()) - if hasattr(sys.implementation, '_architecture'): - self.assertIn(sys.implementation._architecture, + if hasattr(sys.implementation, 'arch'): + self.assertIn(sys.implementation.arch, ['win32', 'amd64', 'arm32', 'arm64', '']) @test.support.cpython_only From 721f3b2929adf6e21ed0adb920a186f690e2654b Mon Sep 17 00:00:00 2001 From: ruang Date: Thu, 17 Oct 2024 08:29:43 +0800 Subject: [PATCH 25/28] Add docs --- Doc/library/sys.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index b0e40a4ea06946..a9d527c962ac6e 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1122,6 +1122,12 @@ always available. ``cache_tag`` is set to ``None``, it indicates that module caching should be disabled. + *arch* describes the architecture of the current interpreter runtime system. + + .. versionadded:: 3.14 + + .. availability:: Windows. + :data:`sys.implementation` may contain additional attributes specific to the Python implementation. These non-standard attributes must start with an underscore, and are not described here. Regardless of its contents, From 23285581b58889216b35af96069146525bf31860 Mon Sep 17 00:00:00 2001 From: "RUANG (Roy James)" Date: Thu, 17 Oct 2024 08:32:07 +0800 Subject: [PATCH 26/28] Update 2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst --- .../next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst b/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst index eca14c28c22bb4..dd4f97935907fd 100644 --- a/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst +++ b/Misc/NEWS.d/next/Library/2024-09-26-14-43-32.gh-issue-102536.xLiIvi.rst @@ -1,2 +1,2 @@ -Added ``_architecture`` attribute to :data:`sys.implementation` +Added ``arch`` attribute to :data:`sys.implementation` to describe the current system platform. From 8b629d6c382dc440d3452882331fb4f6f91e8aad Mon Sep 17 00:00:00 2001 From: "RUANG (Roy James)" Date: Wed, 23 Oct 2024 16:09:37 +0800 Subject: [PATCH 27/28] Change docs --- Doc/library/sys.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index a9d527c962ac6e..137c03768dd364 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1122,7 +1122,8 @@ always available. ``cache_tag`` is set to ``None``, it indicates that module caching should be disabled. - *arch* describes the architecture of the current interpreter runtime system. + *arch* The build architecture of the current interpreter is determined by the + platform on which it was built (independent of the current platform). .. versionadded:: 3.14 From 89ef30d90fc2ea02e2f64b920e6110bcea9183c4 Mon Sep 17 00:00:00 2001 From: "RUANG (Roy James)" Date: Thu, 24 Oct 2024 08:27:39 +0800 Subject: [PATCH 28/28] Change docs --- Doc/library/sys.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/sys.rst b/Doc/library/sys.rst index 137c03768dd364..13b21ef1a89be5 100644 --- a/Doc/library/sys.rst +++ b/Doc/library/sys.rst @@ -1123,7 +1123,7 @@ always available. be disabled. *arch* The build architecture of the current interpreter is determined by the - platform on which it was built (independent of the current platform). + platform for which it was built (which may be different from the current hardware). .. versionadded:: 3.14