From 607812a0b51fe943cf1c5ebc8baeca7e2cf12a1a Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 28 Nov 2023 10:08:14 -0600 Subject: [PATCH 1/7] Fix MSVC MT/MD incompatibility in PYBIND11_BUILD_ABI --- include/pybind11/detail/internals.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index fa224e0326..5ad0e36ad6 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -311,11 +311,11 @@ struct type_info { #endif /// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility. -/// On MSVC, changes in _MSC_VER may indicate ABI incompatibility (#2898). +/// On MSVC, mixing /MT and /MD will result in crashes. See (#4779) #ifndef PYBIND11_BUILD_ABI # if defined(__GXX_ABI_VERSION) # define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION) -# elif defined(_MSC_VER) +# elif defined(_MSC_VER) && defined(_MT) # define PYBIND11_BUILD_ABI "_mscver" PYBIND11_TOSTRING(_MSC_VER) # else # define PYBIND11_BUILD_ABI "" From 71b0e9e55679f19ac982373a1db476c44ca41e7b Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 28 Nov 2023 12:46:48 -0600 Subject: [PATCH 2/7] Update comment about which PR --- include/pybind11/detail/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 5ad0e36ad6..e1f1cda4ea 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -311,7 +311,7 @@ struct type_info { #endif /// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility. -/// On MSVC, mixing /MT and /MD will result in crashes. See (#4779) +/// On MSVC, mixing /MT and /MD will result in crashes. See (#4953) #ifndef PYBIND11_BUILD_ABI # if defined(__GXX_ABI_VERSION) # define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION) From d1695f1f6124b42382eda25476e775601a7d9bad Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Thu, 30 Nov 2023 17:37:07 -0600 Subject: [PATCH 3/7] Use msvc major version --- include/pybind11/detail/internals.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index e1f1cda4ea..390af547a9 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -316,7 +316,11 @@ struct type_info { # if defined(__GXX_ABI_VERSION) # define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION) # elif defined(_MSC_VER) && defined(_MT) -# define PYBIND11_BUILD_ABI "_mscver" PYBIND11_TOSTRING(_MSC_VER) +# define PYBIND11_BUILD_ABI "_mt_mscver" PYBIND11_TOSTRING(_MSC_VER) +# elif defined(_MSC_VER) && defined(_MD) && (_MSC_VER >= 1900) && (_MSC_VER < 2000) +# define PYBIND11_BUILD_ABI "_md_mscver14" +# elif defined(_MSC_VER) && defined(_MD) +# define PYBIND11_BUILD_ABI "_md_mscver" PYBIND11_TOSTRING(_MSC_VER) # else # define PYBIND11_BUILD_ABI "" # endif From 4c6c344641671dcb956836c4b8d958a078b1c779 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Mon, 30 Sep 2024 19:53:53 -0500 Subject: [PATCH 4/7] Use _MSC_VER/100 --- include/pybind11/detail/internals.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 390af547a9..47afb9ae26 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -317,10 +317,8 @@ struct type_info { # define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION) # elif defined(_MSC_VER) && defined(_MT) # define PYBIND11_BUILD_ABI "_mt_mscver" PYBIND11_TOSTRING(_MSC_VER) -# elif defined(_MSC_VER) && defined(_MD) && (_MSC_VER >= 1900) && (_MSC_VER < 2000) -# define PYBIND11_BUILD_ABI "_md_mscver14" # elif defined(_MSC_VER) && defined(_MD) -# define PYBIND11_BUILD_ABI "_md_mscver" PYBIND11_TOSTRING(_MSC_VER) +# define PYBIND11_BUILD_ABI "_md_mscver" PYBIND11_TOSTRING(((int) (_MSC_VER) / 100)) # else # define PYBIND11_BUILD_ABI "" # endif From 5b9078d6f5b8c16376a19c6a993f3fd0c9c472f0 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sun, 13 Oct 2024 11:27:02 -0700 Subject: [PATCH 5/7] Minor cleanup of `PYBIND11_BUILD_ABI` logic/comments. Eliminate fall-through for MSVC. --- include/pybind11/detail/internals.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 28f037ddcd..3219bd060f 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -310,15 +310,17 @@ struct type_info { # endif #endif -/// On Linux/OSX, changes in __GXX_ABI_VERSION__ indicate ABI incompatibility. -/// On MSVC, mixing /MT and /MD will result in crashes. See (#4953) #ifndef PYBIND11_BUILD_ABI -# if defined(__GXX_ABI_VERSION) +# if defined(__GXX_ABI_VERSION) // Linux/OSX. # define PYBIND11_BUILD_ABI "_cxxabi" PYBIND11_TOSTRING(__GXX_ABI_VERSION) -# elif defined(_MSC_VER) && defined(_MT) -# define PYBIND11_BUILD_ABI "_mt_mscver" PYBIND11_TOSTRING(_MSC_VER) -# elif defined(_MSC_VER) && defined(_MD) -# define PYBIND11_BUILD_ABI "_md_mscver" PYBIND11_TOSTRING(((int) (_MSC_VER) / 100)) +# elif defined(_MSC_VER) // See PR #4953. +# if defined(_MT) +# define PYBIND11_BUILD_ABI "_mt_mscver" PYBIND11_TOSTRING(_MSC_VER) +# elif defined(_MD) +# define PYBIND11_BUILD_ABI "_md_mscver" PYBIND11_TOSTRING(((int) (_MSC_VER) / 100)) +# else +# error "UNEXPECTED MSVC ENVIRONMENT: PLEASE REVISE THIS CODE." +# endif # else # define PYBIND11_BUILD_ABI "" # endif From b0f9089fb291b2f29a30793f93b8af313413cc29 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sun, 13 Oct 2024 12:47:21 -0700 Subject: [PATCH 6/7] Disable fall-through `""` for `PYBIND11_BUILD_ABI` --- include/pybind11/detail/internals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index 3219bd060f..f2109cc280 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -322,7 +322,7 @@ struct type_info { # error "UNEXPECTED MSVC ENVIRONMENT: PLEASE REVISE THIS CODE." # endif # else -# define PYBIND11_BUILD_ABI "" +# error "INTENTIONAL BREAKAGE" # endif #endif From 24914e9f4c0e605f0c587f6f54658a9a3f695c5f Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Sun, 13 Oct 2024 20:44:06 -0700 Subject: [PATCH 7/7] Special case for `__NVCOMPILER`, no fallback for `PYBIND11_BUILD_ABI` in the general case. --- include/pybind11/detail/internals.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/pybind11/detail/internals.h b/include/pybind11/detail/internals.h index f2109cc280..1bf4043792 100644 --- a/include/pybind11/detail/internals.h +++ b/include/pybind11/detail/internals.h @@ -319,10 +319,12 @@ struct type_info { # elif defined(_MD) # define PYBIND11_BUILD_ABI "_md_mscver" PYBIND11_TOSTRING(((int) (_MSC_VER) / 100)) # else -# error "UNEXPECTED MSVC ENVIRONMENT: PLEASE REVISE THIS CODE." +# error "UNEXPECTED PREPROCESSOR MACROS (MSVC): PLEASE REVISE THIS CODE." # endif +# elif defined(__NVCOMPILER) // NVHPC (PGI-based, outdated). +# define PYBIND11_BUILD_ABI "" // This was never properly guarded. # else -# error "INTENTIONAL BREAKAGE" +# error "UNEXPECTED PREPROCESSOR MACROS: PLEASE REVISE THIS CODE." # endif #endif