8000 bpo-39553: Delete HAVE_SXS protected code (GH-18356) · python/cpython@b439a71 · GitHub
[go: up one dir, main page]

Skip to content

Commit b439a71

Browse files
authored
bpo-39553: Delete HAVE_SXS protected code (GH-18356)
https://bugs.python.org/issue39553 Automerge-Triggered-By: @zooba
1 parent cf5b109 commit b439a71

File tree

4 files changed

+1
-95
lines changed

4 files changed

+1
-95
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Delete unused code related to SxS manifests.

PC/dl_nt.c

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -23,68 +23,6 @@ char dllVersionBuffer[16] = ""; // a private buffer
2323
HMODULE PyWin_DLLhModule = NULL;
2424
const char *PyWin_DLLVersionString = dllVersionBuffer;
2525

26-
#if HAVE_SXS
27-
// Windows "Activation Context" work.
28-
// Our .pyd extension modules are generally built without a manifest (ie,
29-
// those included with Python and those built with a default distutils.
30-
// This requires we perform some "activation context" magic when loading our
31-
// extensions. In summary:
32-
// * As our DLL loads we save the context being used.
33-
// * Before loading our extensions we re-activate our saved context.
34-
// * After extension load is complete we restore the old context.
35-
// As an added complication, this magic only works on XP or later - we simply
36-
// use the existence (or not) of the relevant function pointers from kernel32.
37-
// See bug 4566 (http://python.org/sf/4566) for more details.
38-
// In Visual Studio 2010, side by side assemblies are no longer used by
39-
// default.
40-
41-
typedef BOOL (WINAPI * PFN_GETCURRENTACTCTX)(HANDLE *);
42-
typedef BOOL (WINAPI * PFN_ACTIVATEACTCTX)(HANDLE, ULONG_PTR *);
43-
typedef BOOL (WINAPI * PFN_DEACTIVATEACTCTX)(DWORD, ULONG_PTR);
44-
typedef BOOL (WINAPI * PFN_ADDREFACTCTX)(HANDLE);
45-
typedef BOOL (WINAPI * PFN_RELEASEACTCTX)(HANDLE);
46-
47-
// locals and function pointers for this activation context magic.
48-
static HANDLE PyWin_DLLhActivationContext = NULL; // one day it might be public
49-
static PFN_GETCURRENTACTCTX pfnGetCurrentActCtx = NULL;
50-
static PFN_ACTIVATEACTCTX pfnActivateActCtx = NULL;
51-
static PFN_DEACTIVATEACTCTX pfnDeactivateActCtx = NULL;
52-
static PFN_ADDREFACTCTX pfnAddRefActCtx = NULL;
53-
static PFN_RELEASEACTCTX pfnReleaseActCtx = NULL;
54-
55-
void _LoadActCtxPointers()
56-
{
57-
HINSTANCE hKernel32 = GetModuleHandleW(L"kernel32.dll");
58-
if (hKernel32)
59-
pfnGetCurrentActCtx = (PFN_GETCURRENTACTCTX) GetProcAddress(hKernel32, "GetCurrentActCtx");
60-
// If we can't load GetCurrentActCtx (ie, pre XP) , don't bother with the rest.
61-
if (pfnGetCurrentActCtx) {
62-
pfnActivateActCtx = (PFN_ACTIVATEACTCTX) GetProcAddress(hKernel32, "ActivateActCtx");
63-
pfnDeactivateActCtx = (PFN_DEACTIVATEACTCTX) GetProcAddress(hKernel32, "DeactivateActCtx");
64-
pfnAddRefActCtx = (PFN_ADDREFACTCTX) GetProcAddress(hKernel32, "AddRefActCtx");
65-
pfnReleaseActCtx = (PFN_RELEASEACTCTX) GetProcAddress(hKernel32, "ReleaseActCtx");
66-
}
67-
}
68-
69-
ULONG_PTR _Py_ActivateActCtx()
70-
{
71-
ULONG_PTR ret = 0;
72-
if (PyWin_DLLhActivationContext && pfnActivateActCtx)
73-
if (!(*pfnActivateActCtx)(PyWin_DLLhActivationContext, &ret)) {
74-
OutputDebugString("Python failed to activate the activation context before loading a DLL\n");
75-
ret = 0; // no promise the failing function didn't change it!
76-
}
77-
return ret;
78-
}
79-
80-
void _Py_DeactivateActCtx(ULONG_PTR cookie)
81-
{
82-
if (cookie && pfnDeactivateActCtx)
83-
if (!(*pfnDeactivateActCtx)(0, cookie))
84-
OutputDebugString("Python failed to de-activate the activation context\n");
85-
}
86-
#endif /* HAVE_SXS */
87-
8826
BOOL WINAPI DllMain (HANDLE hInst,
8927
ULONG ul_reason_for_call,
9028
LPVOID lpReserved)
@@ -98,22 +36,9 @@ BOOL WINAPI DllMain (HANDLE hInst,
9836
// 1000 is a magic number I picked out of the air. Could do with a #define, I spose...
9937
LoadString(hInst, 1000, dllVersionBuffer, sizeof(dllVersionBuffer));
10038
#endif
101-
102-
#if HAVE_SXS
103-
// and capture our activation context for use when loading extensions.
104-
_LoadActCtxPointers();
105-
if (pfnGetCurrentActCtx && pfnAddRefActCtx)
106-
if ((*pfnGetCurrentActCtx)(&PyWin_DLLhActivationContext))
107-
if (!(*pfnAddRefActCtx)(PyWin_DLLhActivationContext))
108-
OutputDebugString("Python failed to load the default activation context\n");
109-
#endif
11039
break;
11140

11241
case DLL_PROCESS_DETACH:
113-
#if HAVE_SXS
114-
if (pfnReleaseActCtx)
115-
(*pfnReleaseActCtx)(PyWin_DLLhActivationContext);
116-
#endif
11742
break;
11843
}
11944
return TRUE;

