Skip to content

Commit 0901f64

Browse files
committed
Removes unused function.
Moves COM work onto separate thread.
1 parent 2efbc44 commit 0901f64

2 files changed

Lines changed: 18 additions & 60 deletions

File tree

Lib/distutils/_msvccompiler.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,22 @@ def _find_vc2015():
5757

5858
def _find_vc2017():
5959
import _findvs
60+
import threading
61+
6062
best_version = 0, # tuple for full version comparisons
6163
best_dir = None
62-
for name, version_str, path, packages in _findvs.findall():
64+
65+
# We need to call findall() on its own thread because it will
66+
# initialize COM.
67+
all_packages = []
68+
def _getall():
69+
# DO NOT MERGE - faulthandler triggers on non-fatal exception 0x40010006
70+
all_packages.extend(_findvs.findall())
71+
t = threading.Thread(target=_getall)
72+
t.start()
73+
t.join()
74+
75+
for name, version_str, path, packages in all_packages:
6376
if 'Microsoft.VisualCpp.Tools.Core' in packages:
6477
vc_dir = os.path.join(path, 'VC', 'Auxiliary', 'Build')
6578
if not os.path.isdir(vc_dir):

PC/_findvs.cpp

Lines changed: 4 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ static PyObject *find_all_instances()
196196

197197
PyDoc_STRVAR(findvs_findall_doc, "findall()\
198198
\
199-
Finds all installed versions of Visual Studio.");
199+
Finds all installed versions of Visual Studio.\
200+
\
201+
This function will initialize COM temporarily. To avoid impact on other parts\
202+
of your application, use a new thread to make this call.");
200203

201204
static PyObject *findvs_findall(PyObject *self, PyObject *args, PyObject *kwargs)
202205
{
@@ -210,67 +213,9 @@ static PyObject *findvs_findall(PyObject *self, PyObject *args, PyObject *kwargs
210213
return res;
211214
}
212215

213-
PyDoc_STRVAR(findvs_getversion_doc, "getversion(path)\
214-
\
215-
Reads the product version from the specified file.");
216-
217-
static PyObject *findvs_getversion(PyObject *self, PyObject *args, PyObject *kwargs)
218-
{
219-
LPVOID verblock;
220-
DWORD verblock_size;
221-
222-
PyObject *res = NULL;
223-
224-
PyObject *path_obj;
225-
const wchar_t *path;
226-
Py_ssize_t path_len;
227-
228-
static const char* keywords[] = { "path", NULL };
229-
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:getversion",
230-
(char**)keywords, PyUnicode_FSDecoder, &path_obj))
231-
return NULL;
232-
233-
path = PyUnicode_AsWideCharString(path_obj, &path_len);
234-
Py_DECREF(path_obj);
235-
if (!path) {
236-
return NULL;
237-
}
238-
239-
if ((verblock_size = GetFileVersionInfoSizeW(path, NULL)) &&
240-
(verblock = malloc(verblock_size))) {
241-
WORD *langinfo;
242-
wchar_t *verstr;
243-
UINT langinfo_size, ver_size;
244-
245-
if (GetFileVersionInfoW(path, 0, verblock_size, verblock) &&
246-
VerQueryValueW(verblock, L"\\VarFileInfo\\Translation",
247-
(LPVOID*)&langinfo, &langinfo_size)) {
248-
wchar_t rsrc_name[256];
249-
StringCchPrintfW(rsrc_name, 256,
250-
L"\\StringFileInfo\\%04x%04x\\ProductVersion",
251-
langinfo[0], langinfo[1]);
252-
if (VerQueryValueW(verblock, rsrc_name, (LPVOID*)&verstr, &ver_size)) {
253-
while (ver_size > 0 && !verstr[ver_size]) {
254-
ver_size -= 1;
255-
}
256-
res = PyUnicode_FromWideChar(verstr, ver_size - 1);
257-
}
258-
}
259-
free(verblock);
260-
}
261-
262-
PyMem_Free((void*)path);
263-
if (!res) {
264-
Py_RETURN_NONE;
265-
}
266-
return res;
267-
}
268-
269-
270216
// List of functions to add to findvs in exec_findvs().
271217
static PyMethodDef findvs_functions[] = {
272218
{ "findall", (PyCFunction)findvs_findall, METH_VARARGS | METH_KEYWORDS, findvs_findall_doc },
273-
{ "getversion", (PyCFunction)findvs_getversion, METH_VARARGS | METH_KEYWORDS, findvs_getversion_doc },
274219
{ NULL, NULL, 0, NULL }
275220
};
276221

0 commit comments

Comments
 (0)