pybind11/tests
Jason Rhinelander 464d98962d Allow binding factory functions as constructors
This allows you to use:

    cls.def(py::init(&factory_function));

where `factory_function` returns a pointer, holder, or value of the
class type (or a derived type).  Various compile-time checks
(static_asserts) are performed to ensure the function is valid, and
various run-time type checks where necessary.

Some other details of this feature:
- The `py::init` name doesn't conflict with the templated no-argument
  `py::init<...>()`, but keeps the naming consistent: the existing
  templated, no-argument one wraps constructors, the no-template,
  function-argument one wraps factory functions.
- If returning a CppClass (whether by value or pointer) when an CppAlias
  is required (i.e. python-side inheritance and a declared alias), a
  dynamic_cast to the alias is attempted (for the pointer version); if
  it fails, or if returned by value, an Alias(Class &&) constructor
  is invoked.  If this constructor doesn't exist, a runtime error occurs.
- for holder returns when an alias is required, we try a dynamic_cast of
  the wrapped pointer to the alias to see if it is already an alias
  instance; if it isn't, we raise an error.
- `py::init(class_factory, alias_factory)` is also available that takes
  two factories: the first is called when an alias is not needed, the
  second when it is.
- Reimplement factory instance clearing.  The previous implementation
  failed under python-side multiple inheritance: *each* inherited
  type's factory init would clear the instance instead of only setting
  its own type value.  The new implementation here clears just the
  relevant value pointer.
- dealloc is updated to explicitly set the leftover value pointer to
  nullptr and the `holder_constructed` flag to false so that it can be
  used to clear preallocated value without needing to rebuild the
  instance internals data.
- Added various tests to test out new allocation/deallocation code.
- With preallocation now done lazily, init factory holders can
  completely avoid the extra overhead of needing an extra
  allocation/deallocation.
- Updated documentation to make factory constructors the default
  advanced constructor style.
- If an `__init__` is called a second time, we have two choices: we can
  throw away the first instance, replacing it with the second; or we can
  ignore the second call.  The latter is slightly easier, so do that.
2017-08-17 09:33:27 -04:00
..
test_cmake_build Add test for custom CMake export group 2017-08-07 23:08:20 +02:00
test_embed Fix embedded threads test on MSVC2015 / Python 2.7 2017-06-24 21:59:55 +02:00
CMakeLists.txt Allow binding factory functions as constructors 2017-08-17 09:33:27 -04:00
conftest.py Allow binding factory functions as constructors 2017-08-17 09:33:27 -04:00
constructor_stats.h Support multiple inheritance from python 2017-06-12 09:56:55 -03:00
local_bindings.h Add test for mixing STL casters and local binders across modules 2017-08-14 01:11:52 +02:00
object.h Improve custom holder support (#607) 2017-01-31 17:05:44 +01:00
pybind11_cross_module_tests.cpp Add test for mixing STL casters and local binders across modules 2017-08-14 01:11:52 +02:00
pybind11_tests.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
pybind11_tests.h Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
pytest.ini Don't let pytest discover tests from test_cmake_build and test_embed 2017-06-10 16:44:21 +02:00
test_buffers.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_buffers.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_builtin_casters.cpp Implicit conversions to bool + np.bool_ conversion (#925) 2017-07-23 11:02:43 -04:00
test_builtin_casters.py Ignore undefined name long errors on Python 3 2017-08-05 18:46:22 -04:00
test_call_policies.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_call_policies.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_callbacks.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_callbacks.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_chrono.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_chrono.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_class.cpp Add a polymorphic static assert when using an alias 2017-08-17 09:33:27 -04:00
test_class.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_constants_and_functions.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_constants_and_functions.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_copy_move.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_copy_move.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_docstring_options.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_docstring_options.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_eigen.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_eigen.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_enum.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_enum.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_eval_call.py Add checks to maintain a consistent Python code style and prevent bugs (#515) 2016-11-20 21:21:54 +01:00
test_eval.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_eval.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_exceptions.cpp Simplify error_already_set 2017-07-28 20:40:35 -04:00
test_exceptions.py Fix builtin exception handlers to work across modules 2017-08-04 10:47:34 -04:00
test_factory_constructors.cpp Allow binding factory functions as constructors 2017-08-17 09:33:27 -04:00
test_factory_constructors.py Allow binding factory functions as constructors 2017-08-17 09:33:27 -04:00
test_kwargs_and_defaults.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_kwargs_and_defaults.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_local_bindings.cpp Add test for mixing STL casters and local binders across modules 2017-08-14 01:11:52 +02:00
test_local_bindings.py Add test for mixing STL casters and local binders across modules 2017-08-14 01:11:52 +02:00
test_methods_and_attributes.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_methods_and_attributes.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_modules.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_modules.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_multiple_inheritance.cpp Make init_holder do registration, and rename to init_instance 2017-07-28 20:39:33 -04:00
test_multiple_inheritance.py Allow binding factory functions as constructors 2017-08-17 09:33:27 -04:00
test_numpy_array.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_numpy_array.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_numpy_dtypes.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_numpy_dtypes.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_numpy_vectorize.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_numpy_vectorize.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_opaque_types.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_opaque_types.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_operator_overloading.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_operator_overloading.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_pickling.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_pickling.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_pytypes.cpp Split test_python_types.cpp into builtin_casters, stl and pytypes 2017-06-27 10:38:41 +02:00
test_pytypes.py Make PYBIND11_OBJECT_CVT only convert if the type check fails 2017-08-04 10:14:55 -04:00
test_sequences_and_iterators.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_sequences_and_iterators.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_smart_ptr.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_smart_ptr.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_stl_binders.cpp Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_stl_binders.py Update all remaining tests to new test styles 2017-08-05 18:46:22 -04:00
test_stl.cpp Add support for boost::variant in C++11 mode 2017-08-12 21:27:44 +02:00
test_stl.py Fix regression: container pointers not castable 2017-07-16 11:04:43 -04:00
test_virtual_functions.cpp Allow binding factory functions as constructors 2017-08-17 09:33:27 -04:00
test_virtual_functions.py Allow binding factory functions as constructors 2017-08-17 09:33:27 -04:00