Skip to content

Commit a224d0c

Browse files
fix: vs2022 compilation, issue #3477 (#3497)
* fix: vs2022 compilation, issue #3477 * silence warning for python 2.7 * disable warning around mbstowcs call * move disable warning code closer to call site * turn on vs2022 ci test * ci: don't run helpers on Windows 2022 & Python 3.5 * limit workaround for stdlib shipped with vs2022 or later * fix for: limit workaround for stdlib shipped with vs2022 or later * fix 2 for: limit workaround for stdlib shipped with vs2022 or later * comment * ci: add a Windows 2019 run * ci: add Python 2.7 check too Co-authored-by: Henry Schreiner <[email protected]>
1 parent b4939fc commit a224d0c

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26-
runs-on: [ubuntu-latest, windows-latest, macos-latest]
26+
runs-on: [ubuntu-latest, windows-2022, macos-latest]
2727
python:
2828
- '2.7'
2929
- '3.5'
@@ -37,19 +37,24 @@ jobs:
3737
# present), or add new keys to an existing matrix element if all the
3838
# existing keys match.
3939
#
40-
# We support an optional keys: args, for cmake args
40+
# We support an optional key: args, for cmake args
4141
include:
4242
# Just add a key
4343
- runs-on: ubuntu-latest
44-
python: 3.6
44+
python: '3.6'
4545
args: >
4646
-DPYBIND11_FINDPYTHON=ON
4747
- runs-on: windows-latest
48-
python: 3.6
48+
python: '3.6'
4949
args: >
5050
-DPYBIND11_FINDPYTHON=ON
5151
- runs-on: macos-latest
52-
python: pypy-2.7
52+
python: 'pypy-2.7'
53+
# Inject a couple Windows 2019 runs
54+
- runs-on: windows-2019
55+
python: '3.9'
56+
- runs-on: windows-2019
57+
python: '2.7'
5358

5459
name: "🐍 ${{ matrix.python }} • ${{ matrix.runs-on }} • x64 ${{ matrix.args }}"
5560
runs-on: ${{ matrix.runs-on }}
@@ -181,6 +186,7 @@ jobs:
181186
# setuptools
182187
- name: Setuptools helpers test
183188
run: pytest tests/extra_setuptools
189+
if: "!(matrix.python == '3.5' && matrix.runs-on == 'windows-2022')"
184190

185191

186192
deadsnakes:

include/pybind11/detail/common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@
154154
// C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only)
155155
# pragma warning(disable: 4505)
156156
# if defined(_DEBUG) && !defined(Py_DEBUG)
157+
// Workaround for a VS 2022 issue.
158+
// NOTE: This workaround knowingly violates the Python.h include order requirement:
159+
// https://docs.python.org/3/c-api/intro.html#include-files
160+
// See https://github.com/pybind/pybind11/pull/3497 for full context.
161+
# include <yvals.h>
162+
# if _MSVC_STL_VERSION >= 143
163+
# include <crtdefs.h>
164+
# endif
157165
# define PYBIND11_DEBUG_MARKER
158166
# undef _DEBUG
159167
# endif

include/pybind11/embed.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ inline wchar_t *widen_chars(const char *safe_arg) {
102102
wchar_t *widened_arg = Py_DecodeLocale(safe_arg, nullptr);
103103
#else
104104
wchar_t *widened_arg = nullptr;
105+
106+
// warning C4996: 'mbstowcs': This function or variable may be unsafe.
107+
#if defined(_MSC_VER)
108+
#pragma warning(push)
109+
#pragma warning(disable:4996)
110+
#endif
111+
105112
# if defined(HAVE_BROKEN_MBSTOWCS) && HAVE_BROKEN_MBSTOWCS
106113
size_t count = strlen(safe_arg);
107114
# else
@@ -111,6 +118,11 @@ inline wchar_t *widen_chars(const char *safe_arg) {
111118
widened_arg = new wchar_t[count + 1];
112119
mbstowcs(widened_arg, safe_arg, count + 1);
113120
}
121+
122+
#if defined(_MSC_VER)
123+
#pragma warning(pop)
124+
#endif
125+
114126
#endif
115127
return widened_arg;
116128
}

0 commit comments

Comments
 (0)