xcoll 0.5.12__py3-none-any.whl → 0.6.1__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 +5 -18
- xcoll/__init__.py.orig +26 -0
- xcoll/beam_elements/__init__.py +1 -0
- xcoll/beam_elements/absorber.py +12 -2
- xcoll/beam_elements/base.py +162 -62
- xcoll/beam_elements/blowup.py +1 -0
- xcoll/beam_elements/elements_src/black_absorber.h +57 -58
- xcoll/beam_elements/elements_src/black_crystal.h +49 -50
- xcoll/beam_elements/elements_src/everest_block.h +21 -11
- xcoll/beam_elements/elements_src/everest_collimator.h +100 -91
- xcoll/beam_elements/elements_src/everest_crystal.h +145 -140
- xcoll/beam_elements/elements_src/transparent_collimator.h +126 -0
- xcoll/beam_elements/elements_src/transparent_crystal.h +118 -0
- xcoll/beam_elements/everest.py +16 -5
- xcoll/beam_elements/monitor.py +1 -0
- xcoll/beam_elements/transparent.py +83 -0
- xcoll/colldb.py +15 -6
- xcoll/general.py +1 -1
- xcoll/general.py.orig +20 -0
- xcoll/headers/particle_states.py +51 -0
- xcoll/initial_distribution.py +121 -91
- xcoll/initial_distribution.py.orig +256 -0
- xcoll/interaction_record/interaction_record.py +2 -1
- xcoll/interaction_record/interaction_types.py +2 -2
- xcoll/line_tools.py +163 -73
- xcoll/lossmap.py +519 -127
- xcoll/plot.py +109 -0
- xcoll/rf_sweep.py +6 -0
- xcoll/scattering_routines/engine.py +414 -217
- xcoll/scattering_routines/environment.py +297 -0
- xcoll/scattering_routines/everest/amorphous.h +95 -71
- xcoll/scattering_routines/everest/{channeling.h → channelling.h} +121 -112
- xcoll/scattering_routines/everest/constants.h +1 -1
- xcoll/scattering_routines/everest/crystal_parameters.h +9 -9
- xcoll/scattering_routines/everest/everest.h +8 -3
- xcoll/scattering_routines/everest/everest.py +2 -1
- xcoll/scattering_routines/everest/ionisation_loss.h +141 -0
- xcoll/scattering_routines/everest/jaw.h +19 -24
- xcoll/scattering_routines/everest/materials.py +2 -0
- xcoll/scattering_routines/everest/multiple_coulomb_scattering.h +2 -2
- xcoll/scattering_routines/everest/nuclear_interaction.h +35 -19
- xcoll/scattering_routines/everest/properties.h +3 -72
- xcoll/xaux.py +65 -109
- {xcoll-0.5.12.dist-info → xcoll-0.6.1.dist-info}/METADATA +5 -5
- xcoll-0.6.1.dist-info/RECORD +138 -0
- xcoll/_manager.py +0 -22
- xcoll/headers/particle_states.h +0 -25
- xcoll/install.py +0 -35
- xcoll/scattering_routines/geant4/collimasim/.git +0 -1
- xcoll/scattering_routines/geant4/collimasim/.gitignore +0 -12
- xcoll/scattering_routines/geant4/collimasim/.gitmodules +0 -3
- xcoll/scattering_routines/geant4/collimasim/CMakeLists.txt +0 -26
- xcoll/scattering_routines/geant4/collimasim/README.md +0 -21
- xcoll/scattering_routines/geant4/collimasim/docs/Makefile +0 -20
- xcoll/scattering_routines/geant4/collimasim/docs/make.bat +0 -35
- xcoll/scattering_routines/geant4/collimasim/docs/source/collimasim.rst +0 -10
- xcoll/scattering_routines/geant4/collimasim/docs/source/conf.py +0 -59
- xcoll/scattering_routines/geant4/collimasim/docs/source/index.rst +0 -26
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.appveyor.yml +0 -37
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-format +0 -19
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.clang-tidy +0 -65
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.cmake-format.yaml +0 -73
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.git +0 -1
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CODEOWNERS +0 -9
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/CONTRIBUTING.md +0 -386
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/bug-report.yml +0 -45
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/ISSUE_TEMPLATE/config.yml +0 -8
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/dependabot.yml +0 -16
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler.yml +0 -8
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/labeler_merged.yml +0 -3
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/pull_request_template.md +0 -19
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/ci.yml +0 -969
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/configure.yml +0 -84
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/format.yml +0 -48
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/labeler.yml +0 -16
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.github/workflows/pip.yml +0 -103
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.gitignore +0 -45
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.pre-commit-config.yaml +0 -151
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/.readthedocs.yml +0 -3
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/CMakeLists.txt +0 -297
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/LICENSE +0 -29
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/MANIFEST.in +0 -6
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/README.rst +0 -180
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Doxyfile +0 -23
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/Makefile +0 -192
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/_static/theme_overrides.css +0 -11
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/chrono.rst +0 -81
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/custom.rst +0 -93
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/eigen.rst +0 -310
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/functional.rst +0 -109
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/index.rst +0 -43
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/overview.rst +0 -171
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/stl.rst +0 -251
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/cast/strings.rst +0 -305
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/classes.rst +0 -1297
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/embedding.rst +0 -262
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/exceptions.rst +0 -396
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/functions.rst +0 -568
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/misc.rst +0 -337
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/index.rst +0 -13
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/numpy.rst +0 -463
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/object.rst +0 -286
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/pycpp/utilities.rst +0 -155
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/advanced/smart_ptrs.rst +0 -174
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/basics.rst +0 -308
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.py +0 -91
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/benchmark.rst +0 -95
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/changelog.rst +0 -2050
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/classes.rst +0 -542
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/cmake/index.rst +0 -8
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/compiling.rst +0 -648
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/conf.py +0 -381
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/faq.rst +0 -343
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/index.rst +0 -48
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/installing.rst +0 -105
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/limitations.rst +0 -72
- 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 +0 -427
- 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 +0 -427
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/reference.rst +0 -130
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/release.rst +0 -96
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/requirements.txt +0 -8
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/docs/upgrade.rst +0 -548
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/attr.h +0 -605
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/buffer_info.h +0 -144
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/cast.h +0 -1432
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/chrono.h +0 -213
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/common.h +0 -2
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/complex.h +0 -65
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/class.h +0 -709
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/common.h +0 -1021
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/descr.h +0 -104
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/init.h +0 -346
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/internals.h +0 -467
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h +0 -978
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/typeid.h +0 -55
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eigen.h +0 -606
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/embed.h +0 -284
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/eval.h +0 -163
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/functional.h +0 -121
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/gil.h +0 -193
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/iostream.h +0 -275
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/numpy.h +0 -1741
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/operators.h +0 -163
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/options.h +0 -65
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pybind11.h +0 -2497
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/pytypes.h +0 -1879
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl/filesystem.h +0 -103
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl.h +0 -375
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/stl_bind.h +0 -747
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/noxfile.py +0 -88
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__init__.py +0 -11
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/__main__.py +0 -52
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.py +0 -12
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/_version.pyi +0 -6
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/commands.py +0 -21
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/py.typed +0 -0
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.py +0 -482
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pybind11/setup_helpers.pyi +0 -63
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/pyproject.toml +0 -41
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.cfg +0 -56
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/setup.py +0 -155
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/CMakeLists.txt +0 -503
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/conftest.py +0 -208
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/constructor_stats.h +0 -275
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/cross_module_gil_utils.cpp +0 -73
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/env.py +0 -33
- 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 +0 -279
- 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 +0 -143
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/local_bindings.h +0 -85
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/object.h +0 -179
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_cross_module_tests.cpp +0 -151
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.cpp +0 -91
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pybind11_tests.h +0 -85
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/pytest.ini +0 -19
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/requirements.txt +0 -12
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.cpp +0 -26
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_async.py +0 -25
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.cpp +0 -216
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_buffers.py +0 -163
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.cpp +0 -286
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_builtin_casters.py +0 -536
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.cpp +0 -107
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_call_policies.py +0 -248
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.cpp +0 -227
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_callbacks.py +0 -202
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.cpp +0 -84
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_chrono.py +0 -210
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.cpp +0 -550
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_class.py +0 -473
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/CMakeLists.txt +0 -84
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/embed.cpp +0 -21
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_embed/CMakeLists.txt +0 -28
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_function/CMakeLists.txt +0 -39
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/installed_target/CMakeLists.txt +0 -46
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/main.cpp +0 -6
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_embed/CMakeLists.txt +0 -41
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_function/CMakeLists.txt +0 -35
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/subdirectory_target/CMakeLists.txt +0 -41
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_cmake_build/test.py +0 -10
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.cpp +0 -165
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_constants_and_functions.py +0 -53
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.cpp +0 -238
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_copy_move.py +0 -126
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.cpp +0 -141
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_casters.py +0 -117
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.cpp +0 -41
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_custom_type_setup.py +0 -50
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.cpp +0 -69
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_docstring_options.py +0 -42
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.cpp +0 -348
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eigen.py +0 -771
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/CMakeLists.txt +0 -47
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/catch.cpp +0 -22
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/external_module.cpp +0 -23
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.cpp +0 -326
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_embed/test_interpreter.py +0 -15
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.cpp +0 -148
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_enum.py +0 -272
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.cpp +0 -119
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval.py +0 -51
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_eval_call.py +0 -5
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.cpp +0 -285
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.h +0 -12
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_exceptions.py +0 -265
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.cpp +0 -397
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_factory_constructors.py +0 -520
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.cpp +0 -49
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_gil_scoped.py +0 -94
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.cpp +0 -125
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_iostream.py +0 -331
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.cpp +0 -153
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_kwargs_and_defaults.py +0 -284
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.cpp +0 -107
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_local_bindings.py +0 -257
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.cpp +0 -412
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_methods_and_attributes.py +0 -517
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.cpp +0 -102
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_modules.py +0 -92
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.cpp +0 -233
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_multiple_inheritance.py +0 -360
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.cpp +0 -472
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_array.py +0 -593
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.cpp +0 -524
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_dtypes.py +0 -441
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.cpp +0 -103
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_numpy_vectorize.py +0 -267
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.cpp +0 -73
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_opaque_types.py +0 -59
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.cpp +0 -235
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_operator_overloading.py +0 -146
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.cpp +0 -189
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pickling.py +0 -82
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.cpp +0 -560
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_pytypes.py +0 -651
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.cpp +0 -500
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_sequences_and_iterators.py +0 -253
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.cpp +0 -452
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_smart_ptr.py +0 -318
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.cpp +0 -342
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl.py +0 -291
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.cpp +0 -131
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_stl_binders.py +0 -318
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.cpp +0 -144
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_tagbased_polymorphic.py +0 -29
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.cpp +0 -66
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_thread.py +0 -44
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.cpp +0 -22
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_union.py +0 -9
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.cpp +0 -510
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/test_virtual_functions.py +0 -408
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-numpy-scipy.supp +0 -140
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tests/valgrind-python.supp +0 -117
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindCatch.cmake +0 -70
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindEigen3.cmake +0 -86
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/FindPythonLibsNew.cmake +0 -257
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/check-style.sh +0 -44
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/cmake_uninstall.cmake.in +0 -23
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/libsize.py +0 -39
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/make_changelog.py +0 -64
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Common.cmake +0 -402
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Config.cmake.in +0 -233
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11NewTools.cmake +0 -276
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pybind11Tools.cmake +0 -214
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/pyproject.toml +0 -3
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_global.py.in +0 -65
- xcoll/scattering_routines/geant4/collimasim/lib/pybind11/tools/setup_main.py.in +0 -41
- xcoll/scattering_routines/geant4/collimasim/pyproject.toml +0 -8
- xcoll/scattering_routines/geant4/collimasim/setup.py +0 -144
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.cpp +0 -403
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSPyATInterface.hh +0 -100
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.cpp +0 -763
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/BDSXtrackInterface.hh +0 -118
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/__init__.py +0 -8
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/bindings.cpp +0 -63
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/pyCollimatorPass.py +0 -142
- xcoll/scattering_routines/geant4/collimasim/src/collimasim/xtrack_collimator.py +0 -556
- xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/PKG-INFO +0 -6
- xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/SOURCES.txt +0 -24
- xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/dependency_links.txt +0 -1
- xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/not-zip-safe +0 -1
- xcoll/scattering_routines/geant4/collimasim/src/collimasim.egg-info/top_level.txt +0 -1
- xcoll/scattering_routines/geant4/collimasim/tests/README.md +0 -25
- xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_forions.dat +0 -25
- xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_new_example.dat +0 -18
- xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_old_example.dat +0 -68
- xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_testing.dat +0 -15
- xcoll/scattering_routines/geant4/collimasim/tests/resources/CollDB_yaml_example.yaml +0 -110
- xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps.dat +0 -7
- xcoll/scattering_routines/geant4/collimasim/tests/resources/collgaps_pyat_test.dat +0 -3
- xcoll/scattering_routines/geant4/collimasim/tests/resources/collonly_twiss_file_example.tfs +0 -54
- xcoll/scattering_routines/geant4/collimasim/tests/resources/settings.gmad +0 -3
- xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_black_absorber.gmad +0 -3
- xcoll/scattering_routines/geant4/collimasim/tests/resources/settings_ions.gmad +0 -5
- xcoll/scattering_routines/geant4/collimasim/tests/resources/twiss_file_testing.tfs +0 -51
- xcoll/scattering_routines/geant4/collimasim/tests/test_pyat.py +0 -65
- xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_passmethod.py +0 -59
- xcoll/scattering_routines/geant4/collimasim/tests/test_pyat_tracking.py +0 -102
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack.py +0 -75
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_angle.py +0 -74
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_colldb_load.py +0 -84
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction.py +0 -159
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_interaction_ion.py +0 -99
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_ions.py +0 -78
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_lost_energy.py +0 -88
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tilt.py +0 -80
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking.py +0 -97
- xcoll/scattering_routines/geant4/collimasim/tests/test_xtrack_tracking_ions.py +0 -96
- xcoll-0.5.12.dist-info/RECORD +0 -415
- {xcoll-0.5.12.dist-info → xcoll-0.6.1.dist-info}/LICENSE +0 -0
- {xcoll-0.5.12.dist-info → xcoll-0.6.1.dist-info}/NOTICE +0 -0
- {xcoll-0.5.12.dist-info → xcoll-0.6.1.dist-info}/WHEEL +0 -0
xcoll/scattering_routines/geant4/collimasim/lib/pybind11/include/pybind11/detail/type_caster_base.h
DELETED
|
@@ -1,978 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
pybind11/detail/type_caster_base.h (originally first part of pybind11/cast.h)
|
|
3
|
-
|
|
4
|
-
Copyright (c) 2016 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 "../pytypes.h"
|
|
13
|
-
#include "common.h"
|
|
14
|
-
#include "descr.h"
|
|
15
|
-
#include "internals.h"
|
|
16
|
-
#include "typeid.h"
|
|
17
|
-
#include <cstdint>
|
|
18
|
-
#include <iterator>
|
|
19
|
-
#include <new>
|
|
20
|
-
#include <string>
|
|
21
|
-
#include <type_traits>
|
|
22
|
-
#include <typeindex>
|
|
23
|
-
#include <typeinfo>
|
|
24
|
-
#include <unordered_map>
|
|
25
|
-
#include <utility>
|
|
26
|
-
#include <vector>
|
|
27
|
-
|
|
28
|
-
PYBIND11_NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
|
|
29
|
-
PYBIND11_NAMESPACE_BEGIN(detail)
|
|
30
|
-
|
|
31
|
-
/// A life support system for temporary objects created by `type_caster::load()`.
|
|
32
|
-
/// Adding a patient will keep it alive up until the enclosing function returns.
|
|
33
|
-
class loader_life_support {
|
|
34
|
-
private:
|
|
35
|
-
loader_life_support* parent = nullptr;
|
|
36
|
-
std::unordered_set<PyObject *> keep_alive;
|
|
37
|
-
|
|
38
|
-
#if defined(WITH_THREAD)
|
|
39
|
-
// Store stack pointer in thread-local storage.
|
|
40
|
-
static PYBIND11_TLS_KEY_REF get_stack_tls_key() {
|
|
41
|
-
# if PYBIND11_INTERNALS_VERSION == 4
|
|
42
|
-
return get_local_internals().loader_life_support_tls_key;
|
|
43
|
-
# else
|
|
44
|
-
return get_internals().loader_life_support_tls_key;
|
|
45
|
-
# endif
|
|
46
|
-
}
|
|
47
|
-
static loader_life_support *get_stack_top() {
|
|
48
|
-
return static_cast<loader_life_support *>(PYBIND11_TLS_GET_VALUE(get_stack_tls_key()));
|
|
49
|
-
}
|
|
50
|
-
static void set_stack_top(loader_life_support *value) {
|
|
51
|
-
PYBIND11_TLS_REPLACE_VALUE(get_stack_tls_key(), value);
|
|
52
|
-
}
|
|
53
|
-
#else
|
|
54
|
-
// Use single global variable for stack.
|
|
55
|
-
static loader_life_support **get_stack_pp() {
|
|
56
|
-
static loader_life_support *global_stack = nullptr;
|
|
57
|
-
return global_stack;
|
|
58
|
-
}
|
|
59
|
-
static loader_life_support *get_stack_top() { return *get_stack_pp(); }
|
|
60
|
-
static void set_stack_top(loader_life_support *value) { *get_stack_pp() = value; }
|
|
61
|
-
#endif
|
|
62
|
-
|
|
63
|
-
public:
|
|
64
|
-
/// A new patient frame is created when a function is entered
|
|
65
|
-
loader_life_support() {
|
|
66
|
-
parent = get_stack_top();
|
|
67
|
-
set_stack_top(this);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/// ... and destroyed after it returns
|
|
71
|
-
~loader_life_support() {
|
|
72
|
-
if (get_stack_top() != this)
|
|
73
|
-
pybind11_fail("loader_life_support: internal error");
|
|
74
|
-
set_stack_top(parent);
|
|
75
|
-
for (auto* item : keep_alive)
|
|
76
|
-
Py_DECREF(item);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/// This can only be used inside a pybind11-bound function, either by `argument_loader`
|
|
80
|
-
/// at argument preparation time or by `py::cast()` at execution time.
|
|
81
|
-
PYBIND11_NOINLINE static void add_patient(handle h) {
|
|
82
|
-
loader_life_support *frame = get_stack_top();
|
|
83
|
-
if (!frame) {
|
|
84
|
-
// NOTE: It would be nice to include the stack frames here, as this indicates
|
|
85
|
-
// use of pybind11::cast<> outside the normal call framework, finding such
|
|
86
|
-
// a location is challenging. Developers could consider printing out
|
|
87
|
-
// stack frame addresses here using something like __builtin_frame_address(0)
|
|
88
|
-
throw cast_error("When called outside a bound function, py::cast() cannot "
|
|
89
|
-
"do Python -> C++ conversions which require the creation "
|
|
90
|
-
"of temporary values");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (frame->keep_alive.insert(h.ptr()).second)
|
|
94
|
-
Py_INCREF(h.ptr());
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// Gets the cache entry for the given type, creating it if necessary. The return value is the pair
|
|
99
|
-
// returned by emplace, i.e. an iterator for the entry and a bool set to `true` if the entry was
|
|
100
|
-
// just created.
|
|
101
|
-
inline std::pair<decltype(internals::registered_types_py)::iterator, bool> all_type_info_get_cache(PyTypeObject *type);
|
|
102
|
-
|
|
103
|
-
// Populates a just-created cache entry.
|
|
104
|
-
PYBIND11_NOINLINE void all_type_info_populate(PyTypeObject *t, std::vector<type_info *> &bases) {
|
|
105
|
-
std::vector<PyTypeObject *> check;
|
|
106
|
-
for (handle parent : reinterpret_borrow<tuple>(t->tp_bases))
|
|
107
|
-
check.push_back((PyTypeObject *) parent.ptr());
|
|
108
|
-
|
|
109
|
-
auto const &type_dict = get_internals().registered_types_py;
|
|
110
|
-
for (size_t i = 0; i < check.size(); i++) {
|
|
111
|
-
auto type = check[i];
|
|
112
|
-
// Ignore Python2 old-style class super type:
|
|
113
|
-
if (!PyType_Check((PyObject *) type)) continue;
|
|
114
|
-
|
|
115
|
-
// Check `type` in the current set of registered python types:
|
|
116
|
-
auto it = type_dict.find(type);
|
|
117
|
-
if (it != type_dict.end()) {
|
|
118
|
-
// We found a cache entry for it, so it's either pybind-registered or has pre-computed
|
|
119
|
-
// pybind bases, but we have to make sure we haven't already seen the type(s) before: we
|
|
120
|
-
// want to follow Python/virtual C++ rules that there should only be one instance of a
|
|
121
|
-
// common base.
|
|
122
|
-
for (auto *tinfo : it->second) {
|
|
123
|
-
// NB: Could use a second set here, rather than doing a linear search, but since
|
|
124
|
-
// having a large number of immediate pybind11-registered types seems fairly
|
|
125
|
-
// unlikely, that probably isn't worthwhile.
|
|
126
|
-
bool found = false;
|
|
127
|
-
for (auto *known : bases) {
|
|
128
|
-
if (known == tinfo) { found = true; break; }
|
|
129
|
-
}
|
|
130
|
-
if (!found) bases.push_back(tinfo);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
else if (type->tp_bases) {
|
|
134
|
-
// It's some python type, so keep follow its bases classes to look for one or more
|
|
135
|
-
// registered types
|
|
136
|
-
if (i + 1 == check.size()) {
|
|
137
|
-
// When we're at the end, we can pop off the current element to avoid growing
|
|
138
|
-
// `check` when adding just one base (which is typical--i.e. when there is no
|
|
139
|
-
// multiple inheritance)
|
|
140
|
-
check.pop_back();
|
|
141
|
-
i--;
|
|
142
|
-
}
|
|
143
|
-
for (handle parent : reinterpret_borrow<tuple>(type->tp_bases))
|
|
144
|
-
check.push_back((PyTypeObject *) parent.ptr());
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Extracts vector of type_info pointers of pybind-registered roots of the given Python type. Will
|
|
151
|
-
* be just 1 pybind type for the Python type of a pybind-registered class, or for any Python-side
|
|
152
|
-
* derived class that uses single inheritance. Will contain as many types as required for a Python
|
|
153
|
-
* class that uses multiple inheritance to inherit (directly or indirectly) from multiple
|
|
154
|
-
* pybind-registered classes. Will be empty if neither the type nor any base classes are
|
|
155
|
-
* pybind-registered.
|
|
156
|
-
*
|
|
157
|
-
* The value is cached for the lifetime of the Python type.
|
|
158
|
-
*/
|
|
159
|
-
inline const std::vector<detail::type_info *> &all_type_info(PyTypeObject *type) {
|
|
160
|
-
auto ins = all_type_info_get_cache(type);
|
|
161
|
-
if (ins.second)
|
|
162
|
-
// New cache entry: populate it
|
|
163
|
-
all_type_info_populate(type, ins.first->second);
|
|
164
|
-
|
|
165
|
-
return ins.first->second;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Gets a single pybind11 type info for a python type. Returns nullptr if neither the type nor any
|
|
170
|
-
* ancestors are pybind11-registered. Throws an exception if there are multiple bases--use
|
|
171
|
-
* `all_type_info` instead if you want to support multiple bases.
|
|
172
|
-
*/
|
|
173
|
-
PYBIND11_NOINLINE detail::type_info* get_type_info(PyTypeObject *type) {
|
|
174
|
-
auto &bases = all_type_info(type);
|
|
175
|
-
if (bases.empty())
|
|
176
|
-
return nullptr;
|
|
177
|
-
if (bases.size() > 1)
|
|
178
|
-
pybind11_fail("pybind11::detail::get_type_info: type has multiple pybind11-registered bases");
|
|
179
|
-
return bases.front();
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
inline detail::type_info *get_local_type_info(const std::type_index &tp) {
|
|
183
|
-
auto &locals = get_local_internals().registered_types_cpp;
|
|
184
|
-
auto it = locals.find(tp);
|
|
185
|
-
if (it != locals.end())
|
|
186
|
-
return it->second;
|
|
187
|
-
return nullptr;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
inline detail::type_info *get_global_type_info(const std::type_index &tp) {
|
|
191
|
-
auto &types = get_internals().registered_types_cpp;
|
|
192
|
-
auto it = types.find(tp);
|
|
193
|
-
if (it != types.end())
|
|
194
|
-
return it->second;
|
|
195
|
-
return nullptr;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/// Return the type info for a given C++ type; on lookup failure can either throw or return nullptr.
|
|
199
|
-
PYBIND11_NOINLINE detail::type_info *get_type_info(const std::type_index &tp,
|
|
200
|
-
bool throw_if_missing = false) {
|
|
201
|
-
if (auto ltype = get_local_type_info(tp))
|
|
202
|
-
return ltype;
|
|
203
|
-
if (auto gtype = get_global_type_info(tp))
|
|
204
|
-
return gtype;
|
|
205
|
-
|
|
206
|
-
if (throw_if_missing) {
|
|
207
|
-
std::string tname = tp.name();
|
|
208
|
-
detail::clean_type_id(tname);
|
|
209
|
-
pybind11_fail("pybind11::detail::get_type_info: unable to find type info for \"" + tname + "\"");
|
|
210
|
-
}
|
|
211
|
-
return nullptr;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
PYBIND11_NOINLINE handle get_type_handle(const std::type_info &tp, bool throw_if_missing) {
|
|
215
|
-
detail::type_info *type_info = get_type_info(tp, throw_if_missing);
|
|
216
|
-
return handle(type_info ? ((PyObject *) type_info->type) : nullptr);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Searches the inheritance graph for a registered Python instance, using all_type_info().
|
|
220
|
-
PYBIND11_NOINLINE handle find_registered_python_instance(void *src,
|
|
221
|
-
const detail::type_info *tinfo) {
|
|
222
|
-
auto it_instances = get_internals().registered_instances.equal_range(src);
|
|
223
|
-
for (auto it_i = it_instances.first; it_i != it_instances.second; ++it_i) {
|
|
224
|
-
for (auto instance_type : detail::all_type_info(Py_TYPE(it_i->second))) {
|
|
225
|
-
if (instance_type && same_type(*instance_type->cpptype, *tinfo->cpptype))
|
|
226
|
-
return handle((PyObject *) it_i->second).inc_ref();
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
return handle();
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
struct value_and_holder {
|
|
233
|
-
instance *inst = nullptr;
|
|
234
|
-
size_t index = 0u;
|
|
235
|
-
const detail::type_info *type = nullptr;
|
|
236
|
-
void **vh = nullptr;
|
|
237
|
-
|
|
238
|
-
// Main constructor for a found value/holder:
|
|
239
|
-
value_and_holder(instance *i, const detail::type_info *type, size_t vpos, size_t index) :
|
|
240
|
-
inst{i}, index{index}, type{type},
|
|
241
|
-
vh{inst->simple_layout ? inst->simple_value_holder : &inst->nonsimple.values_and_holders[vpos]}
|
|
242
|
-
{}
|
|
243
|
-
|
|
244
|
-
// Default constructor (used to signal a value-and-holder not found by get_value_and_holder())
|
|
245
|
-
value_and_holder() = default;
|
|
246
|
-
|
|
247
|
-
// Used for past-the-end iterator
|
|
248
|
-
explicit value_and_holder(size_t index) : index{index} {}
|
|
249
|
-
|
|
250
|
-
template <typename V = void> V *&value_ptr() const {
|
|
251
|
-
return reinterpret_cast<V *&>(vh[0]);
|
|
252
|
-
}
|
|
253
|
-
// True if this `value_and_holder` has a non-null value pointer
|
|
254
|
-
explicit operator bool() const { return value_ptr() != nullptr; }
|
|
255
|
-
|
|
256
|
-
template <typename H> H &holder() const {
|
|
257
|
-
return reinterpret_cast<H &>(vh[1]);
|
|
258
|
-
}
|
|
259
|
-
bool holder_constructed() const {
|
|
260
|
-
return inst->simple_layout
|
|
261
|
-
? inst->simple_holder_constructed
|
|
262
|
-
: (inst->nonsimple.status[index] & instance::status_holder_constructed) != 0u;
|
|
263
|
-
}
|
|
264
|
-
// NOLINTNEXTLINE(readability-make-member-function-const)
|
|
265
|
-
void set_holder_constructed(bool v = true) {
|
|
266
|
-
if (inst->simple_layout)
|
|
267
|
-
inst->simple_holder_constructed = v;
|
|
268
|
-
else if (v)
|
|
269
|
-
inst->nonsimple.status[index] |= instance::status_holder_constructed;
|
|
270
|
-
else
|
|
271
|
-
inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_holder_constructed;
|
|
272
|
-
}
|
|
273
|
-
bool instance_registered() const {
|
|
274
|
-
return inst->simple_layout
|
|
275
|
-
? inst->simple_instance_registered
|
|
276
|
-
: ((inst->nonsimple.status[index] & instance::status_instance_registered) != 0);
|
|
277
|
-
}
|
|
278
|
-
// NOLINTNEXTLINE(readability-make-member-function-const)
|
|
279
|
-
void set_instance_registered(bool v = true) {
|
|
280
|
-
if (inst->simple_layout)
|
|
281
|
-
inst->simple_instance_registered = v;
|
|
282
|
-
else if (v)
|
|
283
|
-
inst->nonsimple.status[index] |= instance::status_instance_registered;
|
|
284
|
-
else
|
|
285
|
-
inst->nonsimple.status[index] &= (std::uint8_t) ~instance::status_instance_registered;
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
// Container for accessing and iterating over an instance's values/holders
|
|
290
|
-
struct values_and_holders {
|
|
291
|
-
private:
|
|
292
|
-
instance *inst;
|
|
293
|
-
using type_vec = std::vector<detail::type_info *>;
|
|
294
|
-
const type_vec &tinfo;
|
|
295
|
-
|
|
296
|
-
public:
|
|
297
|
-
explicit values_and_holders(instance *inst)
|
|
298
|
-
: inst{inst}, tinfo(all_type_info(Py_TYPE(inst))) {}
|
|
299
|
-
|
|
300
|
-
struct iterator {
|
|
301
|
-
private:
|
|
302
|
-
instance *inst = nullptr;
|
|
303
|
-
const type_vec *types = nullptr;
|
|
304
|
-
value_and_holder curr;
|
|
305
|
-
friend struct values_and_holders;
|
|
306
|
-
iterator(instance *inst, const type_vec *tinfo)
|
|
307
|
-
: inst{inst}, types{tinfo},
|
|
308
|
-
curr(inst /* instance */,
|
|
309
|
-
types->empty() ? nullptr : (*types)[0] /* type info */,
|
|
310
|
-
0, /* vpos: (non-simple types only): the first vptr comes first */
|
|
311
|
-
0 /* index */)
|
|
312
|
-
{}
|
|
313
|
-
// Past-the-end iterator:
|
|
314
|
-
explicit iterator(size_t end) : curr(end) {}
|
|
315
|
-
|
|
316
|
-
public:
|
|
317
|
-
bool operator==(const iterator &other) const { return curr.index == other.curr.index; }
|
|
318
|
-
bool operator!=(const iterator &other) const { return curr.index != other.curr.index; }
|
|
319
|
-
iterator &operator++() {
|
|
320
|
-
if (!inst->simple_layout)
|
|
321
|
-
curr.vh += 1 + (*types)[curr.index]->holder_size_in_ptrs;
|
|
322
|
-
++curr.index;
|
|
323
|
-
curr.type = curr.index < types->size() ? (*types)[curr.index] : nullptr;
|
|
324
|
-
return *this;
|
|
325
|
-
}
|
|
326
|
-
value_and_holder &operator*() { return curr; }
|
|
327
|
-
value_and_holder *operator->() { return &curr; }
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
iterator begin() { return iterator(inst, &tinfo); }
|
|
331
|
-
iterator end() { return iterator(tinfo.size()); }
|
|
332
|
-
|
|
333
|
-
iterator find(const type_info *find_type) {
|
|
334
|
-
auto it = begin(), endit = end();
|
|
335
|
-
while (it != endit && it->type != find_type) ++it;
|
|
336
|
-
return it;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
size_t size() { return tinfo.size(); }
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
/**
|
|
343
|
-
* Extracts C++ value and holder pointer references from an instance (which may contain multiple
|
|
344
|
-
* values/holders for python-side multiple inheritance) that match the given type. Throws an error
|
|
345
|
-
* if the given type (or ValueType, if omitted) is not a pybind11 base of the given instance. If
|
|
346
|
-
* `find_type` is omitted (or explicitly specified as nullptr) the first value/holder are returned,
|
|
347
|
-
* regardless of type (and the resulting .type will be nullptr).
|
|
348
|
-
*
|
|
349
|
-
* The returned object should be short-lived: in particular, it must not outlive the called-upon
|
|
350
|
-
* instance.
|
|
351
|
-
*/
|
|
352
|
-
PYBIND11_NOINLINE value_and_holder instance::get_value_and_holder(const type_info *find_type /*= nullptr default in common.h*/, bool throw_if_missing /*= true in common.h*/) {
|
|
353
|
-
// Optimize common case:
|
|
354
|
-
if (!find_type || Py_TYPE(this) == find_type->type)
|
|
355
|
-
return value_and_holder(this, find_type, 0, 0);
|
|
356
|
-
|
|
357
|
-
detail::values_and_holders vhs(this);
|
|
358
|
-
auto it = vhs.find(find_type);
|
|
359
|
-
if (it != vhs.end())
|
|
360
|
-
return *it;
|
|
361
|
-
|
|
362
|
-
if (!throw_if_missing)
|
|
363
|
-
return value_and_holder();
|
|
364
|
-
|
|
365
|
-
#if defined(NDEBUG)
|
|
366
|
-
pybind11_fail("pybind11::detail::instance::get_value_and_holder: "
|
|
367
|
-
"type is not a pybind11 base of the given instance "
|
|
368
|
-
"(compile in debug mode for type details)");
|
|
369
|
-
#else
|
|
370
|
-
pybind11_fail("pybind11::detail::instance::get_value_and_holder: `" +
|
|
371
|
-
get_fully_qualified_tp_name(find_type->type) + "' is not a pybind11 base of the given `" +
|
|
372
|
-
get_fully_qualified_tp_name(Py_TYPE(this)) + "' instance");
|
|
373
|
-
#endif
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
PYBIND11_NOINLINE void instance::allocate_layout() {
|
|
377
|
-
auto &tinfo = all_type_info(Py_TYPE(this));
|
|
378
|
-
|
|
379
|
-
const size_t n_types = tinfo.size();
|
|
380
|
-
|
|
381
|
-
if (n_types == 0)
|
|
382
|
-
pybind11_fail("instance allocation failed: new instance has no pybind11-registered base types");
|
|
383
|
-
|
|
384
|
-
simple_layout =
|
|
385
|
-
n_types == 1 && tinfo.front()->holder_size_in_ptrs <= instance_simple_holder_in_ptrs();
|
|
386
|
-
|
|
387
|
-
// Simple path: no python-side multiple inheritance, and a small-enough holder
|
|
388
|
-
if (simple_layout) {
|
|
389
|
-
simple_value_holder[0] = nullptr;
|
|
390
|
-
simple_holder_constructed = false;
|
|
391
|
-
simple_instance_registered = false;
|
|
392
|
-
}
|
|
393
|
-
else { // multiple base types or a too-large holder
|
|
394
|
-
// Allocate space to hold: [v1*][h1][v2*][h2]...[bb...] where [vN*] is a value pointer,
|
|
395
|
-
// [hN] is the (uninitialized) holder instance for value N, and [bb...] is a set of bool
|
|
396
|
-
// values that tracks whether each associated holder has been initialized. Each [block] is
|
|
397
|
-
// padded, if necessary, to an integer multiple of sizeof(void *).
|
|
398
|
-
size_t space = 0;
|
|
399
|
-
for (auto t : tinfo) {
|
|
400
|
-
space += 1; // value pointer
|
|
401
|
-
space += t->holder_size_in_ptrs; // holder instance
|
|
402
|
-
}
|
|
403
|
-
size_t flags_at = space;
|
|
404
|
-
space += size_in_ptrs(n_types); // status bytes (holder_constructed and instance_registered)
|
|
405
|
-
|
|
406
|
-
// Allocate space for flags, values, and holders, and initialize it to 0 (flags and values,
|
|
407
|
-
// in particular, need to be 0). Use Python's memory allocation functions: in Python 3.6
|
|
408
|
-
// they default to using pymalloc, which is designed to be efficient for small allocations
|
|
409
|
-
// like the one we're doing here; in earlier versions (and for larger allocations) they are
|
|
410
|
-
// just wrappers around malloc.
|
|
411
|
-
#if PY_VERSION_HEX >= 0x03050000
|
|
412
|
-
nonsimple.values_and_holders = (void **) PyMem_Calloc(space, sizeof(void *));
|
|
413
|
-
if (!nonsimple.values_and_holders) throw std::bad_alloc();
|
|
414
|
-
#else
|
|
415
|
-
nonsimple.values_and_holders = (void **) PyMem_New(void *, space);
|
|
416
|
-
if (!nonsimple.values_and_holders) throw std::bad_alloc();
|
|
417
|
-
std::memset(nonsimple.values_and_holders, 0, space * sizeof(void *));
|
|
418
|
-
#endif
|
|
419
|
-
nonsimple.status = reinterpret_cast<std::uint8_t *>(&nonsimple.values_and_holders[flags_at]);
|
|
420
|
-
}
|
|
421
|
-
owned = true;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
// NOLINTNEXTLINE(readability-make-member-function-const)
|
|
425
|
-
PYBIND11_NOINLINE void instance::deallocate_layout() {
|
|
426
|
-
if (!simple_layout)
|
|
427
|
-
PyMem_Free(nonsimple.values_and_holders);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
PYBIND11_NOINLINE bool isinstance_generic(handle obj, const std::type_info &tp) {
|
|
431
|
-
handle type = detail::get_type_handle(tp, false);
|
|
432
|
-
if (!type)
|
|
433
|
-
return false;
|
|
434
|
-
return isinstance(obj, type);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
PYBIND11_NOINLINE std::string error_string() {
|
|
438
|
-
if (!PyErr_Occurred()) {
|
|
439
|
-
PyErr_SetString(PyExc_RuntimeError, "Unknown internal error occurred");
|
|
440
|
-
return "Unknown internal error occurred";
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
error_scope scope; // Preserve error state
|
|
444
|
-
|
|
445
|
-
std::string errorString;
|
|
446
|
-
if (scope.type) {
|
|
447
|
-
errorString += handle(scope.type).attr("__name__").cast<std::string>();
|
|
448
|
-
errorString += ": ";
|
|
449
|
-
}
|
|
450
|
-
if (scope.value)
|
|
451
|
-
errorString += (std::string) str(scope.value);
|
|
452
|
-
|
|
453
|
-
PyErr_NormalizeException(&scope.type, &scope.value, &scope.trace);
|
|
454
|
-
|
|
455
|
-
#if PY_MAJOR_VERSION >= 3
|
|
456
|
-
if (scope.trace != nullptr)
|
|
457
|
-
PyException_SetTraceback(scope.value, scope.trace);
|
|
458
|
-
#endif
|
|
459
|
-
|
|
460
|
-
#if !defined(PYPY_VERSION)
|
|
461
|
-
if (scope.trace) {
|
|
462
|
-
auto *trace = (PyTracebackObject *) scope.trace;
|
|
463
|
-
|
|
464
|
-
/* Get the deepest trace possible */
|
|
465
|
-
while (trace->tb_next)
|
|
466
|
-
trace = trace->tb_next;
|
|
467
|
-
|
|
468
|
-
PyFrameObject *frame = trace->tb_frame;
|
|
469
|
-
errorString += "\n\nAt:\n";
|
|
470
|
-
while (frame) {
|
|
471
|
-
int lineno = PyFrame_GetLineNumber(frame);
|
|
472
|
-
errorString +=
|
|
473
|
-
" " + handle(frame->f_code->co_filename).cast<std::string>() +
|
|
474
|
-
"(" + std::to_string(lineno) + "): " +
|
|
475
|
-
handle(frame->f_code->co_name).cast<std::string>() + "\n";
|
|
476
|
-
frame = frame->f_back;
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
#endif
|
|
480
|
-
|
|
481
|
-
return errorString;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
PYBIND11_NOINLINE handle get_object_handle(const void *ptr, const detail::type_info *type ) {
|
|
485
|
-
auto &instances = get_internals().registered_instances;
|
|
486
|
-
auto range = instances.equal_range(ptr);
|
|
487
|
-
for (auto it = range.first; it != range.second; ++it) {
|
|
488
|
-
for (const auto &vh : values_and_holders(it->second)) {
|
|
489
|
-
if (vh.type == type)
|
|
490
|
-
return handle((PyObject *) it->second);
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
return handle();
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
inline PyThreadState *get_thread_state_unchecked() {
|
|
497
|
-
#if defined(PYPY_VERSION)
|
|
498
|
-
return PyThreadState_GET();
|
|
499
|
-
#elif PY_VERSION_HEX < 0x03000000
|
|
500
|
-
return _PyThreadState_Current;
|
|
501
|
-
#elif PY_VERSION_HEX < 0x03050000
|
|
502
|
-
return (PyThreadState*) _Py_atomic_load_relaxed(&_PyThreadState_Current);
|
|
503
|
-
#elif PY_VERSION_HEX < 0x03050200
|
|
504
|
-
return (PyThreadState*) _PyThreadState_Current.value;
|
|
505
|
-
#else
|
|
506
|
-
return _PyThreadState_UncheckedGet();
|
|
507
|
-
#endif
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// Forward declarations
|
|
511
|
-
void keep_alive_impl(handle nurse, handle patient);
|
|
512
|
-
inline PyObject *make_new_instance(PyTypeObject *type);
|
|
513
|
-
|
|
514
|
-
class type_caster_generic {
|
|
515
|
-
public:
|
|
516
|
-
PYBIND11_NOINLINE explicit type_caster_generic(const std::type_info &type_info)
|
|
517
|
-
: typeinfo(get_type_info(type_info)), cpptype(&type_info) {}
|
|
518
|
-
|
|
519
|
-
explicit type_caster_generic(const type_info *typeinfo)
|
|
520
|
-
: typeinfo(typeinfo), cpptype(typeinfo ? typeinfo->cpptype : nullptr) {}
|
|
521
|
-
|
|
522
|
-
bool load(handle src, bool convert) {
|
|
523
|
-
return load_impl<type_caster_generic>(src, convert);
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
PYBIND11_NOINLINE static handle cast(const void *_src, return_value_policy policy, handle parent,
|
|
527
|
-
const detail::type_info *tinfo,
|
|
528
|
-
void *(*copy_constructor)(const void *),
|
|
529
|
-
void *(*move_constructor)(const void *),
|
|
530
|
-
const void *existing_holder = nullptr) {
|
|
531
|
-
if (!tinfo) // no type info: error will be set already
|
|
532
|
-
return handle();
|
|
533
|
-
|
|
534
|
-
void *src = const_cast<void *>(_src);
|
|
535
|
-
if (src == nullptr)
|
|
536
|
-
return none().release();
|
|
537
|
-
|
|
538
|
-
if (handle registered_inst = find_registered_python_instance(src, tinfo))
|
|
539
|
-
return registered_inst;
|
|
540
|
-
|
|
541
|
-
auto inst = reinterpret_steal<object>(make_new_instance(tinfo->type));
|
|
542
|
-
auto wrapper = reinterpret_cast<instance *>(inst.ptr());
|
|
543
|
-
wrapper->owned = false;
|
|
544
|
-
void *&valueptr = values_and_holders(wrapper).begin()->value_ptr();
|
|
545
|
-
|
|
546
|
-
switch (policy) {
|
|
547
|
-
case return_value_policy::automatic:
|
|
548
|
-
case return_value_policy::take_ownership:
|
|
549
|
-
valueptr = src;
|
|
550
|
-
wrapper->owned = true;
|
|
551
|
-
break;
|
|
552
|
-
|
|
553
|
-
case return_value_policy::automatic_reference:
|
|
554
|
-
case return_value_policy::reference:
|
|
555
|
-
valueptr = src;
|
|
556
|
-
wrapper->owned = false;
|
|
557
|
-
break;
|
|
558
|
-
|
|
559
|
-
case return_value_policy::copy:
|
|
560
|
-
if (copy_constructor)
|
|
561
|
-
valueptr = copy_constructor(src);
|
|
562
|
-
else {
|
|
563
|
-
#if defined(NDEBUG)
|
|
564
|
-
throw cast_error("return_value_policy = copy, but type is "
|
|
565
|
-
"non-copyable! (compile in debug mode for details)");
|
|
566
|
-
#else
|
|
567
|
-
std::string type_name(tinfo->cpptype->name());
|
|
568
|
-
detail::clean_type_id(type_name);
|
|
569
|
-
throw cast_error("return_value_policy = copy, but type " +
|
|
570
|
-
type_name + " is non-copyable!");
|
|
571
|
-
#endif
|
|
572
|
-
}
|
|
573
|
-
wrapper->owned = true;
|
|
574
|
-
break;
|
|
575
|
-
|
|
576
|
-
case return_value_policy::move:
|
|
577
|
-
if (move_constructor)
|
|
578
|
-
valueptr = move_constructor(src);
|
|
579
|
-
else if (copy_constructor)
|
|
580
|
-
valueptr = copy_constructor(src);
|
|
581
|
-
else {
|
|
582
|
-
#if defined(NDEBUG)
|
|
583
|
-
throw cast_error("return_value_policy = move, but type is neither "
|
|
584
|
-
"movable nor copyable! "
|
|
585
|
-
"(compile in debug mode for details)");
|
|
586
|
-
#else
|
|
587
|
-
std::string type_name(tinfo->cpptype->name());
|
|
588
|
-
detail::clean_type_id(type_name);
|
|
589
|
-
throw cast_error("return_value_policy = move, but type " +
|
|
590
|
-
type_name + " is neither movable nor copyable!");
|
|
591
|
-
#endif
|
|
592
|
-
}
|
|
593
|
-
wrapper->owned = true;
|
|
594
|
-
break;
|
|
595
|
-
|
|
596
|
-
case return_value_policy::reference_internal:
|
|
597
|
-
valueptr = src;
|
|
598
|
-
wrapper->owned = false;
|
|
599
|
-
keep_alive_impl(inst, parent);
|
|
600
|
-
break;
|
|
601
|
-
|
|
602
|
-
default:
|
|
603
|
-
throw cast_error("unhandled return_value_policy: should not happen!");
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
tinfo->init_instance(wrapper, existing_holder);
|
|
607
|
-
|
|
608
|
-
return inst.release();
|
|
609
|
-
}
|
|
610
|
-
|
|
611
|
-
// Base methods for generic caster; there are overridden in copyable_holder_caster
|
|
612
|
-
void load_value(value_and_holder &&v_h) {
|
|
613
|
-
auto *&vptr = v_h.value_ptr();
|
|
614
|
-
// Lazy allocation for unallocated values:
|
|
615
|
-
if (vptr == nullptr) {
|
|
616
|
-
auto *type = v_h.type ? v_h.type : typeinfo;
|
|
617
|
-
if (type->operator_new) {
|
|
618
|
-
vptr = type->operator_new(type->type_size);
|
|
619
|
-
} else {
|
|
620
|
-
#if defined(__cpp_aligned_new) && (!defined(_MSC_VER) || _MSC_VER >= 1912)
|
|
621
|
-
if (type->type_align > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
|
|
622
|
-
vptr = ::operator new(type->type_size,
|
|
623
|
-
std::align_val_t(type->type_align));
|
|
624
|
-
else
|
|
625
|
-
#endif
|
|
626
|
-
vptr = ::operator new(type->type_size);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
value = vptr;
|
|
630
|
-
}
|
|
631
|
-
bool try_implicit_casts(handle src, bool convert) {
|
|
632
|
-
for (auto &cast : typeinfo->implicit_casts) {
|
|
633
|
-
type_caster_generic sub_caster(*cast.first);
|
|
634
|
-
if (sub_caster.load(src, convert)) {
|
|
635
|
-
value = cast.second(sub_caster.value);
|
|
636
|
-
return true;
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
return false;
|
|
640
|
-
}
|
|
641
|
-
bool try_direct_conversions(handle src) {
|
|
642
|
-
for (auto &converter : *typeinfo->direct_conversions) {
|
|
643
|
-
if (converter(src.ptr(), value))
|
|
644
|
-
return true;
|
|
645
|
-
}
|
|
646
|
-
return false;
|
|
647
|
-
}
|
|
648
|
-
void check_holder_compat() {}
|
|
649
|
-
|
|
650
|
-
PYBIND11_NOINLINE static void *local_load(PyObject *src, const type_info *ti) {
|
|
651
|
-
auto caster = type_caster_generic(ti);
|
|
652
|
-
if (caster.load(src, false))
|
|
653
|
-
return caster.value;
|
|
654
|
-
return nullptr;
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
/// Try to load with foreign typeinfo, if available. Used when there is no
|
|
658
|
-
/// native typeinfo, or when the native one wasn't able to produce a value.
|
|
659
|
-
PYBIND11_NOINLINE bool try_load_foreign_module_local(handle src) {
|
|
660
|
-
constexpr auto *local_key = PYBIND11_MODULE_LOCAL_ID;
|
|
661
|
-
const auto pytype = type::handle_of(src);
|
|
662
|
-
if (!hasattr(pytype, local_key))
|
|
663
|
-
return false;
|
|
664
|
-
|
|
665
|
-
type_info *foreign_typeinfo = reinterpret_borrow<capsule>(getattr(pytype, local_key));
|
|
666
|
-
// Only consider this foreign loader if actually foreign and is a loader of the correct cpp type
|
|
667
|
-
if (foreign_typeinfo->module_local_load == &local_load
|
|
668
|
-
|| (cpptype && !same_type(*cpptype, *foreign_typeinfo->cpptype)))
|
|
669
|
-
return false;
|
|
670
|
-
|
|
671
|
-
if (auto result = foreign_typeinfo->module_local_load(src.ptr(), foreign_typeinfo)) {
|
|
672
|
-
value = result;
|
|
673
|
-
return true;
|
|
674
|
-
}
|
|
675
|
-
return false;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
// Implementation of `load`; this takes the type of `this` so that it can dispatch the relevant
|
|
679
|
-
// bits of code between here and copyable_holder_caster where the two classes need different
|
|
680
|
-
// logic (without having to resort to virtual inheritance).
|
|
681
|
-
template <typename ThisT>
|
|
682
|
-
PYBIND11_NOINLINE bool load_impl(handle src, bool convert) {
|
|
683
|
-
if (!src) return false;
|
|
684
|
-
if (!typeinfo) return try_load_foreign_module_local(src);
|
|
685
|
-
|
|
686
|
-
auto &this_ = static_cast<ThisT &>(*this);
|
|
687
|
-
this_.check_holder_compat();
|
|
688
|
-
|
|
689
|
-
PyTypeObject *srctype = Py_TYPE(src.ptr());
|
|
690
|
-
|
|
691
|
-
// Case 1: If src is an exact type match for the target type then we can reinterpret_cast
|
|
692
|
-
// the instance's value pointer to the target type:
|
|
693
|
-
if (srctype == typeinfo->type) {
|
|
694
|
-
this_.load_value(reinterpret_cast<instance *>(src.ptr())->get_value_and_holder());
|
|
695
|
-
return true;
|
|
696
|
-
}
|
|
697
|
-
// Case 2: We have a derived class
|
|
698
|
-
if (PyType_IsSubtype(srctype, typeinfo->type)) {
|
|
699
|
-
auto &bases = all_type_info(srctype);
|
|
700
|
-
bool no_cpp_mi = typeinfo->simple_type;
|
|
701
|
-
|
|
702
|
-
// Case 2a: the python type is a Python-inherited derived class that inherits from just
|
|
703
|
-
// one simple (no MI) pybind11 class, or is an exact match, so the C++ instance is of
|
|
704
|
-
// the right type and we can use reinterpret_cast.
|
|
705
|
-
// (This is essentially the same as case 2b, but because not using multiple inheritance
|
|
706
|
-
// is extremely common, we handle it specially to avoid the loop iterator and type
|
|
707
|
-
// pointer lookup overhead)
|
|
708
|
-
if (bases.size() == 1 && (no_cpp_mi || bases.front()->type == typeinfo->type)) {
|
|
709
|
-
this_.load_value(reinterpret_cast<instance *>(src.ptr())->get_value_and_holder());
|
|
710
|
-
return true;
|
|
711
|
-
}
|
|
712
|
-
// Case 2b: the python type inherits from multiple C++ bases. Check the bases to see if
|
|
713
|
-
// we can find an exact match (or, for a simple C++ type, an inherited match); if so, we
|
|
714
|
-
// can safely reinterpret_cast to the relevant pointer.
|
|
715
|
-
if (bases.size() > 1) {
|
|
716
|
-
for (auto base : bases) {
|
|
717
|
-
if (no_cpp_mi ? PyType_IsSubtype(base->type, typeinfo->type) : base->type == typeinfo->type) {
|
|
718
|
-
this_.load_value(reinterpret_cast<instance *>(src.ptr())->get_value_and_holder(base));
|
|
719
|
-
return true;
|
|
720
|
-
}
|
|
721
|
-
}
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
// Case 2c: C++ multiple inheritance is involved and we couldn't find an exact type match
|
|
725
|
-
// in the registered bases, above, so try implicit casting (needed for proper C++ casting
|
|
726
|
-
// when MI is involved).
|
|
727
|
-
if (this_.try_implicit_casts(src, convert))
|
|
728
|
-
return true;
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
// Perform an implicit conversion
|
|
732
|
-
if (convert) {
|
|
733
|
-
for (auto &converter : typeinfo->implicit_conversions) {
|
|
734
|
-
auto temp = reinterpret_steal<object>(converter(src.ptr(), typeinfo->type));
|
|
735
|
-
if (load_impl<ThisT>(temp, false)) {
|
|
736
|
-
loader_life_support::add_patient(temp);
|
|
737
|
-
return true;
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
if (this_.try_direct_conversions(src))
|
|
741
|
-
return true;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
// Failed to match local typeinfo. Try again with global.
|
|
745
|
-
if (typeinfo->module_local) {
|
|
746
|
-
if (auto gtype = get_global_type_info(*typeinfo->cpptype)) {
|
|
747
|
-
typeinfo = gtype;
|
|
748
|
-
return load(src, false);
|
|
749
|
-
}
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
// Global typeinfo has precedence over foreign module_local
|
|
753
|
-
if (try_load_foreign_module_local(src)) {
|
|
754
|
-
return true;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
// Custom converters didn't take None, now we convert None to nullptr.
|
|
758
|
-
if (src.is_none()) {
|
|
759
|
-
// Defer accepting None to other overloads (if we aren't in convert mode):
|
|
760
|
-
if (!convert) return false;
|
|
761
|
-
value = nullptr;
|
|
762
|
-
return true;
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
return false;
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
// Called to do type lookup and wrap the pointer and type in a pair when a dynamic_cast
|
|
770
|
-
// isn't needed or can't be used. If the type is unknown, sets the error and returns a pair
|
|
771
|
-
// with .second = nullptr. (p.first = nullptr is not an error: it becomes None).
|
|
772
|
-
PYBIND11_NOINLINE static std::pair<const void *, const type_info *> src_and_type(
|
|
773
|
-
const void *src, const std::type_info &cast_type, const std::type_info *rtti_type = nullptr) {
|
|
774
|
-
if (auto *tpi = get_type_info(cast_type))
|
|
775
|
-
return {src, const_cast<const type_info *>(tpi)};
|
|
776
|
-
|
|
777
|
-
// Not found, set error:
|
|
778
|
-
std::string tname = rtti_type ? rtti_type->name() : cast_type.name();
|
|
779
|
-
detail::clean_type_id(tname);
|
|
780
|
-
std::string msg = "Unregistered type : " + tname;
|
|
781
|
-
PyErr_SetString(PyExc_TypeError, msg.c_str());
|
|
782
|
-
return {nullptr, nullptr};
|
|
783
|
-
}
|
|
784
|
-
|
|
785
|
-
const type_info *typeinfo = nullptr;
|
|
786
|
-
const std::type_info *cpptype = nullptr;
|
|
787
|
-
void *value = nullptr;
|
|
788
|
-
};
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* Determine suitable casting operator for pointer-or-lvalue-casting type casters. The type caster
|
|
792
|
-
* needs to provide `operator T*()` and `operator T&()` operators.
|
|
793
|
-
*
|
|
794
|
-
* If the type supports moving the value away via an `operator T&&() &&` method, it should use
|
|
795
|
-
* `movable_cast_op_type` instead.
|
|
796
|
-
*/
|
|
797
|
-
template <typename T>
|
|
798
|
-
using cast_op_type =
|
|
799
|
-
conditional_t<std::is_pointer<remove_reference_t<T>>::value,
|
|
800
|
-
typename std::add_pointer<intrinsic_t<T>>::type,
|
|
801
|
-
typename std::add_lvalue_reference<intrinsic_t<T>>::type>;
|
|
802
|
-
|
|
803
|
-
/**
|
|
804
|
-
* Determine suitable casting operator for a type caster with a movable value. Such a type caster
|
|
805
|
-
* needs to provide `operator T*()`, `operator T&()`, and `operator T&&() &&`. The latter will be
|
|
806
|
-
* called in appropriate contexts where the value can be moved rather than copied.
|
|
807
|
-
*
|
|
808
|
-
* These operator are automatically provided when using the PYBIND11_TYPE_CASTER macro.
|
|
809
|
-
*/
|
|
810
|
-
template <typename T>
|
|
811
|
-
using movable_cast_op_type =
|
|
812
|
-
conditional_t<std::is_pointer<typename std::remove_reference<T>::type>::value,
|
|
813
|
-
typename std::add_pointer<intrinsic_t<T>>::type,
|
|
814
|
-
conditional_t<std::is_rvalue_reference<T>::value,
|
|
815
|
-
typename std::add_rvalue_reference<intrinsic_t<T>>::type,
|
|
816
|
-
typename std::add_lvalue_reference<intrinsic_t<T>>::type>>;
|
|
817
|
-
|
|
818
|
-
// std::is_copy_constructible isn't quite enough: it lets std::vector<T> (and similar) through when
|
|
819
|
-
// T is non-copyable, but code containing such a copy constructor fails to actually compile.
|
|
820
|
-
template <typename T, typename SFINAE = void> struct is_copy_constructible : std::is_copy_constructible<T> {};
|
|
821
|
-
|
|
822
|
-
// Specialization for types that appear to be copy constructible but also look like stl containers
|
|
823
|
-
// (we specifically check for: has `value_type` and `reference` with `reference = value_type&`): if
|
|
824
|
-
// so, copy constructability depends on whether the value_type is copy constructible.
|
|
825
|
-
template <typename Container> struct is_copy_constructible<Container, enable_if_t<all_of<
|
|
826
|
-
std::is_copy_constructible<Container>,
|
|
827
|
-
std::is_same<typename Container::value_type &, typename Container::reference>,
|
|
828
|
-
// Avoid infinite recursion
|
|
829
|
-
negation<std::is_same<Container, typename Container::value_type>>
|
|
830
|
-
>::value>> : is_copy_constructible<typename Container::value_type> {};
|
|
831
|
-
|
|
832
|
-
// Likewise for std::pair
|
|
833
|
-
// (after C++17 it is mandatory that the copy constructor not exist when the two types aren't themselves
|
|
834
|
-
// copy constructible, but this can not be relied upon when T1 or T2 are themselves containers).
|
|
835
|
-
template <typename T1, typename T2> struct is_copy_constructible<std::pair<T1, T2>>
|
|
836
|
-
: all_of<is_copy_constructible<T1>, is_copy_constructible<T2>> {};
|
|
837
|
-
|
|
838
|
-
// The same problems arise with std::is_copy_assignable, so we use the same workaround.
|
|
839
|
-
template <typename T, typename SFINAE = void> struct is_copy_assignable : std::is_copy_assignable<T> {};
|
|
840
|
-
template <typename Container> struct is_copy_assignable<Container, enable_if_t<all_of<
|
|
841
|
-
std::is_copy_assignable<Container>,
|
|
842
|
-
std::is_same<typename Container::value_type &, typename Container::reference>
|
|
843
|
-
>::value>> : is_copy_assignable<typename Container::value_type> {};
|
|
844
|
-
template <typename T1, typename T2> struct is_copy_assignable<std::pair<T1, T2>>
|
|
845
|
-
: all_of<is_copy_assignable<T1>, is_copy_assignable<T2>> {};
|
|
846
|
-
|
|
847
|
-
PYBIND11_NAMESPACE_END(detail)
|
|
848
|
-
|
|
849
|
-
// polymorphic_type_hook<itype>::get(src, tinfo) determines whether the object pointed
|
|
850
|
-
// to by `src` actually is an instance of some class derived from `itype`.
|
|
851
|
-
// If so, it sets `tinfo` to point to the std::type_info representing that derived
|
|
852
|
-
// type, and returns a pointer to the start of the most-derived object of that type
|
|
853
|
-
// (in which `src` is a subobject; this will be the same address as `src` in most
|
|
854
|
-
// single inheritance cases). If not, or if `src` is nullptr, it simply returns `src`
|
|
855
|
-
// and leaves `tinfo` at its default value of nullptr.
|
|
856
|
-
//
|
|
857
|
-
// The default polymorphic_type_hook just returns src. A specialization for polymorphic
|
|
858
|
-
// types determines the runtime type of the passed object and adjusts the this-pointer
|
|
859
|
-
// appropriately via dynamic_cast<void*>. This is what enables a C++ Animal* to appear
|
|
860
|
-
// to Python as a Dog (if Dog inherits from Animal, Animal is polymorphic, Dog is
|
|
861
|
-
// registered with pybind11, and this Animal is in fact a Dog).
|
|
862
|
-
//
|
|
863
|
-
// You may specialize polymorphic_type_hook yourself for types that want to appear
|
|
864
|
-
// polymorphic to Python but do not use C++ RTTI. (This is a not uncommon pattern
|
|
865
|
-
// in performance-sensitive applications, used most notably in LLVM.)
|
|
866
|
-
//
|
|
867
|
-
// polymorphic_type_hook_base allows users to specialize polymorphic_type_hook with
|
|
868
|
-
// std::enable_if. User provided specializations will always have higher priority than
|
|
869
|
-
// the default implementation and specialization provided in polymorphic_type_hook_base.
|
|
870
|
-
template <typename itype, typename SFINAE = void>
|
|
871
|
-
struct polymorphic_type_hook_base
|
|
872
|
-
{
|
|
873
|
-
static const void *get(const itype *src, const std::type_info*&) { return src; }
|
|
874
|
-
};
|
|
875
|
-
template <typename itype>
|
|
876
|
-
struct polymorphic_type_hook_base<itype, detail::enable_if_t<std::is_polymorphic<itype>::value>>
|
|
877
|
-
{
|
|
878
|
-
static const void *get(const itype *src, const std::type_info*& type) {
|
|
879
|
-
type = src ? &typeid(*src) : nullptr;
|
|
880
|
-
return dynamic_cast<const void*>(src);
|
|
881
|
-
}
|
|
882
|
-
};
|
|
883
|
-
template <typename itype, typename SFINAE = void>
|
|
884
|
-
struct polymorphic_type_hook : public polymorphic_type_hook_base<itype> {};
|
|
885
|
-
|
|
886
|
-
PYBIND11_NAMESPACE_BEGIN(detail)
|
|
887
|
-
|
|
888
|
-
/// Generic type caster for objects stored on the heap
|
|
889
|
-
template <typename type> class type_caster_base : public type_caster_generic {
|
|
890
|
-
using itype = intrinsic_t<type>;
|
|
891
|
-
|
|
892
|
-
public:
|
|
893
|
-
static constexpr auto name = _<type>();
|
|
894
|
-
|
|
895
|
-
type_caster_base() : type_caster_base(typeid(type)) { }
|
|
896
|
-
explicit type_caster_base(const std::type_info &info) : type_caster_generic(info) { }
|
|
897
|
-
|
|
898
|
-
static handle cast(const itype &src, return_value_policy policy, handle parent) {
|
|
899
|
-
if (policy == return_value_policy::automatic || policy == return_value_policy::automatic_reference)
|
|
900
|
-
policy = return_value_policy::copy;
|
|
901
|
-
return cast(&src, policy, parent);
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
static handle cast(itype &&src, return_value_policy, handle parent) {
|
|
905
|
-
return cast(&src, return_value_policy::move, parent);
|
|
906
|
-
}
|
|
907
|
-
|
|
908
|
-
// Returns a (pointer, type_info) pair taking care of necessary type lookup for a
|
|
909
|
-
// polymorphic type (using RTTI by default, but can be overridden by specializing
|
|
910
|
-
// polymorphic_type_hook). If the instance isn't derived, returns the base version.
|
|
911
|
-
static std::pair<const void *, const type_info *> src_and_type(const itype *src) {
|
|
912
|
-
auto &cast_type = typeid(itype);
|
|
913
|
-
const std::type_info *instance_type = nullptr;
|
|
914
|
-
const void *vsrc = polymorphic_type_hook<itype>::get(src, instance_type);
|
|
915
|
-
if (instance_type && !same_type(cast_type, *instance_type)) {
|
|
916
|
-
// This is a base pointer to a derived type. If the derived type is registered
|
|
917
|
-
// with pybind11, we want to make the full derived object available.
|
|
918
|
-
// In the typical case where itype is polymorphic, we get the correct
|
|
919
|
-
// derived pointer (which may be != base pointer) by a dynamic_cast to
|
|
920
|
-
// most derived type. If itype is not polymorphic, we won't get here
|
|
921
|
-
// except via a user-provided specialization of polymorphic_type_hook,
|
|
922
|
-
// and the user has promised that no this-pointer adjustment is
|
|
923
|
-
// required in that case, so it's OK to use static_cast.
|
|
924
|
-
if (const auto *tpi = get_type_info(*instance_type))
|
|
925
|
-
return {vsrc, tpi};
|
|
926
|
-
}
|
|
927
|
-
// Otherwise we have either a nullptr, an `itype` pointer, or an unknown derived pointer, so
|
|
928
|
-
// don't do a cast
|
|
929
|
-
return type_caster_generic::src_and_type(src, cast_type, instance_type);
|
|
930
|
-
}
|
|
931
|
-
|
|
932
|
-
static handle cast(const itype *src, return_value_policy policy, handle parent) {
|
|
933
|
-
auto st = src_and_type(src);
|
|
934
|
-
return type_caster_generic::cast(
|
|
935
|
-
st.first, policy, parent, st.second,
|
|
936
|
-
make_copy_constructor(src), make_move_constructor(src));
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
static handle cast_holder(const itype *src, const void *holder) {
|
|
940
|
-
auto st = src_and_type(src);
|
|
941
|
-
return type_caster_generic::cast(
|
|
942
|
-
st.first, return_value_policy::take_ownership, {}, st.second,
|
|
943
|
-
nullptr, nullptr, holder);
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
template <typename T> using cast_op_type = detail::cast_op_type<T>;
|
|
947
|
-
|
|
948
|
-
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
949
|
-
operator itype*() { return (type *) value; }
|
|
950
|
-
// NOLINTNEXTLINE(google-explicit-constructor)
|
|
951
|
-
operator itype&() { if (!value) throw reference_cast_error(); return *((itype *) value); }
|
|
952
|
-
|
|
953
|
-
protected:
|
|
954
|
-
using Constructor = void *(*)(const void *);
|
|
955
|
-
|
|
956
|
-
/* Only enabled when the types are {copy,move}-constructible *and* when the type
|
|
957
|
-
does not have a private operator new implementation. A comma operator is used in the decltype
|
|
958
|
-
argument to apply SFINAE to the public copy/move constructors.*/
|
|
959
|
-
template <typename T, typename = enable_if_t<is_copy_constructible<T>::value>>
|
|
960
|
-
static auto make_copy_constructor(const T *) -> decltype(new T(std::declval<const T>()), Constructor{}) {
|
|
961
|
-
return [](const void *arg) -> void * {
|
|
962
|
-
return new T(*reinterpret_cast<const T *>(arg));
|
|
963
|
-
};
|
|
964
|
-
}
|
|
965
|
-
|
|
966
|
-
template <typename T, typename = enable_if_t<std::is_move_constructible<T>::value>>
|
|
967
|
-
static auto make_move_constructor(const T *) -> decltype(new T(std::declval<T&&>()), Constructor{}) {
|
|
968
|
-
return [](const void *arg) -> void * {
|
|
969
|
-
return new T(std::move(*const_cast<T *>(reinterpret_cast<const T *>(arg))));
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
static Constructor make_copy_constructor(...) { return nullptr; }
|
|
974
|
-
static Constructor make_move_constructor(...) { return nullptr; }
|
|
975
|
-
};
|
|
976
|
-
|
|
977
|
-
PYBIND11_NAMESPACE_END(detail)
|
|
978
|
-
PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)
|