Skip to content

Commit

Permalink
Avoid MSVC ICE in nanobind's nb_func.h (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul authored Jul 19, 2024
1 parent 9b50f5d commit 73524dd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ if(BUILD_PYTHON)
git apply
${CMAKE_CURRENT_SOURCE_DIR}/cmake/0001-Replace-zero-size-array.patch
${CMAKE_CURRENT_SOURCE_DIR}/cmake/0002-Give-anonymous-union-a-name.patch
# https://github.com/wjakob/nanobind/issues/613
${CMAKE_CURRENT_SOURCE_DIR}/cmake/0003-Avoid-MSVC-ICE-in-nb_func.h.patch
UPDATE_DISCONNECTED 1
)
fetchcontent_makeavailable(nanobind)
Expand Down
2 changes: 1 addition & 1 deletion cmake/0001-Replace-zero-size-array.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Sat, 6 Jul 2024 14:27:32 -0700
Subject: [PATCH 1/2] Replace zero-size array
Subject: [PATCH 1/3] Replace zero-size array

---
include/nanobind/nb_attr.h | 6 ------
Expand Down
2 changes: 1 addition & 1 deletion cmake/0002-Give-anonymous-union-a-name.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Sat, 6 Jul 2024 14:31:24 -0700
Subject: [PATCH 2/2] Give anonymous union a name
Subject: [PATCH 2/3] Give anonymous union a name

---
include/nanobind/nb_class.h | 2 +-
Expand Down
38 changes: 38 additions & 0 deletions cmake/0003-Avoid-MSVC-ICE-in-nb_func.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Tyler Veness <calcmogul@gmail.com>
Date: Fri, 19 Jul 2024 12:08:44 -0700
Subject: [PATCH 3/3] Avoid MSVC ICE in nb_func.h

---
include/nanobind/nb_func.h | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/include/nanobind/nb_func.h b/include/nanobind/nb_func.h
index e53e1a42cc94e73ad882af05ff269d4b92d11433..58aef31ad9f6aedf63a9f5751cf695f6d9c28927 100644
--- a/include/nanobind/nb_func.h
+++ b/include/nanobind/nb_func.h
@@ -199,14 +199,24 @@ NB_INLINE PyObject *func_create(Func &&func, Return (*)(Args...),

PyObject *result;
if constexpr (std::is_void_v<Return>) {
+#ifdef _MSC_VER
+ cap->func(static_cast<cast_t<Args>>(in.template get<Is>())...);
+#else
cap->func(in.template get<Is>().operator cast_t<Args>()...);
+#endif
result = Py_None;
Py_INCREF(result);
} else {
+#ifdef _MSC_VER
+ result = cast_out::from_cpp(
+ cap->func(static_cast<cast_t<Args>>(in.template get<Is>())...),
+ policy, cleanup).ptr();
+#else
result = cast_out::from_cpp(
cap->func((in.template get<Is>())
.operator cast_t<Args>()...),
policy, cleanup).ptr();
+#endif
}

if constexpr (Info::keep_alive)
7 changes: 0 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,6 @@ install_args = [ ]
BUILD_TESTING = "OFF"
BUILD_PYTHON = "ON"

# https://github.com/wjakob/nanobind/issues/613
#
# Visual Studio 17.10.4's MSVC compiler gives an ICE in nanobind's nb_func.h,
# but clang-cl does not.
[tool.py-build-cmake.windows.cmake.options]
CMAKE_GENERATOR_TOOLSET = "ClangCl"

[tool.pytest.ini_options]
minversion = "6.0"
testpaths = [ "jormungandr/test", "examples/CurrentManager/test" ]

0 comments on commit 73524dd

Please sign in to comment.