From b9cbd41ed6c56f0d0764e650a15cefa3cef01247 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sun, 28 Nov 2021 08:27:20 -0800 Subject: [PATCH] snapshot of current PR #3497 --- .github/workflows/ci.yml | 3 ++- include/pybind11/detail/common.h | 8 ++++++++ include/pybind11/embed.h | 12 ++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f36cff4c90..a0d46be978 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: strategy: fail-fast: false matrix: - runs-on: [ubuntu-latest, windows-latest, macos-latest] + runs-on: [ubuntu-latest, windows-2022, macos-latest] python: - '2.7' - '3.5' @@ -182,6 +182,7 @@ jobs: # setuptools - name: Setuptools helpers test run: pytest tests/extra_setuptools + if: "!(matrix.python == '3.5' && matrix.runs-on == 'windows-2022')" deadsnakes: diff --git a/include/pybind11/detail/common.h b/include/pybind11/detail/common.h index 862451fd13..f5bcc48f92 100644 --- a/include/pybind11/detail/common.h +++ b/include/pybind11/detail/common.h @@ -154,6 +154,14 @@ // C4505: 'PySlice_GetIndicesEx': unreferenced local function has been removed (PyPy only) # pragma warning(disable: 4505) # if defined(_DEBUG) && !defined(Py_DEBUG) +// Workaround for a VS 2022 issue. +// NOTE: This workaround knowingly violates the Python.h include order requirement: +// https://docs.python.org/3/c-api/intro.html#include-files +// See https://github.com/pybind/pybind11/pull/3497 for full context. +# include +# if _MSVC_STL_VERSION >= 143 +# include +# endif # define PYBIND11_DEBUG_MARKER # undef _DEBUG # endif diff --git a/include/pybind11/embed.h b/include/pybind11/embed.h index 9843f0f973..af36340f36 100644 --- a/include/pybind11/embed.h +++ b/include/pybind11/embed.h @@ -102,6 +102,13 @@ inline wchar_t *widen_chars(const char *safe_arg) { wchar_t *widened_arg = Py_DecodeLocale(safe_arg, nullptr); #else wchar_t *widened_arg = nullptr; + +// warning C4996: 'mbstowcs': This function or variable may be unsafe. +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4996) +#endif + # if defined(HAVE_BROKEN_MBSTOWCS) && HAVE_BROKEN_MBSTOWCS size_t count = strlen(safe_arg); # else @@ -111,6 +118,11 @@ inline wchar_t *widen_chars(const char *safe_arg) { widened_arg = new wchar_t[count + 1]; mbstowcs(widened_arg, safe_arg, count + 1); } + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + #endif return widened_arg; }