Skip to content

Commit ea4ed4c

Browse files
committed
Patching pybind11 to fix premature deletion of python objects
Patching pybind11 to fix premature deletion of python objects created and wrapped in c++. This patch is based off an open PR for pybind11. pybind/pybind11#2839
1 parent bce9d1c commit ea4ed4c

File tree

7 files changed

+6614
-1838
lines changed

7 files changed

+6614
-1838
lines changed

CMake/External_pybind11.cmake

+11
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,23 @@ if (PYTHON_EXECUTABLE)
66
set(pybind_PYTHON_ARGS -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE})
77
endif()
88

9+
# If a patch file exists, apply it
10+
set (pybind11_patch ${fletch_SOURCE_DIR}/Patches/pybind11)
11+
if (EXISTS ${pybind11_patch})
12+
set(pybind11_PATCH_COMMAND ${CMAKE_COMMAND}
13+
-Dpybind11_patch:PATH=${pybind11_patch}
14+
-Dpybind11_source:PATH=${fletch_BUILD_PREFIX}/src/pybind11
15+
-P ${pybind11_patch}/Patch.cmake
16+
)
17+
endif()
18+
919
ExternalProject_Add(pybind11
1020
URL ${pybind11_url}
1121
URL_MD5 ${pybind11_md5}
1222
DOWNLOAD_NAME ${pybind11_dlname}
1323
${COMMON_EP_ARGS}
1424
${COMMON_CMAKE_EP_ARGS}
25+
PATCH_COMMAND ${pybind11_PATCH_COMMAND}
1526
CMAKE_ARGS
1627
${COMMON_CMAKE_ARGS}
1728
-DCMAKE_CXX_STANDARD=17

Patches/pybind11/Patch.cmake

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#+
2+
# This file is called as CMake -P script for the patch step of
3+
# External_pybind11.cmake pybind11_patch and pybind11_source are defined on the command
4+
# line along with the call.
5+
#-
6+
7+
# Patching files based off of open PR for pybind11
8+
# https://github.com/pybind/pybind11/pull/2839
9+
configure_file(
10+
${pybind11_patch}/cast.h
11+
${pybind11_source}/include/pybind11/
12+
COPYONLY
13+
)
14+
15+
configure_file(
16+
${pybind11_patch}/pybind11.h
17+
${pybind11_source}/include/pybind11/
18+
COPYONLY
19+
)
20+
21+
configure_file(
22+
${pybind11_patch}/detail/class.h
23+
${pybind11_source}/include/pybind11/detail
24+
COPYONLY
25+
)
26+
27+
configure_file(
28+
${pybind11_patch}/detail/common.h
29+
${pybind11_source}/include/pybind11/detail
30+
COPYONLY
31+
)

0 commit comments

Comments
 (0)