1. 17 Nov, 2016 2 commits
    • Wenzel Jakob's avatar
      make arithmetic operators of enum_ optional (#508) · 405f6d1d
      Wenzel Jakob authored
      Following commit 90d278, the object code generated by the python
      bindings of nanogui (github.com/wjakob/nanogui) went up by a whopping
      12%. It turns out that that project has quite a few enums where we don't
      really care about arithmetic operators.
      
      This commit thus partially reverts the effects of #503 by introducing
      an additional attribute py::arithmetic() that must be specified if the
      arithmetic operators are desired.
      405f6d1d
    • Dean Moldovan's avatar
      Add default and converting constructors for all concrete Python types · e18bc02f
      Dean Moldovan authored
      * Deprecate the `py::object::str()` member function since `py::str(obj)`
        is now equivalent and preferred
      
      * Make `py::repr()` a free function
      
      * Make sure obj.cast<T>() works as expected when T is a Python type
      
      `obj.cast<T>()` should be the same as `T(obj)`, i.e. it should convert
      the given object to a different Python type. However, `obj.cast<T>()`
      usually calls `type_caster::load()` which only checks the type without
      doing any actual conversion. That causes a very unexpected `cast_error`.
      This commit makes it so that `obj.cast<T>()` and `T(obj)` are the same
      when T is a Python type.
      
      * Simplify pytypes converting constructor implementation
      
      It's not necessary to maintain a full set of converting constructors
      and assignment operators + const& and &&. A single converting const&
      constructor will work and there is no impact on binary size. On the
      other hand, the conversion functions can be significantly simplified.
      e18bc02f
  2. 16 Nov, 2016 1 commit
  3. 15 Nov, 2016 1 commit
  4. 04 Nov, 2016 1 commit
  5. 03 Nov, 2016 2 commits
  6. 01 Nov, 2016 1 commit
    • Dean Moldovan's avatar
      Make reference(_internal) the default return value policy for properties (#473) · 03f627eb
      Dean Moldovan authored
      * Make reference(_internal) the default return value policy for properties
      
      Before this, all `def_property*` functions used `automatic` as their
      default return value policy. This commit makes it so that:
      
       * Non-static properties use `reference_interal` by default, thus
         matching `def_readonly` and `def_readwrite`.
      
       * Static properties use `reference` by default, thus matching
         `def_readonly_static` and `def_readwrite_static`.
      
      In case `cpp_function` is passed to any `def_property*`, its policy will
      be used instead of any defaults. User-defined arguments in `extras`
      still have top priority and will override both the default policies and
      the ones from `cpp_function`.
      
      Resolves #436.
      
      * Almost always use return_value_policy::move for rvalues
      
      For functions which return rvalues or rvalue references, the only viable
      return value policies are `copy` and `move`. `reference(_internal)` and
      `take_ownership` would take the address of a temporary which is always
      an error.
      
      This commit prevents possible user errors by overriding the bad rvalue
      policies with `move`. Besides `move`, only `copy` is allowed, and only
      if it's explicitly selected by the user.
      
      This is also a necessary safety feature to support the new default
      return value policies for properties: `reference(_internal)`.
      03f627eb
  7. 24 Oct, 2016 1 commit
  8. 22 Oct, 2016 1 commit
  9. 20 Oct, 2016 3 commits
  10. 13 Oct, 2016 1 commit
  11. 27 Sep, 2016 1 commit
  12. 23 Sep, 2016 1 commit
  13. 21 Sep, 2016 3 commits
  14. 19 Sep, 2016 2 commits
  15. 16 Sep, 2016 1 commit
    • Jason Rhinelander's avatar
      Added py::register_exception for simple case (#296) · b3794f10
      Jason Rhinelander authored
      The custom exception handling added in PR #273 is robust, but is overly
      complex for declaring the most common simple C++ -> Python exception
      mapping that needs only to copy `what()`.  This add a simpler
      `py::register_exception<CppExp>(module, "PyExp");` function that greatly
      simplifies the common basic case of translation of a simple CppException
      into a simple PythonException, while not removing the more advanced
      capabilities of defining custom exception handlers.
      b3794f10
  16. 13 Sep, 2016 2 commits
  17. 11 Sep, 2016 2 commits
    • Jason Rhinelander's avatar
      Update OVERLOAD macros to support ref/ptr return type overloads · 7dfb932e
      Jason Rhinelander authored
      This adds a static local variable (in dead code unless actually needed)
      in the overload code that is used for storage if the overload is for
      some convert-by-value type (such as numeric values or std::string).
      
      This has limitations (as written up in the advanced doc), but is better
      than simply not being able to overload reference or pointer methods.
      7dfb932e
    • Jason Rhinelander's avatar
      Fix doc typo · 6eca083e
      Jason Rhinelander authored
      "trampoline" is doubled in the first sentence.
      6eca083e
  18. 10 Sep, 2016 1 commit
  19. 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
  20. 07 Sep, 2016 1 commit
    • Jason Rhinelander's avatar
      Allow passing base types as a template parameter · 6b52c838
      Jason Rhinelander authored
      This allows a slightly cleaner base type specification of:
      
          py::class_<Type, Base>("Type")
      
      as an alternative to
      
          py::class_<Type>("Type", py::base<Base>())
      
      As with the other template parameters, the order relative to the holder
      or trampoline types doesn't matter.
      
      This also includes a compile-time assertion failure if attempting to
      specify more than one base class (but is easily extendible to support
      multiple inheritance, someday, by updating the class_selector::set_bases
      function to set multiple bases).
      6b52c838
  21. 06 Sep, 2016 5 commits
    • 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
    • Dean Moldovan's avatar
    • Wenzel Jakob's avatar
      6f017cf6
    • Wenzel Jakob's avatar
      48ce0727
    • Wenzel Jakob's avatar
      minor doc & style fixes · fe34241e
      Wenzel Jakob authored
      fe34241e
  22. 05 Sep, 2016 2 commits
  23. 29 Aug, 2016 1 commit
  24. 28 Aug, 2016 1 commit
  25. 27 Aug, 2016 1 commit
  26. 24 Aug, 2016 1 commit