Skip to content

Commit 97fa07c

Browse files
committed
VS2010 Support: Backport "Fix python#13210. Port the Windows build from VS2008 to VS2010."
This commit is a partial backport of python/cpython@401f9f3. It was originally designed to work with python-cmake-buildsystem. The following modules have NOT been backported: * Tools/msi * Tools/buildbot * PCBuild
1 parent ca079a3 commit 97fa07c

File tree

6 files changed

+46
-10
lines changed

6 files changed

+46
-10
lines changed

Lib/distutils/command/build_ext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def finalize_options(self):
193193
# Append the source distribution include and library directories,
194194
# this allows distutils on windows to work in the source tree
195195
self.include_dirs.append(os.path.join(sys.exec_prefix, 'PC'))
196-
if MSVC_VERSION == 9:
196+
if MSVC_VERSION >= 9:
197197
# Use the .lib files for the correct architecture
198198
if self.plat_name == 'win32':
199199
suffix = ''

Lib/distutils/msvc9compiler.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -662,11 +662,12 @@ def link(self,
662662
if mfinfo is not None:
663663
mffilename, mfid = mfinfo
664664
out_arg = '-outputresource:%s;%s' % (output_filename, mfid)
665-
try:
666-
self.spawn(['mt.exe', '-nologo', '-manifest',
667-
mffilename, out_arg])
668-
except DistutilsExecError, msg:
669-
raise LinkError(msg)
665+
if self.__version < 10:
666+
try:
667+
self.spawn(['mt.exe', '-nologo', '-manifest',
668+
temp_manifest, out_arg])
669+
except PackagingExecError as msg:
670+
raise LinkError(msg)
670671
else:
671672
log.debug("skipping %s (up-to-date)", output_filename)
672673

PC/dl_nt.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ char dllVersionBuffer[16] = ""; // a private buffer
1818
HMODULE PyWin_DLLhModule = NULL;
1919
const char *PyWin_DLLVersionString = dllVersionBuffer;
2020

21-
// Windows "Activation Context" work:
21+
#if HAVE_SXS
22+
// Windows "Activation Context" work.
2223
// Our .pyd extension modules are generally built without a manifest (ie,
2324
// those included with Python and those built with a default distutils.
2425
// This requires we perform some "activation context" magic when loading our
@@ -29,6 +30,8 @@ const char *PyWin_DLLVersionString = dllVersionBuffer;
2930
// As an added complication, this magic only works on XP or later - we simply
3031
// use the existence (or not) of the relevant function pointers from kernel32.
3132
// See bug 4566 (http://python.org/sf/4566) for more details.
33+
// In Visual Studio 2010, side by side assemblies are no longer used by
34+
// default.
3235

3336
typedef BOOL (WINAPI * PFN_GETCURRENTACTCTX)(HANDLE *);
3437
typedef BOOL (WINAPI * PFN_ACTIVATEACTCTX)(HANDLE, ULONG_PTR *);
@@ -76,6 +79,8 @@ void _Py_DeactivateActCtx(ULONG_PTR cookie)
7679
OutputDebugString("Python failed to de-activate the activation context\n");
7780
}
7881

82+
#endif /* HAVE_SXS */
83+
7984
BOOL WINAPI DllMain (HANDLE hInst,
8085
ULONG ul_reason_for_call,
8186
LPVOID lpReserved)
@@ -87,17 +92,21 @@ BOOL WINAPI DllMain (HANDLE hInst,
8792
// 1000 is a magic number I picked out of the air. Could do with a #define, I spose...
8893
LoadString(hInst, 1000, dllVersionBuffer, sizeof(dllVersionBuffer));
8994

95+
#if HAVE_SXS
9096
// and capture our activation context for use when loading extensions.
9197
_LoadActCtxPointers();
9298
if (pfnGetCurrentActCtx && pfnAddRefActCtx)
9399
if ((*pfnGetCurrentActCtx)(&PyWin_DLLhActivationContext))
94100
if (!(*pfnAddRefActCtx)(PyWin_DLLhActivationContext))
95101
OutputDebugString("Python failed to load the default activation context\n");
102+
#endif
96103
break;
97104

98105
case DLL_PROCESS_DETACH:
106+
#if HAVE_SXS
99107
if (pfnReleaseActCtx)
100108
(*pfnReleaseActCtx)(PyWin_DLLhActivationContext);
109+
#endif
101110
break;
102111
}
103112
return TRUE;