PC/pyconfig.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,6 @@ typedef int pid_t;
195195
#define Py_IS_FINITE(X) _finite(X)
196196
#define copysign _copysign
197197

198-
/* Side by Side assemblies supported in VS 2005 and VS 2008 but not 2010*/
199-
#if _MSC_VER >= 1400 && _MSC_VER < 1600
200-
#define HAVE_SXS 1
201-
#endif
202-
203198
/* define some ANSI types that are not defined in earlier Win headers */
204199
#if _MSC_VER >= 1200
205200
/* This file only exists in VC 6.0 or higher */

Python/dynload_win.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@
1212
#include "patchlevel.h"
1313
#include <windows.h>
1414

15-
// "activation context" magic - see dl_nt.c...
16-
#if HAVE_SXS
17-
extern ULONG_PTR _Py_ActivateActCtx();
18-
void _Py_DeactivateActCtx(ULONG_PTR cookie);
19-
#endif
20-
2115
#ifdef _DEBUG
2216
#define PYD_DEBUG_SUFFIX "_d"
2317
#else
@@ -187,16 +181,10 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
187181
{
188182
HINSTANCE hDLL = NULL;
189183
unsigned int old_mode;
190-
#if HAVE_SXS
191-
ULONG_PTR cookie = 0;
192-
#endif
193184

194185
/* Don't display a message box when Python can't load a DLL */
195186
old_mode = SetErrorMode(SEM_FAILCRITICALERRORS);
196187

197-
#if HAVE_SXS
198-
cookie = _Py_ActivateActCtx();
199-
#endif
200188
/* bpo-36085: We use LoadLibraryEx with restricted search paths
201189
to avoid DLL preloading attacks and enable use of the
202190
AddDllDirectory function. We add SEARCH_DLL_LOAD_DIR to
@@ -206,9 +194,6 @@ dl_funcptr _PyImport_FindSharedFuncptrWindows(const char *prefix,
206194
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS |
207195
LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
208196
Py_END_ALLOW_THREADS
209-
#if HAVE_SXS
210-
_Py_DeactivateActCtx(cookie);
211-
#endif
212197

213198
/* restore old error mode settings */
214199
SetErrorMode(old_mode);

0 commit comments

Comments
 (0)
0