1. 07 May, 2017 4 commits
    • Use numpy rather than Eigen for copying · b68959e8
      We're current copy by creating an Eigen::Map into the input numpy
      array, then assigning that to the basic eigen type, effectively having
      Eigen do the copy.  That doesn't work for negative strides, though:
      Eigen doesn't allow them.
      
      This commit makes numpy do the copying instead by allocating the eigen
      type, then having numpy copy from the input array into a numpy reference
      into the eigen object's data.  This also saves a copy when type
      conversion is required: numpy can do the conversion on-the-fly as part
      of the copy.
      
      Finally this commit also makes non-reference parameters respect the
      convert flag, declining the load when called in a noconvert pass with a
      convertible, but non-array input or an array with the wrong dtype.
      Jason Rhinelander committed
    • Making a copy when casting a numpy array with negative strides to Eigen. · 627da3f1
      `EigenConformable::stride_compatible` returns false if the strides are
      negative. In this case, do not use `EigenConformable::stride`, as it
      is {0,0}. We cannot write negative strides in this element, as Eigen
      will throw an assertion if we do.
      
      The `type_caster` specialization for regular, dense Eigen matrices now
      does a second `array_t::ensure` to copy data in case of negative strides.
      I'm not sure that this is the best way to implement this.
      
      I have added "TODO" tags linking these changes to Eigen bug #747, which,
      when fixed, will allow Eigen to accept negative strides.
      Cris Luengo committed
  2. 02 May, 2017 1 commit
  3. 29 Apr, 2017 5 commits
  4. 28 Apr, 2017 5 commits
    • Fix ambiguous initialize_list arguments · 51d18aa2
      This removes the convert-from-arithemtic-scalar constructor of
      any_container as it can result in ambiguous calls, as in:
      
          py::array_t<float>({ 1, 2 })
      
      which could be intepreted as either of:
      
          py::array_t<float>(py::array_t<float>(1, 2))
          py::array_t<float>(py::detail::any_container({ 1, 2 }))
      
      Removing the convert-from-arithmetic constructor reduces the number of
      implicit conversions, avoiding the ambiguity for array and array_t.
      This also re-adds the array/array_t constructors taking a scalar
      argument for backwards compatibility.
      Jason Rhinelander committed
    • travis-ci: Remove clang 4/c++17 from allow_failures · 2761f78f
      The job is using the released clang and stable-branch libc++, which
      wasn't the case when it was added.  Leave the g++7/c++17 in
      allow_failures for now as it's still a pre-release compiler (and pulled
      from debian experimental).
      Jason Rhinelander committed
    • Don't let PyInstanceMethod hide itself · 0a90b2db
      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`.
      Jason Rhinelander committed
    • Fix Python 3 `bytes` conversion to std::string/char* · a7f704b3
      The Unicode support added in 2.1 (PR #624) inadvertently broke accepting
      `bytes` as std::string/char* arguments.  This restores it with a
      separate path that does a plain conversion (i.e. completely bypassing
      all the encoding/decoding code), but only for single-byte string types.
      Jason Rhinelander committed
    • Add numpy version check (#819) · ce494d65
      The numpy API constants can check past the end of the API array if the
      numpy version is too old thus causing a segfault.  The current list of
      functions requires numpy >= 1.7.0, so this adds a check and exception if
      numpy is too old.
      
      The added feature version API element was added in numpy 1.4.0, so this
      could still segfault if loaded in 1.3.0 or earlier, but given that
      1.4.0 was released at the end of 2009, it seems reasonable enough to
      not worry about that case.  (1.7.0 was released in early 2013).
      Jason Rhinelander committed
  5. 27 Apr, 2017 3 commits
    • Track base class pointers of instances · 1f8a100d
      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.
      Jason Rhinelander committed
    • Fix downcasting of base class pointers · 14e70650
      When we are returned a base class pointer (either directly or via
      shared_from_this()) we detect its runtime type (using `typeid`), then
      end up essentially reinterpret_casting the pointer to the derived type.
      This is invalid when the base class pointer was a non-first base, and we
      end up with an invalid pointer.  We could dynamic_cast to the
      most-derived type, but if *that* type isn't pybind11-registered, the
      resulting pointer given to the base `cast` implementation isn't necessarily valid
      to be reinterpret_cast'ed back to the backup type.
      
      This commit removes the "backup" type argument from the many-argument
      `cast(...)` and instead does the derived-or-pointer type decision and
      type lookup in type_caster_base, where the dynamic_cast has to be to
      correctly get the derived pointer, but also has to do the type lookup to
      ensure that we don't pass the wrong (derived) pointer when the backup
      type (i.e. the type caster intrinsic type) pointer is needed.
      
      Since the lookup is needed before calling the base cast(), this also
      changes the input type to a detail::type_info rather than doing a
      (second) lookup in cast().
      Jason Rhinelander committed
    • Expose more instance management functions · 92900995
      This breaks up the instance management functions in class_support.h a
      little bit so that other pybind11 code can use it.  In particular:
      
      - added make_new_instance() which does what pybind11_object_new does,
        but also allows instance allocation without `value` allocation.  This
        lets `cast.h` use the same instance allocation rather than having its
        own separate implementation.
      - instance registration is now moved to a
        `register_instance()`/deregister_instance()` pair (rather than having
        individual code add or remove things from `registered_instances`
        directory).
      - clear_instance() does everything `pybind11_object_dealloc()` needs
        except for the deallocation; this is helpful for factory construction
        which needs to be able to replace the internals of an instance without
        deallocating it.
      - clear_instance() now also calls `dealloc` when `holder_constructed`
        is true, even if `value` is false.  This can happen in factory
        construction when the pointer is moved from one instance to another,
        but the holder itself is only copied (i.e. for a shared_ptr holder).
      Jason Rhinelander committed
  6. 22 Apr, 2017 1 commit
  7. 19 Apr, 2017 1 commit
  8. 18 Apr, 2017 5 commits
    • Don't allow mixed static/non-static overloads · d355f2fc
      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.
      Jason Rhinelander committed
    • Keep skipping buffer tests on pypy · 90bac963
      Adding numpy to the pypy test exposed a segfault caused by the buffer
      tests in test_stl_binders.py: the first such test was explicitly skipped
      on pypy, but the second (test_vector_buffer_numpy) which also seems to
      cause an occasional segfault was just marked as requiring numpy.
      
      Explicitly skip it on pypy as well (until a workaround, fix, or pypy fix
      are found).
      Jason Rhinelander committed
    • Remove unneeded exports · d170731f
      Various bash variables that are only used in the travis-ci script and
      don't need to propagate (e.g. to cmake) are being pointlessly exported;
      this removes these `export`s.
      Jason Rhinelander committed
    • Switch clang-4.0 build to trusty; cache libc++ · f0c7c008
      This uses the trusty container rather than docker for the clang 4.0
      build.  It also caches the local libc++ installation so that it doesn't
      need to be compiled every time, which should speed up the job
      considerably.
      Jason Rhinelander committed
    • travis-ci: switch to trusty; cache pip packages · 3d500516
      This applies several changes to the non-docker travis-ci builds:
      
      - Make all builds use trusty rather than precise.  pybind can't really
        build in precise anyway (we install essentially the entire toolchain
        backported from trusty on every build), and so this saves needing to
        install all the backported packages during the build setup.
      - Updated the 3.5 build to 3.6 (via deadsnakes, which didn't backport
        3.6 to ubuntu releases earlier than trusty).
      - As a result of the switch to trusty, the BAREBONES build now picks up
        the (default installed) python 3.5 installation.
      - Invoke pip everywhere via $PYTHON -m pip rather than the pip
        executable, which saves us having to figure out what the pip
        executable is, and ensures that we are using the correct pip.
      - Install packages with `pip --user` rather than in a virtualenv.
      - Add the local user python package archive to the travis-ci cache
        (rather than the pip cache).  This saves needing to install packages
        during installation (unless there are updates, in which case the
        package and the cache are updated).
      - Install numpy and scipy on the pypy build.  This has to build from
        source (and so blas and fortran need to be installed on the build),
        but given the above caching, the build will only be slow for the first
        build after a new numpy/scipy release.  This testing is valuable:
        numpy has various behaviour differences under pypy.
      - Added set -e/+e around the before_install/install blocks so that a
        failure here (e.g. a pip install failure or dependency download
        failure) triggers a build failure.
      - Update eigen version to latest (3.3.3), mainly to be consistent with
        the appveyor build.
      - The travis trusty environment has an upgraded cmake, so this
        downgrades cmake (to the stock trusty version) on the first couple
        jobs so that we're still including some cmake 2.8.12 testing.
      Jason Rhinelander committed
  9. 17 Apr, 2017 1 commit
  10. 15 Apr, 2017 1 commit
  11. 14 Apr, 2017 1 commit
  12. 13 Apr, 2017 4 commits
    • Make any_container implicitly constructible from arithmetic values · 201796d9
      This further reduces the constructors required in buffer_info/numpy by
      removing the need for the constructors that take a single size_t and
      just forward it on via an initializer_list to the container-accepting
      constructor.
      
      Unfortunately, in `array` one of the constructors runs into an ambiguity
      problem with the deprecated `array(handle, bool)` constructor (because
      both the bool constructor and the any_container constructor involve an
      implicit conversion, so neither has precedence), so a forwarding
      constructor is kept there (until the deprecated constructor is
      eventually removed).
      Jason Rhinelander committed
    • Accept abitrary containers and iterators for shape/strides · 5f383862
      This adds support for constructing `buffer_info` and `array`s using
      arbitrary containers or iterator pairs instead of requiring a vector.
      
      This is primarily needed by PR #782 (which makes strides signed to
      properly support negative strides, and will likely also make shape and
      itemsize to avoid mixed integer issues), but also needs to preserve
      backwards compatibility with 2.1 and earlier which accepts the strides
      parameter as a vector of size_t's.
      
      Rather than adding nearly duplicate constructors for each stride-taking
      constructor, it seems nicer to simply allow any type of container (or
      iterator pairs).  This works by replacing the existing vector arguments
      with a new `detail::any_container` class that handles implicit
      conversion of arbitrary containers into a vector of the desired type.
      It can also be explicitly instantiated with a pair of iterators (e.g.
      by passing {begin, end} instead of the container).
      Jason Rhinelander committed
    • Move buffer_info to its own header · dbb4c5b5
      Upcoming changes to buffer_info make it need some things declared in
      common.h; it also feels a bit misplaced in common.h (which is arguably
      too large already), so move it out.  (Separating this and the subsequent
      changes into separate commits to make the changes easier to distinguish
      from the move.)
      Jason Rhinelander committed
    • array: set exception message on failure · 5749b502
      When attempting to get a raw array pointer we return nullptr if given a
      nullptr, which triggers an error_already_set(), but we haven't set an
      exception message, which results in "Unknown internal error".
      
      Callers that want explicit allowing of a nullptr here already handle it
      (by clearing the exception after the call).
      Jason Rhinelander committed
  13. 12 Apr, 2017 1 commit
    • improve mkdoc.py determinism · 257df10f
      When processing many files that contain top-level items with the same
      name (e.g. "operator<<"), the output was non-deterministic and depended
      on the order in which the different Clang processes finished. This
      commit adds sorting that also accounts for the filename to prevent
      random changes from run to run.
      Wenzel Jakob committed
  14. 11 Apr, 2017 1 commit
  15. 10 Apr, 2017 1 commit
  16. 09 Apr, 2017 2 commits
    • Appveyor: Remove /m to attempt to resolve build failures · 4c72ec22
      /m also doesn't seem to have made the builds any faster.
      Jason Rhinelander committed
    • Fix Eigen argument doc strings · e9e17746
      Many of the Eigen type casters' name() methods weren't wrapping the type
      description in a `type_descr` object, which thus wasn't adding the
      "{...}" annotation used to identify an argument which broke the help
      output by skipping eigen arguments.
      
      The test code I had added even had some (unnoticed) broken output (with
      the "arg0: " showing up in the return value).
      
      This commit also adds test code to ensure that named eigen arguments
      actually work properly, despite the invalid help output.  (The added
      tests pass without the rest of this commit).
      Jason Rhinelander committed
  17. 08 Apr, 2017 2 commits
  18. 07 Apr, 2017 1 commit