Skip to content

Commit 899dce4

Browse files
jeremyd2019alexpilotti
authored andcommitted
Fix building with mingw-w64.
Include <locale> for std::wstring_convert. Several cases where code was trying to take a reference to an rvalue. Issue where mingw-w64 defaulted to 0x0502 (server 2003) instead of latest available version in SDKDDKVer.h, as mentioned in comments of targetver.h. Only override new_compiler if python was built with MSC (as opposed to GCC).
1 parent ee53f4c commit 899dce4

7 files changed

Lines changed: 19 additions & 12 deletions

File tree

MI/MI++.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static void MICheckResult(MI_Result result, const MI_Instance* extError = nullpt
3838
Instance instance((MI_Instance*)extError, false);
3939
if(IsInstanceOf(instance, L"MSFT_WmiError"))
4040
{
41-
MI_Char* message = instance[L"Message"]->m_value.string;
41+
const MI_Char* message = instance[L"Message"]->m_value.string;
4242
message = message ? message : L"";
4343

4444
auto errorCode = instance[L"error_code"]->m_value.uint32;

MI/targetver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
66
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
77

8+
#define _WIN32_WINNT 0x0a00
9+
810
#include <SDKDDKVer.h>

PyMI/Class.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ static PyObject* Class_GetClassName(Class* self, PyObject*)
112112
{
113113
try
114114
{
115-
std::wstring& className = self->miClass->GetClassName();
115+
std::wstring className = self->miClass->GetClassName();
116116
return PyUnicode_FromWideChar(className.c_str(), className.length());
117117
}
118118
catch (std::exception& ex)
@@ -126,7 +126,7 @@ static PyObject* Class_GetNameSpace(Class* self, PyObject*)
126126
{
127127
try
128128
{
129-
std::wstring& nameSpace = self->miClass->GetNameSpace();
129+
std::wstring nameSpace = self->miClass->GetNameSpace();
130130
return PyUnicode_FromWideChar(nameSpace.c_str(), nameSpace.length());
131131
}
132132
catch (std::exception& ex)
@@ -140,7 +140,7 @@ static PyObject* Class_GetServerName(Class* self, PyObject*)
140140
{
141141
try
142142
{
143-
std::wstring& serverName = self->miClass->GetServerName();
143+
std::wstring serverName = self->miClass->GetServerName();
144144
return PyUnicode_FromWideChar(serverName.c_str(), serverName.length());
145145
}
146146
catch (std::exception& ex)

PyMI/Instance.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ static PyObject* Instance_GetClassName(Instance *self, PyObject*)
212212
{
213213
try
214214
{
215-
std::wstring& className = self->instance->GetClassName();
215+
std::wstring className = self->instance->GetClassName();
216216
return PyUnicode_FromWideChar(className.c_str(), className.length());
217217
}
218218
catch (std::exception& ex)
@@ -226,7 +226,7 @@ static PyObject* Instance_GetNameSpace(Instance* self, PyObject*)
226226
{
227227
try
228228
{
229-
std::wstring& nameSpace = self->instance->GetNameSpace();
229+
std::wstring nameSpace = self->instance->GetNameSpace();
230230
return PyUnicode_FromWideChar(nameSpace.c_str(), nameSpace.length());
231231
}
232232
catch (std::exception& ex)
@@ -240,7 +240,7 @@ static PyObject* Instance_GetServerName(Instance* self, PyObject*)
240240
{
241241
try
242242
{
243-
std::wstring& serverName = self->instance->GetServerName();
243+
std::wstring serverName = self->instance->GetServerName();
244244
return PyUnicode_FromWideChar(serverName.c_str(), serverName.length());
245245
}
246246
catch (std::exception& ex)

PyMI/Utils.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "Utils.h"
44
#include "instance.h"
55
#include <codecvt>
6+
#include <locale>
67

78
#include <datetime.h>
89

@@ -151,7 +152,7 @@ std::wstring Py2WString(PyObject* pyValue)
151152
throw MI::Exception(L"PyUnicode_AsWideChar failed");
152153
}
153154

154-
auto& value = std::wstring(w, len);
155+
auto value = std::wstring(w, len);
155156
delete[] w;
156157
return value;
157158
}
@@ -167,9 +168,9 @@ std::shared_ptr<MI::MIValue> Py2StrMIValue(PyObject* pyValue)
167168
try
168169
{
169170
#ifdef IS_PY3K
170-
auto& value = Py2WString(pyStrValue);
171+
auto value = Py2WString(pyStrValue);
171172
#else
172-
auto& value = std::string(PyString_AsString(pyStrValue));
173+
auto value = std::string(PyString_AsString(pyStrValue));
173174
#endif
174175
Py_DECREF(pyStrValue);
175176
return MI::MIValue::FromString(value);
@@ -372,7 +373,7 @@ std::shared_ptr<MI::MIValue> Py2MI(PyObject* pyValue, MI_Type valueType)
372373
pyObj = PyList_GetItem(pyValue, i);
373374
}
374375

375-
auto& tmpValue = Py2MI(pyObj, itemType);
376+
auto tmpValue = Py2MI(pyObj, itemType);
376377
value->SetArrayItem(*tmpValue, (unsigned)i);
377378
}
378379
return value;

PyMI/targetver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
66
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
77

8+
#define _WIN32_WINNT 0x0a00
9+
810
#include <SDKDDKVer.h>

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from distutils import ccompiler
33
import os
44
import setuptools
5+
import sys
56

67
try:
78
import multiprocessing # noqa
@@ -37,7 +38,8 @@ def new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0):
3738
return Compiler(None, dry_run, force)
3839

3940

40-
ccompiler.new_compiler = new_compiler
41+
if 'MSC' in sys.version:
42+
ccompiler.new_compiler = new_compiler
4143

4244

4345
# Setuptools requires relative paths

0 commit comments

Comments
 (0)