PC/msvcrtmodule.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#ifdef _MSC_VER
2626
#if _MSC_VER >= 1500 && _MSC_VER < 1600
2727
#include <crtassem.h>
28+
#elif _MSC_VER >= 1600
29+
#include <crtversion.h>
2830
#endif
2931
#endif
3032

@@ -398,7 +400,7 @@ PyMODINIT_FUNC
398400
initmsvcrt(void)
399401
{
400402
int st;
401-
PyObject *d;
403+
PyObject *d, *version;
402404
PyObject *m = Py_InitModule("msvcrt", msvcrt_functions);
403405
if (m == NULL)
404406
return;
@@ -412,6 +414,7 @@ initmsvcrt(void)
412414
insertint(d, "LK_UNLCK", _LK_UNLCK);
413415

414416
/* constants for the crt versions */
417+
(void)st;
415418
#ifdef _VC_ASSEMBLY_PUBLICKEYTOKEN
416419
st = PyModule_AddStringConstant(m, "VC_ASSEMBLY_PUBLICKEYTOKEN",
417420
_VC_ASSEMBLY_PUBLICKEYTOKEN);
@@ -427,4 +430,14 @@ initmsvcrt(void)
427430
__LIBRARIES_ASSEMBLY_NAME_PREFIX);
428431
if (st < 0)return;
429432
#endif
433+
434+
/* constants for the 2010 crt versions */
435+
#if defined(_VC_CRT_MAJOR_VERSION) && defined (_VC_CRT_MINOR_VERSION) && defined(_VC_CRT_BUILD_VERSION) && defined(_VC_CRT_RBUILD_VERSION)
436+
version = PyUnicode_FromFormat("%d.%d.%d.%d", _VC_CRT_MAJOR_VERSION,
437+
_VC_CRT_MINOR_VERSION,
438+
_VC_CRT_BUILD_VERSION,
439+
_VC_CRT_RBUILD_VERSION);
440+
st = PyModule_AddObject(m, "CRT_ASSEMBLY_VERSION", version);
441+
if (st < 0) return NULL;
442+
#endif
430443
}

PC/pyconfig.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,19 @@ typedef int pid_t;
231231
#define hypot _hypot
232232
#endif
233233

234-
#endif /* _MSC_VER */
234+
/* Side by Side assemblies supported in VS 2005 and VS 2008 but not 2010*/
235+
#if _MSC_VER >= 1400 && _MSC_VER < 1600
236+
#define HAVE_SXS 1
237+
#endif
235238

236239
/* define some ANSI types that are not defined in earlier Win headers */
237-
#if defined(_MSC_VER) && _MSC_VER >= 1200
240+
#if _MSC_VER >= 1200
238241
/* This file only exists in VC 6.0 or higher */
239242
#include <basetsd.h>
240243
#endif
241244

245+
#endif /* _MSC_VER */
246+
242247
/* ------------------------------------------------------------------------*/
243248
/* The Borland compiler defines __BORLANDC__ */
244249
/* XXX These defines are likely incomplete, but should be easy to fix. */

Python/dynload_win.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
#include <windows.h>
1313

1414
// "activation context" magic - see dl_nt.c...
15+
#if HAVE_SXS
1516
extern ULONG_PTR _Py_ActivateActCtx();
1617
void _Py_DeactivateActCtx(ULONG_PTR cookie);
18+
#endif
1719

1820
const struct filedescr _PyImport_DynLoadFiletab[] = {
1921
#ifdef _DEBUG
@@ -176,7 +178,9 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
176178
char pathbuf[260];
177179
LPTSTR dummy;
178180
unsigned int old_mode;
181+
#if HAVE_SXS
179182
ULONG_PTR cookie = 0;
183+
#endif
180184
/* We use LoadLibraryEx so Windows looks for dependent DLLs
181185
in directory of pathname first. However, Windows95
182186
can sometimes not work correctly unless the absolute
@@ -190,11 +194,15 @@ dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
190194
sizeof(pathbuf),
191195
pathbuf,
192196
&dummy)) {
197+
#if HAVE_SXS
193198
ULONG_PTR cookie = _Py_ActivateActCtx();
199+
#endif
194200
/* XXX This call doesn't exist in Windows CE */
195201
hDLL = LoadLibraryEx(pathname, NULL,
196202
LOAD_WITH_ALTERED_SEARCH_PATH);
203+
#if HAVE_SXS
197204
_Py_DeactivateActCtx(cookie);
205+
#endif
198206
}
199207

200208
/* restore old error mode settings */

0 commit comments

Comments
 (0)