xcoll 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of xcoll might be problematic. Click here for more details.
- xcoll/__init__.py +2 -1
- xcoll/beam_elements/__init__.py +7 -1
- xcoll/beam_elements/absorber.py +2 -2
- xcoll/beam_elements/base.py +105 -67
- xcoll/beam_elements/blowup.py +198 -0
- xcoll/beam_elements/{collimators_src → elements_src}/black_absorber.h +21 -3
- xcoll/beam_elements/{collimators_src → elements_src}/black_crystal.h +20 -2
- xcoll/beam_elements/elements_src/blowup.h +42 -0
- xcoll/beam_elements/elements_src/emittance_monitor.h +109 -0
- xcoll/beam_elements/{collimators_src → elements_src}/everest_block.h +19 -2
- xcoll/beam_elements/{collimators_src → elements_src}/everest_collimator.h +19 -3
- xcoll/beam_elements/{collimators_src → elements_src}/everest_crystal.h +30 -9
- xcoll/beam_elements/everest.py +5 -6
- xcoll/beam_elements/monitor.py +428 -0
- xcoll/colldb.py +103 -74
- xcoll/general.py +4 -4
- xcoll/initial_distribution.py +18 -6
- xcoll/install.py +3 -1
- xcoll/interaction_record/interaction_record.py +126 -80
- xcoll/interaction_record/interaction_record_src/interaction_record.h +43 -43
- xcoll/line_tools.py +8 -9
- xcoll/lossmap.py +48 -38
- xcoll/scattering_routines/everest/amorphous.h +4 -11
- xcoll/scattering_routines/everest/channeling.h +3 -8
- xcoll/scattering_routines/everest/everest.h +4 -1
- xcoll/scattering_routines/everest/jaw.h +4 -3
- xcoll/scattering_routines/everest/materials.py +35 -15
- xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
- xcoll/scattering_routines/everest/nuclear_interaction.h +1 -1
- xcoll/scattering_routines/everest/properties.h +6 -1
- xcoll/scattering_routines/fluka/flukaio/lib/libFlukaIO64.a +0 -0
- xcoll/scattering_routines/geant4/collimasim/.git +1 -0
- xcoll/scattering_routines/geant4/collimasim/.gitignore +12 -0
- xcoll/scattering_routines/geant4/collimasim/.gitmodules +3 -0
- xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +26 -0
- xcoll/scattering_routines/geant4/collimasim/README.md +21 -0
- xcoll/scattering_routines/geant4/collimasim/docs/Makefile +20 -0
- xcoll/scattering_routines/geant4/collimasim/docs/make.bat +35 -0
- xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +10 -0
- xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +59 -0
- xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +26 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +37 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +19 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +65 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +73 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +1 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +9 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +386 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +45 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +8 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +16 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +8 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +3 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +19 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +969 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +84 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +48 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +16 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +103 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +45 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +151 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +3 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +297 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +29 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +6 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +180 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +23 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +192 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +11 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +81 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +93 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +310 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +109 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +43 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +171 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +251 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +305 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +1297 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +262 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +396 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +568 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +337 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +13 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +463 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +286 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +155 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +174 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +308 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +91 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +95 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +2050 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +542 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +8 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +648 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +381 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +343 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +48 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +105 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +72 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11-logo.png +0 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.png +0 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python1.svg +427 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.png +0 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/pybind11_vs_boost_python2.svg +427 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +130 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +96 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +8 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +548 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +605 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +144 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +1432 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +213 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +2 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +65 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +709 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +1021 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +104 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +346 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +467 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +978 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +55 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +606 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +284 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +163 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +121 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +193 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +275 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +1741 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +163 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +65 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +2497 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +1879 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +103 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +375 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +747 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +88 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +11 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +52 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +12 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +6 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +21 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +482 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +63 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +41 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +56 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +155 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +503 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +208 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +275 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +73 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +33 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/pytest.ini +0 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_python_package/test_files.py +279 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/pytest.ini +0 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/extra_setuptools/test_setuphelper.py +143 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +85 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +179 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +151 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +91 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +85 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +19 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +12 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +26 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +25 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +216 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +163 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +286 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +536 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +107 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +248 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +227 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +202 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +84 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +210 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +550 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +473 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +84 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +21 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +28 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +39 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +46 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +6 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +41 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +35 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +41 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +10 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +165 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +53 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +238 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +126 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +141 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +117 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +41 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +50 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +69 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +42 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +348 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +771 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +47 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +22 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +23 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +326 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +15 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +148 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +272 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +119 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +51 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +5 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +285 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +12 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +265 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +397 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +520 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +49 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +94 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +125 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +331 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +153 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +284 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +107 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +257 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +412 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +517 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +102 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +92 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +233 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +360 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +472 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +593 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +524 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +441 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +103 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +267 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +73 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +59 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +235 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +146 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +189 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +82 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +560 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +651 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +500 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +253 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +452 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +318 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +342 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +291 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +131 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +318 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +144 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +29 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +66 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +44 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +22 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +9 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +510 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +408 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +140 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +117 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +70 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +86 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +257 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +44 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +23 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +39 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +64 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +402 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +233 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +276 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +214 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +3 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +65 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +41 -0
- xcoll/scattering_routines/geant4/collimasim/pyproject.toml +8 -0
- xcoll/scattering_routines/geant4/collimasim/setup.py +144 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +403 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +100 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +763 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +118 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +8 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +63 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +142 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +556 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +6 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +24 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +1 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +1 -0
- xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +1 -0
- xcoll/scattering_routines/geant4/collimasim/tests/README.md +25 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +25 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +18 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +68 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +15 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +110 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +7 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +3 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +54 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +3 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +3 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +5 -0
- xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +51 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +65 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +59 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +102 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +75 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +74 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +84 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +159 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +99 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +78 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +88 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +80 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +97 -0
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +96 -0
- xcoll/scattering_routines/geometry/collimator_geometry.h +9 -10
- xcoll/scattering_routines/geometry/crystal_geometry.h +9 -6
- {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/METADATA +1 -1
- xcoll-0.5.0.dist-info/RECORD +413 -0
- xcoll/scattering_routines/fluka/build_fluka_input.py +0 -58
- xcoll-0.4.0.dist-info/RECORD +0 -126
- {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/LICENSE +0 -0
- {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/NOTICE +0 -0
- {xcoll-0.4.0.dist-info → xcoll-0.5.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,709 @@
|
|
|
1
|
+
/*
|
|
2
|
+
pybind11/detail/class.h: Python C API implementation details for py::class_
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2017 Wenzel Jakob <wenzel.jakob@epfl.ch>
|
|
5
|
+
|
|
6
|
+
All rights reserved. Use of this source code is governed by a
|
|
7
|
+
BSD-style license that can be found in the LICENSE file.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include "../attr.h"
|
|
13
|
+
#include "../options.h"
|
|
14
|
+
|
|
15
|
+
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
|
16
|
+
PYBIND11_NAMESPACE_BEGIN(detail)
|
|
17
|
+
|
|
18
|
+
#if PY_VERSION_HEX >= 0x03030000 && !defined(PYPY_VERSION)
|
|
19
|
+
# define PYBIND11_BUILTIN_QUALNAME
|
|
20
|
+
# define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj)
|
|
21
|
+
#else
|
|
22
|
+
// In pre-3.3 Python, we still set __qualname__ so that we can produce reliable function type
|
|
23
|
+
// signatures; in 3.3+ this macro expands to nothing:
|
|
24
|
+
# define PYBIND11_SET_OLDPY_QUALNAME(obj, nameobj) setattr((PyObject *) obj, "__qualname__", nameobj)
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
inline std::string get_fully_qualified_tp_name(PyTypeObject *type) {
|
|
28
|
+
#if !defined(PYPY_VERSION)
|
|
29
|
+
return type->tp_name;
|
|
30
|
+
#else
|
|
31
|
+
auto module_name = handle((PyObject *) type).attr("__module__").cast<std::string>();
|
|
32
|
+
if (module_name == PYBIND11_BUILTINS_MODULE)
|
|
33
|
+
return type->tp_name;
|
|
34
|
+
else
|
|
35
|
+
return std::move(module_name) + "." + type->tp_name;
|
|
36
|
+
#endif
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
inline PyTypeObject *type_incref(PyTypeObject *type) {
|
|
40
|
+
Py_INCREF(type);
|
|
41
|
+
return type;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#if !defined(PYPY_VERSION)
|
|
45
|
+
|
|
46
|
+
/// `pybind11_static_property.__get__()`: Always pass the class instead of the instance.
|
|
47
|
+
extern "C" inline PyObject *pybind11_static_get(PyObject *self, PyObject * /*ob*/, PyObject *cls) {
|
|
48
|
+
return PyProperty_Type.tp_descr_get(self, cls, cls);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// `pybind11_static_property.__set__()`: Just like the above `__get__()`.
|
|
52
|
+
extern "C" inline int pybind11_static_set(PyObject *self, PyObject *obj, PyObject *value) {
|
|
53
|
+
PyObject *cls = PyType_Check(obj) ? obj : (PyObject *) Py_TYPE(obj);
|
|
54
|
+
return PyProperty_Type.tp_descr_set(self, cls, value);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A `static_property` is the same as a `property` but the `__get__()` and `__set__()`
|
|
58
|
+
methods are modified to always use the object type instead of a concrete instance.
|
|
59
|
+
Return value: New reference. */
|
|
60
|
+
inline PyTypeObject *make_static_property_type() {
|
|
61
|
+
constexpr auto *name = "pybind11_static_property";
|
|
62
|
+
auto name_obj = reinterpret_steal<object>(PYBIND11_FROM_STRING(name));
|
|
63
|
+
|
|
64
|
+
/* Danger zone: from now (and until PyType_Ready), make sure to
|
|
65
|
+
issue no Python C API calls which could potentially invoke the
|
|
66
|
+
garbage collector (the GC will call type_traverse(), which will in
|
|
67
|
+
turn find the newly constructed type in an invalid state) */
|
|
68
|
+
auto heap_type = (PyHeapTypeObject *) PyType_Type.tp_alloc(&PyType_Type, 0);
|
|
69
|
+
if (!heap_type)
|
|
70
|
+
pybind11_fail("make_static_property_type(): error allocating type!");
|
|
71
|
+
|
|
72
|
+
heap_type->ht_name = name_obj.inc_ref().ptr();
|
|
73
|
+
#ifdef PYBIND11_BUILTIN_QUALNAME
|
|
74
|
+
heap_type->ht_qualname = name_obj.inc_ref().ptr();
|
|
75
|
+
#endif
|
|
76
|
+
|
|
77
|
+
auto type = &heap_type->ht_type;
|
|
78
|
+
type->tp_name = name;
|
|
79
|
+
type->tp_base = type_incref(&PyProperty_Type);
|
|
80
|
+
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;
|
|
81
|
+
type->tp_descr_get = pybind11_static_get;
|
|
82
|
+
type->tp_descr_set = pybind11_static_set;
|
|
83
|
+
|
|
84
|
+
if (PyType_Ready(type) < 0)
|
|
85
|
+
pybind11_fail("make_static_property_type(): failure in PyType_Ready()!");
|
|
86
|
+
|
|
87
|
+
setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
|
|
88
|
+
PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
|
|
89
|
+
|
|
90
|
+
return type;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#else // PYPY
|
|
94
|
+
|
|
95
|
+
/** PyPy has some issues with the above C API, so we evaluate Python code instead.
|
|
96
|
+
This function will only be called once so performance isn't really a concern.
|
|
97
|
+
Return value: New reference. */
|
|
98
|
+
inline PyTypeObject *make_static_property_type() {
|
|
99
|
+
auto d = dict();
|
|
100
|
+
PyObject *result = PyRun_String(R"(\
|
|
101
|
+
class pybind11_static_property(property):
|
|
102
|
+
def __get__(self, obj, cls):
|
|
103
|
+
return property.__get__(self, cls, cls)
|
|
104
|
+
|
|
105
|
+
def __set__(self, obj, value):
|
|
106
|
+
cls = obj if isinstance(obj, type) else type(obj)
|
|
107
|
+
property.__set__(self, cls, value)
|
|
108
|
+
)", Py_file_input, d.ptr(), d.ptr()
|
|
109
|
+
);
|
|
110
|
+
if (result == nullptr)
|
|
111
|
+
throw error_already_set();
|
|
112
|
+
Py_DECREF(result);
|
|
113
|
+
return (PyTypeObject *) d["pybind11_static_property"].cast<object>().release().ptr();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#endif // PYPY
|
|
117
|
+
|
|
118
|
+
/** Types with static properties need to handle `Type.static_prop = x` in a specific way.
|
|
119
|
+
By default, Python replaces the `static_property` itself, but for wrapped C++ types
|
|
120
|
+
we need to call `static_property.__set__()` in order to propagate the new value to
|
|
121
|
+
the underlying C++ data structure. */
|
|
122
|
+
extern "C" inline int pybind11_meta_setattro(PyObject* obj, PyObject* name, PyObject* value) {
|
|
123
|
+
// Use `_PyType_Lookup()` instead of `PyObject_GetAttr()` in order to get the raw
|
|
124
|
+
// descriptor (`property`) instead of calling `tp_descr_get` (`property.__get__()`).
|
|
125
|
+
PyObject *descr = _PyType_Lookup((PyTypeObject *) obj, name);
|
|
126
|
+
|
|
127
|
+
// The following assignment combinations are possible:
|
|
128
|
+
// 1. `Type.static_prop = value` --> descr_set: `Type.static_prop.__set__(value)`
|
|
129
|
+
// 2. `Type.static_prop = other_static_prop` --> setattro: replace existing `static_prop`
|
|
130
|
+
// 3. `Type.regular_attribute = value` --> setattro: regular attribute assignment
|
|
131
|
+
const auto static_prop = (PyObject *) get_internals().static_property_type;
|
|
132
|
+
const auto call_descr_set = (descr != nullptr) && (value != nullptr)
|
|
133
|
+
&& (PyObject_IsInstance(descr, static_prop) != 0)
|
|
134
|
+
&& (PyObject_IsInstance(value, static_prop) == 0);
|
|
135
|
+
if (call_descr_set) {
|
|
136
|
+
// Call `static_property.__set__()` instead of replacing the `static_property`.
|
|
137
|
+
#if !defined(PYPY_VERSION)
|
|
138
|
+
return Py_TYPE(descr)->tp_descr_set(descr, obj, value);
|
|
139
|
+
#else
|
|
140
|
+
if (PyObject *result = PyObject_CallMethod(descr, "__set__", "OO", obj, value)) {
|
|
141
|
+
Py_DECREF(result);
|
|
142
|
+
return 0;
|
|
143
|
+
} else {
|
|
144
|
+
return -1;
|
|
145
|
+
}
|
|
146
|
+
#endif
|
|
147
|
+
} else {
|
|
148
|
+
// Replace existing attribute.
|
|
149
|
+
return PyType_Type.tp_setattro(obj, name, value);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#if PY_MAJOR_VERSION >= 3
|
|
154
|
+
/**
|
|
155
|
+
* Python 3's PyInstanceMethod_Type hides itself via its tp_descr_get, which prevents aliasing
|
|
156
|
+
* methods via cls.attr("m2") = cls.attr("m1"): instead the tp_descr_get returns a plain function,
|
|
157
|
+
* when called on a class, or a PyMethod, when called on an instance. Override that behaviour here
|
|
158
|
+
* to do a special case bypass for PyInstanceMethod_Types.
|
|
159
|
+
*/
|
|
160
|
+
extern "C" inline PyObject *pybind11_meta_getattro(PyObject *obj, PyObject *name) {
|
|
161
|
+
PyObject *descr = _PyType_Lookup((PyTypeObject *) obj, name);
|
|
162
|
+
if (descr && PyInstanceMethod_Check(descr)) {
|
|
163
|
+
Py_INCREF(descr);
|
|
164
|
+
return descr;
|
|
165
|
+
}
|
|
166
|
+
return PyType_Type.tp_getattro(obj, name);
|
|
167
|
+
}
|
|
168
|
+
#endif
|
|
169
|
+
|
|
170
|
+
/// metaclass `__call__` function that is used to create all pybind11 objects.
|
|
171
|
+
extern "C" inline PyObject *pybind11_meta_call(PyObject *type, PyObject *args, PyObject *kwargs) {
|
|
172
|
+
|
|
173
|
+
// use the default metaclass call to create/initialize the object
|
|
174
|
+
PyObject *self = PyType_Type.tp_call(type, args, kwargs);
|
|
175
|
+
if (self == nullptr) {
|
|
176
|
+
return nullptr;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// This must be a pybind11 instance
|
|
180
|
+
auto instance = reinterpret_cast<detail::instance *>(self);
|
|
181
|
+
|
|
182
|
+
// Ensure that the base __init__ function(s) were called
|
|
183
|
+
for (const auto &vh : values_and_holders(instance)) {
|
|
184
|
+
if (!vh.holder_constructed()) {
|
|
185
|
+
PyErr_Format(PyExc_TypeError, "%.200s.__init__() must be called when overriding __init__",
|
|
186
|
+
get_fully_qualified_tp_name(vh.type->type).c_str());
|
|
187
|
+
Py_DECREF(self);
|
|
188
|
+
return nullptr;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return self;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/// Cleanup the type-info for a pybind11-registered type.
|
|
196
|
+
extern "C" inline void pybind11_meta_dealloc(PyObject *obj) {
|
|
197
|
+
auto *type = (PyTypeObject *) obj;
|
|
198
|
+
auto &internals = get_internals();
|
|
199
|
+
|
|
200
|
+
// A pybind11-registered type will:
|
|
201
|
+
// 1) be found in internals.registered_types_py
|
|
202
|
+
// 2) have exactly one associated `detail::type_info`
|
|
203
|
+
auto found_type = internals.registered_types_py.find(type);
|
|
204
|
+
if (found_type != internals.registered_types_py.end() &&
|
|
205
|
+
found_type->second.size() == 1 &&
|
|
206
|
+
found_type->second[0]->type == type) {
|
|
207
|
+
|
|
208
|
+
auto *tinfo = found_type->second[0];
|
|
209
|
+
auto tindex = std::type_index(*tinfo->cpptype);
|
|
210
|
+
internals.direct_conversions.erase(tindex);
|
|
211
|
+
|
|
212
|
+
if (tinfo->module_local)
|
|
213
|
+
get_local_internals().registered_types_cpp.erase(tindex);
|
|
214
|
+
else
|
|
215
|
+
internals.registered_types_cpp.erase(tindex);
|
|
216
|
+
internals.registered_types_py.erase(tinfo->type);
|
|
217
|
+
|
|
218
|
+
// Actually just `std::erase_if`, but that's only available in C++20
|
|
219
|
+
auto &cache = internals.inactive_override_cache;
|
|
220
|
+
for (auto it = cache.begin(), last = cache.end(); it != last; ) {
|
|
221
|
+
if (it->first == (PyObject *) tinfo->type)
|
|
222
|
+
it = cache.erase(it);
|
|
223
|
+
else
|
|
224
|
+
++it;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
delete tinfo;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
PyType_Type.tp_dealloc(obj);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/** This metaclass is assigned by default to all pybind11 types and is required in order
|
|
234
|
+
for static properties to function correctly. Users may override this using `py::metaclass`.
|
|
235
|
+
Return value: New reference. */
|
|
236
|
+
inline PyTypeObject* make_default_metaclass() {
|
|
237
|
+
constexpr auto *name = "pybind11_type";
|
|
238
|
+
auto name_obj = reinterpret_steal<object>(PYBIND11_FROM_STRING(name));
|
|
239
|
+
|
|
240
|
+
/* Danger zone: from now (and until PyType_Ready), make sure to
|
|
241
|
+
issue no Python C API calls which could potentially invoke the
|
|
242
|
+
garbage collector (the GC will call type_traverse(), which will in
|
|
243
|
+
turn find the newly constructed type in an invalid state) */
|
|
244
|
+
auto heap_type = (PyHeapTypeObject *) PyType_Type.tp_alloc(&PyType_Type, 0);
|
|
245
|
+
if (!heap_type)
|
|
246
|
+
pybind11_fail("make_default_metaclass(): error allocating metaclass!");
|
|
247
|
+
|
|
248
|
+
heap_type->ht_name = name_obj.inc_ref().ptr();
|
|
249
|
+
#ifdef PYBIND11_BUILTIN_QUALNAME
|
|
250
|
+
heap_type->ht_qualname = name_obj.inc_ref().ptr();
|
|
251
|
+
#endif
|
|
252
|
+
|
|
253
|
+
auto type = &heap_type->ht_type;
|
|
254
|
+
type->tp_name = name;
|
|
255
|
+
type->tp_base = type_incref(&PyType_Type);
|
|
256
|
+
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;
|
|
257
|
+
|
|
258
|
+
type->tp_call = pybind11_meta_call;
|
|
259
|
+
|
|
260
|
+
type->tp_setattro = pybind11_meta_setattro;
|
|
261
|
+
#if PY_MAJOR_VERSION >= 3
|
|
262
|
+
type->tp_getattro = pybind11_meta_getattro;
|
|
263
|
+
#endif
|
|
264
|
+
|
|
265
|
+
type->tp_dealloc = pybind11_meta_dealloc;
|
|
266
|
+
|
|
267
|
+
if (PyType_Ready(type) < 0)
|
|
268
|
+
pybind11_fail("make_default_metaclass(): failure in PyType_Ready()!");
|
|
269
|
+
|
|
270
|
+
setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
|
|
271
|
+
PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
|
|
272
|
+
|
|
273
|
+
return type;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/// For multiple inheritance types we need to recursively register/deregister base pointers for any
|
|
277
|
+
/// base classes with pointers that are difference from the instance value pointer so that we can
|
|
278
|
+
/// correctly recognize an offset base class pointer. This calls a function with any offset base ptrs.
|
|
279
|
+
inline void traverse_offset_bases(void *valueptr, const detail::type_info *tinfo, instance *self,
|
|
280
|
+
bool (*f)(void * /*parentptr*/, instance * /*self*/)) {
|
|
281
|
+
for (handle h : reinterpret_borrow<tuple>(tinfo->type->tp_bases)) {
|
|
282
|
+
if (auto parent_tinfo = get_type_info((PyTypeObject *) h.ptr())) {
|
|
283
|
+
for (auto &c : parent_tinfo->implicit_casts) {
|
|
284
|
+
if (c.first == tinfo->cpptype) {
|
|
285
|
+
auto *parentptr = c.second(valueptr);
|
|
286
|
+
if (parentptr != valueptr)
|
|
287
|
+
f(parentptr, self);
|
|
288
|
+
traverse_offset_bases(parentptr, parent_tinfo, self, f);
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
inline bool register_instance_impl(void *ptr, instance *self) {
|
|
297
|
+
get_internals().registered_instances.emplace(ptr, self);
|
|
298
|
+
return true; // unused, but gives the same signature as the deregister func
|
|
299
|
+
}
|
|
300
|
+
inline bool deregister_instance_impl(void *ptr, instance *self) {
|
|
301
|
+
auto ®istered_instances = get_internals().registered_instances;
|
|
302
|
+
auto range = registered_instances.equal_range(ptr);
|
|
303
|
+
for (auto it = range.first; it != range.second; ++it) {
|
|
304
|
+
if (self == it->second) {
|
|
305
|
+
registered_instances.erase(it);
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
inline void register_instance(instance *self, void *valptr, const type_info *tinfo) {
|
|
313
|
+
register_instance_impl(valptr, self);
|
|
314
|
+
if (!tinfo->simple_ancestors)
|
|
315
|
+
traverse_offset_bases(valptr, tinfo, self, register_instance_impl);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
inline bool deregister_instance(instance *self, void *valptr, const type_info *tinfo) {
|
|
319
|
+
bool ret = deregister_instance_impl(valptr, self);
|
|
320
|
+
if (!tinfo->simple_ancestors)
|
|
321
|
+
traverse_offset_bases(valptr, tinfo, self, deregister_instance_impl);
|
|
322
|
+
return ret;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/// Instance creation function for all pybind11 types. It allocates the internal instance layout for
|
|
326
|
+
/// holding C++ objects and holders. Allocation is done lazily (the first time the instance is cast
|
|
327
|
+
/// to a reference or pointer), and initialization is done by an `__init__` function.
|
|
328
|
+
inline PyObject *make_new_instance(PyTypeObject *type) {
|
|
329
|
+
#if defined(PYPY_VERSION)
|
|
330
|
+
// PyPy gets tp_basicsize wrong (issue 2482) under multiple inheritance when the first inherited
|
|
331
|
+
// object is a plain Python type (i.e. not derived from an extension type). Fix it.
|
|
332
|
+
ssize_t instance_size = static_cast<ssize_t>(sizeof(instance));
|
|
333
|
+
if (type->tp_basicsize < instance_size) {
|
|
334
|
+
type->tp_basicsize = instance_size;
|
|
335
|
+
}
|
|
336
|
+
#endif
|
|
337
|
+
PyObject *self = type->tp_alloc(type, 0);
|
|
338
|
+
auto inst = reinterpret_cast<instance *>(self);
|
|
339
|
+
// Allocate the value/holder internals:
|
|
340
|
+
inst->allocate_layout();
|
|
341
|
+
|
|
342
|
+
return self;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/// Instance creation function for all pybind11 types. It only allocates space for the
|
|
346
|
+
/// C++ object, but doesn't call the constructor -- an `__init__` function must do that.
|
|
347
|
+
extern "C" inline PyObject *pybind11_object_new(PyTypeObject *type, PyObject *, PyObject *) {
|
|
348
|
+
return make_new_instance(type);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/// An `__init__` function constructs the C++ object. Users should provide at least one
|
|
352
|
+
/// of these using `py::init` or directly with `.def(__init__, ...)`. Otherwise, the
|
|
353
|
+
/// following default function will be used which simply throws an exception.
|
|
354
|
+
extern "C" inline int pybind11_object_init(PyObject *self, PyObject *, PyObject *) {
|
|
355
|
+
PyTypeObject *type = Py_TYPE(self);
|
|
356
|
+
std::string msg = get_fully_qualified_tp_name(type) + ": No constructor defined!";
|
|
357
|
+
PyErr_SetString(PyExc_TypeError, msg.c_str());
|
|
358
|
+
return -1;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
inline void add_patient(PyObject *nurse, PyObject *patient) {
|
|
362
|
+
auto &internals = get_internals();
|
|
363
|
+
auto instance = reinterpret_cast<detail::instance *>(nurse);
|
|
364
|
+
instance->has_patients = true;
|
|
365
|
+
Py_INCREF(patient);
|
|
366
|
+
internals.patients[nurse].push_back(patient);
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
inline void clear_patients(PyObject *self) {
|
|
370
|
+
auto instance = reinterpret_cast<detail::instance *>(self);
|
|
371
|
+
auto &internals = get_internals();
|
|
372
|
+
auto pos = internals.patients.find(self);
|
|
373
|
+
assert(pos != internals.patients.end());
|
|
374
|
+
// Clearing the patients can cause more Python code to run, which
|
|
375
|
+
// can invalidate the iterator. Extract the vector of patients
|
|
376
|
+
// from the unordered_map first.
|
|
377
|
+
auto patients = std::move(pos->second);
|
|
378
|
+
internals.patients.erase(pos);
|
|
379
|
+
instance->has_patients = false;
|
|
380
|
+
for (PyObject *&patient : patients)
|
|
381
|
+
Py_CLEAR(patient);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/// Clears all internal data from the instance and removes it from registered instances in
|
|
385
|
+
/// preparation for deallocation.
|
|
386
|
+
inline void clear_instance(PyObject *self) {
|
|
387
|
+
auto instance = reinterpret_cast<detail::instance *>(self);
|
|
388
|
+
|
|
389
|
+
// Deallocate any values/holders, if present:
|
|
390
|
+
for (auto &v_h : values_and_holders(instance)) {
|
|
391
|
+
if (v_h) {
|
|
392
|
+
|
|
393
|
+
// We have to deregister before we call dealloc because, for virtual MI types, we still
|
|
394
|
+
// need to be able to get the parent pointers.
|
|
395
|
+
if (v_h.instance_registered() && !deregister_instance(instance, v_h.value_ptr(), v_h.type))
|
|
396
|
+
pybind11_fail("pybind11_object_dealloc(): Tried to deallocate unregistered instance!");
|
|
397
|
+
|
|
398
|
+
if (instance->owned || v_h.holder_constructed())
|
|
399
|
+
v_h.type->dealloc(v_h);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
// Deallocate the value/holder layout internals:
|
|
403
|
+
instance->deallocate_layout();
|
|
404
|
+
|
|
405
|
+
if (instance->weakrefs)
|
|
406
|
+
PyObject_ClearWeakRefs(self);
|
|
407
|
+
|
|
408
|
+
PyObject **dict_ptr = _PyObject_GetDictPtr(self);
|
|
409
|
+
if (dict_ptr)
|
|
410
|
+
Py_CLEAR(*dict_ptr);
|
|
411
|
+
|
|
412
|
+
if (instance->has_patients)
|
|
413
|
+
clear_patients(self);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/// Instance destructor function for all pybind11 types. It calls `type_info.dealloc`
|
|
417
|
+
/// to destroy the C++ object itself, while the rest is Python bookkeeping.
|
|
418
|
+
extern "C" inline void pybind11_object_dealloc(PyObject *self) {
|
|
419
|
+
clear_instance(self);
|
|
420
|
+
|
|
421
|
+
auto type = Py_TYPE(self);
|
|
422
|
+
type->tp_free(self);
|
|
423
|
+
|
|
424
|
+
#if PY_VERSION_HEX < 0x03080000
|
|
425
|
+
// `type->tp_dealloc != pybind11_object_dealloc` means that we're being called
|
|
426
|
+
// as part of a derived type's dealloc, in which case we're not allowed to decref
|
|
427
|
+
// the type here. For cross-module compatibility, we shouldn't compare directly
|
|
428
|
+
// with `pybind11_object_dealloc`, but with the common one stashed in internals.
|
|
429
|
+
auto pybind11_object_type = (PyTypeObject *) get_internals().instance_base;
|
|
430
|
+
if (type->tp_dealloc == pybind11_object_type->tp_dealloc)
|
|
431
|
+
Py_DECREF(type);
|
|
432
|
+
#else
|
|
433
|
+
// This was not needed before Python 3.8 (Python issue 35810)
|
|
434
|
+
// https://github.com/pybind/pybind11/issues/1946
|
|
435
|
+
Py_DECREF(type);
|
|
436
|
+
#endif
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/** Create the type which can be used as a common base for all classes. This is
|
|
440
|
+
needed in order to satisfy Python's requirements for multiple inheritance.
|
|
441
|
+
Return value: New reference. */
|
|
442
|
+
inline PyObject *make_object_base_type(PyTypeObject *metaclass) {
|
|
443
|
+
constexpr auto *name = "pybind11_object";
|
|
444
|
+
auto name_obj = reinterpret_steal<object>(PYBIND11_FROM_STRING(name));
|
|
445
|
+
|
|
446
|
+
/* Danger zone: from now (and until PyType_Ready), make sure to
|
|
447
|
+
issue no Python C API calls which could potentially invoke the
|
|
448
|
+
garbage collector (the GC will call type_traverse(), which will in
|
|
449
|
+
turn find the newly constructed type in an invalid state) */
|
|
450
|
+
auto heap_type = (PyHeapTypeObject *) metaclass->tp_alloc(metaclass, 0);
|
|
451
|
+
if (!heap_type)
|
|
452
|
+
pybind11_fail("make_object_base_type(): error allocating type!");
|
|
453
|
+
|
|
454
|
+
heap_type->ht_name = name_obj.inc_ref().ptr();
|
|
455
|
+
#ifdef PYBIND11_BUILTIN_QUALNAME
|
|
456
|
+
heap_type->ht_qualname = name_obj.inc_ref().ptr();
|
|
457
|
+
#endif
|
|
458
|
+
|
|
459
|
+
auto type = &heap_type->ht_type;
|
|
460
|
+
type->tp_name = name;
|
|
461
|
+
type->tp_base = type_incref(&PyBaseObject_Type);
|
|
462
|
+
type->tp_basicsize = static_cast<ssize_t>(sizeof(instance));
|
|
463
|
+
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HEAPTYPE;
|
|
464
|
+
|
|
465
|
+
type->tp_new = pybind11_object_new;
|
|
466
|
+
type->tp_init = pybind11_object_init;
|
|
467
|
+
type->tp_dealloc = pybind11_object_dealloc;
|
|
468
|
+
|
|
469
|
+
/* Support weak references (needed for the keep_alive feature) */
|
|
470
|
+
type->tp_weaklistoffset = offsetof(instance, weakrefs);
|
|
471
|
+
|
|
472
|
+
if (PyType_Ready(type) < 0)
|
|
473
|
+
pybind11_fail("PyType_Ready failed in make_object_base_type():" + error_string());
|
|
474
|
+
|
|
475
|
+
setattr((PyObject *) type, "__module__", str("pybind11_builtins"));
|
|
476
|
+
PYBIND11_SET_OLDPY_QUALNAME(type, name_obj);
|
|
477
|
+
|
|
478
|
+
assert(!PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC));
|
|
479
|
+
return (PyObject *) heap_type;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/// dynamic_attr: Support for `d = instance.__dict__`.
|
|
483
|
+
extern "C" inline PyObject *pybind11_get_dict(PyObject *self, void *) {
|
|
484
|
+
PyObject *&dict = *_PyObject_GetDictPtr(self);
|
|
485
|
+
if (!dict)
|
|
486
|
+
dict = PyDict_New();
|
|
487
|
+
Py_XINCREF(dict);
|
|
488
|
+
return dict;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/// dynamic_attr: Support for `instance.__dict__ = dict()`.
|
|
492
|
+
extern "C" inline int pybind11_set_dict(PyObject *self, PyObject *new_dict, void *) {
|
|
493
|
+
if (!PyDict_Check(new_dict)) {
|
|
494
|
+
PyErr_Format(PyExc_TypeError, "__dict__ must be set to a dictionary, not a '%.200s'",
|
|
495
|
+
get_fully_qualified_tp_name(Py_TYPE(new_dict)).c_str());
|
|
496
|
+
return -1;
|
|
497
|
+
}
|
|
498
|
+
PyObject *&dict = *_PyObject_GetDictPtr(self);
|
|
499
|
+
Py_INCREF(new_dict);
|
|
500
|
+
Py_CLEAR(dict);
|
|
501
|
+
dict = new_dict;
|
|
502
|
+
return 0;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/// dynamic_attr: Allow the garbage collector to traverse the internal instance `__dict__`.
|
|
506
|
+
extern "C" inline int pybind11_traverse(PyObject *self, visitproc visit, void *arg) {
|
|
507
|
+
PyObject *&dict = *_PyObject_GetDictPtr(self);
|
|
508
|
+
Py_VISIT(dict);
|
|
509
|
+
return 0;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/// dynamic_attr: Allow the GC to clear the dictionary.
|
|
513
|
+
extern "C" inline int pybind11_clear(PyObject *self) {
|
|
514
|
+
PyObject *&dict = *_PyObject_GetDictPtr(self);
|
|
515
|
+
Py_CLEAR(dict);
|
|
516
|
+
return 0;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
/// Give instances of this type a `__dict__` and opt into garbage collection.
|
|
520
|
+
inline void enable_dynamic_attributes(PyHeapTypeObject *heap_type) {
|
|
521
|
+
auto type = &heap_type->ht_type;
|
|
522
|
+
type->tp_flags |= Py_TPFLAGS_HAVE_GC;
|
|
523
|
+
type->tp_dictoffset = type->tp_basicsize; // place dict at the end
|
|
524
|
+
type->tp_basicsize += (ssize_t)sizeof(PyObject *); // and allocate enough space for it
|
|
525
|
+
type->tp_traverse = pybind11_traverse;
|
|
526
|
+
type->tp_clear = pybind11_clear;
|
|
527
|
+
|
|
528
|
+
static PyGetSetDef getset[] = {
|
|
529
|
+
{const_cast<char*>("__dict__"), pybind11_get_dict, pybind11_set_dict, nullptr, nullptr},
|
|
530
|
+
{nullptr, nullptr, nullptr, nullptr, nullptr}
|
|
531
|
+
};
|
|
532
|
+
type->tp_getset = getset;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/// buffer_protocol: Fill in the view as specified by flags.
|
|
536
|
+
extern "C" inline int pybind11_getbuffer(PyObject *obj, Py_buffer *view, int flags) {
|
|
537
|
+
// Look for a `get_buffer` implementation in this type's info or any bases (following MRO).
|
|
538
|
+
type_info *tinfo = nullptr;
|
|
539
|
+
for (auto type : reinterpret_borrow<tuple>(Py_TYPE(obj)->tp_mro)) {
|
|
540
|
+
tinfo = get_type_info((PyTypeObject *) type.ptr());
|
|
541
|
+
if (tinfo && tinfo->get_buffer)
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
if (view == nullptr || !tinfo || !tinfo->get_buffer) {
|
|
545
|
+
if (view)
|
|
546
|
+
view->obj = nullptr;
|
|
547
|
+
PyErr_SetString(PyExc_BufferError, "pybind11_getbuffer(): Internal error");
|
|
548
|
+
return -1;
|
|
549
|
+
}
|
|
550
|
+
std::memset(view, 0, sizeof(Py_buffer));
|
|
551
|
+
buffer_info *info = tinfo->get_buffer(obj, tinfo->get_buffer_data);
|
|
552
|
+
if ((flags & PyBUF_WRITABLE) == PyBUF_WRITABLE && info->readonly) {
|
|
553
|
+
delete info;
|
|
554
|
+
// view->obj = nullptr; // Was just memset to 0, so not necessary
|
|
555
|
+
PyErr_SetString(PyExc_BufferError, "Writable buffer requested for readonly storage");
|
|
556
|
+
return -1;
|
|
557
|
+
}
|
|
558
|
+
view->obj = obj;
|
|
559
|
+
view->ndim = 1;
|
|
560
|
+
view->internal = info;
|
|
561
|
+
view->buf = info->ptr;
|
|
562
|
+
view->itemsize = info->itemsize;
|
|
563
|
+
view->len = view->itemsize;
|
|
564
|
+
for (auto s : info->shape)
|
|
565
|
+
view->len *= s;
|
|
566
|
+
view->readonly = static_cast<int>(info->readonly);
|
|
567
|
+
if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT)
|
|
568
|
+
view->format = const_cast<char *>(info->format.c_str());
|
|
569
|
+
if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) {
|
|
570
|
+
view->ndim = (int) info->ndim;
|
|
571
|
+
view->strides = &info->strides[0];
|
|
572
|
+
view->shape = &info->shape[0];
|
|
573
|
+
}
|
|
574
|
+
Py_INCREF(view->obj);
|
|
575
|
+
return 0;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/// buffer_protocol: Release the resources of the buffer.
|
|
579
|
+
extern "C" inline void pybind11_releasebuffer(PyObject *, Py_buffer *view) {
|
|
580
|
+
delete (buffer_info *) view->internal;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/// Give this type a buffer interface.
|
|
584
|
+
inline void enable_buffer_protocol(PyHeapTypeObject *heap_type) {
|
|
585
|
+
heap_type->ht_type.tp_as_buffer = &heap_type->as_buffer;
|
|
586
|
+
#if PY_MAJOR_VERSION < 3
|
|
587
|
+
heap_type->ht_type.tp_flags |= Py_TPFLAGS_HAVE_NEWBUFFER;
|
|
588
|
+
#endif
|
|
589
|
+
|
|
590
|
+
heap_type->as_buffer.bf_getbuffer = pybind11_getbuffer;
|
|
591
|
+
heap_type->as_buffer.bf_releasebuffer = pybind11_releasebuffer;
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/** Create a brand new Python type according to the `type_record` specification.
|
|
595
|
+
Return value: New reference. */
|
|
596
|
+
inline PyObject* make_new_python_type(const type_record &rec) {
|
|
597
|
+
auto name = reinterpret_steal<object>(PYBIND11_FROM_STRING(rec.name));
|
|
598
|
+
|
|
599
|
+
auto qualname = name;
|
|
600
|
+
if (rec.scope && !PyModule_Check(rec.scope.ptr()) && hasattr(rec.scope, "__qualname__")) {
|
|
601
|
+
#if PY_MAJOR_VERSION >= 3
|
|
602
|
+
qualname = reinterpret_steal<object>(
|
|
603
|
+
PyUnicode_FromFormat("%U.%U", rec.scope.attr("__qualname__").ptr(), name.ptr()));
|
|
604
|
+
#else
|
|
605
|
+
qualname = str(rec.scope.attr("__qualname__").cast<std::string>() + "." + rec.name);
|
|
606
|
+
#endif
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
object module_;
|
|
610
|
+
if (rec.scope) {
|
|
611
|
+
if (hasattr(rec.scope, "__module__"))
|
|
612
|
+
module_ = rec.scope.attr("__module__");
|
|
613
|
+
else if (hasattr(rec.scope, "__name__"))
|
|
614
|
+
module_ = rec.scope.attr("__name__");
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
auto full_name = c_str(
|
|
618
|
+
#if !defined(PYPY_VERSION)
|
|
619
|
+
module_ ? str(module_).cast<std::string>() + "." + rec.name :
|
|
620
|
+
#endif
|
|
621
|
+
rec.name);
|
|
622
|
+
|
|
623
|
+
char *tp_doc = nullptr;
|
|
624
|
+
if (rec.doc && options::show_user_defined_docstrings()) {
|
|
625
|
+
/* Allocate memory for docstring (using PyObject_MALLOC, since
|
|
626
|
+
Python will free this later on) */
|
|
627
|
+
size_t size = strlen(rec.doc) + 1;
|
|
628
|
+
tp_doc = (char *) PyObject_MALLOC(size);
|
|
629
|
+
memcpy((void *) tp_doc, rec.doc, size);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
auto &internals = get_internals();
|
|
633
|
+
auto bases = tuple(rec.bases);
|
|
634
|
+
auto base = (bases.empty()) ? internals.instance_base
|
|
635
|
+
: bases[0].ptr();
|
|
636
|
+
|
|
637
|
+
/* Danger zone: from now (and until PyType_Ready), make sure to
|
|
638
|
+
issue no Python C API calls which could potentially invoke the
|
|
639
|
+
garbage collector (the GC will call type_traverse(), which will in
|
|
640
|
+
turn find the newly constructed type in an invalid state) */
|
|
641
|
+
auto metaclass = rec.metaclass.ptr() ? (PyTypeObject *) rec.metaclass.ptr()
|
|
642
|
+
: internals.default_metaclass;
|
|
643
|
+
|
|
644
|
+
auto heap_type = (PyHeapTypeObject *) metaclass->tp_alloc(metaclass, 0);
|
|
645
|
+
if (!heap_type)
|
|
646
|
+
pybind11_fail(std::string(rec.name) + ": Unable to create type object!");
|
|
647
|
+
|
|
648
|
+
heap_type->ht_name = name.release().ptr();
|
|
649
|
+
#ifdef PYBIND11_BUILTIN_QUALNAME
|
|
650
|
+
heap_type->ht_qualname = qualname.inc_ref().ptr();
|
|
651
|
+
#endif
|
|
652
|
+
|
|
653
|
+
auto type = &heap_type->ht_type;
|
|
654
|
+
type->tp_name = full_name;
|
|
655
|
+
type->tp_doc = tp_doc;
|
|
656
|
+
type->tp_base = type_incref((PyTypeObject *)base);
|
|
657
|
+
type->tp_basicsize = static_cast<ssize_t>(sizeof(instance));
|
|
658
|
+
if (!bases.empty())
|
|
659
|
+
type->tp_bases = bases.release().ptr();
|
|
660
|
+
|
|
661
|
+
/* Don't inherit base __init__ */
|
|
662
|
+
type->tp_init = pybind11_object_init;
|
|
663
|
+
|
|
664
|
+
/* Supported protocols */
|
|
665
|
+
type->tp_as_number = &heap_type->as_number;
|
|
666
|
+
type->tp_as_sequence = &heap_type->as_sequence;
|
|
667
|
+
type->tp_as_mapping = &heap_type->as_mapping;
|
|
668
|
+
#if PY_VERSION_HEX >= 0x03050000
|
|
669
|
+
type->tp_as_async = &heap_type->as_async;
|
|
670
|
+
#endif
|
|
671
|
+
|
|
672
|
+
/* Flags */
|
|
673
|
+
type->tp_flags |= Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HEAPTYPE;
|
|
674
|
+
#if PY_MAJOR_VERSION < 3
|
|
675
|
+
type->tp_flags |= Py_TPFLAGS_CHECKTYPES;
|
|
676
|
+
#endif
|
|
677
|
+
if (!rec.is_final)
|
|
678
|
+
type->tp_flags |= Py_TPFLAGS_BASETYPE;
|
|
679
|
+
|
|
680
|
+
if (rec.dynamic_attr)
|
|
681
|
+
enable_dynamic_attributes(heap_type);
|
|
682
|
+
|
|
683
|
+
if (rec.buffer_protocol)
|
|
684
|
+
enable_buffer_protocol(heap_type);
|
|
685
|
+
|
|
686
|
+
if (rec.custom_type_setup_callback)
|
|
687
|
+
rec.custom_type_setup_callback(heap_type);
|
|
688
|
+
|
|
689
|
+
if (PyType_Ready(type) < 0)
|
|
690
|
+
pybind11_fail(std::string(rec.name) + ": PyType_Ready failed (" + error_string() + ")!");
|
|
691
|
+
|
|
692
|
+
assert(!rec.dynamic_attr || PyType_HasFeature(type, Py_TPFLAGS_HAVE_GC));
|
|
693
|
+
|
|
694
|
+
/* Register type with the parent scope */
|
|
695
|
+
if (rec.scope)
|
|
696
|
+
setattr(rec.scope, rec.name, (PyObject *) type);
|
|
697
|
+
else
|
|
698
|
+
Py_INCREF(type); // Keep it alive forever (reference leak)
|
|
699
|
+
|
|
700
|
+
if (module_) // Needed by pydoc
|
|
701
|
+
setattr((PyObject *) type, "__module__", module_);
|
|
702
|
+
|
|
703
|
+
PYBIND11_SET_OLDPY_QUALNAME(type, qualname);
|
|
704
|
+
|
|
705
|
+
return (PyObject *) type;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
PYBIND11_NAMESPACE_END(detail)
|
|
709
|
+
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
|