Skip to content

Commit 2efbc44

Browse files
committed
Style improvements.
1 parent c31149f commit 2efbc44

2 files changed

Lines changed: 48 additions & 34 deletions

File tree

PC/_findvs.cpp

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
//
2+
// Helper library for location Visual Studio installations
3+
// using the COM-based query API.
4+
//
5+
// Copyright (c) Microsoft Corporation
6+
// Licensed to PSF under a contributor agreement
7+
//
8+
9+
// Version history
10+
// 2017-05: Initial contribution (Steve Dower)
11+
112
#include <Windows.h>
213
#include <Strsafe.h>
314
#include "external\include\Setup.Configuration.h"
@@ -8,15 +19,15 @@
819

920
#include <Python.h>
1021

11-
PyObject *error_from_hr(HRESULT hr)
22+
static PyObject *error_from_hr(HRESULT hr)
1223
{
1324
if (FAILED(hr))
1425
PyErr_Format(PyExc_OSError, "Error %08x", hr);
1526
assert(PyErr_Occurred());
1627
return nullptr;
1728
}
1829

19-
PyObject *get_install_name(ISetupInstance2 *inst)
30+
static PyObject *get_install_name(ISetupInstance2 *inst)
2031
{
2132
HRESULT hr;
2233
BSTR name;
@@ -31,7 +42,7 @@ PyObject *get_install_name(ISetupInstance2 *inst)
3142
return error_from_hr(hr);
3243
}
3344

34-
PyObject *get_install_version(ISetupInstance *inst)
45+
static PyObject *get_install_version(ISetupInstance *inst)
3546
{
3647
HRESULT hr;
3748
BSTR ver;
@@ -46,7 +57,7 @@ PyObject *get_install_version(ISetupInstance *inst)
4657
return error_from_hr(hr);
4758
}
4859

49-
PyObject *get_install_path(ISetupInstance *inst)
60+
static PyObject *get_install_path(ISetupInstance *inst)
5061
{
5162
HRESULT hr;
5263
BSTR path;
@@ -61,7 +72,7 @@ PyObject *get_install_path(ISetupInstance *inst)
6172
return error_from_hr(hr);
6273
}
6374

64-
PyObject *get_installed_packages(ISetupInstance2 *inst)
75+
static PyObject *get_installed_packages(ISetupInstance2 *inst)
6576
{
6677
HRESULT hr;
6778
PyObject *res = nullptr;
@@ -114,7 +125,7 @@ PyObject *get_installed_packages(ISetupInstance2 *inst)
114125
return error_from_hr(hr);
115126
}
116127

117-
PyObject *find_all_instances()
128+
static PyObject *find_all_instances()
118129
{
119130
ISetupConfiguration *sc = nullptr;
120131
ISetupConfiguration2 *sc2 = nullptr;
@@ -137,7 +148,7 @@ PyObject *find_all_instances()
137148
)) && hr != REGDB_E_CLASSNOTREG)
138149
goto error;
139150

140-
/* If the class is not registered, there are no VS instances installed */
151+
// If the class is not registered, there are no VS instances installed
141152
if (hr == REGDB_E_CLASSNOTREG)
142153
return res;
143154

