1. 21 Jun, 2018 1 commit
  2. 15 Jun, 2018 1 commit
    • Antony Lee's avatar
      Properly report exceptions thrown during module initialization. · 58e551cc
      Antony Lee authored
      If an exception is thrown during module initialization, the
      error_already_set destructor will try to call `get_internals()` *after*
      setting Python's error indicator, resulting in a `SystemError: ...
      returned with an error set`.
      
      Fix that by temporarily stashing away the error indicator in the
      destructor.
      58e551cc
  3. 24 May, 2018 1 commit
  4. 18 May, 2018 1 commit
  5. 07 May, 2018 1 commit
  6. 06 May, 2018 3 commits
  7. 29 Apr, 2018 2 commits
  8. 24 Apr, 2018 1 commit
  9. 22 Apr, 2018 2 commits
    • Wenzel Jakob's avatar
      Minor fix for MSVC warning CS4459 (#1374) · ed670055
      Wenzel Jakob authored
      When using pybind11 to bind enums on MSVC and warnings (/W4) enabled,
      the following warning pollutes builds. This fix renames one of the
      occurrences.
      
      pybind11\include\pybind11\pybind11.h(1398): warning C4459: declaration of 'self' hides global declaration
      pybind11\include\pybind11\operators.h(41): note: see declaration of 'pybind11::detail::self'
      ed670055
    • Henry Schreiner's avatar
      Fix pip issues on AppVeyor CI (#1369) · ffd56ebe
      Henry Schreiner authored
      ffd56ebe
  10. 16 Apr, 2018 1 commit
  11. 14 Apr, 2018 1 commit
    • oremanj's avatar
      Add basic support for tag-based static polymorphism (#1326) · fd9bc8f5
      oremanj authored
      * Add basic support for tag-based static polymorphism
      
      Sometimes it is possible to look at a C++ object and know what its dynamic type is,
      even if it doesn't use C++ polymorphism, because instances of the object and its
      subclasses conform to some other mechanism for being self-describing; for example,
      perhaps there's an enumerated "tag" or "kind" member in the base class that's always
      set to an indication of the correct type. This might be done for performance reasons,
      or to permit most-derived types to be trivially copyable. One of the most widely-known
      examples is in LLVM: https://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html
      
      This PR permits pybind11 to be informed of such conventions via a new specializable
      detail::polymorphic_type_hook<> template, which generalizes the previous logic for
      determining the runtime type of an object based on C++ RTTI. Implementors provide
      a way to map from a base class object to a const std::type_info* for the dynamic
      type; pybind11 then uses this to ensure that casting a Base* to Python creates a
      Python object that knows it's wrapping the appropriate sort of Derived.
      
      There are a number of restrictions with this tag-based static polymorphism support
      compared to pybind11's existing support for built-in C++ polymorphism:
      
      - there is no support for this-pointer adjustment, so only single inheritance is permitted
      - there is no way to make C++ code call new Python-provided subclasses
      - when binding C++ classes that redefine a method in a subclass, the .def() must be
        repeated in the binding for Python to know about the update
      
      But these are not much of an issue in practice in many cases, the impact on the
      complexity of pybind11's innards is minimal and localized, and the support for
      automatic downcasting improves usability a great deal.
      fd9bc8f5
  12. 09 Apr, 2018 1 commit
  13. 07 Apr, 2018 1 commit
    • Boris Staletic's avatar
      Implement an enum_ property "name" · 289e5d9c
      Boris Staletic authored
      The property returns the enum_ value as a string.
      For example:
      
      >>> import module
      >>> module.enum.VALUE
      enum.VALUE
      >>> str(module.enum.VALUE)
      'enum.VALUE'
      >>> module.enum.VALUE.name
      'VALUE'
      
      This is actually the equivalent of Boost.Python "name" property.
      289e5d9c
  14. 05 Apr, 2018 1 commit
    • Jason Rhinelander's avatar
      Add workaround for clang 3.3/3.4 · 6862cb9b
      Jason Rhinelander authored
      As reported in #1349, clang before 3.5 can segfault on a function-local
      variable referenced inside a lambda.  This moves the function-local
      static into a separate function that the lambda can invoke to avoid the
      issue.
      
      Fixes #1349
      6862cb9b
  15. 03 Apr, 2018 2 commits
  16. 11 Mar, 2018 1 commit
    • Jason Rhinelander's avatar
      Reimplement version check and combine init macros · 6d0b4708
      Jason Rhinelander authored
      This reimplements the version check to avoid sscanf (which has
      reportedly started throwing warnings under MSVC, even when used
      perfectly safely -- #1314).  It also extracts the mostly duplicated
      parts of PYBIND11_MODULE/PYBIND11_PLUGIN into separate macros.
      6d0b4708
  17. 10 Mar, 2018 4 commits
    • Jason Rhinelander's avatar
      9f41c8ea
    • Jason Rhinelander's avatar
      Improve macro type handling for types with commas · e88656ab
      Jason Rhinelander authored
      - PYBIND11_MAKE_OPAQUE now takes ... rather than a single argument and
        expands it with __VA_ARGS__; this lets templated, comma-containing
        types get through correctly.
      - Adds a new macro PYBIND11_TYPE() that lets you pass the type into a
        macro as a single argument, such as:
      
            PYBIND11_OVERLOAD(PYBIND11_TYPE(R<1,2>), PYBIND11_TYPE(C<3,4>), func)
      
        Unfortunately this only works for one macro call: to forward the
        argument on to the next macro call (without the processor breaking it
        up again) requires also adding the PYBIND11_TYPE(...) to type macro
        arguments in the PYBIND11_OVERLOAD_... macro chain.
      - updated the documentation with these two changes, and use them at a couple
        places in the test suite to test that they work.
      e88656ab
    • Marc Schlaich's avatar
      Correct VS version in FAQ · ab003dbd
      Marc Schlaich authored
      ab003dbd
    • Jason Rhinelander's avatar
      Fix for Python3 via brew · 1ddfacba
      Jason Rhinelander authored
      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).
      1ddfacba
  18. 28 Feb, 2018 2 commits
  19. 18 Feb, 2018 1 commit
  20. 07 Feb, 2018 1 commit
  21. 06 Feb, 2018 1 commit
  22. 12 Jan, 2018 3 commits
    • Jason Rhinelander's avatar
      add56ccd
    • Jason Rhinelander's avatar
      Remove unnecessary `detail::` · 657a51e8
      Jason Rhinelander authored
      This function already has a `using namespace detail`, so all the
      `detail::` qualifications are not needed.
      657a51e8
    • Jason Rhinelander's avatar
      Use stricter brace initialization · adbc8111
      Jason Rhinelander authored
      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).
      adbc8111
  23. 11 Jan, 2018 5 commits
    • Jason Rhinelander's avatar
      Fix segfault when reloading interpreter with external modules (#1092) · 326deef2
      Jason Rhinelander authored
      * 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).
      326deef2
    • Jeff VanOss's avatar
      fix return from std::map bindings to __delitem__ (#1229) · 05d379a9
      Jeff VanOss authored
      Fix return from `std::map` bindings to `__delitem__`: we should be returning `void`, not an iterator.
      
      Also adds a test for map item deletion.
      05d379a9
    • luz.paz's avatar
      misc. typos · 28cb6764
      luz.paz authored
      Found via `codespell`
      28cb6764
    • Jason Rhinelander's avatar
      Use a named rather than anon struct in instance · 507da418
      Jason Rhinelander authored
      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).
      507da418
    • Jason Rhinelander's avatar
      Fixes for numpy 1.14.0 compatibility · 88efb251
      Jason Rhinelander authored
      - 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.
      88efb251
  24. 27 Dec, 2017 2 commits
    • Antony Lee's avatar
      Add spaces around "=" in signature repr. · 0826b3c1
      Antony Lee authored
      PEP8 indicates (correctly, IMO) that when an annotation is present, the
      signature should include spaces around the equal sign, i.e.
      
          def f(x: int = 1): ...
      
      instead of
      
          def f(x: int=1): ...
      
      (in the latter case the equal appears to bind to the type, not to the
      argument).
      
      pybind11 signatures always includes a type annotation so we can always
      add the spaces.
      0826b3c1
    • Ivan Smirnov's avatar
      Make register_dtype() accept any field containers (#1225) · d1db2ccf
      Ivan Smirnov authored
      * Make register_dtype() accept any field containers
      
      * Add a test for programmatic dtype registration
      d1db2ccf