~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to PC/dl_nt.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-07-06 16:52:42 UTC
  • mfrom: (1.2.1 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20100706165242-2xv4i019r3et6c0j
Tags: 3.1.2+20100706-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.
  - Add debian/patches/overwrite-semaphore-check for Lucid buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
Entry point for the Windows NT DLL.
4
4
 
5
5
About the only reason for having this, is so initall() can automatically
6
 
be called, removing that burden (and possible source of frustration if 
 
6
be called, removing that burden (and possible source of frustration if
7
7
forgotten) from the programmer.
8
8
 
9
9
*/
46
46
 
47
47
void _LoadActCtxPointers()
48
48
{
49
 
        HINSTANCE hKernel32 = GetModuleHandleW(L"kernel32.dll");
50
 
        if (hKernel32)
51
 
                pfnGetCurrentActCtx = (PFN_GETCURRENTACTCTX) GetProcAddress(hKernel32, "GetCurrentActCtx");
52
 
        // If we can't load GetCurrentActCtx (ie, pre XP) , don't bother with the rest.
53
 
        if (pfnGetCurrentActCtx) {
54
 
                pfnActivateActCtx = (PFN_ACTIVATEACTCTX) GetProcAddress(hKernel32, "ActivateActCtx");
55
 
                pfnDeactivateActCtx = (PFN_DEACTIVATEACTCTX) GetProcAddress(hKernel32, "DeactivateActCtx");
56
 
                pfnAddRefActCtx = (PFN_ADDREFACTCTX) GetProcAddress(hKernel32, "AddRefActCtx");
57
 
                pfnReleaseActCtx = (PFN_RELEASEACTCTX) GetProcAddress(hKernel32, "ReleaseActCtx");
58
 
        }
 
49
    HINSTANCE hKernel32 = GetModuleHandleW(L"kernel32.dll");
 
50
    if (hKernel32)
 
51
        pfnGetCurrentActCtx = (PFN_GETCURRENTACTCTX) GetProcAddress(hKernel32, "GetCurrentActCtx");
 
52
    // If we can't load GetCurrentActCtx (ie, pre XP) , don't bother with the rest.
 
53
    if (pfnGetCurrentActCtx) {
 
54
        pfnActivateActCtx = (PFN_ACTIVATEACTCTX) GetProcAddress(hKernel32, "ActivateActCtx");
 
55
        pfnDeactivateActCtx = (PFN_DEACTIVATEACTCTX) GetProcAddress(hKernel32, "DeactivateActCtx");
 
56
        pfnAddRefActCtx = (PFN_ADDREFACTCTX) GetProcAddress(hKernel32, "AddRefActCtx");
 
57
        pfnReleaseActCtx = (PFN_RELEASEACTCTX) GetProcAddress(hKernel32, "ReleaseActCtx");
 
58
    }
59
59
}
60
60
 
61
61
ULONG_PTR _Py_ActivateActCtx()
62
62
{
63
 
        ULONG_PTR ret = 0;
64
 
        if (PyWin_DLLhActivationContext && pfnActivateActCtx)
65
 
                if (!(*pfnActivateActCtx)(PyWin_DLLhActivationContext, &ret)) {
66
 
                        OutputDebugString("Python failed to activate the activation context before loading a DLL\n");
67
 
                        ret = 0; // no promise the failing function didn't change it!
68
 
                }
69
 
        return ret;
 
63
    ULONG_PTR ret = 0;
 
64
    if (PyWin_DLLhActivationContext && pfnActivateActCtx)
 
65
        if (!(*pfnActivateActCtx)(PyWin_DLLhActivationContext, &ret)) {
 
66
            OutputDebugString("Python failed to activate the activation context before loading a DLL\n");
 
67
            ret = 0; // no promise the failing function didn't change it!
 
68
        }
 
69
    return ret;
70
70
}
71
71
 
72
72
void _Py_DeactivateActCtx(ULONG_PTR cookie)
73
73
{
74
 
        if (cookie && pfnDeactivateActCtx)
75
 
                if (!(*pfnDeactivateActCtx)(0, cookie))
76
 
                        OutputDebugString("Python failed to de-activate the activation context\n");
 
74
    if (cookie && pfnDeactivateActCtx)
 
75
        if (!(*pfnDeactivateActCtx)(0, cookie))
 
76
            OutputDebugString("Python failed to de-activate the activation context\n");
77
77
}
78
78
 
79
 
BOOL    WINAPI  DllMain (HANDLE hInst, 
80
 
                                                ULONG ul_reason_for_call,
81
 
                                                LPVOID lpReserved)
 
79
BOOL    WINAPI  DllMain (HANDLE hInst,
 
80
                                                ULONG ul_reason_for_call,
 
81
                                                LPVOID lpReserved)
82
82
{
83
 
        switch (ul_reason_for_call)
84
 
        {
85
 
                case DLL_PROCESS_ATTACH:
86
 
                        PyWin_DLLhModule = hInst;
87
 
                        // 1000 is a magic number I picked out of the air.  Could do with a #define, I spose...
88
 
                        LoadString(hInst, 1000, dllVersionBuffer, sizeof(dllVersionBuffer));
89
 
 
90
 
                        // and capture our activation context for use when loading extensions.
91
 
                        _LoadActCtxPointers();
92
 
                        if (pfnGetCurrentActCtx && pfnAddRefActCtx)
93
 
                                if ((*pfnGetCurrentActCtx)(&PyWin_DLLhActivationContext))
94
 
                                        if (!(*pfnAddRefActCtx)(PyWin_DLLhActivationContext))
95
 
                                                OutputDebugString("Python failed to load the default activation context\n");
96
 
                        break;
97
 
 
98
 
                case DLL_PROCESS_DETACH:
99
 
                        if (pfnReleaseActCtx)
100
 
                                (*pfnReleaseActCtx)(PyWin_DLLhActivationContext);
101
 
                        break;
102
 
        }
103
 
        return TRUE;
 
83
    switch (ul_reason_for_call)
 
84
    {
 
85
        case DLL_PROCESS_ATTACH:
 
86
            PyWin_DLLhModule = hInst;
 
87
            // 1000 is a magic number I picked out of the air.  Could do with a #define, I spose...
 
88
            LoadString(hInst, 1000, dllVersionBuffer, sizeof(dllVersionBuffer));
 
89
 
 
90
            // and capture our activation context for use when loading extensions.
 
91
            _LoadActCtxPointers();
 
92
            if (pfnGetCurrentActCtx && pfnAddRefActCtx)
 
93
                if ((*pfnGetCurrentActCtx)(&PyWin_DLLhActivationContext))
 
94
                    if (!(*pfnAddRefActCtx)(PyWin_DLLhActivationContext))
 
95
                        OutputDebugString("Python failed to load the default activation context\n");
 
96
            break;
 
97
 
 
98
        case DLL_PROCESS_DETACH:
 
99
            if (pfnReleaseActCtx)
 
100
                (*pfnReleaseActCtx)(PyWin_DLLhActivationContext);
 
101
            break;
 
102
    }
 
103
    return TRUE;
104
104
}
105
105
 
106
106
#endif /* Py_ENABLE_SHARED */