mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-23 13:45:10 +00:00
afdc09deda
* override: Fix wrong caching of the overrides There was a problem when the python type, which was stored in override cache for C++ functions, was destroyed and the record wasn't removed from the override cache. Therefor, dangling pointer was stored there. Then when the memory was reused and new type was allocated at the given address and the method with the same name (as previously stored in the cache) was actually overridden in python, it would wrongly find it in the override cache for C++ functions and therefor override from python wouldn't be called. The fix is to erase the type from the override cache when the type is destroyed. * test: Pass by const ref instead of by value (clang-tidy) * test: Rename classes and move to different files Rename the classes and files so they're no too generic. Also, better place to test the stuff is in test_virtual_functions.cpp/.py as we're basically testing the virtual functions/trampolines. * Add TODO for erasure code * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
48 lines
1.8 KiB
CMake
48 lines
1.8 KiB
CMake
possibly_uninitialized(PYTHON_MODULE_EXTENSION Python_INTERPRETER_ID)
|
|
|
|
if("${PYTHON_MODULE_EXTENSION}" MATCHES "pypy" OR "${Python_INTERPRETER_ID}" STREQUAL "PyPy")
|
|
message(STATUS "Skipping embed test on PyPy")
|
|
add_custom_target(cpptest) # Dummy target on PyPy. Embedding is not supported.
|
|
set(_suppress_unused_variable_warning "${DOWNLOAD_CATCH}")
|
|
return()
|
|
endif()
|
|
|
|
find_package(Catch 2.13.2)
|
|
|
|
if(CATCH_FOUND)
|
|
message(STATUS "Building interpreter tests using Catch v${CATCH_VERSION}")
|
|
else()
|
|
message(STATUS "Catch not detected. Interpreter tests will be skipped. Install Catch headers"
|
|
" manually or use `cmake -DDOWNLOAD_CATCH=ON` to fetch them automatically.")
|
|
return()
|
|
endif()
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
add_executable(test_embed catch.cpp test_interpreter.cpp)
|
|
pybind11_enable_warnings(test_embed)
|
|
|
|
target_link_libraries(test_embed PRIVATE pybind11::embed Catch2::Catch2 Threads::Threads)
|
|
|
|
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
|
|
file(COPY test_interpreter.py test_trampoline.py DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
|
|
endif()
|
|
|
|
add_custom_target(
|
|
cpptest
|
|
COMMAND "$<TARGET_FILE:test_embed>"
|
|
DEPENDS test_embed
|
|
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
pybind11_add_module(external_module THIN_LTO external_module.cpp)
|
|
set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY
|
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
|
foreach(config ${CMAKE_CONFIGURATION_TYPES})
|
|
string(TOUPPER ${config} config)
|
|
set_target_properties(external_module PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${config}
|
|
"${CMAKE_CURRENT_BINARY_DIR}")
|
|
endforeach()
|
|
add_dependencies(cpptest external_module)
|
|
|
|
add_dependencies(check cpptest)
|