Skip to content

Commit

Permalink
Patching pybind11 to fix premature deletion of python objects
Browse files Browse the repository at this point in the history
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
  • Loading branch information
chetnieter committed May 27, 2023
1 parent 5357500 commit 0ed38a6
Show file tree
Hide file tree
Showing 7 changed files with 6,614 additions and 1,838 deletions.
11 changes: 11 additions & 0 deletions CMake/External_pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@ if (PYTHON_EXECUTABLE)
set(pybind_PYTHON_ARGS -DPYTHON_EXECUTABLE:FILEPATH=${PYTHON_EXECUTABLE})
endif()

# If a patch file exists, apply it
set (pybind11_patch ${fletch_SOURCE_DIR}/Patches/pybind11)
if (EXISTS ${pybind11_patch})
set(pybind11_PATCH_COMMAND ${CMAKE_COMMAND}
-Dpybind11_patch:PATH=${pybind11_patch}
-Dpybind11_source:PATH=${fletch_BUILD_PREFIX}/src/pybind11
-P ${pybind11_patch}/Patch.cmake
)
endif()

ExternalProject_Add(pybind11
URL ${pybind11_url}
URL_MD5 ${pybind11_md5}
DOWNLOAD_NAME ${pybind11_dlname}
${COMMON_EP_ARGS}
${COMMON_CMAKE_EP_ARGS}
PATCH_COMMAND ${pybind11_PATCH_COMMAND}
CMAKE_ARGS
${COMMON_CMAKE_ARGS}
-DCMAKE_CXX_STANDARD=17
Expand Down
31 changes: 31 additions & 0 deletions Patches/pybind11/Patch.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#+
# This file is called as CMake -P script for the patch step of
# External_pybind11.cmake pybind11_patch and pybind11_source are defined on the command
# line along with the call.
#-

# Patching files based off of open PR for pybind11
# https://github.com/pybind/pybind11/pull/2839
configure_file(
${pybind11_patch}/cast.h
${pybind11_source}/include/pybind11/
COPYONLY
)

configure_file(
${pybind11_patch}/pybind11.h
${pybind11_source}/include/pybind11/
COPYONLY
)

configure_file(
${pybind11_patch}/detail/class.h
${pybind11_source}/include/pybind11/detail
COPYONLY
)

configure_file(
${pybind11_patch}/detail/common.h
${pybind11_source}/include/pybind11/detail
COPYONLY
)
Loading

0 comments on commit 0ed38a6

Please sign in to comment.