├── .gitignore ├── index.html ├── doc ├── index.html ├── images │ ├── bpl.png │ ├── jam.png │ ├── tip.png │ ├── up.png │ ├── alert.png │ ├── blank.png │ ├── boost.png │ ├── draft.png │ ├── home.png │ ├── next.png │ ├── note.png │ ├── prev.png │ ├── smiley.png │ ├── caution.png │ ├── toc-plus.png │ ├── warning.png │ ├── callouts │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 11.png │ │ ├── 12.png │ │ ├── 13.png │ │ ├── 14.png │ │ ├── 15.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ ├── 9.png │ │ ├── 1.svg │ │ ├── 7.svg │ │ ├── 4.svg │ │ ├── 11.svg │ │ ├── 17.svg │ │ ├── 14.svg │ │ ├── 2.svg │ │ ├── 5.svg │ │ ├── 10.svg │ │ ├── 12.svg │ │ ├── 21.svg │ │ ├── 3.svg │ │ ├── 9.svg │ │ ├── 15.svg │ │ ├── 27.svg │ │ ├── 6.svg │ │ └── 24.svg │ ├── important.png │ ├── toc-blank.png │ ├── toc-minus.png │ ├── up_disabled.png │ ├── next_disabled.png │ ├── prev_disabled.png │ ├── up.svg │ ├── next.svg │ └── prev.svg ├── html │ └── images │ │ ├── jam.png │ │ ├── tip.png │ │ ├── up.png │ │ ├── alert.png │ │ ├── blank.png │ │ ├── boost.png │ │ ├── draft.png │ │ ├── home.png │ │ ├── next.png │ │ ├── note.png │ │ ├── prev.png │ │ ├── python.png │ │ ├── smiley.png │ │ ├── caution.png │ │ ├── toc-plus.png │ │ ├── warning.png │ │ ├── callouts │ │ ├── 1.png │ │ ├── 10.png │ │ ├── 11.png │ │ ├── 12.png │ │ ├── 13.png │ │ ├── 14.png │ │ ├── 15.png │ │ ├── 2.png │ │ ├── 3.png │ │ ├── 4.png │ │ ├── 5.png │ │ ├── 6.png │ │ ├── 7.png │ │ ├── 8.png │ │ ├── 9.png │ │ ├── 1.svg │ │ ├── 7.svg │ │ ├── 4.svg │ │ ├── 11.svg │ │ ├── 17.svg │ │ ├── 14.svg │ │ ├── 2.svg │ │ ├── 5.svg │ │ ├── 10.svg │ │ ├── 12.svg │ │ ├── 21.svg │ │ ├── 3.svg │ │ ├── 9.svg │ │ ├── 15.svg │ │ ├── 27.svg │ │ ├── 6.svg │ │ └── 24.svg │ │ ├── important.png │ │ ├── toc-blank.png │ │ ├── toc-minus.png │ │ ├── up_disabled.png │ │ ├── next_disabled.png │ │ ├── prev_disabled.png │ │ ├── python_cpp_mix.png │ │ ├── up.svg │ │ ├── next.svg │ │ └── prev.svg ├── numpy │ ├── _static │ │ ├── bpl.png │ │ ├── home.png │ │ ├── next.png │ │ ├── prev.png │ │ ├── up.png │ │ ├── boost.png │ │ └── style.css │ ├── tutorial │ │ └── index.rst │ ├── reference │ │ └── index.rst │ └── index.rst ├── reference │ ├── embedding.qbk │ ├── topics.qbk │ ├── objects.qbk │ ├── utility.qbk │ ├── conversion.qbk │ ├── components.qbk │ ├── import.qbk │ ├── functions.qbk │ └── to_python_value.qbk ├── release_notes.qbk ├── index.qbk ├── reference.qbk ├── support.qbk └── preface.qbk ├── .ci └── faber ├── test ├── pyrun.py ├── import_.py ├── exec.py ├── operators_wrapper.py ├── polymorphism2_auto_ptr.py ├── polymorphism2_auto_ptr.cpp ├── minimal.py ├── object_fail1.cpp ├── module_init_exception.py ├── simple_type.hpp ├── raw_pyobject_fail1.cpp ├── raw_pyobject_fail2.cpp ├── crossmod_opaque.py ├── module_init_exception.cpp ├── as_to_python_function.cpp ├── crossmod_exception.py ├── crossmod_exception_a.cpp ├── crossmod_exception_b.cpp ├── minimal.cpp ├── int_map_indexing_suite.cpp ├── bienstman2.py ├── shared_ptr.cpp ├── upcast.cpp ├── ben_scott1.py ├── bienstman5.cpp ├── bienstman5.py ├── numpy │ ├── shapes.py │ ├── shapes.cpp │ ├── templates.py │ ├── ufunc.cpp │ └── indexing.cpp ├── boost_shared_ptr.cpp ├── class.cpp ├── const_argument.py ├── bienstman3.cpp ├── bienstman4.py ├── multi_arg_constructor.py ├── enable_shared_from_this.py ├── andreas_beyer.py ├── injected.py ├── bienstman1.py ├── copy_ctor_mutates_rhs.cpp ├── module_nogil.cpp ├── pointer_vector.py ├── exception_translator.cpp ├── module_nogil.py ├── bienstman2.cpp ├── multi_arg_constructor.cpp ├── exception_translator.py ├── crossmod_opaque_a.cpp ├── crossmod_opaque_b.cpp ├── pytype_function.py ├── bienstman3.py ├── wrapper_held_type.py ├── return_arg.py ├── register_ptr_test.py ├── const_argument.cpp ├── long.py ├── back_reference.py ├── aligned_class.cpp ├── bienstman4.cpp ├── stl_iterator.cpp ├── complicated.hpp ├── stl_iterator.py ├── operators_wrapper.cpp ├── tuple.cpp ├── staticmethod.py ├── class.py ├── voidptr.cpp ├── pointee.cpp ├── raw_ctor.py ├── test_class.hpp ├── aligned_class.py ├── borrowed.cpp ├── implicit.py └── bienstman1.cpp ├── example ├── quickstart │ ├── script.py │ └── Jamfile ├── tutorial │ ├── hello.py │ ├── Jamfile │ └── hello.cpp ├── README.md ├── Jamroot └── numpy │ └── Jamfile ├── include └── boost │ └── python │ ├── module.hpp │ ├── detail │ ├── sfinae.hpp │ ├── is_xxx.hpp │ ├── not_specified.hpp │ ├── mpl_lambda.hpp │ ├── indirect_traits.hpp │ ├── api_placeholder.hpp │ ├── scope.hpp │ ├── dealloc.hpp │ ├── def_helper_fwd.hpp │ ├── force_instantiate.hpp │ ├── decref_guard.hpp │ ├── none.hpp │ ├── copy_ctor_mutates_rhs.hpp │ ├── prefix.hpp │ ├── overloads_fwd.hpp │ ├── is_shared_ptr.hpp │ ├── value_arg.hpp │ ├── is_auto_ptr.hpp │ ├── unwrap_type_id.hpp │ ├── aix_init_module.hpp │ ├── value_is_shared_ptr.hpp │ ├── pointee.hpp │ ├── is_wrapper.hpp │ ├── unwrap_wrapper.hpp │ ├── dependent.hpp │ ├── enable_if.hpp │ ├── python_type.hpp │ ├── construct.hpp │ ├── void_ptr.hpp │ ├── void_return.hpp │ ├── make_tuple.hpp │ └── cv_category.hpp │ ├── overloads.hpp │ ├── handle_fwd.hpp │ ├── object_fwd.hpp │ ├── converter │ ├── convertible_function.hpp │ ├── context_result_converter.hpp │ ├── shared_ptr_deleter.hpp │ ├── constructor_function.hpp │ ├── arg_to_python_base.hpp │ ├── to_python_function_type.hpp │ └── registered_pointee.hpp │ ├── import.hpp │ ├── object │ ├── life_support.hpp │ ├── value_holder_fwd.hpp │ ├── iterator_core.hpp │ ├── inheritance_query.hpp │ ├── class_detail.hpp │ ├── find_instance.hpp │ ├── add_to_namespace.hpp │ └── stl_iterator_core.hpp │ ├── tag.hpp │ ├── borrowed.hpp │ ├── has_back_reference.hpp │ ├── return_value_policy.hpp │ ├── ssize_t.hpp │ ├── return_by_value.hpp │ ├── class_fwd.hpp │ ├── object_call.hpp │ ├── register_ptr_to_python.hpp │ ├── object.hpp │ ├── self.hpp │ ├── pointee.hpp │ ├── base_type_traits.hpp │ ├── slice_nil.hpp │ ├── exception_translator.hpp │ ├── other.hpp │ ├── refcount.hpp │ └── wrapper.hpp ├── meta └── libraries.json ├── src ├── import.cpp ├── numpy │ └── numpy.cpp ├── converter │ └── arg_to_python_base.cpp ├── object │ └── iterator.cpp └── tuple.cpp └── .github └── workflows └── deploy-documentation.yml /.gitignore: -------------------------------------------------------------------------------- 1 | bin.SCons 2 | *.pyc 3 | *~ 4 | \#*\# -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/index.html -------------------------------------------------------------------------------- /doc/index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/index.html -------------------------------------------------------------------------------- /doc/images/bpl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/bpl.png -------------------------------------------------------------------------------- /doc/images/jam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/jam.png -------------------------------------------------------------------------------- /doc/images/tip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/tip.png -------------------------------------------------------------------------------- /doc/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/up.png -------------------------------------------------------------------------------- /doc/images/alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/alert.png -------------------------------------------------------------------------------- /doc/images/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/blank.png -------------------------------------------------------------------------------- /doc/images/boost.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/boost.png -------------------------------------------------------------------------------- /doc/images/draft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/draft.png -------------------------------------------------------------------------------- /doc/images/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/home.png -------------------------------------------------------------------------------- /doc/images/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/next.png -------------------------------------------------------------------------------- /doc/images/note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/note.png -------------------------------------------------------------------------------- /doc/images/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/prev.png -------------------------------------------------------------------------------- /doc/images/smiley.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/smiley.png -------------------------------------------------------------------------------- /doc/html/images/jam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/jam.png -------------------------------------------------------------------------------- /doc/html/images/tip.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/tip.png -------------------------------------------------------------------------------- /doc/html/images/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/up.png -------------------------------------------------------------------------------- /doc/images/caution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/caution.png -------------------------------------------------------------------------------- /doc/images/toc-plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/toc-plus.png -------------------------------------------------------------------------------- /doc/images/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/warning.png -------------------------------------------------------------------------------- /doc/html/images/alert.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/alert.png -------------------------------------------------------------------------------- /doc/html/images/blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/blank.png -------------------------------------------------------------------------------- /doc/html/images/boost.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/boost.png -------------------------------------------------------------------------------- /doc/html/images/draft.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/draft.png -------------------------------------------------------------------------------- /doc/html/images/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/home.png -------------------------------------------------------------------------------- /doc/html/images/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/next.png -------------------------------------------------------------------------------- /doc/html/images/note.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/note.png -------------------------------------------------------------------------------- /doc/html/images/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/prev.png -------------------------------------------------------------------------------- /doc/html/images/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/python.png -------------------------------------------------------------------------------- /doc/html/images/smiley.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/smiley.png -------------------------------------------------------------------------------- /doc/images/callouts/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/1.png -------------------------------------------------------------------------------- /doc/images/callouts/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/10.png -------------------------------------------------------------------------------- /doc/images/callouts/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/11.png -------------------------------------------------------------------------------- /doc/images/callouts/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/12.png -------------------------------------------------------------------------------- /doc/images/callouts/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/13.png -------------------------------------------------------------------------------- /doc/images/callouts/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/14.png -------------------------------------------------------------------------------- /doc/images/callouts/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/15.png -------------------------------------------------------------------------------- /doc/images/callouts/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/2.png -------------------------------------------------------------------------------- /doc/images/callouts/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/3.png -------------------------------------------------------------------------------- /doc/images/callouts/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/4.png -------------------------------------------------------------------------------- /doc/images/callouts/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/5.png -------------------------------------------------------------------------------- /doc/images/callouts/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/6.png -------------------------------------------------------------------------------- /doc/images/callouts/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/7.png -------------------------------------------------------------------------------- /doc/images/callouts/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/8.png -------------------------------------------------------------------------------- /doc/images/callouts/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/callouts/9.png -------------------------------------------------------------------------------- /doc/images/important.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/important.png -------------------------------------------------------------------------------- /doc/images/toc-blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/toc-blank.png -------------------------------------------------------------------------------- /doc/images/toc-minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/toc-minus.png -------------------------------------------------------------------------------- /doc/images/up_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/up_disabled.png -------------------------------------------------------------------------------- /doc/numpy/_static/bpl.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/numpy/_static/bpl.png -------------------------------------------------------------------------------- /doc/numpy/_static/home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/numpy/_static/home.png -------------------------------------------------------------------------------- /doc/numpy/_static/next.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/numpy/_static/next.png -------------------------------------------------------------------------------- /doc/numpy/_static/prev.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/numpy/_static/prev.png -------------------------------------------------------------------------------- /doc/numpy/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/numpy/_static/up.png -------------------------------------------------------------------------------- /doc/html/images/caution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/caution.png -------------------------------------------------------------------------------- /doc/html/images/toc-plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/toc-plus.png -------------------------------------------------------------------------------- /doc/html/images/warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/warning.png -------------------------------------------------------------------------------- /doc/images/next_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/next_disabled.png -------------------------------------------------------------------------------- /doc/images/prev_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/images/prev_disabled.png -------------------------------------------------------------------------------- /doc/numpy/_static/boost.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/numpy/_static/boost.png -------------------------------------------------------------------------------- /doc/html/images/callouts/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/1.png -------------------------------------------------------------------------------- /doc/html/images/callouts/10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/10.png -------------------------------------------------------------------------------- /doc/html/images/callouts/11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/11.png -------------------------------------------------------------------------------- /doc/html/images/callouts/12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/12.png -------------------------------------------------------------------------------- /doc/html/images/callouts/13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/13.png -------------------------------------------------------------------------------- /doc/html/images/callouts/14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/14.png -------------------------------------------------------------------------------- /doc/html/images/callouts/15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/15.png -------------------------------------------------------------------------------- /doc/html/images/callouts/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/2.png -------------------------------------------------------------------------------- /doc/html/images/callouts/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/3.png -------------------------------------------------------------------------------- /doc/html/images/callouts/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/4.png -------------------------------------------------------------------------------- /doc/html/images/callouts/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/5.png -------------------------------------------------------------------------------- /doc/html/images/callouts/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/6.png -------------------------------------------------------------------------------- /doc/html/images/callouts/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/7.png -------------------------------------------------------------------------------- /doc/html/images/callouts/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/8.png -------------------------------------------------------------------------------- /doc/html/images/callouts/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/callouts/9.png -------------------------------------------------------------------------------- /doc/html/images/important.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/important.png -------------------------------------------------------------------------------- /doc/html/images/toc-blank.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/toc-blank.png -------------------------------------------------------------------------------- /doc/html/images/toc-minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/toc-minus.png -------------------------------------------------------------------------------- /doc/html/images/up_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/up_disabled.png -------------------------------------------------------------------------------- /doc/html/images/next_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/next_disabled.png -------------------------------------------------------------------------------- /doc/html/images/prev_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/prev_disabled.png -------------------------------------------------------------------------------- /doc/html/images/python_cpp_mix.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/python/HEAD/doc/html/images/python_cpp_mix.png -------------------------------------------------------------------------------- /doc/reference/embedding.qbk: -------------------------------------------------------------------------------- 1 | [chapter Embedding 2 | [quickbook 1.7] 3 | ] 4 | 5 | [include exec.qbk] 6 | [include import.qbk] 7 | -------------------------------------------------------------------------------- /doc/reference/topics.qbk: -------------------------------------------------------------------------------- 1 | [chapter Topics 2 | [quickbook 1.7] 3 | ] 4 | 5 | [include calling.qbk] 6 | [include pickle.qbk] 7 | [include indexing.qbk] 8 | -------------------------------------------------------------------------------- /.ci/faber: -------------------------------------------------------------------------------- 1 | # -*- python -*- 2 | 3 | from faber.tools.boost import boostbook 4 | from faber.tools.python import python 5 | 6 | bb = boostbook(prefix='/usr/share/boostbook') 7 | p = python(command='$PYTHON') 8 | -------------------------------------------------------------------------------- /test/pyrun.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | pythonpath = sys.argv[1] 4 | scriptfile = sys.argv[2] 5 | sys.argv = sys.argv[2:] 6 | sys.path.append(pythonpath) 7 | exec(compile(open(scriptfile).read(), scriptfile, 'exec')) 8 | -------------------------------------------------------------------------------- /test/import_.py: -------------------------------------------------------------------------------- 1 | # Copyright Stefan Seefeld 2007. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | value = 42 6 | -------------------------------------------------------------------------------- /test/exec.py: -------------------------------------------------------------------------------- 1 | # Copyright Stefan Seefeld 2006. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | if 1: 6 | number = 42 7 | -------------------------------------------------------------------------------- /doc/numpy/tutorial/index.rst: -------------------------------------------------------------------------------- 1 | Boost.Python NumPy extension Tutorial 2 | ===================================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | simple 8 | dtype 9 | ndarray 10 | ufunc 11 | fromdata 12 | 13 | -------------------------------------------------------------------------------- /test/operators_wrapper.py: -------------------------------------------------------------------------------- 1 | from operators_wrapper_ext import * 2 | 3 | class D2(vector): pass 4 | d2 = D2() 5 | 6 | for lhs in (v,d,d2): 7 | -lhs 8 | for rhs in (v,d,d2): 9 | lhs + rhs 10 | lhs += rhs 11 | 12 | -------------------------------------------------------------------------------- /doc/numpy/reference/index.rst: -------------------------------------------------------------------------------- 1 | Boost.Python NumPy extension Reference 2 | ====================================== 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | dtype 8 | ndarray 9 | unary_ufunc 10 | binary_ufunc 11 | multi_iter 12 | 13 | -------------------------------------------------------------------------------- /doc/reference/objects.qbk: -------------------------------------------------------------------------------- 1 | [chapter Object Wrappers 2 | [quickbook 1.7] 3 | ] 4 | 5 | [include dict.qbk] 6 | [include list.qbk] 7 | [include long.qbk] 8 | [include object.qbk] 9 | [include str.qbk] 10 | [include slice.qbk] 11 | [include tuple.qbk] 12 | -------------------------------------------------------------------------------- /test/polymorphism2_auto_ptr.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2005. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | import polymorphism2 5 | polymorphism2.test() 6 | -------------------------------------------------------------------------------- /doc/reference/utility.qbk: -------------------------------------------------------------------------------- 1 | [chapter Utility and Infrastructure 2 | [quickbook 1.7] 3 | ] 4 | 5 | [include has_back_reference.qbk] 6 | [include instance_holder.qbk] 7 | [include pointee.qbk] 8 | [include handle.qbk] 9 | [include type_id.qbk] 10 | [include ssize_t.qbk] 11 | -------------------------------------------------------------------------------- /test/polymorphism2_auto_ptr.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2005. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #define HELD_BY_AUTO_PTR 6 | #include "polymorphism2.cpp" 7 | -------------------------------------------------------------------------------- /example/quickstart/script.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright Stefan Seefeld 2006. Distributed under the Boost 3 | # Software License, Version 1.0. (See accompanying 4 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | print('Hello World !') 7 | number = 42 8 | -------------------------------------------------------------------------------- /test/minimal.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | print("IMPORTING minimal_ext") 5 | import minimal_ext 6 | print("DONE IMPORTING minimal_ext") 7 | 8 | -------------------------------------------------------------------------------- /doc/reference/conversion.qbk: -------------------------------------------------------------------------------- 1 | [chapter To/From Python Type Conversion 2 | [quickbook 1.7] 3 | ] 4 | 5 | [include extract.qbk] 6 | [include implicit.qbk] 7 | [include lvalue_from_pytype.qbk] 8 | [include opaque_pointer_converter.qbk] 9 | [include to_python_converter.qbk] 10 | [include register_ptr_to_python.qbk] 11 | -------------------------------------------------------------------------------- /example/tutorial/hello.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright Joel de Guzman 2002-2007. Distributed under the Boost 3 | # Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt 4 | # or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | # Hello World Example from the tutorial 6 | 7 | import hello_ext 8 | print(hello_ext.greet()) 9 | -------------------------------------------------------------------------------- /test/object_fail1.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | 7 | int f(boost::python::object const& x) 8 | { 9 | x._("hello") = 1; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/module_init_exception.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2003 Rational Discovery LLC. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy 3 | # at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | print("running...") 6 | 7 | try: 8 | import module_init_exception_ext 9 | except RuntimeError as e: 10 | print(e) 11 | 12 | print("Done.") 13 | -------------------------------------------------------------------------------- /test/simple_type.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2001. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef SIMPLE_TYPE_DWA2001128_HPP 6 | # define SIMPLE_TYPE_DWA2001128_HPP 7 | 8 | struct simple 9 | { 10 | char* s; 11 | }; 12 | 13 | #endif // SIMPLE_TYPE_DWA2001128_HPP 14 | -------------------------------------------------------------------------------- /test/raw_pyobject_fail1.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | 7 | int main() 8 | { 9 | boost::python::converter::arg_to_python x(0); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /doc/release_notes.qbk: -------------------------------------------------------------------------------- 1 | [chapter Release Notes 2 | [quickbook 1.7] 3 | [id rn] 4 | ] 5 | 6 | [section Version 1.67] 7 | 8 | * The Boost.Python library names now contain the Python version suffix. 9 | A variant compiled with Python 2.7 will thus produce library names 10 | `boost_python27` and `boost_numpy27`, etc., making it possible to host 11 | variants for multiple Python versions next to each other. -------------------------------------------------------------------------------- /test/raw_pyobject_fail2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | 7 | struct X : PyObject {}; 8 | 9 | int main() 10 | { 11 | boost::python::converter::arg_to_python x(0); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /test/crossmod_opaque.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Copyright Gottfried Ganßauge 2006. 3 | # Distributed under the Boost Software License, Version 1.0. (See 4 | # accompanying file LICENSE_1_0.txt or copy at 5 | # http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | if __name__ == '__main__': 8 | print("running...") 9 | 10 | import crossmod_opaque_a 11 | import crossmod_opaque_b 12 | 13 | crossmod_opaque_a.get() 14 | crossmod_opaque_b.get() 15 | 16 | print("Done.") 17 | -------------------------------------------------------------------------------- /test/module_init_exception.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2003 Rational Discovery LLC 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | using namespace boost::python; 10 | 11 | BOOST_PYTHON_MODULE(module_init_exception_ext) 12 | { 13 | throw std::runtime_error("Module init failed"); 14 | } 15 | -------------------------------------------------------------------------------- /doc/reference/components.qbk: -------------------------------------------------------------------------------- 1 | [chapter High Level Components 2 | [quickbook 1.7] 3 | ] 4 | 5 | [include class.qbk] 6 | [include def.qbk] 7 | [include def_visitor.qbk] 8 | [include docstring_options.qbk] 9 | [include enum.qbk] 10 | [include errors.qbk] 11 | [include exception_translator.qbk] 12 | [include init.qbk] 13 | [include iterator.qbk] 14 | [include module.qbk] 15 | [include operators.qbk] 16 | [include scope.qbk] 17 | [include stl_iterator.qbk] 18 | [include wrapper.qbk] 19 | -------------------------------------------------------------------------------- /example/tutorial/Jamfile: -------------------------------------------------------------------------------- 1 | # Copyright Stefan Seefeld 2016. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | import python ; 7 | 8 | project tutorial 9 | : requirements 10 | . 11 | ; 12 | 13 | python-extension hello_ext : hello.cpp ; 14 | 15 | run-test hello : hello_ext hello.py ; 16 | 17 | alias test : hello ; 18 | explicit test ; 19 | 20 | -------------------------------------------------------------------------------- /test/as_to_python_function.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | struct hopefully_illegal 9 | { 10 | static PyObject* convert(int&); 11 | }; 12 | 13 | PyObject* x = boost::python::converter::as_to_python_function::convert(0); 14 | -------------------------------------------------------------------------------- /include/boost/python/module.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2001. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef MODULE_DWA2001128_HPP 6 | # define MODULE_DWA2001128_HPP 7 | 8 | # include 9 | 10 | # include 11 | # define BOOST_PYTHON_MODULE BOOST_PYTHON_MODULE_INIT 12 | 13 | #endif // MODULE_DWA20011221_HPP 14 | -------------------------------------------------------------------------------- /include/boost/python/detail/sfinae.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #ifndef SFINAE_DWA2004723_HPP 5 | # define SFINAE_DWA2004723_HPP 6 | 7 | # include 8 | 9 | # if defined(BOOST_NO_SFINAE) && !defined(BOOST_MSVC) 10 | # define BOOST_PYTHON_NO_SFINAE 11 | # endif 12 | 13 | #endif // SFINAE_DWA2004723_HPP 14 | -------------------------------------------------------------------------------- /include/boost/python/overloads.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef OVERLOADS_DWA2002101_HPP 6 | # define OVERLOADS_DWA2002101_HPP 7 | 8 | # include 9 | 10 | # include 11 | # include 12 | 13 | #endif // OVERLOADS_DWA2002101_HPP 14 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | ![logo](https://raw.githubusercontent.com/boostorg/python/develop/doc/images/bpl.png) 2 | 3 | # Examples 4 | 5 | This directory contains various examples using Boost.Python. 6 | You may compile these using the `b2` command either in this directory 7 | or in any of the subdirectories. 8 | You may need to adjust the paths in the Jamroot file if Boost.Python 9 | is not installed in a default location. 10 | See http://boostorg.github.io/python/doc/html/building/no_install_quickstart.html 11 | for details. 12 | -------------------------------------------------------------------------------- /test/crossmod_exception.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2003 Rational Discovery LLC. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy 3 | # at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | print("running...") 6 | 7 | import crossmod_exception_a 8 | import crossmod_exception_b 9 | 10 | try: 11 | crossmod_exception_b.tossit() 12 | except IndexError: 13 | pass 14 | try: 15 | crossmod_exception_a.tossit() 16 | except IndexError: 17 | pass 18 | 19 | print("Done.") 20 | -------------------------------------------------------------------------------- /include/boost/python/detail/is_xxx.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2005. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef IS_XXX_DWA2003224_HPP 6 | # define IS_XXX_DWA2003224_HPP 7 | 8 | # include 9 | 10 | # define BOOST_PYTHON_IS_XXX_DEF(name, qualified_name, nargs) \ 11 | BOOST_DETAIL_IS_XXX_DEF(name, qualified_name, nargs) 12 | 13 | #endif // IS_XXX_DWA2003224_HPP 14 | -------------------------------------------------------------------------------- /include/boost/python/detail/not_specified.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef NOT_SPECIFIED_DWA2002321_HPP 6 | # define NOT_SPECIFIED_DWA2002321_HPP 7 | 8 | namespace boost { namespace python { namespace detail { 9 | 10 | struct not_specified {}; 11 | 12 | }}} // namespace boost::python::detail 13 | 14 | #endif // NOT_SPECIFIED_DWA2002321_HPP 15 | -------------------------------------------------------------------------------- /doc/numpy/index.rst: -------------------------------------------------------------------------------- 1 | .. Boost.Python NumPy extension documentation master file, created by 2 | sphinx-quickstart on Thu Oct 27 09:04:58 2011. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Welcome to the documentation of the Boost.Python NumPy extension! 7 | ================================================================= 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | 12 | Tutorial 13 | Reference 14 | 15 | -------------------------------------------------------------------------------- /include/boost/python/detail/mpl_lambda.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef MPL_LAMBDA_DWA2002122_HPP 6 | # define MPL_LAMBDA_DWA2002122_HPP 7 | 8 | // this header should go away soon 9 | # include 10 | # define BOOST_PYTHON_MPL_LAMBDA_SUPPORT BOOST_MPL_AUX_LAMBDA_SUPPORT 11 | 12 | #endif // MPL_LAMBDA_DWA2002122_HPP 13 | -------------------------------------------------------------------------------- /test/crossmod_exception_a.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2003 Rational Discovery LLC 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | namespace python = boost::python; 9 | 10 | void tossit(){ 11 | PyErr_SetString(PyExc_IndexError,"a-blah!"); 12 | throw python::error_already_set(); 13 | } 14 | 15 | BOOST_PYTHON_MODULE(crossmod_exception_a) 16 | { 17 | python::def("tossit",tossit); 18 | } 19 | -------------------------------------------------------------------------------- /test/crossmod_exception_b.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2003 Rational Discovery LLC 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | 8 | namespace python = boost::python; 9 | 10 | void tossit(){ 11 | PyErr_SetString(PyExc_IndexError,"b-blah!"); 12 | throw python::error_already_set(); 13 | } 14 | 15 | BOOST_PYTHON_MODULE(crossmod_exception_b) 16 | { 17 | python::def("tossit",tossit); 18 | } 19 | -------------------------------------------------------------------------------- /include/boost/python/handle_fwd.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HANDLE_FWD_DWA2002615_HPP 6 | # define HANDLE_FWD_DWA2002615_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { 11 | 12 | template class handle; 13 | 14 | }} // namespace boost::python 15 | 16 | #endif // HANDLE_FWD_DWA2002615_HPP 17 | -------------------------------------------------------------------------------- /test/minimal.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | #include 7 | 8 | #if defined(_AIX) && defined(__EDG_VERSION__) && __EDG_VERSION__ < 245 9 | # include // works around a KCC intermediate code generation bug 10 | #endif 11 | 12 | BOOST_PYTHON_MODULE(minimal_ext) 13 | { 14 | } 15 | 16 | #include "module_tail.cpp" 17 | -------------------------------------------------------------------------------- /include/boost/python/object_fwd.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef OBJECT_FWD_DWA2002724_HPP 6 | # define OBJECT_FWD_DWA2002724_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { 11 | namespace api 12 | { 13 | class object; 14 | } 15 | using api::object; 16 | }} // namespace boost::python 17 | 18 | #endif // OBJECT_FWD_DWA2002724_HPP 19 | -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "python", 3 | "name": "Python", 4 | "authors": [ 5 | "Dave Abrahams" 6 | ], 7 | "description": "The Boost Python Library is a framework for interfacing Python and C++. It allows you to quickly and seamlessly expose C++ classes functions and objects to Python, and vice-versa, using no special tools -- just your C++ compiler.", 8 | "category": [ 9 | "Inter-language" 10 | ], 11 | "maintainers": [ 12 | "Stefan Seefeld " 13 | ], 14 | "cxxstd": "03" 15 | } 16 | -------------------------------------------------------------------------------- /include/boost/python/detail/indirect_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #ifndef INDIRECT_TRAITS_DWA2004915_HPP 5 | # define INDIRECT_TRAITS_DWA2004915_HPP 6 | 7 | # include 8 | 9 | namespace boost { namespace python { 10 | namespace indirect_traits = boost::detail::indirect_traits; 11 | }} // namespace boost::python::detail 12 | 13 | #endif // INDIRECT_TRAITS_DWA2004915_HPP 14 | -------------------------------------------------------------------------------- /include/boost/python/converter/convertible_function.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef CONVERTIBLE_FUNCTION_DWA200278_HPP 6 | # define CONVERTIBLE_FUNCTION_DWA200278_HPP 7 | 8 | namespace boost { namespace python { namespace converter { 9 | 10 | typedef void* (*convertible_function)(PyObject*); 11 | 12 | }}} // namespace boost::python::converter 13 | 14 | #endif // CONVERTIBLE_FUNCTION_DWA200278_HPP 15 | -------------------------------------------------------------------------------- /test/int_map_indexing_suite.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | 8 | void int_map_indexing_suite() 9 | { 10 | using namespace boost::python; 11 | 12 | // Compile check only... 13 | class_ >("IntMap") 14 | .def(map_indexing_suite >()) 15 | ; 16 | } 17 | -------------------------------------------------------------------------------- /example/tutorial/hello.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Joel de Guzman 2002-2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt 3 | // or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | // Hello World Example from the tutorial 5 | // [Joel de Guzman 10/9/2002] 6 | 7 | #include 8 | #include 9 | 10 | char const* greet() 11 | { 12 | return "hello, world"; 13 | } 14 | 15 | BOOST_PYTHON_MODULE(hello_ext) 16 | { 17 | using namespace boost::python; 18 | def("greet", greet); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /include/boost/python/import.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Stefan Seefeld 2005. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef IMPORT_SS20050624_HPP 6 | # define IMPORT_SS20050624_HPP 7 | 8 | # include 9 | # include 10 | 11 | namespace boost 12 | { 13 | namespace python 14 | { 15 | 16 | // Import the named module and return a reference to it. 17 | object BOOST_PYTHON_DECL import(str name); 18 | 19 | } 20 | } 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /include/boost/python/detail/api_placeholder.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | // DEPRECATED HEADER (2006 Jan 12) 7 | // Provided only for backward compatibility. 8 | // The boost::python::len() function is now defined in object.hpp. 9 | 10 | #ifndef BOOST_PYTHON_API_PLACE_HOLDER_HPP 11 | #define BOOST_PYTHON_API_PLACE_HOLDER_HPP 12 | 13 | #include 14 | 15 | #endif // BOOST_PYTHON_API_PLACE_HOLDER_HPP 16 | -------------------------------------------------------------------------------- /include/boost/python/detail/scope.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef SCOPE_DWA2002927_HPP 6 | # define SCOPE_DWA2002927_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { namespace detail { 11 | 12 | void BOOST_PYTHON_DECL scope_setattr_doc(char const* name, object const& obj, char const* doc); 13 | 14 | }}} // namespace boost::python::detail 15 | 16 | #endif // SCOPE_DWA2002927_HPP 17 | -------------------------------------------------------------------------------- /test/bienstman2.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> import bienstman2_ext 6 | ''' 7 | def run(args = None): 8 | import sys 9 | import doctest 10 | 11 | if args is not None: 12 | sys.argv = args 13 | return doctest.testmod(sys.modules.get(__name__)) 14 | 15 | if __name__ == '__main__': 16 | print("running...") 17 | import sys 18 | status = run()[0] 19 | if (status == 0): print("Done.") 20 | sys.exit(status) 21 | -------------------------------------------------------------------------------- /test/shared_ptr.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Copyright Stefan Seefeld 2016. 3 | // Distributed under the Boost Software License, Version 1.0. (See 4 | // accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using std::shared_ptr; 15 | #define MODULE shared_ptr_ext 16 | 17 | #include "shared_ptr.hpp" 18 | #include "module_tail.cpp" 19 | 20 | -------------------------------------------------------------------------------- /include/boost/python/object/life_support.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef LIFE_SUPPORT_DWA200222_HPP 6 | # define LIFE_SUPPORT_DWA200222_HPP 7 | # include 8 | 9 | namespace boost { namespace python { namespace objects { 10 | 11 | BOOST_PYTHON_DECL PyObject* make_nurse_and_patient(PyObject* nurse, PyObject* patient); 12 | 13 | }}} // namespace boost::python::object 14 | 15 | #endif // LIFE_SUPPORT_DWA200222_HPP 16 | -------------------------------------------------------------------------------- /include/boost/python/object/value_holder_fwd.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef VALUE_HOLDER_FWD_DWA2002311_HPP 6 | # define VALUE_HOLDER_FWD_DWA2002311_HPP 7 | 8 | namespace boost { namespace python { namespace objects { 9 | 10 | struct no_back_reference; 11 | 12 | template struct value_holder_generator; 13 | 14 | }}} // namespace boost::python::object 15 | 16 | #endif // VALUE_HOLDER_FWD_DWA2002311_HPP 17 | -------------------------------------------------------------------------------- /doc/index.qbk: -------------------------------------------------------------------------------- 1 | [library Boost.Python 2 | [quickbook 1.3] 3 | [authors [Abrahams, David], [Seefeld, Stefan]] 4 | [copyright 2002 2003 2004 2005 2015 David Abrahams, Stefan Seefeld] 5 | [category inter-language support] 6 | [id python] 7 | [purpose 8 | Reflects C++ classes and functions into Python 9 | ] 10 | [license 11 | Distributed under the Boost Software License, Version 1.0. 12 | (See accompanying file LICENSE_1_0.txt or copy at 13 | [@http://www.boost.org/LICENSE_1_0.txt]) 14 | ] 15 | ] 16 | 17 | [/ QuickBook Document version 1.3 ] 18 | 19 | [include preface.qbk] 20 | -------------------------------------------------------------------------------- /include/boost/python/tag.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef TAG_DWA2002720_HPP 6 | # define TAG_DWA2002720_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { 11 | 12 | // used only to prevent argument-dependent lookup from finding the 13 | // wrong function in some cases. Cheaper than qualification. 14 | enum tag_t { tag }; 15 | 16 | }} // namespace boost::python 17 | 18 | #endif // TAG_DWA2002720_HPP 19 | -------------------------------------------------------------------------------- /test/upcast.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | 9 | struct X { long x; }; 10 | struct Y : X, PyObject {}; 11 | 12 | int main() 13 | { 14 | PyTypeObject o; 15 | Y y; 16 | BOOST_TEST(boost::python::upcast(&o) == reinterpret_cast(&o)); 17 | BOOST_TEST(boost::python::upcast(&y) == &y); 18 | return boost::report_errors(); 19 | } 20 | -------------------------------------------------------------------------------- /test/ben_scott1.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | # This regression test checks that call_method(...) where T is a 5 | # non-reference, non-pointer type that happens to be held inside the 6 | # result object (and thus is found as an lvalue) works. 7 | from ben_scott1_ext import * 8 | 9 | class CreatorImpl(Creator): 10 | def create(self): 11 | return Product() 12 | 13 | factory = Factory() 14 | c = CreatorImpl() 15 | factory.reg(c) 16 | 17 | a = factory.create() 18 | -------------------------------------------------------------------------------- /include/boost/python/detail/dealloc.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Gottfried Ganßauge 2003. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | # ifndef BOOST_PYTHON_DETAIL_DEALLOC_HPP_ 7 | # define BOOST_PYTHON_DETAIL_DEALLOC_HPP_ 8 | namespace boost { namespace python { namespace detail { 9 | extern "C" 10 | { 11 | inline void dealloc(PyObject* self) 12 | { 13 | PyObject_Del(self); 14 | } 15 | } 16 | }}} // namespace boost::python::detail 17 | # endif // BOOST_PYTHON_DETAIL_DEALLOC_HPP_ 18 | -------------------------------------------------------------------------------- /test/bienstman5.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | 13 | struct M {M(const std::complex&) {} }; 14 | 15 | BOOST_PYTHON_MODULE(bienstman5_ext) 16 | { 17 | using namespace boost::python; 18 | 19 | class_("M", init const&>()) 20 | ; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /include/boost/python/object/iterator_core.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef ITERATOR_CORE_DWA2002512_HPP 6 | # define ITERATOR_CORE_DWA2002512_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { namespace objects { 11 | 12 | BOOST_PYTHON_DECL object const& identity_function(); 13 | BOOST_PYTHON_DECL void stop_iteration_error(); 14 | 15 | }}} // namespace boost::python::object 16 | 17 | #endif // ITERATOR_CORE_DWA2002512_HPP 18 | -------------------------------------------------------------------------------- /test/bienstman5.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from bienstman5_ext import * 6 | >>> m = M(1j) 7 | ''' 8 | def run(args = None): 9 | import sys 10 | import doctest 11 | 12 | if args is not None: 13 | sys.argv = args 14 | return doctest.testmod(sys.modules.get(__name__)) 15 | 16 | if __name__ == '__main__': 17 | print("running...") 18 | import sys 19 | status = run()[0] 20 | if (status == 0): print("Done.") 21 | sys.exit(status) 22 | -------------------------------------------------------------------------------- /test/numpy/shapes.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright Jim Bosch & Ankit Daftery 2010-2012. 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (See accompanying file LICENSE_1_0.txt or copy at 6 | # http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | import shapes_ext 9 | import unittest 10 | import numpy 11 | 12 | class TestShapes(unittest.TestCase): 13 | 14 | def testShapes(self): 15 | a1 = numpy.array([(0,1),(2,3)]) 16 | a1_shape = (1,4) 17 | a1 = shapes_ext.reshape(a1,a1_shape) 18 | self.assertEqual(a1_shape,a1.shape) 19 | 20 | if __name__=="__main__": 21 | unittest.main() 22 | -------------------------------------------------------------------------------- /test/boost_shared_ptr.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Copyright Stefan Seefeld 2016. 3 | // Distributed under the Boost Software License, Version 1.0. (See 4 | // accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using boost::shared_ptr; 16 | #define MODULE boost_shared_ptr_ext 17 | 18 | #include "shared_ptr.hpp" 19 | #include "module_tail.cpp" 20 | 21 | -------------------------------------------------------------------------------- /test/class.cpp: -------------------------------------------------------------------------------- 1 | // Distributed under the Boost Software License, Version 1.0. (See 2 | // accompanying file LICENSE_1_0.txt or copy at 3 | // http://www.boost.org/LICENSE_1_0.txt) 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace boost::python; 10 | 11 | struct X 12 | { 13 | int x; 14 | X(int n) : x(n) { } 15 | }; 16 | 17 | int x_function(X& x) 18 | { return x.x; 19 | } 20 | 21 | 22 | BOOST_PYTHON_MODULE(class_ext) 23 | { 24 | class_("X", init()); 25 | def("x_function", x_function); 26 | } 27 | 28 | #include "module_tail.cpp" 29 | -------------------------------------------------------------------------------- /test/numpy/shapes.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Jim Bosch & Ankit Daftery 2010-2012. 2 | // Copyright Stefan Seefeld 2016. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #include 8 | 9 | namespace p = boost::python; 10 | namespace np = boost::python::numpy; 11 | 12 | np::ndarray reshape(np::ndarray old_array, p::tuple shape) 13 | { 14 | np::ndarray local_shape = old_array.reshape(shape); 15 | return local_shape; 16 | } 17 | 18 | BOOST_PYTHON_MODULE(shapes_ext) 19 | { 20 | np::initialize(); 21 | p::def("reshape", reshape); 22 | } 23 | -------------------------------------------------------------------------------- /include/boost/python/borrowed.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BORROWED_DWA2002614_HPP 6 | # define BORROWED_DWA2002614_HPP 7 | 8 | # include 9 | # include 10 | 11 | namespace boost { namespace python { 12 | 13 | template 14 | inline python::detail::borrowed* borrowed(T* p) 15 | { 16 | return (detail::borrowed*)p; 17 | } 18 | 19 | }} // namespace boost::python 20 | 21 | #endif // BORROWED_DWA2002614_HPP 22 | -------------------------------------------------------------------------------- /include/boost/python/detail/def_helper_fwd.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2003. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef DEF_HELPER_FWD_DWA2003810_HPP 6 | # define DEF_HELPER_FWD_DWA2003810_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { namespace detail { 11 | 12 | template 13 | struct def_helper; 14 | 15 | }}} // namespace boost::python::detail 16 | 17 | #endif // DEF_HELPER_FWD_DWA2003810_HPP 18 | -------------------------------------------------------------------------------- /test/const_argument.py: -------------------------------------------------------------------------------- 1 | # Copyright Jonathan Brandmeyer, 2004. Distributed under the Boost 2 | # Software License, Version 1.0 (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | """ 5 | >>> from const_argument_ext import * 6 | >>> accept_const_arg(1) 7 | 1 8 | """ 9 | 10 | def run(args = None): 11 | import sys 12 | import doctest 13 | 14 | if args is not None: 15 | sys.argv = args 16 | return doctest.testmod(sys.modules.get(__name__)) 17 | 18 | if __name__ == '__main__': 19 | print("running...") 20 | import sys 21 | status = run()[0] 22 | if (status == 0): print("Done.") 23 | sys.exit(status) 24 | -------------------------------------------------------------------------------- /include/boost/python/detail/force_instantiate.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef FORCE_INSTANTIATE_DWA200265_HPP 6 | # define FORCE_INSTANTIATE_DWA200265_HPP 7 | 8 | namespace boost { namespace python { namespace detail { 9 | 10 | // Allows us to force the argument to be instantiated without 11 | // incurring unused variable warnings 12 | 13 | template 14 | inline void force_instantiate(T const&) {} 15 | 16 | }}} // namespace boost::python::detail 17 | 18 | #endif // FORCE_INSTANTIATE_DWA200265_HPP 19 | -------------------------------------------------------------------------------- /include/boost/python/detail/decref_guard.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef DECREF_GUARD_DWA20021220_HPP 6 | # define DECREF_GUARD_DWA20021220_HPP 7 | 8 | namespace boost { namespace python { namespace detail { 9 | 10 | struct decref_guard 11 | { 12 | decref_guard(PyObject* o) : obj(o) {} 13 | ~decref_guard() { Py_XDECREF(obj); } 14 | void cancel() { obj = 0; } 15 | private: 16 | PyObject* obj; 17 | }; 18 | 19 | }}} // namespace boost::python::detail 20 | 21 | #endif // DECREF_GUARD_DWA20021220_HPP 22 | -------------------------------------------------------------------------------- /test/bienstman3.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #include 5 | #include 6 | #include 7 | 8 | struct V 9 | { 10 | virtual ~V() {}; // silence compiler warningsa 11 | virtual void f() = 0; 12 | }; 13 | 14 | struct B 15 | { 16 | B(const V&) {} 17 | }; 18 | 19 | BOOST_PYTHON_MODULE(bienstman3_ext) 20 | { 21 | using namespace boost::python; 22 | 23 | class_("V", no_init); 24 | class_("B", init()); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /test/bienstman4.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from bienstman4_ext import * 6 | >>> t1 = T1() 7 | >>> e = Expression() 8 | >>> e.add(t1) 9 | ''' 10 | def run(args = None): 11 | import sys 12 | import doctest 13 | 14 | if args is not None: 15 | sys.argv = args 16 | return doctest.testmod(sys.modules.get(__name__)) 17 | 18 | if __name__ == '__main__': 19 | print("running...") 20 | import sys 21 | status = run()[0] 22 | if (status == 0): print("Done.") 23 | sys.exit(status) 24 | -------------------------------------------------------------------------------- /test/multi_arg_constructor.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from multi_arg_constructor_ext import * 6 | >>> a = A(1.0, 2, 3, 4, 5, 6, 7.0, 8.1, 9.3) 7 | ''' 8 | def run(args = None): 9 | import sys 10 | import doctest 11 | 12 | if args is not None: 13 | sys.argv = args 14 | return doctest.testmod(sys.modules.get(__name__)) 15 | 16 | if __name__ == '__main__': 17 | print("running...") 18 | import sys 19 | status = run()[0] 20 | if (status == 0): print("Done.") 21 | sys.exit(status) 22 | -------------------------------------------------------------------------------- /include/boost/python/detail/none.hpp: -------------------------------------------------------------------------------- 1 | // (C) Copyright David Abrahams 2000. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | // 6 | // The author gratefully acknowleges the support of Dragon Systems, Inc., in 7 | // producing this work. 8 | 9 | #ifndef NONE_DWA_052000_H_ 10 | # define NONE_DWA_052000_H_ 11 | 12 | # include 13 | 14 | namespace boost { namespace python { namespace detail { 15 | 16 | inline PyObject* none() { Py_INCREF(Py_None); return Py_None; } 17 | 18 | }}} // namespace boost::python::detail 19 | 20 | #endif // NONE_DWA_052000_H_ 21 | -------------------------------------------------------------------------------- /include/boost/python/detail/copy_ctor_mutates_rhs.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2003. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COPY_CTOR_MUTATES_RHS_DWA2003219_HPP 6 | # define COPY_CTOR_MUTATES_RHS_DWA2003219_HPP 7 | 8 | #include 9 | #include 10 | 11 | namespace boost { namespace python { namespace detail { 12 | 13 | template 14 | struct copy_ctor_mutates_rhs 15 | : is_auto_ptr 16 | { 17 | }; 18 | 19 | }}} // namespace boost::python::detail 20 | 21 | #endif // COPY_CTOR_MUTATES_RHS_DWA2003219_HPP 22 | -------------------------------------------------------------------------------- /include/boost/python/detail/prefix.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2003. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef PREFIX_DWA2003531_HPP 6 | # define PREFIX_DWA2003531_HPP 7 | 8 | // The rule is that must be included before any system 9 | // headers (so it can get control over some awful macros). 10 | // Unfortunately, Boost.Python needs to #include first, at 11 | // least... but this gets us as close as possible. 12 | 13 | # include 14 | # include 15 | 16 | #endif // PREFIX_DWA2003531_HPP 17 | -------------------------------------------------------------------------------- /include/boost/python/detail/overloads_fwd.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef OVERLOADS_FWD_DWA2002101_HPP 6 | # define OVERLOADS_FWD_DWA2002101_HPP 7 | 8 | namespace boost { namespace python { namespace detail { 9 | 10 | // forward declarations 11 | struct overloads_base; 12 | 13 | template 14 | inline void define_with_defaults(char const* name, OverloadsT const&, NameSpaceT&, SigT const&); 15 | 16 | }}} // namespace boost::python::detail 17 | 18 | #endif // OVERLOADS_FWD_DWA2002101_HPP 19 | -------------------------------------------------------------------------------- /include/boost/python/object/inheritance_query.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2003. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef INHERITANCE_QUERY_DWA2003520_HPP 6 | # define INHERITANCE_QUERY_DWA2003520_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { namespace objects { 11 | 12 | BOOST_PYTHON_DECL void* find_static_type(void* p, type_info src, type_info dst); 13 | BOOST_PYTHON_DECL void* find_dynamic_type(void* p, type_info src, type_info dst); 14 | 15 | }}} // namespace boost::python::object 16 | 17 | #endif // INHERITANCE_QUERY_DWA2003520_HPP 18 | -------------------------------------------------------------------------------- /test/enable_shared_from_this.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from enable_shared_from_this_ext import * 6 | 7 | >>> x = Test.construct() 8 | >>> x.take(x) 9 | >>> x.act() 10 | ''' 11 | 12 | def run(args = None): 13 | import sys 14 | import doctest 15 | 16 | if args is not None: 17 | sys.argv = args 18 | return doctest.testmod(sys.modules.get(__name__)) 19 | 20 | if __name__ == '__main__': 21 | print("running...") 22 | import sys 23 | status = run()[0] 24 | if (status == 0): print("Done.") 25 | sys.exit(status) 26 | 27 | -------------------------------------------------------------------------------- /include/boost/python/converter/context_result_converter.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2003. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef CONTEXT_RESULT_CONVERTER_DWA2003917_HPP 6 | # define CONTEXT_RESULT_CONVERTER_DWA2003917_HPP 7 | 8 | namespace boost { namespace python { namespace converter { 9 | 10 | // A ResultConverter base class used to indicate that this result 11 | // converter should be constructed with the original Python argument 12 | // list. 13 | struct context_result_converter {}; 14 | 15 | }}} // namespace boost::python::converter 16 | 17 | #endif // CONTEXT_RESULT_CONVERTER_DWA2003917_HPP 18 | -------------------------------------------------------------------------------- /include/boost/python/converter/shared_ptr_deleter.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef SHARED_PTR_DELETER_DWA2002121_HPP 6 | # define SHARED_PTR_DELETER_DWA2002121_HPP 7 | 8 | namespace boost { namespace python { namespace converter { 9 | 10 | struct BOOST_PYTHON_DECL shared_ptr_deleter 11 | { 12 | shared_ptr_deleter(handle<> owner); 13 | ~shared_ptr_deleter(); 14 | 15 | void operator()(void const*); 16 | 17 | handle<> owner; 18 | }; 19 | 20 | }}} // namespace boost::python::converter 21 | 22 | #endif // SHARED_PTR_DELETER_DWA2002121_HPP 23 | -------------------------------------------------------------------------------- /test/andreas_beyer.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from andreas_beyer_ext import * 6 | >>> b=B() 7 | >>> a=b.get() # let b create an A 8 | >>> a2=b.get() 9 | >>> assert id(a) == id(a2) 10 | ''' 11 | def run(args = None): 12 | import sys 13 | import doctest 14 | 15 | if args is not None: 16 | sys.argv = args 17 | return doctest.testmod(sys.modules.get(__name__)) 18 | 19 | if __name__ == '__main__': 20 | print("running...") 21 | import sys 22 | status = run()[0] 23 | if (status == 0): print("Done.") 24 | sys.exit(status) 25 | -------------------------------------------------------------------------------- /include/boost/python/object/class_detail.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef CLASS_DETAIL_DWA200295_HPP 6 | # define CLASS_DETAIL_DWA200295_HPP 7 | 8 | # include 9 | # include 10 | 11 | namespace boost { namespace python { namespace objects { 12 | 13 | BOOST_PYTHON_DECL type_handle registered_class_object(type_info id); 14 | BOOST_PYTHON_DECL type_handle class_metatype(); 15 | BOOST_PYTHON_DECL type_handle class_type(); 16 | 17 | }}} // namespace boost::python::object 18 | 19 | #endif // CLASS_DETAIL_DWA200295_HPP 20 | -------------------------------------------------------------------------------- /doc/numpy/_static/style.css: -------------------------------------------------------------------------------- 1 | @import url(boost.css); 2 | 3 | .header h1 a 4 | { 5 | color: #00507f; 6 | font-size: 200%; 7 | font-style: italic; 8 | } 9 | .header h3 { margin: 1px;} 10 | #contents 11 | { 12 | /* border-bottom: solid thin black;*/ 13 | } 14 | 15 | .highlight 16 | { 17 | border: 1px solid #dcdcdc; 18 | background-color: inherit; 19 | padding: 0 1em; 20 | margin: 0 5em; 21 | } 22 | #searchbox 23 | { 24 | float: right; 25 | width: auto; 26 | margin: 0 2em; 27 | } 28 | 29 | .admonition-title { font-weight: bold;} 30 | .toctree-wrapper 31 | { 32 | border: 1px solid #dcdcdc; 33 | padding: 1em; 34 | margin: 0 2em; 35 | } 36 | .toctree-wrapper .caption, 37 | .toctree-wrapper .topic-title { font-weight: bold;} 38 | 39 | -------------------------------------------------------------------------------- /test/injected.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from injected_ext import * 6 | >>> X(3,5).value() - (3+5) 7 | 0 8 | >>> X(a=3,b=5,c=7).value() - (3*5*7) 9 | 0 10 | >>> X().value() 11 | 1000 12 | ''' 13 | 14 | def run(args = None): 15 | import sys 16 | import doctest 17 | 18 | if args is not None: 19 | sys.argv = args 20 | return doctest.testmod(sys.modules.get(__name__)) 21 | 22 | if __name__ == '__main__': 23 | print("running...") 24 | import sys 25 | status = run()[0] 26 | if (status == 0): print("Done.") 27 | sys.exit(status) 28 | 29 | -------------------------------------------------------------------------------- /test/bienstman1.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | # Try to reproduce a Numeric interaction bug if Numeric is installed. 6 | >>> from bienstman1_ext import * 7 | >>> try: from Numeric import * 8 | ... except: pass 9 | ''' 10 | def run(args = None): 11 | import sys 12 | import doctest 13 | 14 | if args is not None: 15 | sys.argv = args 16 | return doctest.testmod(sys.modules.get(__name__)) 17 | 18 | if __name__ == '__main__': 19 | print("running...") 20 | import sys 21 | status = run()[0] 22 | if (status == 0): print("Done.") 23 | sys.exit(status) 24 | -------------------------------------------------------------------------------- /test/copy_ctor_mutates_rhs.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2003. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | struct foo 11 | { 12 | operator std::shared_ptr&() const; 13 | }; 14 | 15 | int main() 16 | { 17 | using namespace boost::python::detail; 18 | BOOST_STATIC_ASSERT(!copy_ctor_mutates_rhs::value); 19 | BOOST_STATIC_ASSERT(!copy_ctor_mutates_rhs::value); 20 | BOOST_STATIC_ASSERT(!copy_ctor_mutates_rhs::value); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /include/boost/python/converter/constructor_function.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef CONSTRUCTOR_FUNCTION_DWA200278_HPP 6 | # define CONSTRUCTOR_FUNCTION_DWA200278_HPP 7 | 8 | namespace boost { namespace python { namespace converter { 9 | 10 | // Declares the type of functions used to construct C++ objects for 11 | // rvalue from_python conversions. 12 | struct rvalue_from_python_stage1_data; 13 | typedef void (*constructor_function)(PyObject* source, rvalue_from_python_stage1_data*); 14 | 15 | }}} // namespace boost::python::converter 16 | 17 | #endif // CONSTRUCTOR_FUNCTION_DWA200278_HPP 18 | -------------------------------------------------------------------------------- /doc/images/callouts/1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /doc/reference.qbk: -------------------------------------------------------------------------------- 1 | [book Boost.Python Reference Manual 2 | [quickbook 1.6] 3 | [authors [Abrahams, David], [Seefeld, Stefan]] 4 | [copyright 2002 2003 2004 2005 2015 David Abrahams, Stefan Seefeld] 5 | [id reference] 6 | [license 7 | Distributed under the Boost Software License, Version 1.0. 8 | (See accompanying file LICENSE_1_0.txt or copy at 9 | [@http://www.boost.org/LICENSE_1_0.txt] 10 | ] 11 | ] 12 | 13 | [include reference/concepts.qbk] 14 | [include reference/components.qbk] 15 | [include reference/objects.qbk] 16 | [include reference/functions.qbk] 17 | [include reference/conversion.qbk] 18 | [include reference/embedding.qbk] 19 | [include reference/utility.qbk] 20 | [include reference/topics.qbk] 21 | [include glossary.qbk] 22 | -------------------------------------------------------------------------------- /test/module_nogil.cpp: -------------------------------------------------------------------------------- 1 | // Test for BOOST_PYTHON_MODULE with optional mod_gil_not_used argument 2 | 3 | #include 4 | #include 5 | 6 | // Simple function to export 7 | int get_value() { 8 | return 1234; 9 | } 10 | 11 | #if defined(HAS_CXX11) && (PY_VERSION_HEX >= 0x03000000) 12 | // C++11 build with Python 3: test with mod_gil_not_used option 13 | BOOST_PYTHON_MODULE(module_nogil_ext, boost::python::mod_gil_not_used()) 14 | { 15 | using namespace boost::python; 16 | def("get_value", get_value); 17 | } 18 | #else 19 | // C++98 build or Python 2: test without optional arguments 20 | BOOST_PYTHON_MODULE(module_nogil_ext) 21 | { 22 | using namespace boost::python; 23 | def("get_value", get_value); 24 | } 25 | #endif 26 | -------------------------------------------------------------------------------- /test/pointer_vector.py: -------------------------------------------------------------------------------- 1 | # Copyright Joel de Guzman 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | 6 | >>> import pointer_vector_ext 7 | >>> d = pointer_vector_ext.DoesSomething() 8 | >>> lst = d.returnList() 9 | >>> lst[0].f(); 10 | 'harru' 11 | 12 | ''' 13 | 14 | 15 | def run(args = None): 16 | import sys 17 | import doctest 18 | 19 | if args is not None: 20 | sys.argv = args 21 | return doctest.testmod(sys.modules.get(__name__)) 22 | 23 | if __name__ == '__main__': 24 | print('running...') 25 | import sys 26 | status = run()[0] 27 | if (status == 0): print("Done.") 28 | sys.exit(status) 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /doc/html/images/callouts/1.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/exception_translator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #include 5 | #include 6 | #include 7 | 8 | struct error {}; 9 | 10 | void translate(error const& /*e*/) 11 | { 12 | PyErr_SetString(PyExc_RuntimeError, "!!!error!!!"); 13 | } 14 | 15 | void throw_error() 16 | { 17 | throw error(); 18 | 19 | } 20 | 21 | BOOST_PYTHON_MODULE(exception_translator_ext) 22 | { 23 | using namespace boost::python; 24 | register_exception_translator(&translate); 25 | 26 | def("throw_error", throw_error); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /test/module_nogil.py: -------------------------------------------------------------------------------- 1 | """ 2 | >>> from module_nogil_ext import * 3 | >>> get_value() 4 | 1234 5 | >>> import sys, sysconfig 6 | >>> Py_GIL_DISABLED = bool(sysconfig.get_config_var('Py_GIL_DISABLED')) 7 | >>> if Py_GIL_DISABLED and sys._is_gil_enabled(): 8 | ... print('GIL is enabled and should not be') 9 | ... else: 10 | ... print('okay') 11 | okay 12 | """ 13 | 14 | from __future__ import print_function 15 | 16 | def run(args = None): 17 | import sys 18 | import doctest 19 | 20 | if args is not None: 21 | sys.argv = args 22 | return doctest.testmod(sys.modules.get(__name__)) 23 | 24 | if __name__ == '__main__': 25 | print("running...") 26 | import sys 27 | status = run()[0] 28 | if (status == 0): print("Done.") 29 | sys.exit(status) 30 | -------------------------------------------------------------------------------- /include/boost/python/has_back_reference.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef HAS_BACK_REFERENCE_DWA2002323_HPP 6 | # define HAS_BACK_REFERENCE_DWA2002323_HPP 7 | 8 | # include 9 | # include 10 | 11 | namespace boost { namespace python { 12 | 13 | // traits class which users can specialize to indicate that a class 14 | // contains a back-reference to its owning PyObject* 15 | template 16 | struct has_back_reference 17 | : mpl::false_ 18 | { 19 | }; 20 | 21 | 22 | }} // namespace boost::python 23 | 24 | #endif // HAS_BACK_REFERENCE_DWA2002323_HPP 25 | -------------------------------------------------------------------------------- /include/boost/python/converter/arg_to_python_base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef ARG_TO_PYTHON_BASE_DWA200237_HPP 6 | # define ARG_TO_PYTHON_BASE_DWA200237_HPP 7 | # include 8 | 9 | namespace boost { namespace python { namespace converter { 10 | 11 | struct registration; 12 | 13 | namespace detail 14 | { 15 | struct BOOST_PYTHON_DECL arg_to_python_base 16 | : handle<> 17 | { 18 | arg_to_python_base(void const volatile* source, registration const&); 19 | }; 20 | } 21 | 22 | }}} // namespace boost::python::converter 23 | 24 | #endif // ARG_TO_PYTHON_BASE_DWA200237_HPP 25 | -------------------------------------------------------------------------------- /src/import.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Stefan Seefeld 2005. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace boost 12 | { 13 | namespace python 14 | { 15 | 16 | object BOOST_PYTHON_DECL import(str name) 17 | { 18 | // should be 'char const *' but older python versions don't use 'const' yet. 19 | char *n = python::extract(name); 20 | python::handle<> module(PyImport_ImportModule(n)); 21 | return python::object(module); 22 | } 23 | 24 | } // namespace boost::python 25 | } // namespace boost 26 | -------------------------------------------------------------------------------- /include/boost/python/return_value_policy.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef RETURN_VALUE_POLICY_DWA2002131_HPP 6 | # define RETURN_VALUE_POLICY_DWA2002131_HPP 7 | 8 | # include 9 | # include 10 | 11 | namespace boost { namespace python { 12 | 13 | template 14 | struct return_value_policy : BasePolicy_ 15 | { 16 | typedef ResultConverterGenerator result_converter; 17 | }; 18 | 19 | }} // namespace boost::python 20 | 21 | #endif // RETURN_VALUE_POLICY_DWA2002131_HPP 22 | -------------------------------------------------------------------------------- /test/bienstman2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #include 5 | #include 6 | #include 7 | 8 | struct C {}; 9 | 10 | struct D {}; 11 | 12 | struct E 13 | { 14 | const D fe (const C&) {return D();} 15 | const D fe2(const C&, const C&) {return D();} 16 | }; 17 | 18 | BOOST_PYTHON_MODULE(bienstman2_ext) 19 | { 20 | using namespace boost::python; 21 | 22 | class_("C"); 23 | class_("D"); 24 | class_("E") 25 | .def("fe", &E::fe) // this compiles. 26 | .def("fe2", &E::fe2) // this doesn't... well, now it does ;-) 27 | ; 28 | } 29 | -------------------------------------------------------------------------------- /test/multi_arg_constructor.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #include 5 | #include 6 | #include 7 | 8 | struct A 9 | { 10 | A(const double, const double, const double, const double, const double 11 | , const double, const double 12 | , const double, const double 13 | ) {} 14 | }; 15 | 16 | BOOST_PYTHON_MODULE(multi_arg_constructor_ext) 17 | { 18 | using namespace boost::python; 19 | 20 | class_( 21 | "A" 22 | , init() 23 | ) 24 | ; 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /doc/images/callouts/7.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /include/boost/python/detail/is_shared_ptr.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2003. 2 | // Copyright Stefan Seefeld 2016. 3 | // Distributed under the Boost Software License, Version 1.0. (See 4 | // accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #ifndef boost_python_detail_is_shared_ptr_hpp_ 8 | #define boost_python_detail_is_shared_ptr_hpp_ 9 | 10 | #include 11 | #include 12 | 13 | namespace boost { namespace python { namespace detail { 14 | 15 | BOOST_PYTHON_IS_XXX_DEF(shared_ptr, shared_ptr, 1) 16 | #if !defined(BOOST_NO_CXX11_SMART_PTR) 17 | template 18 | struct is_shared_ptr > : std::true_type {}; 19 | #endif 20 | 21 | }}} // namespace boost::python::detail 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /doc/html/images/callouts/7.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/exception_translator.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from exception_translator_ext import * 6 | >>> try: 7 | ... throw_error(); 8 | ... except RuntimeError as x: 9 | ... print(x) 10 | ... else: 11 | ... print('Expected a RuntimeError!') 12 | !!!error!!! 13 | ''' 14 | def run(args = None): 15 | import sys 16 | import doctest 17 | 18 | if args is not None: 19 | sys.argv = args 20 | return doctest.testmod(sys.modules.get(__name__)) 21 | 22 | if __name__ == '__main__': 23 | print("running...") 24 | import sys 25 | status = run()[0] 26 | if (status == 0): print("Done.") 27 | sys.exit(status) 28 | -------------------------------------------------------------------------------- /test/crossmod_opaque_a.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Gottfried Ganßauge 2006. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | # include 6 | # include 7 | # include 8 | # include 9 | 10 | typedef struct opaque_ *opaque; 11 | 12 | opaque the_op = ((opaque) 0x47110815); 13 | 14 | opaque get() { return the_op; } 15 | 16 | BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque_) 17 | 18 | namespace bpl = boost::python; 19 | 20 | BOOST_PYTHON_MODULE(crossmod_opaque_a) 21 | { 22 | bpl::def ( 23 | "get", 24 | &::get, 25 | bpl::return_value_policy()); 26 | } 27 | -------------------------------------------------------------------------------- /test/crossmod_opaque_b.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Gottfried Ganßauge 2006. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | # include 6 | # include 7 | # include 8 | # include 9 | 10 | typedef struct opaque_ *opaque; 11 | 12 | opaque the_op = ((opaque) 0x47110815); 13 | 14 | opaque get() { return the_op; } 15 | 16 | BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(opaque_) 17 | 18 | namespace bpl = boost::python; 19 | 20 | BOOST_PYTHON_MODULE(crossmod_opaque_b) 21 | { 22 | bpl::def ( 23 | "get", 24 | &::get, 25 | bpl::return_value_policy()); 26 | } 27 | -------------------------------------------------------------------------------- /test/pytype_function.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | """ 5 | >>> from pytype_function_ext import * 6 | 7 | >>> print(func.__doc__.splitlines()[1]) 8 | func( (A)arg1) -> A : 9 | 10 | >>> print(func.__module__) 11 | pytype_function_ext 12 | 13 | >>> print(func.__name__) 14 | func 15 | """ 16 | def run(args = None): 17 | import sys 18 | import doctest 19 | 20 | if args is not None: 21 | sys.argv = args 22 | return doctest.testmod(sys.modules.get(__name__)) 23 | 24 | if __name__ == '__main__': 25 | print("running...") 26 | import sys 27 | status = run()[0] 28 | if (status == 0): print("Done.") 29 | sys.exit(status) 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /test/bienstman3.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from bienstman3_ext import * 6 | 7 | >>> try: 8 | ... V() 9 | ... except RuntimeError as x: 10 | ... print(x) 11 | ... else: 12 | ... print('expected an exception') 13 | ... 14 | This class cannot be instantiated from Python 15 | 16 | ''' 17 | def run(args = None): 18 | import sys 19 | import doctest 20 | 21 | if args is not None: 22 | sys.argv = args 23 | return doctest.testmod(sys.modules.get(__name__)) 24 | 25 | if __name__ == '__main__': 26 | print("running...") 27 | import sys 28 | status = run()[0] 29 | if (status == 0): print("Done.") 30 | sys.exit(status) 31 | -------------------------------------------------------------------------------- /doc/images/callouts/4.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/html/images/callouts/4.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /include/boost/python/detail/value_arg.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #ifndef VALUE_ARG_DWA2004312_HPP 5 | # define VALUE_ARG_DWA2004312_HPP 6 | 7 | # include 8 | # include 9 | # include 10 | 11 | namespace boost { namespace python { namespace detail { 12 | 13 | template 14 | struct value_arg 15 | : mpl::if_< 16 | copy_ctor_mutates_rhs 17 | , T 18 | , typename add_lvalue_reference< 19 | typename add_const::type 20 | >::type 21 | > 22 | {}; 23 | 24 | }}} // namespace boost::python::detail 25 | 26 | #endif // VALUE_ARG_DWA2004312_HPP 27 | -------------------------------------------------------------------------------- /test/wrapper_held_type.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2005. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from wrapper_held_type_ext import * 6 | >>> d = data() 7 | >>> print(d.id()) 8 | 42 9 | >>> do_nothing( d ) 10 | >>> print(d.id()) 11 | 42 12 | >>> d = create_data() 13 | >>> print(d.id()) 14 | 42 15 | >>> do_nothing( d ) 16 | >>> print(d.id()) 17 | 42 18 | ''' 19 | 20 | def run(args = None): 21 | import sys 22 | import doctest 23 | 24 | if args is not None: 25 | sys.argv = args 26 | return doctest.testmod(sys.modules.get(__name__)) 27 | 28 | if __name__ == '__main__': 29 | print("running...") 30 | import sys 31 | status = run()[0] 32 | if (status == 0): print("Done.") 33 | sys.exit(status) 34 | 35 | -------------------------------------------------------------------------------- /include/boost/python/detail/is_auto_ptr.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2003. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef IS_AUTO_PTR_DWA2003224_HPP 6 | # define IS_AUTO_PTR_DWA2003224_HPP 7 | 8 | # ifndef BOOST_NO_AUTO_PTR 9 | # include 10 | # include 11 | # else 12 | # include 13 | # endif 14 | 15 | namespace boost { namespace python { namespace detail { 16 | 17 | # if !defined(BOOST_NO_AUTO_PTR) 18 | 19 | BOOST_PYTHON_IS_XXX_DEF(auto_ptr, std::auto_ptr, 1) 20 | 21 | # else 22 | 23 | template 24 | struct is_auto_ptr : mpl::false_ 25 | { 26 | }; 27 | 28 | # endif 29 | 30 | }}} // namespace boost::python::detail 31 | 32 | #endif // IS_AUTO_PTR_DWA2003224_HPP 33 | -------------------------------------------------------------------------------- /include/boost/python/detail/unwrap_type_id.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #ifndef UNWRAP_TYPE_ID_DWA2004722_HPP 5 | # define UNWRAP_TYPE_ID_DWA2004722_HPP 6 | 7 | # include 8 | 9 | # include 10 | 11 | namespace boost { namespace python { 12 | 13 | template class wrapper; 14 | 15 | namespace detail { 16 | 17 | template 18 | inline type_info unwrap_type_id(T*, ...) 19 | { 20 | return type_id(); 21 | } 22 | 23 | template 24 | inline type_info unwrap_type_id(U*, wrapper*) 25 | { 26 | return type_id(); 27 | } 28 | 29 | }}} // namespace boost::python::detail 30 | 31 | #endif // UNWRAP_TYPE_ID_DWA2004722_HPP 32 | -------------------------------------------------------------------------------- /test/return_arg.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from return_arg_ext import * 6 | >>> l1=Label() 7 | >>> assert l1 is l1.label("bar") 8 | >>> assert l1 is l1.label("bar").sensitive(0) 9 | >>> assert l1.label("foo").sensitive(0) is l1.sensitive(1).label("bar") 10 | >>> assert return_arg is return_arg(return_arg) 11 | 12 | ''' 13 | 14 | def run(args = None): 15 | import sys 16 | import doctest 17 | 18 | if args is not None: 19 | sys.argv = args 20 | return doctest.testmod(sys.modules.get(__name__)) 21 | 22 | if __name__ == '__main__': 23 | print("running...") 24 | import sys 25 | status = run()[0] 26 | if (status == 0): print("Done.") 27 | sys.exit(status) 28 | -------------------------------------------------------------------------------- /include/boost/python/ssize_t.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Ralf W. Grosse-Kunstleve & David Abrahams 2006. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #ifndef BOOST_PYTHON_SSIZE_T_RWGK20060924_HPP 7 | # define BOOST_PYTHON_SSIZE_T_RWGK20060924_HPP 8 | 9 | # include 10 | 11 | namespace boost { namespace python { 12 | 13 | #if PY_VERSION_HEX >= 0x02050000 14 | 15 | typedef Py_ssize_t ssize_t; 16 | ssize_t const ssize_t_max = PY_SSIZE_T_MAX; 17 | ssize_t const ssize_t_min = PY_SSIZE_T_MIN; 18 | 19 | #else 20 | 21 | typedef int ssize_t; 22 | ssize_t const ssize_t_max = INT_MAX; 23 | ssize_t const ssize_t_min = INT_MIN; 24 | 25 | #endif 26 | 27 | }} // namespace boost::python 28 | 29 | #endif // BOOST_PYTHON_SSIZE_T_RWGK20060924_HPP 30 | -------------------------------------------------------------------------------- /test/register_ptr_test.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | import unittest 5 | from register_ptr import * 6 | 7 | class RegisterPtrTest(unittest.TestCase): 8 | 9 | def testIt(self): 10 | 11 | class B(A): 12 | def f(self): 13 | return 10 14 | 15 | a = New() # this must work 16 | b = B() 17 | self.assertEqual(Call(a), 0) 18 | self.assertEqual(Call(b), 10) 19 | def fails(): 20 | Fail(A()) 21 | self.assertRaises(TypeError, fails) 22 | self.assertEqual(Fail(a), 0) # ok, since a is held by shared_ptr 23 | 24 | if __name__ == '__main__': 25 | unittest.main() 26 | -------------------------------------------------------------------------------- /include/boost/python/converter/to_python_function_type.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP 6 | # define TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP 7 | # include 8 | # include 9 | 10 | namespace boost { namespace python { namespace converter { 11 | 12 | // The type of stored function pointers which actually do conversion 13 | // by-value. The void* points to the object to be converted, and 14 | // type-safety is preserved through runtime registration. 15 | typedef PyObject* (*to_python_function_t)(void const*); 16 | 17 | }}} // namespace boost::python::converter 18 | 19 | #endif // TO_PYTHON_FUNCTION_TYPE_DWA200236_HPP 20 | -------------------------------------------------------------------------------- /include/boost/python/detail/aix_init_module.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef AIX_INIT_MODULE_DWA2002529_HPP 6 | # define AIX_INIT_MODULE_DWA2002529_HPP 7 | # ifdef _AIX 8 | # include 9 | # include 10 | # ifdef __KCC 11 | # include // this works around a problem in KCC 4.0f 12 | # endif 13 | 14 | namespace boost { namespace python { namespace detail { 15 | 16 | extern "C" 17 | { 18 | typedef PyObject* (*so_load_function)(char*,char*,FILE*); 19 | } 20 | 21 | void aix_init_module(so_load_function, char const* name, void (*init_module)()); 22 | 23 | }}} // namespace boost::python::detail 24 | # endif 25 | 26 | #endif // AIX_INIT_MODULE_DWA2002529_HPP 27 | -------------------------------------------------------------------------------- /include/boost/python/return_by_value.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BY_VALUE_DWA20021015_HPP 6 | # define BY_VALUE_DWA20021015_HPP 7 | 8 | # include 9 | 10 | # include 11 | # include 12 | 13 | # include 14 | 15 | namespace boost { namespace python { 16 | 17 | struct return_by_value 18 | { 19 | template 20 | struct apply 21 | { 22 | typedef to_python_value< 23 | typename detail::value_arg::type 24 | > type; 25 | }; 26 | }; 27 | 28 | }} // namespace boost::python 29 | 30 | #endif // BY_VALUE_DWA20021015_HPP 31 | -------------------------------------------------------------------------------- /include/boost/python/class_fwd.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef CLASS_FWD_DWA200222_HPP 6 | # define CLASS_FWD_DWA200222_HPP 7 | 8 | # include 9 | # include 10 | 11 | namespace boost { namespace python { 12 | 13 | template < 14 | class T // class being wrapped 15 | // arbitrarily-ordered optional arguments. Full qualification needed for MSVC6 16 | , class X1 = ::boost::python::detail::not_specified 17 | , class X2 = ::boost::python::detail::not_specified 18 | , class X3 = ::boost::python::detail::not_specified 19 | > 20 | class class_; 21 | 22 | }} // namespace boost::python 23 | 24 | #endif // CLASS_FWD_DWA200222_HPP 25 | -------------------------------------------------------------------------------- /doc/images/callouts/11.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /doc/html/images/callouts/11.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /test/const_argument.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright 2004 Jonathan Brandmeyer 2 | * Use, modification and distribution are subject to the 3 | * Boost Software License, Version 1.0. (See accompanying file 4 | * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 5 | * 6 | * The purpose of this test is to determine if a function can be called from 7 | * Python with a const value type as an argument, and whether or not the 8 | * presence of a prototype without the cv-qualifier will work around the 9 | * compiler's bug. 10 | */ 11 | #include 12 | using namespace boost::python; 13 | 14 | 15 | #if BOOST_WORKAROUND(BOOST_MSVC, == 1200) 16 | bool accept_const_arg( object ); 17 | #endif 18 | 19 | bool accept_const_arg( const object ) 20 | { 21 | return true; 22 | } 23 | 24 | 25 | BOOST_PYTHON_MODULE( const_argument_ext ) 26 | { 27 | def( "accept_const_arg", accept_const_arg ); 28 | } 29 | -------------------------------------------------------------------------------- /test/long.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from long_ext import * 6 | >>> print(new_long()) 7 | 0 8 | >>> print(longify(42)) 9 | 42 10 | >>> print(longify_string('300')) 11 | 300 12 | >>> is_long(long(20)) 13 | 'yes' 14 | >>> is_long('20') 15 | 0 16 | 17 | >>> x = Y(long(4294967295)) 18 | ''' 19 | 20 | import sys 21 | if (sys.version_info.major >= 3): 22 | long = int 23 | 24 | def run(args = None): 25 | import sys 26 | import doctest 27 | 28 | if args is not None: 29 | sys.argv = args 30 | return doctest.testmod(sys.modules.get(__name__)) 31 | 32 | if __name__ == '__main__': 33 | print("running...") 34 | import sys 35 | status = run()[0] 36 | if (status == 0): print("Done.") 37 | sys.exit(status) 38 | -------------------------------------------------------------------------------- /include/boost/python/object_call.hpp: -------------------------------------------------------------------------------- 1 | # if !defined(BOOST_PYTHON_SYNOPSIS) 2 | # // Copyright David Abrahams 2002. 3 | # // Distributed under the Boost Software License, Version 1.0. (See 4 | # // accompanying file LICENSE_1_0.txt or copy at 5 | # // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | # if !defined(BOOST_PP_IS_ITERATING) 8 | # error Boost.Python - do not include this file! 9 | # endif 10 | 11 | # define N BOOST_PP_ITERATION() 12 | 13 | template 14 | typename detail::dependent::type 15 | operator()(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)) const 16 | { 17 | typedef typename detail::dependent::type obj; 18 | U const& self = *static_cast(this); 19 | return call(get_managed_object(self, tag), BOOST_PP_ENUM_PARAMS_Z(1, N, a)); 20 | } 21 | 22 | # undef N 23 | # endif // BOOST_PYTHON_SYNOPSIS 24 | -------------------------------------------------------------------------------- /example/Jamroot: -------------------------------------------------------------------------------- 1 | # Copyright Stefan Seefeld 2016. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | import python ; 7 | 8 | if ! [ python.configured ] 9 | { 10 | ECHO "warning: no Python configured in user-config.jam" ; 11 | ECHO "warning: will use default configuration" ; 12 | using python ; 13 | } 14 | 15 | # Adjust the following if Boost.Python isn't installed in a default location 16 | lib boost_python ; 17 | 18 | project 19 | : requirements 20 | # /path/to/boost/python 21 | boost_python 22 | ; 23 | 24 | rule run-test ( test-name : sources + ) 25 | { 26 | import testing ; 27 | testing.make-test run-pyd : $(sources) : : $(test-name) ; 28 | } 29 | 30 | build-project quickstart ; 31 | build-project tutorial ; 32 | if [ python.numpy ] 33 | { 34 | build-project numpy ; 35 | } 36 | -------------------------------------------------------------------------------- /src/numpy/numpy.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Jim Bosch 2010-2012. 2 | // Copyright Stefan Seefeld 2016. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #define BOOST_PYTHON_NUMPY_INTERNAL_MAIN 8 | #include 9 | #include 10 | 11 | namespace boost { namespace python { namespace numpy { 12 | 13 | #if PY_MAJOR_VERSION == 2 14 | static void wrap_import_array() 15 | { 16 | import_array(); 17 | } 18 | #else 19 | static void * wrap_import_array() 20 | { 21 | import_array(); 22 | return NULL; 23 | } 24 | #endif 25 | 26 | void initialize(bool register_scalar_converters) 27 | { 28 | wrap_import_array(); 29 | import_ufunc(); 30 | if (register_scalar_converters) 31 | dtype::register_scalar_converters(); 32 | } 33 | 34 | }}} // namespace boost::python::numpy 35 | -------------------------------------------------------------------------------- /include/boost/python/register_ptr_to_python.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef REGISTER_PTR_TO_PYTHON_HPP 6 | #define REGISTER_PTR_TO_PYTHON_HPP 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace boost { namespace python { 13 | 14 | template 15 | void register_ptr_to_python() 16 | { 17 | typedef typename boost::python::pointee

