1. 10 Mar, 2018 1 commit
    • Fix for Python3 via brew · 1ddfacba
      Apparently with homebrew the correct package for python3 is now just
      `python`; python 2 was relegated to 'python@2', and `python3` is an
      alias for `python` (which needs to be upgraded rather than installed).
      Jason Rhinelander committed
  2. 28 Feb, 2018 2 commits
  3. 18 Feb, 2018 1 commit
  4. 07 Feb, 2018 1 commit
  5. 06 Feb, 2018 1 commit
  6. 12 Jan, 2018 3 commits
    • Remove unnecessary `detail::` · 657a51e8
      This function already has a `using namespace detail`, so all the
      `detail::` qualifications are not needed.
      Jason Rhinelander committed
    • Use stricter brace initialization · adbc8111
      This updates the `py::init` constructors to only use brace
      initialization for aggregate initiailization if there is no constructor
      with the given arguments.
      
      This, in particular, fixes the regression in #1247 where the presence of
      a `std::initializer_list<T>` constructor started being invoked for
      constructor invocations in 2.2 even when there was a specific
      constructor of the desired type.
      
      The added test case demonstrates: without this change, it fails to
      compile because the `.def(py::init<std::vector<int>>())` constructor
      tries to invoke the `T(std::initializer_list<std::vector<int>>)`
      constructor rather than the `T(std::vector<int>)` constructor.
      
      By only using `new T{...}`-style construction when a `T(...)`
      constructor doesn't exist, we should bypass this by while still allowing
      `py::init<...>` to be used for aggregate type initialization (since such
      types, by definition, don't have a user-declared constructor).
      Jason Rhinelander committed
  7. 11 Jan, 2018 5 commits
    • Fix segfault when reloading interpreter with external modules (#1092) · 326deef2
      * Fix segfault when reloading interpreter with external modules
      
      When embedding the interpreter and loading external modules in that
      embedded interpreter, the external module correctly shares its
      internals_ptr with the one in the embedded interpreter.  When the
      interpreter is shut down, however, only the `internals_ptr` local to
      the embedded code is actually reset to nullptr: the external module
      remains set.
      
      The result is that loading an external pybind11 module, letting the
      interpreter go through a finalize/initialize, then attempting to use
      something in the external module fails because this external module is
      still trying to use the old (destroyed) internals.  This causes
      undefined behaviour (typically a segfault).
      
      This commit fixes it by adding a level of indirection in the internals
      path, converting the local internals variable to `internals **` instead
      of `internals *`.  With this change, we can detect a stale internals
      pointer and reload the internals pointer (either from a capsule or by
      creating a new internals instance).
      
      (No issue number: this was reported on gitter by @henryiii and @aoloe).
      Jason Rhinelander committed
    • fix return from std::map bindings to __delitem__ (#1229) · 05d379a9
      Fix return from `std::map` bindings to `__delitem__`: we should be returning `void`, not an iterator.
      
      Also adds a test for map item deletion.
      Jeff VanOss committed
    • misc. typos · 28cb6764
      Found via `codespell`
      luz.paz committed
    • Use a named rather than anon struct in instance · 507da418
      The anonymous struct nested in a union triggers a -Wnested-anon-type
      warning ("anonymous types declared in an anonymous union are an
      extension") under clang (#1204).  This names the struct and defines it
      out of the definition of `instance` to get around to warning (and makes
      the code slightly simpler).
      Jason Rhinelander committed
    • Fixes for numpy 1.14.0 compatibility · 88efb251
      - UPDATEIFCOPY is deprecated, replaced with similar (but not identical)
        WRITEBACKIFCOPY; trying to access the flag causes a deprecation
        warning under numpy 1.14, so just check the new flag there.
      - Numpy `repr` formatting of floats changed in 1.14.0 to `[1., 2., 3.]`
        instead of the pre-1.14 `[ 1.,  2.,  3.]`.  Updated the tests to
        check for equality with the `repr(...)` value rather than the
        hard-coded (and now version-dependent) string representation.
      Jason Rhinelander committed
  8. 27 Dec, 2017 2 commits
  9. 23 Dec, 2017 6 commits
    • Simplify arg copying · 367d723a
      Jason Rhinelander committed
    • Fix leak in var arg handling · 03874e37
      When using the mixed position + vararg path, pybind over inc_ref's
      the vararg positions. Printing the ref_count() of `item` before
      and after this change you see:
      
      Before change:
      
      ```
      refcount of item before assign 3
      refcount of item after assign 5
      ```
      
      After change
      ```
      refcount of item before assign 3
      refcount of item after assign 4
      ```
      Zach DeVito committed
    • Fix premature destruction of args/kwargs arguments · 48e1f9aa
      The `py::args` or `py::kwargs` arguments aren't properly referenced
      when added to the function_call arguments list: their reference counts
      drop to zero if the first (non-converting) function call fails, which
      means they might be cleaned up before the second pass call runs.
      
      This commit adds a couple of extra `object`s to the `function_call`
      where we can stash a reference to them when needed to tie their
      lifetime to the function_call object's lifetime.
      
      (Credit to YannickJadoul for catching and proposing a fix in #1223).
      Jason Rhinelander committed
    • Silence new MSVC C++17 deprecation warnings · 3be401f2
      In the latest MSVC in C++17 mode including Eigen causes warnings:
      
          warning C4996: 'std::unary_negate<_Fn>': warning STL4008: std::not1(),
          std::not2(), std::unary_negate, and std::binary_negate are deprecated in
          C++17. They are superseded by std::not_fn(). You can define
          _SILENCE_CXX17_NEGATORS_DEPRECATION_WARNING or
          _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS to acknowledge that you have
          received this warning.
      
      This disables 4996 for the Eigen includes.
      
      Catch generates a similar warning for std::uncaught_exception, so
      disable the warning there, too.
      
      In both cases this is temporary; we can (and should) remove the warnings
      disabling once new upstream versions of Eigen and Catch are available
      that address the warning. (The Catch one, in particular, looks to be
      fixed in upstream master, so will probably be fixed in the next (2.0.2)
      release).
      Jason Rhinelander committed
  10. 04 Dec, 2017 1 commit
  11. 30 Nov, 2017 1 commit
    • Matching Python 2 int behavior on Python 2 (#1186) · cf0d0f9d
      Pybind11's default conversion to int always produces a long on Python 2 (`int`s and `long`s were unified in Python 3). This patch fixes `int` handling to match Python 2 on Python 2; for short types (`size_t` or smaller), the number will be returned as an `int` if possible, otherwise `long`. Requires Python 2.5+.
      
      This is needed for things like `sys.exit`, which refuse to accept a `long`.
      Henry Schreiner committed
  12. 24 Nov, 2017 1 commit
  13. 22 Nov, 2017 2 commits
    • Clean up eigen download code (and bump to 3.3.4) · 086d53e8
      This changes the travis-ci eigen download code to extract the tar on the
      fly (rather than saving to a file first), and extracts into an `eigen`
      directory rather than using upstream's `eigen-eigen-xxxxx` directory.
      
      This also bumps the travis-ci eigen release to 3.3.4, in an attempt to
      see if it fixed the -Wdeprecated warnings (it did not); the build setup
      cleanup seems worth committing anyway.
      Jason Rhinelander committed
    • Add -Wdeprecated to test suite and fix associated warnings (#1191) · ba33b2fc
      This commit turns on `-Wdeprecated` in the test suite and fixes several
      associated deprecation warnings that show up as a result:
      
      - in C++17 `static constexpr` members are implicitly inline; our
        redeclaration (needed for C++11/14) is deprecated in C++17.
      
      - various test suite classes have destructors and rely on implicit copy
        constructors, but implicit copy constructor definitions when a
        user-declared destructor is present was deprecated in C++11.
      
      - Eigen also has various implicit copy constructors, so just disable
        `-Wdeprecated` in `eigen.h`.
      Francesco Biscani committed
  14. 17 Nov, 2017 2 commits
  15. 16 Nov, 2017 1 commit
  16. 07 Nov, 2017 2 commits
    • Added write only property functions for issue #1142 (#1144) · 0a0758ce
      py::class_<T>'s `def_property` and `def_property_static` can now take a
      `nullptr` as the getter to allow a write-only property to be established
      (mirroring Python's `property()` built-in when `None` is given for the
      getter).
      
      This also updates properties to use the new nullptr constructor internally.
      Ted Drain committed
    • __qualname__ and nested class naming fixes (#1171) · 71178922
      A few fixes related to how we set `__qualname__` and how we show the
      type name in function signatures:
      
      - `__qualname__` isn't supposed to have the module name at the
      beginning, but we've been putting it there.  This removes it, while
      keeping the `Nested.Class` name chaining.
      
      - print `__module__.__qualname__` rather than `type->tp_name`; the
      latter doesn't work properly for nested classes, so we would get
      `module.B` rather than `module.A.B` for a class `B` with parent `A`.
      This also unifies the Python 3 and PyPy code.  Fixes #1166.
      
      - This now sets a `__qualname__` attribute on the type (as would happen
      in Python 3.3+) for Python <3.3, including PyPy.  While not particularly
      important to have in earlier Python versions, it's useful for us to be
      able to extracted the nested name, which is why `__qualname__` was
      invented in the first place.
      
      - Added tests for the above.
      Jason Rhinelander committed
  17. 02 Nov, 2017 1 commit
  18. 25 Oct, 2017 1 commit
  19. 24 Oct, 2017 1 commit
  20. 22 Oct, 2017 2 commits
    • Miscellaneous travis-ci updates/fixes · 835fa9bc
      - For the debian/buster docker build (GCC 7/C++17) install and use the
        system `catch` package; this also renames "COMPILER_PACKAGES" to
        "EXTRA_PACKAGES" since it now contains a non-compiler package.
      
      - Add a status message indicating the catch version being used for
        compiling the embedded tests
      
      - Simplify some bash code by using VAR+=" foo" to append (rather than
        VAR="${VAR} foo"
      
      - Fix CMAKE_INCLUDE_PATH appending: it was prepending the ':' but not
        the existing $CMAKE_INCLUDE_PATH value and so would end up with
        ":/eigen-path" if CMAKE_INCLUDE_PATH was already set.  (This wasn't
        bug that was actually noticed since currently nothing else sets it).
      Jason Rhinelander committed
    • Build /permissive- under VS2017 · a582d6c7
      Building with the (VS2017) /permissive- flag puts the compiler into
      stricter standards-compliant mode.  It shouldn't cause the compiler to
      work differently--it just disallows some non-conforming code--so should
      be perfectly fine for the test suite under all VS2017 builds.
      
      This commit also fixes one failure under non-permissive mode.
      Jason Rhinelander committed
  21. 12 Oct, 2017 3 commits
    • Fix 2D Nx1/1xN inputs to eigen dense vector args · 6a81dbbb
      This fixes a bug introduced in b68959e8
      when passing in a two-dimensional, but conformable, array as the value
      for a compile-time Eigen vector (such as VectorXd or RowVectorXd).  The
      commit switched to using numpy to copy into the eigen data, but this
      broke the described case because numpy refuses to broadcast a (N,1)
      into a (N).
      
      This commit fixes it by squeezing the input array whenever the output
      array is 1-dimensional, which will let the problematic case through.
      (This shouldn't squeeze inappropriately as dimension compatibility is
      already checked for conformability before getting to the copy code).
      Jason Rhinelander committed
    • Add informative compilation failure for method_adaptor failures · 7672292e
      When using `method_adaptor` (usually implicitly via a `cl.def("f",
      &D::f)`) a compilation failure results if `f` is actually a method of
      an inaccessible base class made public via `using`, such as:
      
          class B { public: void f() {} };
          class D : private B { public: using B::f; };
      
      pybind deduces `&D::f` as a `B` member function pointer.  Since the base
      class is inaccessible, the cast in `method_adaptor` from a base class
      member function pointer to derived class member function pointer isn't
      valid, and a cast failure results.
      
      This was sort of a regression in 2.2, which introduced `method_adaptor`
      to do the expected thing when the base class *is* accessible.  It wasn't
      actually something that *worked* in 2.1, though: you wouldn't get a
      compile-time failure, but the method was not callable (because the `D *`
      couldn't be cast to a `B *` because of the access restriction).  As a
      result, you'd simply get a run-time failure if you ever tried to call
      the function (this is what #855 fixed).
      
      Thus the change in 2.2 essentially promoted a run-time failure to a
      compile-time failure, so isn't really a regression.
      
      This commit simply adds a `static_assert` with an accessible-base-class
      check so that, rather than just a cryptic cast failure, you get
      something more informative (along with a suggestion for a workaround).
      
      The workaround is to use a lambda, e.g.:
      
          class Derived : private Base {
          public:
              using Base::f;
          };
      
          // In binding code:
          //cl.def("f", &Derived::f); // fails: &Derived::f is actually a base
                                      // class member function pointer
          cl.def("f", [](Derived &self) { return self.f(); });
      
      This is a bit of a nuissance (especially if there are a bunch of
      arguments to forward), but I don't really see another solution.
      
      Fixes #1124
      Jason Rhinelander committed
    • Fix `char &` arguments being non-bindable · 1b08df58
      This changes the caster to return a reference to a (new) local `CharT`
      type caster member so that binding lvalue-reference char arguments
      works (currently it results in a compilation failure).
      
      Fixes #1116
      Jason Rhinelander committed