1. 10 Sep, 2016 7 commits
    • Dean Moldovan's avatar
      Make error_already_set fetch and hold the Python error · 135ba8de
      Dean Moldovan authored
      This clears the Python error at the error_already_set throw site, thus
      allowing Python calls to be made in destructors which are triggered by
      the exception. This is preferable to the alternative, which would be
      guarding every Python API call with an error_scope.
      
      This effectively flips the behavior of error_already_set. Previously,
      it was assumed that the error stays in Python, so handling the exception
      in C++ would require explicitly calling PyErr_Clear(), but nothing was
      needed to propagate the error to Python. With this change, handling the
      error in C++ does not require a PyErr_Clear() call, but propagating the
      error to Python requires an explicit error_already_set::restore().
      
      The change does not break old code which explicitly calls PyErr_Clear()
      for cleanup, which should be the majority of user code. The need for an
      explicit restore() call does break old code, but this should be mostly
      confined to the library and not user code.
      135ba8de
    • Wenzel Jakob's avatar
      RAII wrapper for error state · 720136bf
      Wenzel Jakob authored
      720136bf
    • Wenzel Jakob's avatar
      Merge pull request #403 from jagerman/alias-initialization · 1f2e417d
      Wenzel Jakob authored
      Implement py::init_alias<>() constructors
      1f2e417d
    • Wenzel Jakob's avatar
      Merge pull request #406 from wjakob/master · 3d1bb29e
      Wenzel Jakob authored
      operators should return NotImplemented given unsupported input (fixes #393)
      3d1bb29e
    • Wenzel Jakob's avatar
    • Wenzel Jakob's avatar
      Merge pull request #405 from jagerman/retry-apt-get · 8d38ebed
      Wenzel Jakob authored
      apt-get tweaks for the docker/debian builds
      8d38ebed
    • Jason Rhinelander's avatar
      apt-get tweaks for the debian builds · bf14cea7
      Jason Rhinelander authored
      - Try to update and upgrade twice (with a brief pause between attempts)
        to deal with occassional spurious server failures or repository race
        conditions.  Do the same for the main package install.
      - Use dist-upgrade instead of upgrade for updating the image
      - Add -q to the upgrade and install commands to make apt less verbose.
      bf14cea7
  2. 09 Sep, 2016 1 commit
    • Jason Rhinelander's avatar
      Implement py::init_alias<>() constructors · ec62d977
      Jason Rhinelander authored
      This commit adds support for forcing alias type initialization by
      defining constructors with `py::init_alias<arg1, arg2>()` instead of
      `py::init<arg1, arg2>()`.  Currently py::init<> only results in Alias
      initialization if the type is extended in python, or the given
      arguments can't be used to construct the base type, but can be used to
      construct the alias.  py::init_alias<>, in contrast, always invokes the
      constructor of the alias type.
      
      It looks like this was already the intention of
      `py::detail::init_alias`, which was forward-declared in
      86d825f3, but was apparently never
      finished: despite the existance of a .def method accepting it, the
      `detail::init_alias` class isn't actually defined anywhere.
      
      This commit completes the feature (or possibly repurposes it), allowing
      declaration of classes that will always initialize the trampoline which
      is (as I argued in #397) sometimes useful.
      ec62d977
  3. 08 Sep, 2016 8 commits
  4. 07 Sep, 2016 10 commits
  5. 06 Sep, 2016 14 commits
    • Dean Moldovan's avatar
      Replace std::cout with py::print in tests · 81511be3
      Dean Moldovan authored
      With this change both C++ and Python write to sys.stdout which resolves
      the capture issues noted in #351. Therefore, the related workarounds are
      removed.
      81511be3
    • Jason Rhinelander's avatar
      Allow arbitrary class_ template option ordering · 5fffe200
      Jason Rhinelander authored
      The current pybind11::class_<Type, Holder, Trampoline> fixed template
      ordering results in a requirement to repeat the Holder with its default
      value (std::unique_ptr<Type>) argument, which is a little bit annoying:
      it needs to be specified not because we want to override the default,
      but rather because we need to specify the third argument.
      
      This commit removes this limitation by making the class_ template take
      the type name plus a parameter pack of options.  It then extracts the
      first valid holder type and the first subclass type for holder_type and
      trampoline type_alias, respectively.  (If unfound, both fall back to
      their current defaults, `std::unique_ptr<type>` and `type`,
      respectively).  If any unmatched template arguments are provided, a
      static assertion fails.
      
      What this means is that you can specify or omit the arguments in any
      order:
      
          py::class_<A, PyA> c1(m, "A");
          py::class_<B, PyB, std::shared_ptr<B>> c2(m, "B");
          py::class_<C, std::shared_ptr<C>, PyB> c3(m, "C");
      
      It also allows future class attributes (such as base types in the next
      commit) to be passed as class template types rather than needing to use
      a py::base<> wrapper.
      5fffe200
    • Wenzel Jakob's avatar
      c84b37b5
    • Wenzel Jakob's avatar
      Merge pull request #372 from dean0x7d/keywords · a3dbdc67
      Wenzel Jakob authored
      Keyword arguments and generalized unpacking for C++ API
      a3dbdc67
    • Dean Moldovan's avatar
      Make keyword argument hold a py::object instead of T* · 60b26802
      Dean Moldovan authored
      With this change arg_t is no longer a template, but it must remain so
      for backward compatibility. Thus, a non-template arg_v is introduced,
      while a dummy template alias arg_t is there to keep old code from
      breaking. This can be remove in the next major release.
      
      The implementation of arg_v also needed to be placed a little earlier in
      the headers because it's not a template any more and unpacking_collector
      needs more than a forward declaration.
      60b26802
    • Dean Moldovan's avatar
      8fe13b88
    • Dean Moldovan's avatar
      Workaround for py::dict() constructor on MSVC · 56e86ed0
      Dean Moldovan authored
      MSVC fails to compile if the constructor is defined out-of-line.
      The error states that it cannot deduce the type of the default template
      parameter which is used for SFINAE.
      56e86ed0
    • Dean Moldovan's avatar
      Remove superseded handle::operator() overloads · 16db1bfb
      Dean Moldovan authored
      The variadic handle::operator() offers the same functionality as well
      as mixed positional, keyword, * and ** arguments. The tests are also
      superseded by the ones in `test_callbacks`.
      16db1bfb
    • Dean Moldovan's avatar
    • Dean Moldovan's avatar
      Add py::dict() keyword constructor · 15a112f8
      Dean Moldovan authored
      15a112f8
    • Dean Moldovan's avatar
      Add py::str::format() method · 66aa2728
      Dean Moldovan authored
      66aa2728
    • Dean Moldovan's avatar
      Add py::print() function · 67990d9e
      Dean Moldovan authored
      Replicates Python API including keyword arguments.
      67990d9e
    • Dean Moldovan's avatar
      Support keyword arguments and generalized unpacking in C++ · c743e1b1
      Dean Moldovan authored
      A Python function can be called with the syntax:
      ```python
      foo(a1, a2, *args, ka=1, kb=2, **kwargs)
      ```
      This commit adds support for the equivalent syntax in C++:
      ```c++
      foo(a1, a2, *args, "ka"_a=1, "kb"_a=2, **kwargs)
      ```
      
      In addition, generalized unpacking is implemented, as per PEP 448,
      which allows calls with multiple * and ** unpacking:
      ```python
      bar(*args1, 99, *args2, 101, **kwargs1, kz=200, **kwargs2)
      ```
      and
      ```c++
      bar(*args1, 99, *args2, 101, **kwargs1, "kz"_a=200, **kwargs2)
      ```
      c743e1b1
    • Dean Moldovan's avatar
      317524ff