::type X; 18 | objects::class_value_wrapper< 19 | P 20 | , objects::make_ptr_instance< 21 | X 22 | , objects::pointer_holder 23 | > 24 | >(); 25 | } 26 | 27 | }} // namespace boost::python 28 | 29 | #endif // REGISTER_PTR_TO_PYTHON_HPP 30 | 31 | 32 | -------------------------------------------------------------------------------- /doc/images/callouts/17.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /doc/reference/import.qbk: -------------------------------------------------------------------------------- 1 | [section boost/python/import.hpp] 2 | [section Introduction] 3 | Exposes a mechanism for importing python modules. 4 | [endsect] 5 | [section Function `import`] 6 | ``object import(str name);`` 7 | [variablelist 8 | [[Effects][Imports the module named by name.]] 9 | [[Returns][An instance of object which holds a reference to the imported module.]] 10 | ] 11 | [endsect] 12 | [section Examples] 13 | The following example demonstrates the use of import to access a function in python, and later call it from within C++. 14 | `` 15 | #include 16 | #include 17 | 18 | using namespace boost::python; 19 | 20 | void print_python_version() 21 | { 22 | // Load the sys module. 23 | object sys = import("sys"); 24 | 25 | // Extract the python version. 26 | std::string version = extract(sys.attr("version")); 27 | std::cout << version << std::endl; 28 | } 29 | `` 30 | [endsect] 31 | [endsect] 32 | -------------------------------------------------------------------------------- /doc/html/images/callouts/17.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /example/numpy/Jamfile: -------------------------------------------------------------------------------- 1 | # Copyright Stefan Seefeld 2016. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | import python ; 7 | 8 | # Adjust the following if Boost.Python isn't installed in a default location 9 | lib boost_numpy 10 | : 11 | : /usr/local/Boost/lib 12 | /usr/local/Boost/include 13 | ; 14 | 15 | project numpy 16 | : requirements 17 | /usr/local/Boost/include 18 | boost_numpy 19 | . 20 | ; 21 | 22 | exe simple : simple.cpp boost_numpy /python//python ; 23 | exe dtype : dtype.cpp boost_numpy /python//python ; 24 | exe ndarray : ndarray.cpp /python//python ; 25 | exe fromdata : fromdata.cpp /python//python ; 26 | exe ufunc : ufunc.cpp /python//python ; 27 | exe wrap : wrap.cpp /python//python ; 28 | 29 | python-extension gaussian : gaussian.cpp ; 30 | -------------------------------------------------------------------------------- /src/converter/arg_to_python_base.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | namespace boost { namespace python { namespace converter { 13 | 14 | namespace detail 15 | { 16 | arg_to_python_base::arg_to_python_base( 17 | void const volatile* source, registration const& converters) 18 | # if !defined(BOOST_MSVC) || BOOST_MSVC <= 1300 || _MSC_FULL_VER > 13102179 19 | : handle<> 20 | # else 21 | : m_ptr 22 | # endif 23 | (converters.to_python(source)) 24 | { 25 | } 26 | } 27 | 28 | }}} // namespace boost::python::converter 29 | -------------------------------------------------------------------------------- /include/boost/python/object/find_instance.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef FIND_INSTANCE_DWA2002312_HPP 6 | # define FIND_INSTANCE_DWA2002312_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { namespace objects { 11 | 12 | // Given a type_id, find the instance data which corresponds to it, or 13 | // return 0 in case no such type is held. If null_shared_ptr_only is 14 | // true and the type being sought is a shared_ptr, only find an 15 | // instance if it turns out to be NULL. Needed for shared_ptr rvalue 16 | // from_python support. 17 | BOOST_PYTHON_DECL void* find_instance_impl(PyObject*, type_info, bool null_shared_ptr_only = false); 18 | 19 | }}} // namespace boost::python::objects 20 | 21 | #endif // FIND_INSTANCE_DWA2002312_HPP 22 | -------------------------------------------------------------------------------- /include/boost/python/detail/value_is_shared_ptr.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2003. 2 | // Copyright Stefan Seefeld 2016. 3 | // Distributed under the Boost Software License, Version 1.0. (See 4 | // accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #ifndef boost_python_detail_value_is_shared_ptr_hpp_ 8 | #define boost_python_detail_value_is_shared_ptr_hpp_ 9 | 10 | #include 11 | #include 12 | 13 | namespace boost { namespace python { namespace detail { 14 | 15 | template 16 | struct value_is_shared_ptr 17 | { 18 | static bool const value = is_shared_ptr 20 | ::type> 21 | ::type> 22 | ::value; 23 | typedef mpl::bool_ type; 24 | }; 25 | 26 | }}} // namespace boost::python::detail 27 | 28 | #endif // VALUE_IS_SHARED_PTR_DWA2003224_HPP 29 | -------------------------------------------------------------------------------- /include/boost/python/detail/pointee.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef POINTEE_DWA2002323_HPP 6 | # define POINTEE_DWA2002323_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { namespace detail { 11 | 12 | template 13 | struct pointee_impl 14 | { 15 | template struct apply : remove_pointer {}; 16 | }; 17 | 18 | template <> 19 | struct pointee_impl 20 | { 21 | template struct apply 22 | { 23 | typedef typename T::element_type type; 24 | }; 25 | }; 26 | 27 | template 28 | struct pointee 29 | : pointee_impl::value>::template apply 30 | { 31 | }; 32 | 33 | }}} // namespace boost::python::detail 34 | 35 | #endif // POINTEE_DWA2002323_HPP 36 | -------------------------------------------------------------------------------- /test/back_reference.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from back_reference_ext import * 6 | >>> y = Y(3) 7 | >>> z = Z(4) 8 | >>> x_instances() 9 | 2 10 | >>> y2 = copy_Y(y) 11 | >>> x_instances() 12 | 3 13 | >>> z2 = copy_Z(z) 14 | >>> x_instances() 15 | 4 16 | >>> assert y_identity(y) is y 17 | >>> y_equality(y, y) 18 | 1 19 | 20 | >>> print(y_identity.__doc__.splitlines()[1]) 21 | y_identity( (Y)arg1) -> object : 22 | ''' 23 | 24 | def run(args = None): 25 | import sys 26 | import doctest 27 | 28 | if args is not None: 29 | sys.argv = args 30 | return doctest.testmod(sys.modules.get(__name__)) 31 | 32 | if __name__ == '__main__': 33 | print("running...") 34 | import sys 35 | status = run()[0] 36 | if (status == 0): print("Done.") 37 | sys.exit(status) 38 | -------------------------------------------------------------------------------- /doc/images/callouts/14.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /include/boost/python/object.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef OBJECT_DWA2002612_HPP 6 | # define OBJECT_DWA2002612_HPP 7 | 8 | # include 9 | # include 10 | # include 11 | # include 12 | # include 13 | # include 14 | # include 15 | 16 | namespace boost { namespace python { 17 | 18 | inline ssize_t len(object const& obj) 19 | { 20 | ssize_t result = PyObject_Length(obj.ptr()); 21 | if (PyErr_Occurred()) throw_error_already_set(); 22 | return result; 23 | } 24 | 25 | }} // namespace boost::python 26 | 27 | #endif // OBJECT_DWA2002612_HPP 28 | -------------------------------------------------------------------------------- /doc/html/images/callouts/14.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/aligned_class.cpp: -------------------------------------------------------------------------------- 1 | // Distributed under the Boost Software License, Version 1.0. (See 2 | // accompanying file LICENSE_1_0.txt or copy at 3 | // http://www.boost.org/LICENSE_1_0.txt) 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace boost::python; 12 | 13 | struct BOOST_ALIGNMENT(32) X 14 | { 15 | int x; 16 | BOOST_ALIGNMENT(32) float f; 17 | X(int n, float _f) : x(n), f(_f) 18 | { 19 | BOOST_ASSERT((reinterpret_cast(&f) % 32) == 0); 20 | } 21 | }; 22 | 23 | int x_function(X& x) { return x.x;} 24 | float f_function(X& x) { return x.f;} 25 | 26 | BOOST_PYTHON_MODULE(aligned_class_ext) 27 | { 28 | class_("X", init()); 29 | def("x_function", x_function); 30 | def("f_function", f_function); 31 | } 32 | 33 | #include "module_tail.cpp" 34 | -------------------------------------------------------------------------------- /include/boost/python/detail/is_wrapper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #ifndef IS_WRAPPER_DWA2004723_HPP 5 | # define IS_WRAPPER_DWA2004723_HPP 6 | 7 | # include 8 | # include 9 | 10 | namespace boost { namespace python { 11 | 12 | template class wrapper; 13 | 14 | namespace detail 15 | { 16 | typedef char (&is_not_wrapper)[2]; 17 | is_not_wrapper is_wrapper_helper(...); 18 | template 19 | char is_wrapper_helper(wrapper const volatile*); 20 | 21 | // A metafunction returning true iff T is [derived from] wrapper 22 | template 23 | struct is_wrapper 24 | : mpl::bool_<(sizeof(detail::is_wrapper_helper((T*)0)) == 1)> 25 | {}; 26 | 27 | }}} // namespace boost::python::detail 28 | 29 | #endif // IS_WRAPPER_DWA2004723_HPP 30 | -------------------------------------------------------------------------------- /test/bienstman4.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | struct Type1 {}; 13 | 14 | struct Term {Term(Type1 const&) {} }; 15 | 16 | struct Expression {void add(Term const&) {} }; 17 | 18 | BOOST_PYTHON_MODULE(bienstman4_ext) 19 | { 20 | using namespace boost::python; 21 | using boost::mpl::list; 22 | 23 | implicitly_convertible(); 24 | 25 | class_("Expression") 26 | .def("add", &Expression::add) 27 | ; 28 | 29 | class_("T1") 30 | ; 31 | 32 | class_("Term", init()) 33 | ; 34 | 35 | Type1 t1; 36 | Expression e; 37 | e.add(t1); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /test/stl_iterator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Eric Niebler 2005. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace boost::python; 12 | 13 | typedef std::list list_int; 14 | 15 | void assign(list_int& x, object const& y) 16 | { 17 | stl_input_iterator begin(y), end; 18 | x.clear(); 19 | for( ; begin != end; ++begin) 20 | x.push_back(*begin); 21 | } 22 | 23 | BOOST_PYTHON_MODULE(stl_iterator_ext) 24 | { 25 | using boost::python::iterator; // gcc 2.96 bug workaround 26 | 27 | class_("list_int") 28 | .def("assign", assign) 29 | .def("__iter__", iterator()) 30 | ; 31 | } 32 | 33 | #include "module_tail.cpp" 34 | -------------------------------------------------------------------------------- /doc/images/callouts/2.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /include/boost/python/object/add_to_namespace.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef ADD_TO_NAMESPACE_DWA200286_HPP 6 | # define ADD_TO_NAMESPACE_DWA200286_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { namespace objects { 11 | 12 | // 13 | // A setattr that's "smart" about function overloading (and docstrings). 14 | // 15 | BOOST_PYTHON_DECL void add_to_namespace( 16 | object const& name_space, char const* name, object const& attribute); 17 | 18 | BOOST_PYTHON_DECL void add_to_namespace( 19 | object const& name_space, char const* name, object const& attribute, char const* doc); 20 | 21 | BOOST_PYTHON_DECL object const& add_doc(object const& attribute, char const* doc); 22 | 23 | }}} // namespace boost::python::objects 24 | 25 | #endif // ADD_TO_NAMESPACE_DWA200286_HPP 26 | -------------------------------------------------------------------------------- /include/boost/python/object/stl_iterator_core.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Eric Niebler 2005. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef STL_ITERATOR_CORE_EAN20051028_HPP 6 | # define STL_ITERATOR_CORE_EAN20051028_HPP 7 | 8 | # include 9 | # include 10 | 11 | namespace boost { namespace python { namespace objects { 12 | 13 | struct BOOST_PYTHON_DECL stl_input_iterator_impl 14 | { 15 | stl_input_iterator_impl(); 16 | stl_input_iterator_impl(boost::python::object const &ob); 17 | void increment(); 18 | bool equal(stl_input_iterator_impl const &that) const; 19 | boost::python::handle<> const ¤t() const; 20 | private: 21 | boost::python::object it_; 22 | boost::python::handle<> ob_; 23 | }; 24 | 25 | }}} // namespace boost::python::object 26 | 27 | #endif // STL_ITERATOR_CORE_EAN20051028_HPP 28 | -------------------------------------------------------------------------------- /doc/html/images/callouts/2.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/complicated.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2001. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef COMPLICATED_DWA20011215_HPP 6 | # define COMPLICATED_DWA20011215_HPP 7 | # include 8 | 9 | # include "simple_type.hpp" 10 | 11 | struct complicated 12 | { 13 | complicated(simple const&, int = 0); 14 | ~complicated(); 15 | 16 | int get_n() const; 17 | 18 | char* s; 19 | int n; 20 | }; 21 | 22 | inline complicated::complicated(simple const&s, int _n) 23 | : s(s.s), n(_n) 24 | { 25 | std::cout << "constructing complicated: " << this->s << ", " << _n << std::endl; 26 | } 27 | 28 | inline complicated::~complicated() 29 | { 30 | std::cout << "destroying complicated: " << this->s << ", " << n << std::endl; 31 | } 32 | 33 | inline int complicated::get_n() const 34 | { 35 | return n; 36 | } 37 | 38 | #endif // COMPLICATED_DWA20011215_HPP 39 | -------------------------------------------------------------------------------- /test/stl_iterator.py: -------------------------------------------------------------------------------- 1 | # Copyright Eric Niebler 2005. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from stl_iterator_ext import * 6 | >>> x = list_int() 7 | >>> x.assign(iter([1,2,3,4,5])) 8 | >>> for y in x: 9 | ... print(y) 10 | 1 11 | 2 12 | 3 13 | 4 14 | 5 15 | >>> def generator(): 16 | ... yield 1 17 | ... yield 2 18 | ... raise RuntimeError("oops") 19 | >>> try: 20 | ... x.assign(iter(generator())) 21 | ... print("NOT OK") 22 | ... except RuntimeError: 23 | ... print("OK") 24 | OK 25 | ''' 26 | def run(args = None): 27 | import sys 28 | import doctest 29 | 30 | if args is not None: 31 | sys.argv = args 32 | return doctest.testmod(sys.modules.get(__name__)) 33 | 34 | if __name__ == '__main__': 35 | print("running...") 36 | import sys 37 | status = run()[0] 38 | if (status == 0): print("Done.") 39 | sys.exit(status) 40 | -------------------------------------------------------------------------------- /test/operators_wrapper.cpp: -------------------------------------------------------------------------------- 1 | #include "boost/python.hpp" 2 | #include 3 | 4 | struct vector 5 | { 6 | virtual ~vector() {} 7 | 8 | vector operator+( const vector& ) const 9 | { return vector(); } 10 | 11 | vector& operator+=( const vector& ) 12 | { return *this; } 13 | 14 | vector operator-() const 15 | { return *this; } 16 | }; 17 | 18 | struct dvector : vector 19 | {}; 20 | 21 | using namespace boost::python; 22 | 23 | struct vector_wrapper 24 | : vector, wrapper< vector > 25 | { 26 | vector_wrapper(vector const&) {} 27 | vector_wrapper() {} 28 | }; 29 | 30 | BOOST_PYTHON_MODULE( operators_wrapper_ext ) 31 | { 32 | class_< vector_wrapper >( "vector" ) 33 | .def( self + self ) 34 | .def( self += self ) 35 | .def( -self ) 36 | ; 37 | 38 | scope().attr("v") = vector(); 39 | std::shared_ptr dp(new dvector); 40 | register_ptr_to_python< std::shared_ptr >(); 41 | scope().attr("d") = dp; 42 | } 43 | -------------------------------------------------------------------------------- /test/tuple.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2005. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace boost::python; 11 | 12 | object convert_to_tuple(object data) 13 | { 14 | return tuple(data); 15 | } 16 | 17 | void test_operators(tuple t1, tuple t2, object print) 18 | { 19 | print(t1 + t2); 20 | } 21 | 22 | tuple mktuple0() { return make_tuple(); } 23 | tuple mktuple1(int x) { return make_tuple(x); } 24 | tuple mktuple2(char const* a1, int x) { return make_tuple(a1, x); } 25 | 26 | BOOST_PYTHON_MODULE(tuple_ext) 27 | { 28 | def("convert_to_tuple",convert_to_tuple); 29 | def("test_operators",test_operators); 30 | def("make_tuple", mktuple0); 31 | def("make_tuple", mktuple1); 32 | def("make_tuple", mktuple2); 33 | } 34 | -------------------------------------------------------------------------------- /test/staticmethod.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from staticmethod_ext import * 6 | 7 | >>> class X1(X): 8 | ... pass 9 | 10 | 11 | >>> x = X(16) 12 | >>> x1 = X1(17) 13 | 14 | 15 | 16 | >>> x1.count() 17 | 2 18 | 19 | >>> x.count() 20 | 2 21 | 22 | >>> X1.count() 23 | 2 24 | 25 | >>> X.count() 26 | 2 27 | 28 | 29 | >>> x1.magic() 30 | 7654321 31 | 32 | >>> x.magic() 33 | 7654321 34 | 35 | >>> X1.magic() 36 | 7654321 37 | 38 | >>> X.magic() 39 | 7654321 40 | 41 | 42 | ''' 43 | 44 | def run(args = None): 45 | import sys 46 | import doctest 47 | 48 | if args is not None: 49 | sys.argv = args 50 | return doctest.testmod(sys.modules.get(__name__)) 51 | 52 | if __name__ == '__main__': 53 | print("running...") 54 | import sys 55 | status = run()[0] 56 | if (status == 0): print("Done.") 57 | sys.exit(status) 58 | -------------------------------------------------------------------------------- /doc/images/callouts/5.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/html/images/callouts/5.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /include/boost/python/self.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef SELF_DWA2002531_HPP 6 | # define SELF_DWA2002531_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { 11 | 12 | #define BOOST_PYTHON_SELF_IS_CLASS 13 | 14 | // Sink self_t into its own namespace so that we have a safe place to 15 | // put the completely general operator templates which operate on 16 | // it. It is possible to avoid this, but it turns out to be much more 17 | // complicated and finally GCC 2.95.2 chokes on it. 18 | namespace self_ns 19 | { 20 | # ifndef BOOST_PYTHON_SELF_IS_CLASS 21 | enum self_t { self }; 22 | # else 23 | struct self_t {}; 24 | extern BOOST_PYTHON_DECL self_t self; 25 | # endif 26 | } 27 | 28 | using self_ns::self_t; 29 | using self_ns::self; 30 | 31 | }} // namespace boost::python 32 | 33 | #endif // SELF_DWA2002531_HPP 34 | -------------------------------------------------------------------------------- /test/class.py: -------------------------------------------------------------------------------- 1 | # Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from class_ext import * 6 | 7 | Ensure sanity: 8 | 9 | >>> x = X(42) 10 | >>> x_function(x) 11 | 42 12 | 13 | Demonstrate extraction in the presence of metaclass changes: 14 | 15 | >>> class MetaX(X.__class__): 16 | ... def __new__(cls, *args): 17 | ... return super(MetaX, cls).__new__(cls, *args) 18 | >>> class XPlusMetatype(X): 19 | ... __metaclass__ = MetaX 20 | >>> x = XPlusMetatype(42) 21 | >>> x_function(x) 22 | 42 23 | 24 | 25 | ''' 26 | 27 | def run(args = None): 28 | import sys 29 | import doctest 30 | 31 | if args is not None: 32 | sys.argv = args 33 | return doctest.testmod(sys.modules.get(__name__)) 34 | 35 | if __name__ == '__main__': 36 | print("running...") 37 | import sys 38 | status = run()[0] 39 | if (status == 0): print("Done.") 40 | sys.exit(status) 41 | -------------------------------------------------------------------------------- /include/boost/python/detail/unwrap_wrapper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #ifndef UNWRAP_WRAPPER_DWA2004723_HPP 5 | # define UNWRAP_WRAPPER_DWA2004723_HPP 6 | 7 | # include 8 | # include 9 | # include 10 | # include 11 | 12 | namespace boost { namespace python { namespace detail { 13 | 14 | template 15 | struct unwrap_wrapper_helper 16 | { 17 | typedef typename T::_wrapper_wrapped_type_ type; 18 | }; 19 | 20 | template 21 | struct unwrap_wrapper_ 22 | : mpl::eval_if,unwrap_wrapper_helper,mpl::identity > 23 | {}; 24 | 25 | template 26 | typename unwrap_wrapper_::type* 27 | unwrap_wrapper(T*) 28 | { 29 | return 0; 30 | } 31 | 32 | }}} // namespace boost::python::detail 33 | 34 | #endif // UNWRAP_WRAPPER_DWA2004723_HPP 35 | -------------------------------------------------------------------------------- /doc/support.qbk: -------------------------------------------------------------------------------- 1 | [chapter Support Resources 2 | [quickbook 1.7] 3 | [id support] 4 | ] 5 | 6 | 7 | [h2 Synopsis] 8 | This is a list of available resources for support with Boost.Python problems and feature requests. Please try to resist emailing the Boost.Python developers directly for support. Use the following resources instead; the developers are listening! 9 | 10 | [h2 Support] 11 | * The _bp_list_ is a forum for discussing Python/C++ interoperability, and Boost.Python in particular. Post your Boost.Python questions here. 12 | * The _bb_list_ is a forum for discussing Boost's Build System. 13 | * The Boost.Python [@https://github.com/boostorg/python/issues Issue tracker] 14 | [note In the past we used Trac, which still hosts a considerable number of [@https://svn.boost.org/trac/boost/query?status=!closed&component=python+USE+GITHUB open issues]. We hope to be able to either close them or migrate them to the new issue tracker.] 15 | * The Boost.Python [@https://github.com/boostorg/python/wiki Wiki] 16 | * Boost.Python [@https://github.com/boostorg/python Source repository] 17 | 18 | -------------------------------------------------------------------------------- /include/boost/python/detail/dependent.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef DEPENDENT_DWA200286_HPP 6 | # define DEPENDENT_DWA200286_HPP 7 | 8 | namespace boost { namespace python { namespace detail { 9 | 10 | // A way to turn a concrete type T into a type dependent on U. This 11 | // keeps conforming compilers (those implementing proper 2-phase 12 | // name lookup for templates) from complaining about incomplete 13 | // types in situations where it would otherwise be inconvenient or 14 | // impossible to re-order code so that all types are defined in time. 15 | 16 | // One such use is when we must return an incomplete T from a member 17 | // function template (which must be defined in the class body to 18 | // keep MSVC happy). 19 | template 20 | struct dependent 21 | { 22 | typedef T type; 23 | }; 24 | 25 | }}} // namespace boost::python::detail 26 | 27 | #endif // DEPENDENT_DWA200286_HPP 28 | -------------------------------------------------------------------------------- /include/boost/python/pointee.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef POINTEE_DWA2002323_HPP 6 | # define POINTEE_DWA2002323_HPP 7 | 8 | # include 9 | # include 10 | 11 | namespace boost { namespace python { 12 | 13 | namespace detail 14 | { 15 | template 16 | struct pointee_impl 17 | { 18 | template struct apply : detail::remove_pointer {}; 19 | }; 20 | 21 | template <> 22 | struct pointee_impl 23 | { 24 | template struct apply 25 | { 26 | typedef typename T::element_type type; 27 | }; 28 | }; 29 | } 30 | 31 | template 32 | struct pointee 33 | : detail::pointee_impl< 34 | detail::is_pointer::value 35 | >::template apply 36 | { 37 | }; 38 | 39 | }} // namespace boost::python 40 | 41 | #endif // POINTEE_DWA2002323_HPP 42 | -------------------------------------------------------------------------------- /include/boost/python/base_type_traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BASE_TYPE_TRAITS_DWA2002614_HPP 6 | # define BASE_TYPE_TRAITS_DWA2002614_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { 11 | 12 | namespace detail 13 | { 14 | struct unspecialized {}; 15 | } 16 | 17 | // Derive from unspecialized so we can detect whether traits are 18 | // specialized 19 | template struct base_type_traits 20 | : detail::unspecialized 21 | {}; 22 | 23 | template <> 24 | struct base_type_traits 25 | { 26 | typedef PyObject type; 27 | }; 28 | 29 | template <> 30 | struct base_type_traits 31 | { 32 | typedef PyObject type; 33 | }; 34 | 35 | template <> 36 | struct base_type_traits 37 | { 38 | typedef PyObject type; 39 | }; 40 | 41 | }} // namespace boost::python 42 | 43 | #endif // BASE_TYPE_TRAITS_DWA2002614_HPP 44 | -------------------------------------------------------------------------------- /include/boost/python/converter/registered_pointee.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef REGISTERED_POINTEE_DWA2002710_HPP 6 | # define REGISTERED_POINTEE_DWA2002710_HPP 7 | # include 8 | # include 9 | # include 10 | # include 11 | 12 | namespace boost { namespace python { namespace converter { 13 | 14 | struct registration; 15 | 16 | template 17 | struct registered_pointee 18 | : registered< 19 | typename boost::python::detail::remove_pointer< 20 | typename boost::python::detail::remove_cv< 21 | typename boost::python::detail::remove_reference::type 22 | >::type 23 | >::type 24 | > 25 | { 26 | }; 27 | }}} // namespace boost::python::converter 28 | 29 | #endif // REGISTERED_POINTEE_DWA2002710_HPP 30 | -------------------------------------------------------------------------------- /test/voidptr.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Niall Douglas 2005. 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // (See accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | # include 7 | # include 8 | # include 9 | # include 10 | 11 | static void *test=(void *) 78; 12 | 13 | void *get() 14 | { 15 | return test; 16 | } 17 | 18 | void *getnull() 19 | { 20 | return 0; 21 | } 22 | 23 | void use(void *a) 24 | { 25 | if(a!=test) 26 | throw std::runtime_error(std::string("failed")); 27 | } 28 | 29 | int useany(void *a) 30 | { 31 | return a ? 1 : 0; 32 | } 33 | 34 | 35 | namespace bpl = boost::python; 36 | 37 | BOOST_PYTHON_MODULE(voidptr_ext) 38 | { 39 | bpl::def("get", &::get, bpl::return_value_policy()); 40 | bpl::def("getnull", &::getnull, bpl::return_value_policy()); 41 | bpl::def("use", &::use); 42 | bpl::def("useany", &::useany); 43 | } 44 | -------------------------------------------------------------------------------- /doc/images/up.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | ]> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/pointee.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | struct A; 12 | 13 | int main() 14 | { 15 | BOOST_STATIC_ASSERT( 16 | (boost::python::detail::is_same< 17 | boost::python::pointee >::type 18 | , char** 19 | >::value)); 20 | 21 | BOOST_STATIC_ASSERT( 22 | (boost::python::detail::is_same< 23 | boost::python::pointee >::type 24 | , A>::value)); 25 | 26 | #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION 27 | BOOST_STATIC_ASSERT( 28 | (boost::python::detail::is_same< 29 | boost::python::pointee::type 30 | , char 31 | >::value)); 32 | #endif 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /doc/html/images/up.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | ]> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/next.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | ]> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/prev.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | ]> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/reference/functions.qbk: -------------------------------------------------------------------------------- 1 | [chapter Function Invocation and Creation 2 | [quickbook 1.7] 3 | ] 4 | 5 | [include args.qbk] 6 | [include call.qbk] 7 | [include call_method.qbk] 8 | [include data_members.qbk] 9 | [include make_function.qbk] 10 | [include overloads.qbk] 11 | [include ptr.qbk] 12 | [include raw_function.qbk] 13 | [section Function documentation] 14 | [include function_doc_signature.qbk] 15 | [include pytype_function.qbk] 16 | [endsect] 17 | [section Models of CallPolicies] 18 | [include default_call_policies.qbk] 19 | [include return_arg.qbk] 20 | [include return_internal_reference.qbk] 21 | [include return_value_policy.qbk] 22 | [include with_custodian_and_ward.qbk] 23 | [endsect] 24 | [section Models of ResultConverter] 25 | [include to_python_indirect.qbk] 26 | [include to_python_value.qbk] 27 | [endsect] 28 | [section Models of ResultConverterGenerator] 29 | [include copy_const_reference.qbk] 30 | [include copy_non_const_reference.qbk] 31 | [include manage_new_object.qbk] 32 | [include reference_existing_object.qbk] 33 | [include return_by_value.qbk] 34 | [include return_opaque_pointer.qbk] 35 | [endsect] 36 | -------------------------------------------------------------------------------- /doc/html/images/next.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | ]> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/html/images/prev.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | ]> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/callouts/10.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /test/numpy/templates.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright Jim Bosch & Ankit Daftery 2010-2012. 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (See accompanying file LICENSE_1_0.txt or copy at 6 | # http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | import templates_ext 9 | import unittest 10 | import numpy 11 | 12 | class TestTemplates(unittest.TestCase): 13 | 14 | def testTemplates(self): 15 | for dtype in (numpy.int16, numpy.int32, numpy.float32, numpy.complex128): 16 | v = numpy.arange(12, dtype=dtype) 17 | for shape in ((12,), (4, 3), (2, 6)): 18 | a1 = numpy.zeros(shape, dtype=dtype) 19 | a2 = v.reshape(a1.shape) 20 | templates_ext.fill(a1) 21 | self.assertTrue((a1 == a2).all()) 22 | a1 = numpy.zeros((12,), dtype=numpy.float64) 23 | self.assertRaises(TypeError, templates_ext.fill, a1) 24 | a1 = numpy.zeros((12,2,3), dtype=numpy.float32) 25 | self.assertRaises(TypeError, templates_ext.fill, a1) 26 | 27 | if __name__=="__main__": 28 | unittest.main() 29 | -------------------------------------------------------------------------------- /doc/html/images/callouts/10.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/images/callouts/12.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /include/boost/python/detail/enable_if.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #ifndef ENABLE_IF_DWA2004722_HPP 5 | # define ENABLE_IF_DWA2004722_HPP 6 | 7 | # include 8 | # include 9 | 10 | #if !defined(BOOST_NO_SFINAE) 11 | # include 12 | 13 | namespace boost { namespace python { namespace detail { 14 | 15 | template 16 | struct enable_if_arg 17 | : enable_if 18 | {}; 19 | 20 | template 21 | struct disable_if_arg 22 | : disable_if 23 | {}; 24 | 25 | template 26 | struct enable_if_ret 27 | : enable_if 28 | {}; 29 | 30 | template 31 | struct disable_if_ret 32 | : disable_if 33 | {}; 34 | 35 | }}} // namespace boost::python::detail 36 | 37 | # endif 38 | 39 | #endif // ENABLE_IF_DWA2004722_HPP 40 | -------------------------------------------------------------------------------- /include/boost/python/detail/python_type.hpp: -------------------------------------------------------------------------------- 1 | // Copyright Nikolay Mladenov 2007. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef BOOST_PYTHON_OBJECT_PYTHON_TYPE_H 6 | #define BOOST_PYTHON_OBJECT_PYTHON_TYPE_H 7 | 8 | #include 9 | 10 | namespace boost {namespace python {namespace detail{ 11 | 12 | 13 | template struct python_class : PyObject 14 | { 15 | typedef python_class this_type; 16 | 17 | typedef T type; 18 | 19 | static void *converter (PyObject *p){ 20 | return p; 21 | } 22 | 23 | static void register_() 24 | { 25 | static bool first_time = true; 26 | 27 | if ( !first_time ) return; 28 | 29 | first_time = false; 30 | converter::registry::insert(&converter, boost::python::type_id(), &converter::registered_pytype_direct::get_pytype); 31 | } 32 | }; 33 | 34 | 35 | }}} //namespace boost :: python :: detail 36 | 37 | #endif //BOOST_PYTHON_OBJECT_PYTHON_TYPE_H 38 | -------------------------------------------------------------------------------- /include/boost/python/slice_nil.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef SLICE_NIL_DWA2002620_HPP 6 | # define SLICE_NIL_DWA2002620_HPP 7 | 8 | # include 9 | # include 10 | 11 | namespace boost { namespace python { namespace api { 12 | 13 | class slice_nil : public object 14 | { 15 | public: 16 | slice_nil() : object() {} 17 | }; 18 | 19 | # ifndef _ // Watch out for GNU gettext users, who #define _(x) 20 | static const slice_nil _ = slice_nil(); 21 | # endif 22 | 23 | template 24 | struct slice_bound 25 | { 26 | typedef object type; 27 | }; 28 | 29 | template <> 30 | struct slice_bound 31 | { 32 | typedef slice_nil type; 33 | }; 34 | 35 | } 36 | 37 | using api::slice_nil; 38 | # ifndef _ // Watch out for GNU gettext users, who #define _(x) 39 | using api::_; 40 | # endif 41 | 42 | }} // namespace boost::python 43 | 44 | #endif // SLICE_NIL_DWA2002620_HPP 45 | -------------------------------------------------------------------------------- /src/object/iterator.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace boost { namespace python { namespace objects { 12 | 13 | namespace 14 | { 15 | PyObject* identity(PyObject* args_, PyObject*) 16 | { 17 | PyObject* x = PyTuple_GET_ITEM(args_,0); 18 | Py_INCREF(x); 19 | return x; 20 | } 21 | } 22 | 23 | BOOST_PYTHON_DECL object const& identity_function() 24 | { 25 | static object result( 26 | function_object( 27 | py_function(&identity, mpl::vector2()) 28 | ) 29 | ); 30 | return result; 31 | } 32 | 33 | void stop_iteration_error() 34 | { 35 | PyErr_SetObject(PyExc_StopIteration, Py_None); 36 | throw_error_already_set(); 37 | } 38 | 39 | }}} // namespace boost::python::objects 40 | -------------------------------------------------------------------------------- /test/numpy/ufunc.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Jim Bosch & Ankit Daftery 2010-2012. 2 | // Copyright Stefan Seefeld 2016. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #include 8 | 9 | namespace p = boost::python; 10 | namespace np = boost::python::numpy; 11 | 12 | struct UnaryCallable 13 | { 14 | typedef double argument_type; 15 | typedef double result_type; 16 | 17 | double operator()(double r) const { return r * 2;} 18 | }; 19 | 20 | struct BinaryCallable 21 | { 22 | typedef double first_argument_type; 23 | typedef double second_argument_type; 24 | typedef double result_type; 25 | 26 | double operator()(double a, double b) const { return a * 2 + b * 3;} 27 | }; 28 | 29 | BOOST_PYTHON_MODULE(ufunc_ext) 30 | { 31 | np::initialize(); 32 | p::class_("UnaryCallable") 33 | .def("__call__", np::unary_ufunc::make()); 34 | p::class_< BinaryCallable>("BinaryCallable") 35 | .def("__call__", np::binary_ufunc::make()); 36 | } 37 | -------------------------------------------------------------------------------- /doc/html/images/callouts/12.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /doc/images/callouts/21.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/tuple.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | 7 | namespace boost { namespace python { namespace detail { 8 | 9 | detail::new_reference tuple_base::call(object const& arg_) 10 | { 11 | return (detail::new_reference)PyObject_CallFunction( 12 | (PyObject*)&PyTuple_Type, const_cast("(O)"), 13 | arg_.ptr()); 14 | } 15 | 16 | tuple_base::tuple_base() 17 | : object(detail::new_reference(PyTuple_New(0))) 18 | {} 19 | 20 | tuple_base::tuple_base(object_cref sequence) 21 | : object(call(sequence)) 22 | {} 23 | 24 | static struct register_tuple_pytype_ptr 25 | { 26 | register_tuple_pytype_ptr() 27 | { 28 | const_cast( 29 | converter::registry::lookup(boost::python::type_id()) 30 | ).m_class_object = &PyTuple_Type; 31 | } 32 | }register_tuple_pytype_ptr_; 33 | 34 | 35 | }}} // namespace boost::python 36 | -------------------------------------------------------------------------------- /doc/html/images/callouts/21.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /include/boost/python/exception_translator.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef EXCEPTION_TRANSLATOR_DWA2002810_HPP 6 | # define EXCEPTION_TRANSLATOR_DWA2002810_HPP 7 | 8 | # include 9 | 10 | # include 11 | # include 12 | # include 13 | # include 14 | # include 15 | 16 | namespace boost { namespace python { 17 | 18 | template 19 | void register_exception_translator(Translate translate, boost::type* = 0) 20 | { 21 | using namespace boost::placeholders; 22 | detail::register_exception_handler( 23 | boost::bind(detail::translate_exception(), _1, _2, translate) 24 | ); 25 | } 26 | 27 | }} // namespace boost::python 28 | 29 | #endif // EXCEPTION_TRANSLATOR_DWA2002810_HPP 30 | -------------------------------------------------------------------------------- /test/raw_ctor.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | """ 5 | >>> 'importing' 6 | 'importing' 7 | >>> from raw_ctor_ext import * 8 | >>> 'imported' 9 | 'imported' 10 | >>> import sys 11 | >>> sys.stdout.flush() 12 | >>> f = Foo(1, 2, 'a', bar = 3, baz = 4) 13 | >>> f.args 14 | (1, 2, 'a') 15 | >>> sorted(f.kw.items()) 16 | [('bar', 3), ('baz', 4)] 17 | """ 18 | def run(args = None): 19 | import sys 20 | import doctest 21 | 22 | if args is not None: 23 | sys.argv = args 24 | return doctest.testmod(sys.modules.get(__name__)) 25 | 26 | if __name__ == '__main__': 27 | print("running...") 28 | import sys 29 | status = run()[0] 30 | if (status == 0): print("Done.") 31 | sys.exit(status) 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /doc/images/callouts/3.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/html/images/callouts/3.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /include/boost/python/other.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_PYTHON_OTHER_HPP 2 | # define BOOST_PYTHON_OTHER_HPP 3 | 4 | # include 5 | // Copyright David Abrahams 2002. 6 | // Distributed under the Boost Software License, Version 1.0. (See 7 | // accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | # include 11 | 12 | namespace boost { namespace python { 13 | 14 | template struct other 15 | { 16 | typedef T type; 17 | }; 18 | 19 | namespace detail 20 | { 21 | template 22 | class is_other 23 | { 24 | public: 25 | BOOST_STATIC_CONSTANT(bool, value = false); 26 | }; 27 | 28 | template 29 | class is_other > 30 | { 31 | public: 32 | BOOST_STATIC_CONSTANT(bool, value = true); 33 | }; 34 | 35 | template 36 | class unwrap_other 37 | { 38 | public: 39 | typedef T type; 40 | }; 41 | 42 | template 43 | class unwrap_other > 44 | { 45 | public: 46 | typedef T type; 47 | }; 48 | } 49 | 50 | }} // namespace boost::python 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /test/test_class.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef TEST_CLASS_DWA2002326_HPP 6 | # define TEST_CLASS_DWA2002326_HPP 7 | # include 8 | 9 | template 10 | struct test_class 11 | { 12 | explicit test_class(int x) : x(x), magic(7654321 + n) { ++counter; } 13 | test_class(test_class const& rhs) : x(rhs.x), magic(7654321 + n) { ++counter; } 14 | virtual ~test_class() { BOOST_ASSERT(magic == 7654321 + n); magic = 6666666; x = 9999; --counter; } 15 | 16 | void set(int _x) { BOOST_ASSERT(magic == 7654321 + n); this->x = _x; } 17 | int value() const { BOOST_ASSERT(magic == 7654321 + n); return x; } 18 | operator int() const { return x; } 19 | static int count() { return counter; } 20 | 21 | int x; 22 | long magic; 23 | static int counter; 24 | 25 | private: 26 | void operator=(test_class const&); 27 | }; 28 | 29 | template 30 | int test_class::counter; 31 | 32 | #endif // TEST_CLASS_DWA2002326_HPP 33 | -------------------------------------------------------------------------------- /doc/images/callouts/9.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /include/boost/python/detail/construct.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef CONSTRUCT_REFERENCE_DWA2002716_HPP 6 | # define CONSTRUCT_REFERENCE_DWA2002716_HPP 7 | 8 | namespace boost { namespace python { namespace detail { 9 | 10 | template 11 | void construct_pointee(void* storage, Arg& x, T const volatile*) 12 | { 13 | new (storage) T(x); 14 | } 15 | 16 | template 17 | void construct_referent_impl(void* storage, Arg& x, T&(*)()) 18 | { 19 | construct_pointee(storage, x, (T*)0); 20 | } 21 | 22 | template 23 | void construct_referent(void* storage, Arg const& x, T(*tag)() = 0) 24 | { 25 | construct_referent_impl(storage, x, tag); 26 | } 27 | 28 | template 29 | void construct_referent(void* storage, Arg& x, T(*tag)() = 0) 30 | { 31 | construct_referent_impl(storage, x, tag); 32 | } 33 | 34 | }}} // namespace boost::python::detail 35 | 36 | #endif // CONSTRUCT_REFERENCE_DWA2002716_HPP 37 | -------------------------------------------------------------------------------- /include/boost/python/detail/void_ptr.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef VOID_PTR_DWA200239_HPP 6 | # define VOID_PTR_DWA200239_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { namespace detail { 11 | 12 | template 13 | inline U& void_ptr_to_reference(void const volatile* p, U&(*)()) 14 | { 15 | return *(U*)p; 16 | } 17 | 18 | template 19 | inline void write_void_ptr(void const volatile* storage, void* ptr, T*) 20 | { 21 | *(T**)storage = (T*)ptr; 22 | } 23 | 24 | // writes U(ptr) into the storage 25 | template 26 | inline void write_void_ptr_reference(void const volatile* storage, void* ptr, U&(*)()) 27 | { 28 | // stripping CV qualification suppresses warnings on older EDGs 29 | typedef typename remove_cv::type u_stripped; 30 | write_void_ptr(storage, ptr, u_stripped(0)); 31 | } 32 | 33 | }}} // namespace boost::python::detail 34 | 35 | #endif // VOID_PTR_DWA200239_HPP 36 | -------------------------------------------------------------------------------- /test/numpy/indexing.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Jim Bosch & Ankit Daftery 2010-2012. 2 | // Copyright Stefan Seefeld 2016. 3 | // Distributed under the Boost Software License, Version 1.0. 4 | // (See accompanying file LICENSE_1_0.txt or copy at 5 | // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | #include 8 | #include 9 | 10 | namespace p = boost::python; 11 | namespace np = boost::python::numpy; 12 | 13 | p::object single(np::ndarray ndarr, int i) { return ndarr[i];} 14 | p::object slice(np::ndarray ndarr, p::slice sl) { return ndarr[sl];} 15 | p::object indexarray(np::ndarray ndarr, np::ndarray d1) { return ndarr[d1];} 16 | p::object indexarray_2d(np::ndarray ndarr, np::ndarray d1,np::ndarray d2) { return ndarr[p::make_tuple(d1,d2)];} 17 | p::object indexslice(np::ndarray ndarr, np::ndarray d1, p::slice sl) { return ndarr[p::make_tuple(d1, sl)];} 18 | 19 | BOOST_PYTHON_MODULE(indexing_ext) 20 | { 21 | np::initialize(); 22 | p::def("single", single); 23 | p::def("slice", slice); 24 | p::def("indexarray", indexarray); 25 | p::def("indexarray", indexarray_2d); 26 | p::def("indexslice", indexslice); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /doc/html/images/callouts/9.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/aligned_class.py: -------------------------------------------------------------------------------- 1 | # Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from aligned_class_ext import * 6 | 7 | Ensure sanity: 8 | 9 | >>> x = X(42, 16) 10 | >>> x_function(x) 11 | 42 12 | >>> f_function(x) 13 | 16.0 14 | 15 | Demonstrate extraction in the presence of metaclass changes: 16 | 17 | >>> class MetaX(X.__class__): 18 | ... def __new__(cls, *args): 19 | ... return super(MetaX, cls).__new__(cls, *args) 20 | >>> class XPlusMetatype(X): 21 | ... __metaclass__ = MetaX 22 | >>> x = XPlusMetatype(42, 16) 23 | >>> x_function(x) 24 | 42 25 | >>> f_function(x) 26 | 16.0 27 | 28 | 29 | ''' 30 | 31 | def run(args = None): 32 | import sys 33 | import doctest 34 | 35 | if args is not None: 36 | sys.argv = args 37 | return doctest.testmod(sys.modules.get(__name__)) 38 | 39 | if __name__ == '__main__': 40 | print("running...") 41 | import sys 42 | status = run()[0] 43 | if (status == 0): print("Done.") 44 | sys.exit(status) 45 | -------------------------------------------------------------------------------- /doc/images/callouts/15.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/callouts/27.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/reference/to_python_value.qbk: -------------------------------------------------------------------------------- 1 | [section boost/python/to_python_value.hpp] 2 | [section Introduction] 3 | `to_python_value` is a model of [link concepts.resultconverter ResultConverter] which copies its argument into a new Python object. 4 | [endsect] 5 | [section Class template `to_python_value`] 6 | `` 7 | namespace boost { namespace python 8 | { 9 | template 10 | struct to_python_value 11 | { 12 | typedef typename add_reference< 13 | typename add_const::type 14 | >::type argument_type; 15 | 16 | static bool convertible(); 17 | PyObject* operator()(argument_type) const; 18 | }; 19 | }} 20 | `` 21 | [endsect] 22 | [section Class `to_python_value` observers] 23 | ``static bool convertible();`` 24 | [variablelist 25 | [[Returns][`true` iff a converter has been registered which can convert `T` to python by-value. ]] 26 | ] 27 | ``PyObject* operator()(argument_type x) const;`` 28 | [variablelist 29 | [[Requires][`convertible() == true`]] 30 | [[Effects][converts `x` to python]] 31 | [[Returns][the resulting Python object iff a converter for `T` has been registered, `0` otherwise. ]] 32 | ] 33 | [endsect] 34 | [endsect] 35 | -------------------------------------------------------------------------------- /doc/html/images/callouts/15.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/html/images/callouts/27.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /include/boost/python/refcount.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef REFCOUNT_DWA2002615_HPP 6 | # define REFCOUNT_DWA2002615_HPP 7 | 8 | # include 9 | # include 10 | 11 | namespace boost { namespace python { 12 | 13 | template 14 | inline T* incref(T* p) 15 | { 16 | Py_INCREF(python::upcast(p)); 17 | return p; 18 | } 19 | 20 | template 21 | inline T* xincref(T* p) 22 | { 23 | Py_XINCREF(python::upcast(p)); 24 | return p; 25 | } 26 | 27 | template 28 | inline void decref(T* p) 29 | { 30 | assert( Py_REFCNT(python::upcast(p)) > 0 ); 31 | Py_DECREF(python::upcast(p)); 32 | } 33 | 34 | template 35 | inline void xdecref(T* p) 36 | { 37 | assert( !p || Py_REFCNT(python::upcast(p)) > 0 ); 38 | Py_XDECREF(python::upcast(p)); 39 | } 40 | 41 | }} // namespace boost::python 42 | 43 | #endif // REFCOUNT_DWA2002615_HPP 44 | -------------------------------------------------------------------------------- /test/borrowed.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #include 6 | #include 7 | #include 8 | 9 | using namespace boost::python; 10 | 11 | template 12 | void assert_borrowed_ptr(T const&) 13 | { 14 | BOOST_STATIC_ASSERT(boost::python::detail::is_borrowed_ptr::value); 15 | } 16 | 17 | template 18 | void assert_not_borrowed_ptr(T const&) 19 | { 20 | BOOST_STATIC_ASSERT(!boost::python::detail::is_borrowed_ptr::value); 21 | } 22 | 23 | int main() 24 | { 25 | assert_borrowed_ptr(borrowed((PyObject*)0)); 26 | assert_borrowed_ptr(borrowed((PyTypeObject*)0)); 27 | assert_borrowed_ptr((detail::borrowed const*)0); 28 | assert_borrowed_ptr((detail::borrowed volatile*)0); 29 | assert_borrowed_ptr((detail::borrowed const volatile*)0); 30 | assert_not_borrowed_ptr((PyObject*)0); 31 | assert_not_borrowed_ptr(0); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /example/quickstart/Jamfile: -------------------------------------------------------------------------------- 1 | # Copyright Stefan Seefeld 2016. 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at 4 | # http://www.boost.org/LICENSE_1_0.txt) 5 | 6 | import python ; 7 | import testing ; 8 | 9 | project quickstart 10 | : requirements 11 | . 12 | ; 13 | 14 | # Declare a Python extension called hello. 15 | python-extension extending : extending.cpp ; 16 | 17 | # Declare an executable called embedding that embeds Python 18 | exe embedding : embedding.cpp /python//python ; 19 | 20 | # Declare a test of the extension module 21 | testing.make-test run-pyd : extending test_extending.py : : test_ext ; 22 | 23 | # Declare a test of the embedding application 24 | testing.run embedding embedding.cpp 25 | : # any ordinary arguments 26 | : script.py # any arguments that should be treated as relative paths 27 | : # requirements 28 | : test_embed ; # name of test 29 | 30 | # Create a "test" target that runs all the tests 31 | alias test : test_ext test_embed ; 32 | 33 | # make sure the tests don't run by default 34 | explicit test_ext test_embed test ; 35 | 36 | -------------------------------------------------------------------------------- /test/implicit.py: -------------------------------------------------------------------------------- 1 | # Copyright David Abrahams 2004. Distributed under the Boost 2 | # Software License, Version 1.0. (See accompanying 3 | # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | ''' 5 | >>> from implicit_ext import * 6 | >>> x_value(X(42)) 7 | 42 8 | >>> x_value(42) 9 | 42 10 | >>> x = make_x(X(42)) 11 | >>> x.value() 12 | 42 13 | >>> try: make_x('fool') 14 | ... except TypeError: pass 15 | ... else: print('no error') 16 | 17 | >>> print(x_value.__doc__.splitlines()[1]) 18 | x_value( (X)arg1) -> int : 19 | 20 | >>> print(make_x.__doc__.splitlines()[1]) 21 | make_x( (object)arg1) -> X : 22 | 23 | >>> print(X.value.__doc__.splitlines()[1]) 24 | value( (X)arg1) -> int : 25 | 26 | >>> print(X.set.__doc__.splitlines()[1]) 27 | set( (X)arg1, (object)arg2) -> None : 28 | 29 | ''' 30 | 31 | def run(args = None): 32 | import sys 33 | import doctest 34 | 35 | if args is not None: 36 | sys.argv = args 37 | return doctest.testmod(sys.modules.get(__name__)) 38 | 39 | if __name__ == '__main__': 40 | print("running...") 41 | import sys 42 | status = run()[0] 43 | if (status == 0): print("Done.") 44 | sys.exit(status) 45 | -------------------------------------------------------------------------------- /doc/preface.qbk: -------------------------------------------------------------------------------- 1 | [preface Introduction 2 | [quickbook 1.6] 3 | ] 4 | 5 | [section Synopsis] 6 | 7 | Welcome to version 2 of Boost.Python, a C++ library which enables seamless interoperability between C++ and the Python programming language. The new version has been rewritten from the ground up, with a more convenient and flexible interface, and many new capabilities, including support for: 8 | 9 | * References and Pointers 10 | * Globally Registered Type Coercions 11 | * Automatic Cross-Module Type Conversions 12 | * Efficient Function Overloading 13 | * C++ to Python Exception Translation 14 | * Default Arguments 15 | * Keyword Arguments 16 | * Manipulating Python objects in C++ 17 | * Exporting C++ Iterators as Python Iterators 18 | * Documentation Strings 19 | 20 | The development of these features was funded in part by grants to Boost Consulting from the Lawrence Livermore National Laboratories and by the Computational Crystallography Initiative at Lawrence Berkeley National Laboratories. 21 | 22 | [endsect] 23 | [section Articles] 24 | 25 | "Building Hybrid Systems With Boost Python", by Dave Abrahams and Ralf W. Grosse-Kunstleve (PDF) 26 | [endsect] 27 | -------------------------------------------------------------------------------- /include/boost/python/wrapper.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #ifndef WRAPPER_DWA2004720_HPP 5 | # define WRAPPER_DWA2004720_HPP 6 | 7 | # include 8 | # include 9 | # include 10 | # include 11 | 12 | namespace boost { namespace python { 13 | 14 | template 15 | class wrapper : public detail::wrapper_base 16 | { 17 | public: 18 | // Do not touch this implementation detail! 19 | typedef T _wrapper_wrapped_type_; 20 | 21 | protected: 22 | override get_override(char const* name) const 23 | { 24 | typedef detail::wrapper_base base; 25 | converter::registration const& r 26 | = converter::registered::converters; 27 | PyTypeObject* type = r.get_class_object(); 28 | 29 | return this->base::get_override(name, type); 30 | } 31 | }; 32 | 33 | }} // namespace boost::python 34 | 35 | #endif // WRAPPER_DWA2004720_HPP 36 | -------------------------------------------------------------------------------- /include/boost/python/detail/void_return.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef VOID_RETURN_DWA200274_HPP 6 | # define VOID_RETURN_DWA200274_HPP 7 | 8 | # include 9 | 10 | namespace boost { namespace python { namespace detail { 11 | 12 | struct void_return 13 | { 14 | void_return() {} 15 | private: 16 | void operator=(void_return const&); 17 | }; 18 | 19 | template 20 | struct returnable 21 | { 22 | typedef T type; 23 | }; 24 | 25 | # ifdef BOOST_NO_VOID_RETURNS 26 | template <> 27 | struct returnable 28 | { 29 | typedef void_return type; 30 | }; 31 | 32 | # ifndef BOOST_NO_CV_VOID_SPECIALIZATIONS 33 | template <> struct returnable : returnable {}; 34 | template <> struct returnable : returnable {}; 35 | template <> struct returnable : returnable {}; 36 | # endif 37 | 38 | # endif // BOOST_NO_VOID_RETURNS 39 | 40 | }}} // namespace boost::python::detail 41 | 42 | #endif // VOID_RETURN_DWA200274_HPP 43 | -------------------------------------------------------------------------------- /doc/images/callouts/6.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /include/boost/python/detail/make_tuple.hpp: -------------------------------------------------------------------------------- 1 | # ifndef BOOST_PYTHON_SYNOPSIS 2 | # // Copyright David Abrahams 2002. 3 | # // Distributed under the Boost Software License, Version 1.0. (See 4 | # // accompanying file LICENSE_1_0.txt or copy at 5 | # // http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | # if !defined(BOOST_PP_IS_ITERATING) 8 | # error Boost.Python - do not include this file! 9 | # endif 10 | 11 | # define N BOOST_PP_ITERATION() 12 | 13 | # define BOOST_PYTHON_MAKE_TUPLE_ARG(z, N, ignored) \ 14 | PyTuple_SET_ITEM( \ 15 | result.ptr() \ 16 | , N \ 17 | , python::incref(python::object(a##N).ptr()) \ 18 | ); 19 | 20 | template 21 | tuple 22 | make_tuple(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a)) 23 | { 24 | tuple result((detail::new_reference)::PyTuple_New(N)); 25 | BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_MAKE_TUPLE_ARG, _) 26 | return result; 27 | } 28 | 29 | # undef BOOST_PYTHON_MAKE_TUPLE_ARG 30 | 31 | # undef N 32 | # endif // BOOST_PYTHON_SYNOPSIS 33 | -------------------------------------------------------------------------------- /.github/workflows/deploy-documentation.yml: -------------------------------------------------------------------------------- 1 | name: deploy documentation 2 | 3 | on: [push] 4 | 5 | jobs: 6 | deploy: 7 | runs-on: ubuntu-24.04 8 | steps: 9 | - uses: actions/checkout@v5 10 | - name: setup 11 | run: | 12 | sudo apt-get update 13 | sudo apt-get install \ 14 | libboost-tools-dev \ 15 | python3 \ 16 | python3-numpy \ 17 | python3-sphinx \ 18 | xsltproc \ 19 | docbook-xsl 20 | sudo python3 -m pip install --upgrade pip 21 | sudo python3 -m pip install faber 22 | - name: build 23 | run: | 24 | sed -e "s/\$PYTHON/python3/g" .ci/faber > ~/.faber 25 | faber --builddir=build doc.html 26 | if [ "${GITHUB_REF##*/}" == master ]; then 27 | echo "destination_dir=doc/html" >> $GITHUB_ENV 28 | else 29 | echo "destination_dir=doc/develop/html" >> $GITHUB_ENV 30 | fi 31 | - name: deploy 32 | uses: peaceiris/actions-gh-pages@v4 33 | with: 34 | github_token: ${{ secrets.GITHUB_TOKEN }} 35 | publish_dir: build/doc/html 36 | destination_dir: ${{ env.destination_dir }} 37 | keep_files: true 38 | -------------------------------------------------------------------------------- /doc/html/images/callouts/6.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/images/callouts/24.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /doc/html/images/callouts/24.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | ]> 7 | 9 | 10 | 11 | 12 | 15 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /test/bienstman1.cpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2004. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying 3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | struct A {}; 11 | 12 | struct V 13 | { 14 | virtual ~V() {}; // silence compiler warningsa 15 | virtual void f() = 0; 16 | 17 | const A* inside() {return &a;} 18 | 19 | A a; 20 | }; 21 | 22 | const A* outside(const V& v) {return &v.a;} 23 | 24 | BOOST_PYTHON_MODULE(bienstman1_ext) 25 | { 26 | using namespace boost::python; 27 | using boost::shared_ptr; 28 | using boost::python::return_value_policy; 29 | using boost::python::reference_existing_object; 30 | 31 | class_("A"); 32 | 33 | class_("V", no_init) 34 | .def("inside", &V::inside, 35 | return_value_policy()) 36 | .def("outside", outside, 37 | return_value_policy()) 38 | ; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /include/boost/python/detail/cv_category.hpp: -------------------------------------------------------------------------------- 1 | // Copyright David Abrahams 2002. 2 | // Distributed under the Boost Software License, Version 1.0. (See 3 | // accompanying file LICENSE_1_0.txt or copy at 4 | // http://www.boost.org/LICENSE_1_0.txt) 5 | #ifndef CV_CATEGORY_DWA200222_HPP 6 | # define CV_CATEGORY_DWA200222_HPP 7 | # include 8 | 9 | namespace boost { namespace python { namespace detail { 10 | 11 | template 12 | struct cv_tag 13 | { 14 | BOOST_STATIC_CONSTANT(bool, is_const = is_const_); 15 | BOOST_STATIC_CONSTANT(bool, is_volatile = is_volatile_); 16 | }; 17 | 18 | typedef cv_tag cv_unqualified; 19 | typedef cv_tag const_; 20 | typedef cv_tag volatile_; 21 | typedef cv_tag const_volatile_; 22 | 23 | template 24 | struct cv_category 25 | { 26 | // BOOST_STATIC_CONSTANT(bool, c = is_const::value); 27 | // BOOST_STATIC_CONSTANT(bool, v = is_volatile::value); 28 | typedef cv_tag< 29 | is_const::value 30 | , is_volatile::value 31 | > type; 32 | }; 33 | 34 | }}} // namespace boost::python::detail 35 | 36 | #endif // CV_CATEGORY_DWA200222_HPP 37 | --------------------------------------------------------------------------------