@@ -187,7 +198,8 @@ PyDoc_STRVAR(findvs_findall_doc, "findall()\
187198
\
188199
Finds all installed versions of Visual Studio.");
189200

190-
PyObject *findvs_findall(PyObject *self, PyObject *args, PyObject *kwargs) {
201+
static PyObject *findvs_findall(PyObject *self, PyObject *args, PyObject *kwargs)
202+
{
191203
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
192204
if (hr == RPC_E_CHANGED_MODE)
193205
hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
@@ -202,7 +214,8 @@ PyDoc_STRVAR(findvs_getversion_doc, "getversion(path)\
202214
\
203215
Reads the product version from the specified file.");
204216

205-
PyObject *findvs_getversion(PyObject *self, PyObject *args, PyObject *kwargs) {
217+
static PyObject *findvs_getversion(PyObject *self, PyObject *args, PyObject *kwargs)
218+
{
206219
LPVOID verblock;
207220
DWORD verblock_size;
208221

@@ -213,7 +226,8 @@ PyObject *findvs_getversion(PyObject *self, PyObject *args, PyObject *kwargs) {
213226
Py_ssize_t path_len;
214227

215228
static const char* keywords[] = { "path", NULL };
216-
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:getversion", (char**)keywords, PyUnicode_FSDecoder, &path_obj))
229+
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O&:getversion",
230+
(char**)keywords, PyUnicode_FSDecoder, &path_obj))
217231
return NULL;
218232

219233
path = PyUnicode_AsWideCharString(path_obj, &path_len);
@@ -229,9 +243,12 @@ PyObject *findvs_getversion(PyObject *self, PyObject *args, PyObject *kwargs) {
229243
UINT langinfo_size, ver_size;
230244

231245
if (GetFileVersionInfoW(path, 0, verblock_size, verblock) &&
232-
VerQueryValueW(verblock, L"\\VarFileInfo\\Translation", (LPVOID*)&langinfo, &langinfo_size)) {
246+
VerQueryValueW(verblock, L"\\VarFileInfo\\Translation",
247+
(LPVOID*)&langinfo, &langinfo_size)) {
233248
wchar_t rsrc_name[256];
234-
StringCchPrintfW(rsrc_name, 256, L"\\StringFileInfo\\%04x%04x\\ProductVersion", langinfo[0], langinfo[1]);
249+
StringCchPrintfW(rsrc_name, 256,
250+
L"\\StringFileInfo\\%04x%04x\\ProductVersion",
251+
langinfo[0], langinfo[1]);
235252
if (VerQueryValueW(verblock, rsrc_name, (LPVOID*)&verstr, &ver_size)) {
236253
while (ver_size > 0 && !verstr[ver_size]) {
237254
ver_size -= 1;
@@ -250,31 +267,24 @@ PyObject *findvs_getversion(PyObject *self, PyObject *args, PyObject *kwargs) {
250267
}
251268

252269

253-
/*
254-
* List of functions to add to findvs in exec_findvs().
255-
*/
270+
// List of functions to add to findvs in exec_findvs().
256271
static PyMethodDef findvs_functions[] = {
257272
{ "findall", (PyCFunction)findvs_findall, METH_VARARGS | METH_KEYWORDS, findvs_findall_doc },
258273
{ "getversion", (PyCFunction)findvs_getversion, METH_VARARGS | METH_KEYWORDS, findvs_getversion_doc },
259-
{ NULL, NULL, 0, NULL } /* marks end of array */
274+
{ NULL, NULL, 0, NULL }
260275
};
261276

262-
/*
263-
* Initialize findvs. May be called multiple times, so avoid
264-
* using static state.
265-
*/
266-
int exec_findvs(PyObject *module) {
277+
// Initialize findvs. May be called multiple times, so avoid
278+
// using static state.
279+
static int exec_findvs(PyObject *module)
280+
{
267281
PyModule_AddFunctions(module, findvs_functions);
268282

269-
return 0; /* success */
283+
return 0; // success
270284
}
271285

272-
/*
273-
* Documentation for findvs.
274-
*/
275286
PyDoc_STRVAR(findvs_doc, "The _findvs helper module");
276287

277-
278288
static PyModuleDef_Slot findvs_slots[] = {
279289
{ Py_mod_exec, exec_findvs },
280290
{ 0, NULL }
@@ -284,16 +294,17 @@ static PyModuleDef findvs_def = {
284294
PyModuleDef_HEAD_INIT,
285295
"_findvs",
286296
findvs_doc,
287-
0, /* m_size */
288-
NULL, /* m_methods */
297+
0, // m_size
298+
NULL, // m_methods
289299
findvs_slots,
290-
NULL, /* m_traverse */
291-
NULL, /* m_clear */
292-
NULL, /* m_free */
300+
NULL, // m_traverse
301+
NULL, // m_clear
302+
NULL, // m_free
293303
};
294304

295305
extern "C" {
296-
PyMODINIT_FUNC PyInit__findvs(void) {
297-
return PyModuleDef_Init(&findvs_def);
298-
}
306+
PyMODINIT_FUNC PyInit__findvs(void)
307+
{
308+
return PyModuleDef_Init(&findvs_def);
309+
}
299310
}

PC/external/Externals.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The files in this folder are from the Microsoft.VisualStudio.Setup.Configuration.Native package on Nuget.
2+
3+
They are licensed under the MIT license.

0 commit comments

Comments
 (0)