| 59 | } |
| 60 | |
| 61 | bool CPythonEngine::InitMainInterp(void) |
| 62 | { |
| 63 | // ensure only 1 engine/thread initialises this only |
| 64 | CSLock l(m_initLock); |
| 65 | if (!m_haveInit) { |
| 66 | PyGILState_STATE old_state; |
| 67 | if (Py_IsInitialized()) |
| 68 | old_state = PyGILState_Ensure(); |
| 69 | else { |
| 70 | Py_Initialize(); |
| 71 | old_state = PyGILState_UNLOCKED; |
| 72 | } |
| 73 | PyEval_InitThreads(); |
| 74 | |
| 75 | if (!g_IsFrozen) { |
| 76 | TCHAR *dll_path = GetModulePath(); |
| 77 | AddToPythonPath(dll_path); |
| 78 | free(dll_path); |
| 79 | PyErr_Clear(); |
| 80 | } |
| 81 | |
| 82 | // isapidllhandle to match dllhandle, frozendllhandle, etc :) Also a |
| 83 | // nice way for a program to know they are in an ISAPI context. |
| 84 | PyObject *obh = PyLong_FromVoidPtr(g_hInstance); |
| 85 | PySys_SetObject("isapidllhandle", obh); |
| 86 | Py_XDECREF(obh); |
| 87 | // Locate the special exception we use to trigger a reload. |
| 88 | PyObject *isapi_package = PyImport_ImportModule("isapi"); |
| 89 | if (isapi_package) |
| 90 | m_reload_exception = PyObject_GetAttrString(isapi_package, |
| 91 | "InternalReloadException"); |
| 92 | Py_XDECREF(isapi_package); |
| 93 | |
| 94 | // ready our types. |
| 95 | InitExtensionTypes(); |
| 96 | InitFilterTypes(); |
| 97 | |
| 98 | PyGILState_Release(old_state); |
| 99 | FindModuleName(); |
| 100 | m_haveInit = true; |
| 101 | } |
| 102 | return true; |
| 103 | } |
| 104 | |
| 105 | void CPythonEngine::FindModuleName() |
| 106 | { |
no test coverage detected