Skip to content

Commit 20ee935

Browse files
Use decltype to deduce return type of PyThread_create_key
1 parent 8965644 commit 20ee935

File tree

5 files changed

+6
-6
lines changed

5 files changed

+6
-6
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ if(MSVC)
8181
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
8282
endif()
8383
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
84-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
84+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wconversion")
8585
endif()
8686

8787

example/example10.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
double my_func(int x, float y, double z) {
1515
std::cout << "my_func(x:int=" << x << ", y:float=" << y << ", z:float=" << z << ")" << std::endl;
16-
return x*y*z;
16+
return (float) x*y*z;
1717
}
1818

1919
std::complex<double> my_func3(std::complex<double> c) {

example/example4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ void test_function2(EMyEnumeration k) {
3838

3939
float test_function3(int i) {
4040
std::cout << "test_function(" << i << ")" << std::endl;
41-
return i / 2.f;
41+
return (float) i / 2.f;
4242
}
4343

4444
py::bytes return_bytes() {

include/pybind11/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ struct internals {
262262
std::unordered_map<const void *, void*> registered_instances; // void * -> PyObject*
263263
std::unordered_set<std::pair<const PyObject *, const char *>, overload_hash> inactive_overload_cache;
264264
#if defined(WITH_THREAD)
265-
long tstate = 0;
265+
decltype(PyThread_create_key()) tstate = 0; // Usually an int but a long on Cygwin64 with Python 3.x
266266
PyInterpreterState *istate = nullptr;
267267
#endif
268268
};

include/pybind11/pybind11.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ class gil_scoped_release {
11151115
gil_scoped_release(bool disassoc = false) : disassoc(disassoc) {
11161116
tstate = PyEval_SaveThread();
11171117
if (disassoc) {
1118-
int key = detail::get_internals().tstate;
1118+
auto key = detail::get_internals().tstate;
11191119
#if PY_MAJOR_VERSION < 3
11201120
PyThread_delete_key_value(key);
11211121
#else
@@ -1128,7 +1128,7 @@ class gil_scoped_release {
11281128
return;
11291129
PyEval_RestoreThread(tstate);
11301130
if (disassoc) {
1131-
int key = detail::get_internals().tstate;
1131+
auto key = detail::get_internals().tstate;
11321132
#if PY_MAJOR_VERSION < 3
11331133
PyThread_delete_key_value(key);
11341134
#endif

0 commit comments

Comments
 (0)