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

Skip to content

Commit 03a144b

Browse files
committed
#22980 Adds platform and version tags to .pyd files
1 parent 09bd9ec commit 03a144b

5 files changed

Lines changed: 52 additions & 4 deletions

File tree

Lib/test/test_importlib/test_windows.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
machinery = test_util.import_importlib('importlib.machinery')
33

44
import os
5+
import re
56
import sys
67
import unittest
78
from test import support
9+
from distutils.util import get_platform
810
from contextlib import contextmanager
911
from .util import temp_module
1012

@@ -83,3 +85,25 @@ def test_module_not_found(self):
8385
(Frozen_WindowsRegistryFinderTests,
8486
Source_WindowsRegistryFinderTests
8587
) = test_util.test_both(WindowsRegistryFinderTests, machinery=machinery)
88+
89+
@unittest.skipUnless(sys.platform.startswith('win'), 'requires Windows')
90+
class WindowsExtensionSuffixTests:
91+
def test_tagged_suffix(self):
92+
suffixes = self.machinery.EXTENSION_SUFFIXES
93+
expected_tag = ".cp{0.major}{0.minor}-{1}.pyd".format(sys.version_info,
94+
re.sub('[^a-zA-Z0-9]', '_', get_platform()))
95+
try:
96+
untagged_i = suffixes.index(".pyd")
97+
except ValueError:
98+
untagged_i = suffixes.index("_d.pyd")
99+
expected_tag = "_d" + expected_tag
100+
101+
self.assertIn(expected_tag, suffixes)
102+
103+
# Ensure the tags are in the correct order
104+
tagged_i = suffixes.index(expected_tag)
105+
self.assertLess(tagged_i, untagged_i)
106+
107+
(Frozen_WindowsExtensionSuffixTests,
108+
Source_WindowsExtensionSuffixTests
109+
) = test_util.test_both(WindowsExtensionSuffixTests, machinery=machinery)

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,6 +1584,9 @@ Windows
15841584
- Issue #10747: Use versioned labels in the Windows start menu.
15851585
Patch by Olive Kilburn.
15861586

1587+
- Issue #22980: .pyd files with a version and platform tag (for example,
1588+
".cp35-win32.pyd") will now be loaded in preference to those without tags.
1589+
15871590
What's New in Python 3.4.0?
15881591
===========================
15891592

PC/pyconfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,11 @@ WIN32 is still required for the locale module.
145145
#if defined(_M_IA64)
146146
#define COMPILER _Py_PASTE_VERSION("64 bit (Itanium)")
147147
#define MS_WINI64
148+
#define PYD_PLATFORM_TAG "win_ia64"
148149
#elif defined(_M_X64) || defined(_M_AMD64)
149150
#define COMPILER _Py_PASTE_VERSION("64 bit (AMD64)")
150151
#define MS_WINX64
152+
#define PYD_PLATFORM_TAG "win_amd64"
151153
#else
152154
#define COMPILER _Py_PASTE_VERSION("64 bit (Unknown)")
153155
#endif
@@ -193,8 +195,10 @@ typedef _W64 int ssize_t;
193195
#if defined(MS_WIN32) && !defined(MS_WIN64)
194196
#if defined(_M_IX86)
195197
#define COMPILER _Py_PASTE_VERSION("32 bit (Intel)")
198+
#define PYD_PLATFORM_TAG "win32"
196199
#elif defined(_M_ARM)
197200
#define COMPILER _Py_PASTE_VERSION("32 bit (ARM)")
201+
#define PYD_PLATFORM_TAG "win_arm"
198202
#else
199203
#define COMPILER _Py_PASTE_VERSION("32 bit (Unknown)")
200204
#endif

PCbuild/python.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@
9696

9797
<!-- The name of the resulting pythonXY.dll (without the extension) -->
9898
<PyDllName>python$(MajorVersionNumber)$(MinorVersionNumber)$(PyDebugExt)</PyDllName>
99+
100+
<!-- The version and platform tag to include in .pyd filenames -->
101+
<PydTag Condition="$(Platform) == 'Win32'">.cp$(MajorVersionNumber)$(MinorVersionNumber)-win32</PydTag>
102+
<PydTag Condition="$(Platform) == 'x64'">.cp$(MajorVersionNumber)$(MinorVersionNumber)-win_amd64</PydTag>
99103
</PropertyGroup>
100104

101105
<!-- Displays the calculated version info -->

Python/dynload_win.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <ctype.h>
1010

1111
#include "importdl.h"
12+
#include "patchlevel.h"
1213
#include <windows.h>
1314

1415
// "activation context" magic - see dl_nt.c...
@@ -17,16 +18,28 @@ extern ULONG_PTR _Py_ActivateActCtx();
1718
void _Py_DeactivateActCtx(ULONG_PTR cookie);
1819
#endif
1920

20-
const char *_PyImport_DynLoadFiletab[] = {
2121
#ifdef _DEBUG
22-
"_d.pyd",
22+
#define PYD_DEBUG_SUFFIX "_d"
23+
#else
24+
#define PYD_DEBUG_SUFFIX ""
25+
#endif
26+
27+
#define STRINGIZE2(x) #x
28+
#define STRINGIZE(x) STRINGIZE2(x)
29+
#ifdef PYD_PLATFORM_TAG
30+
#define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX ".cp" STRINGIZE(PY_MAJOR_VERSION) STRINGIZE(PY_MINOR_VERSION) "-" PYD_PLATFORM_TAG ".pyd"
2331
#else
24-
".pyd",
32+
#define PYD_TAGGED_SUFFIX PYD_DEBUG_SUFFIX ".cp" STRINGIZE(PY_MAJOR_VERSION) STRINGIZE(PY_MINOR_VERSION) ".pyd"
2533
#endif
34+
35+
#define PYD_UNTAGGED_SUFFIX PYD_DEBUG_SUFFIX ".pyd"
36+
37+
const char *_PyImport_DynLoadFiletab[] = {
38+
PYD_TAGGED_SUFFIX,
39+
PYD_UNTAGGED_SUFFIX,
2640
NULL
2741
};
2842

29-
3043
/* Case insensitive string compare, to avoid any dependencies on particular
3144
C RTL implementations */
3245

0 commit comments

Comments
 (0)