1. 24 Jun, 2017 3 commits
    • Bruce Merry's avatar
      Hold strong references to keep_alive patients · 9d698f7f
      Bruce Merry authored
      This fixes #856. Instead of the weakref trick, the internals structure
      holds an unordered_map from PyObject* to a vector of references. To
      avoid the cost of the unordered_map lookup for objects that don't have
      any keep_alive patients, a flag is added to each instance to indicate
      whether there is anything to do.
      9d698f7f
    • Jason Rhinelander's avatar
      Use std::type_info::name() for type lookups outside stdlibc++ · 21966967
      Jason Rhinelander authored
      Using `std::type_info::operator==` fails under libc++ because the .so
      is loaded with RTLD_LOCAL.  libc++ considers types under such .sos
      distinct, and so comparing typeid() values directly isn't going to work.
      
      This adds a custom hasher and equality class for the type lookup maps
      when not under stdlibc++, and adds a `detail::same_type` function to
      perform the equality test.  It also converts a few pointer arguments to
      const lvalue references, particularly since doing the pointer
      comparison wasn't technically valid to being with (though in practice,
      appeared to work everywhere).
      
      This fixes #912.
      21966967
    • Dean Moldovan's avatar
      Fix GIL release and acquire when embedding the interpreter · 2d6116b5
      Dean Moldovan authored
      Fixes a race condition when multiple threads try to acquire the GIL
      before `detail::internals` have been initialized. `gil_scoped_release`
      is now tasked with initializing `internals` (guaranteed single-threaded)
      to ensure the safety of subsequent `acquire` calls from multiple threads.
      2d6116b5
  2. 12 Jun, 2017 1 commit
    • Jason Rhinelander's avatar
      Support multiple inheritance from python · e45c2114
      Jason Rhinelander authored
      This commit allows multiple inheritance of pybind11 classes from
      Python, e.g.
      
          class MyType(Base1, Base2):
              def __init__(self):
                  Base1.__init__(self)
                  Base2.__init__(self)
      
      where Base1 and Base2 are pybind11-exported classes.
      
      This requires collapsing the various builtin base objects
      (pybind11_object_56, ...) introduced in 2.1 into a single
      pybind11_object of a fixed size; this fixed size object allocates enough
      space to contain either a simple object (one base class & small* holder
      instance), or a pointer to a new allocation that can contain an
      arbitrary number of base classes and holders, with holder size
      unrestricted.
      
      * "small" here means having a sizeof() of at most 2 pointers, which is
      enough to fit unique_ptr (sizeof is 1 ptr) and shared_ptr (sizeof is 2
      ptrs).
      
      To minimize the performance impact, this repurposes
      `internals::registered_types_py` to store a vector of pybind-registered
      base types.  For direct-use pybind types (e.g. the `PyA` for a C++ `A`)
      this is simply storing the same thing as before, but now in a vector;
      for Python-side inherited types, the map lets us avoid having to do a
      base class traversal as long as we've seen the class before.  The
      change to vector is needed for multiple inheritance: Python types
      inheriting from multiple registered bases have one entry per base.
      e45c2114
  3. 10 Jun, 2017 1 commit
  4. 07 Jun, 2017 1 commit
  5. 28 May, 2017 1 commit
  6. 25 May, 2017 2 commits
    • Jason Rhinelander's avatar
      Add and use detail::remove_reference_t · 129a7256
      Jason Rhinelander authored
      Adds `remove_reference_t` and converts various `typename
      std::remove_reference<...>::type` to using it.
      129a7256
    • Jason Rhinelander's avatar
      Add PYBIND11_EXPAND_SIDE_EFFECTS macro · 926e2cf3
      Jason Rhinelander authored
      This allows calling of functions (typically void) over a parameter
      pack, replacing usage such as:
      
          bool unused[] = { (voidfunc(param_pack_arg), false)..., false };
          (void) unused;
      
      with a much cleaner:
      
          PYBIND11_EXPAND_SIDE_EFFECTS(voidfunc(param_pack_arg));
      926e2cf3
  7. 24 May, 2017 2 commits
    • Jason Rhinelander's avatar
      Allow py::arg().none(false) argument attribute · 4e1e4a58
      Jason Rhinelander authored
      This attribute lets you disable (or explicitly enable) passing None to
      an argument that otherwise would allow it by accepting
      a value by raw pointer or shared_ptr.
      4e1e4a58
    • Jason Rhinelander's avatar
      Add movable cast support to type casters · 813d7e86
      Jason Rhinelander authored
      This commit allows type_casters to allow their local values to be moved
      away, rather than copied, when the type caster instance itself is an rvalue.
      
      This only applies (automatically) to type casters using
      PYBIND11_TYPE_CASTER; the generic type type casters don't own their own
      pointer, and various value casters (e.g. std::string, std::pair,
      arithmetic types) already cast to an rvalue (i.e. they return by value).
      
      This updates various calling code to attempt to get a movable value
      whenever the value is itself coming from a type caster about to be
      destroyed: for example, when constructing an std::pair or various stl.h
      containers.  For types that don't support value moving, the cast_op
      falls back to an lvalue cast.
      
      There wasn't an obvious place to add the tests, so I added them to
      test_copy_move_policies, but also renamed it to drop the _policies as it
      now tests more than just policies.
      813d7e86
  8. 22 May, 2017 3 commits
    • Bruce Merry's avatar
      Support pointers to member functions in def_buffer. · fe0cf8b7
      Bruce Merry authored
      Closes #857, by adding overloads to def_buffer that match pointers to
      member functions and wrap them in lambdas.
      fe0cf8b7
    • Jason Rhinelander's avatar
      Style cleanup of javadoc-style comments · 37b2383a
      Jason Rhinelander authored
      This changes javadoc-style documenting comments from:
      
          /** Text starts here
           * and continues here
           */
      
      to:
      
          /**
           * Test starts here
           * and continues here
           */
      
      which looks a little better, and also matches the javadoc-recommended
      way of writing documenting comments.
      37b2383a
    • Jason Rhinelander's avatar
      Use dynamic cast for shared_from_this holder init · b8ac4383
      Jason Rhinelander authored
      Using a dynamic_cast instead of a static_cast is needed to safely cast
      from a base to a derived type.  The previous static_pointer_cast isn't
      safe, however, when downcasting (and fails to compile when downcasting
      with virtual inheritance).
      
      Switching this to always use a dynamic_pointer_cast shouldn't incur any
      additional overhead when a static_pointer_cast is safe (i.e. when
      upcasting, or self-casting): compilers don't need RTTI checks in those
      cases.
      b8ac4383
  9. 09 May, 2017 3 commits
    • Jason Rhinelander's avatar
      Update PYBIND11_CPP1{4,7} macros for MSVC · ca0e82b7
      Jason Rhinelander authored
      The PYBIND11_CPP14 macro started out as a guard for the compile-time
      path code in `descr.h`, but has since come to mean other things.  This
      means that while the `descr.h` check has just checked the
      `PYBIND11_CPP14` macro, various other places now check `PYBIND11_CPP14
      || _MSC_VER`.  This reverses that by now setting the CPP14 macro when
      MSVC is trying to support C++14, but disabling the `descr.h` C++14 code
      (which still fails under MSVC 2017).
      
      The CPP17 macro also gets enabled when MSVC 2017 is compiling with
      /std:c++latest (the default is /std:c++14), which enables
      `std::optional` and `std::variant` support under MSVC.
      ca0e82b7
    • Jason Rhinelander's avatar
      d15b217f
    • Jason Rhinelander's avatar
      gcc 7 disable warning · 88ebc49b
      Jason Rhinelander authored
      GCC 7 generates (when compiling in C++11/14 mode) warnings such as:
      
          mangled name for ‘pybind11::class_<type_, options>&
          pybind11::class_<type_, options>::def(const char*, Func&&, const Extra&
          ...) [with Func = int (test_exc_sp::C::*)(int) noexcept; Extra = {};
          type_ = test_exc_sp::C; options = {}]’ will change in C++17 because the
          exception specification is part of a function type [-Wnoexcept-type]
      
      There's nothing we can actually do in the code to avoid this, so just
      disable the warning.
      88ebc49b
  10. 07 May, 2017 1 commit
  11. 29 Apr, 2017 1 commit
    • Wenzel Jakob's avatar
      enum_: fix implicit conversion on Python 2.7 · e6fd2cd5
      Wenzel Jakob authored
      Enumerations on Python 2.7 were not always implicitly converted to
      integers (depending on the target size). This patch adds a __long__
      conversion function (only enabled on 2.7) which fixes this issue.
      
      The attached test case fails without this patch.
      e6fd2cd5
  12. 28 Apr, 2017 1 commit
    • Jason Rhinelander's avatar
      Don't let PyInstanceMethod hide itself · 0a90b2db
      Jason Rhinelander authored
      Python 3's `PyInstanceMethod_Type` hides itself via its `tp_descr_get`,
      which prevents aliasing methods via `cls.attr("m2") = cls.attr("m1")`:
      instead the `tp_descr_get` returns a plain function, when called on a
      class, or a `PyMethod`, when called on an instance.  Override that
      behaviour for pybind11 types with a special bypass for
      `PyInstanceMethod_Types`.
      0a90b2db
  13. 27 Apr, 2017 1 commit
    • Jason Rhinelander's avatar
      Track base class pointers of instances · 1f8a100d
      Jason Rhinelander authored
      This commits adds base class pointers of offset base classes (i.e. due
      to multiple inheritance) to `registered_instances` so that if such a
      pointer is returned we properly recognize it as an existing instance.
      
      Without this, returning a base class pointer will cast to the existing
      instance if the pointer happens to coincide with the instance pointer,
      but constructs a new instance (quite possibly with a segfault, if
      ownership is applied) for unequal base class pointers due to multiple
      inheritance.
      1f8a100d
  14. 18 Apr, 2017 1 commit
    • Jason Rhinelander's avatar
      Don't allow mixed static/non-static overloads · d355f2fc
      Jason Rhinelander authored
      We currently fail at runtime when trying to call a method that is
      overloaded with both static and non-static methods.  This is something
      python won't allow: the object is either a function or an instance, and
      can't be both.
      d355f2fc
  15. 02 Apr, 2017 2 commits
  16. 30 Mar, 2017 1 commit
  17. 22 Mar, 2017 2 commits
  18. 19 Mar, 2017 1 commit
    • Jason Rhinelander's avatar
      Error message wording tweak · 0f5ec0a8
      Jason Rhinelander authored
      py::arg() doesn't only specify named arguments anymore, so the error
      message was misleading (e.g. when using `py::arg().noconvert()` and
      forgetting `py::arg()` for a second positional argument).
      0f5ec0a8
  19. 18 Mar, 2017 1 commit
  20. 17 Mar, 2017 1 commit
    • Jason Rhinelander's avatar
      Fail to compile with MI via class_ ctor parameters · b961626c
      Jason Rhinelander authored
      We can't support this for classes from imported modules (which is the
      primary purpose of a ctor argument base class) because we *have* to
      have both parent and derived to properly extract a multiple-inheritance
      base class pointer from a derived class pointer.
      
      We could support this for actual `class_<Base, ...> instances, but since
      in that case the `Base` is already present in the code, it seems more
      consistent to simply always require MI to go via template options.
      b961626c
  21. 13 Mar, 2017 1 commit
  22. 12 Mar, 2017 1 commit
    • Jason Rhinelander's avatar
      Add MSVC 2017 cpp_function ICE workaround · 2d965d43
      Jason Rhinelander authored
      The `decltype(...)` in the template parameter that gives us SFINAE
      matching for a lambda makes MSVC 2017 ICE; this works around if by
      changing the test to an explicit not-a-function-or-pointer test, which
      seems to work everywhere.
      2d965d43
  23. 08 Mar, 2017 1 commit
    • Jason Rhinelander's avatar
      Fix extra docstring newlines under `options.disable_function_signatures()` · 10d13048
      Jason Rhinelander authored
      When using pybind::options to disable function signatures, user-defined
      docstrings only get appended if they exist, but newlines were getting
      appended unconditionally, so the docstring could end up with blank lines
      (depending on which overloads, in particular, provided docstrings).
      
      This commit suppresses the empty lines by only adding newlines for
      overloads when needed.
      10d13048
  24. 04 Mar, 2017 1 commit
  25. 03 Mar, 2017 1 commit
  26. 26 Feb, 2017 1 commit
  27. 24 Feb, 2017 3 commits
    • Jason Rhinelander's avatar
      Add an ability to avoid forcing rvp::move · 546f6fce
      Jason Rhinelander authored
      Eigen::Ref objects, when returned, are almost always returned as
      rvalues; what's important is the data they reference, not the outer
      shell, and so we want to be able to use `::copy`,
      `::reference_internal`, etc. to refer to the data the Eigen::Ref
      references (in the following commits), rather than the Eigen::Ref
      instance itself.
      
      This moves the policy override into a struct so that code that wants to
      avoid it (or wants to provide some other Return-type-conditional
      override) can create a specialization of
      return_value_policy_override<Return> in order to override the override.
      
      This lets an Eigen::Ref-returning function be bound with `rvp::copy`,
      for example, to specify that the data should be copied into a new numpy
      array rather than referenced, or `rvp::reference_internal` to indicate
      that it should be referenced, but a keep-alive used (actually, we used
      the array's `base` rather than a py::keep_alive in such a case, but it
      accomplishes the same thing).
      546f6fce
    • Jason Rhinelander's avatar
      Show kwargs in failed method invocation · 231e1678
      Jason Rhinelander authored
      With the previous commit, output can be very confusing because you only
      see positional arguments in the "invoked with" line, but you can have a
      failure from kwargs as well (in particular, when a value is invalidly
      specified via both via positional and kwargs).  This commits adds
      kwargs to the output, and updates the associated tests to match.
      231e1678
    • Jason Rhinelander's avatar
      Make bad kwarg arguments try next overload · caa1379e
      Jason Rhinelander authored
      Fixes #688.
      
      My (commented) assumption that such an error is "highly likely to be a
      caller mistake" was proven false by #688.
      caa1379e
  28. 23 Feb, 2017 1 commit
    • Dean Moldovan's avatar
      Enable static properties (py::metaclass) by default · dd01665e
      Dean Moldovan authored
      Now that only one shared metaclass is ever allocated, it's extremely
      cheap to enable it for all pybind11 types.
      
      * Deprecate the default py::metaclass() since it's not needed anymore.
      * Allow users to specify a custom metaclass via py::metaclass(handle).
      dd01665e