Commit Graph

570 Commits

Author SHA1 Message Date
Jason Rhinelander
7b8e3f9ec8 Re-add (but deprecated) bool operator for attr/items
PR #425 removed the bool operator from attribute accessors.  This is
likely in use by existing code as it was the only way before #425 added
the `hasattr` function to check for the existence of an attribute, via:

    if (obj.attr("foo")) { ... }

This commit adds it back in for attr and item accessors, but with a
deprecation warning to use `hasattr(obj, ...)` or `obj.contains(...)`
instead.
2016-10-02 16:39:51 -04:00
Wenzel Jakob
103d78d368 failed implicit conversions shouldn't lead to nullptr dereference 2016-09-30 13:43:19 +02:00
Wenzel Jakob
cd4d7d6bf8 very minor caster simplification 2016-09-30 12:20:19 +02:00
Dean Moldovan
71af3b07fb Simplify base class detection for Eigen types 2016-09-29 10:38:13 +02:00
Wenzel Jakob
632dee1e11 Merge pull request #356 from TrentHouliston/master
Add in casts for c++11s chrono classes to pythons datetime
2016-09-27 17:58:34 +02:00
Trent Houliston
a3603e6df0 Simplify redundant code, conform to style suggestions, improve logic 2016-09-28 01:01:44 +10:00
Wenzel Jakob
b0c4444687 format_descr constexpr tweak for MSVC by @jagerman (fixes #416) 2016-09-27 11:23:59 +02:00
Dean Moldovan
2bab5793f7 Later assignments to accessors should not overwrite the original field
`auto var = l[0]` has a strange quirk: `var` is actually an accessor and
not an object, so any later assignment of `var = ...` would modify l[0]
instead of `var`. This is surprising compared to the non-auto assignment
`py::object var = l[0]; var = ...`.

By overloading `operator=` on lvalue/rvalue, the expected behavior is
restored even for `auto` variables.
2016-09-23 02:00:01 +02:00
Dean Moldovan
ea763a57a8 Extend tuple and list accessor interface 2016-09-23 02:00:01 +02:00
Dean Moldovan
242b146a51 Extend attribute and item accessor interface using object_api 2016-09-23 02:00:01 +02:00
Dean Moldovan
865e43034b Make attr and item accessors throw on error instead of returning nullptr
This also adds the `hasattr` and `getattr` functions which are needed
with the new attribute behavior. The new functions behave exactly like
their Python counterparts.

Similarly `object` gets a `contains` method which calls `__contains__`,
i.e. it's the same as the `in` keyword in Python.
2016-09-23 01:40:22 +02:00
Dean Moldovan
37e22e436e Move common object functions into object_api mixin 2016-09-23 01:38:35 +02:00
Dzhelil Rufat
c250ee5146 Use more consistent indentation and typenames names. 2016-09-22 14:51:41 -07:00
Wenzel Jakob
e72a676b72 More verbose error messages when PyType_Ready fails 2016-09-19 13:45:34 +02:00
Wenzel Jakob
c1fc27e2b5 use detail::enable_if_t everywhere 2016-09-19 13:45:34 +02:00
Wenzel Jakob
8e5dceb6a6 Multiple inheritance support 2016-09-19 13:45:31 +02:00
Wenzel Jakob
bad589a477 deprecated py::base<>, added a macro for improved readability 2016-09-19 13:43:47 +02:00
Wenzel Jakob
e99ebaedcf nicer error message for invalid function arguments 2016-09-19 13:43:43 +02:00
Jason Rhinelander
b3794f1087 Added py::register_exception for simple case (#296)
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.
2016-09-16 08:04:15 +02:00
Trent Houliston
ad3bb9bbab Include the cmath header for std::lround.
Fix spaces before parens for style guide.
2016-09-14 19:27:53 +10:00
Trent Houliston
2f597687e7 Changed non system clocks to be time deltas
Allowed durations and non system clocks to be set from floats.
2016-09-13 20:40:28 +10:00
Trent Houliston
207d0da31c Move the python datetime header into the chrono header 2016-09-13 19:58:05 +10:00
Trent Houliston
0ee97dd6d0 Only import PyDateTime if we have to 2016-09-13 19:58:05 +10:00
Trent Houliston
352149e892 Refactor the chrono cast functions into chrono.h.
Add unit tests and documentation for the chrono cast.
2016-09-13 19:58:05 +10:00
Trent Houliston
6ddfd1e090 Add in casts for c++11s chrono classes to pythons datetime 2016-09-13 19:41:48 +10:00
Jason Rhinelander
4a4fb396e7 Fix build under debug mode
Take load_type by nested type_caster template arguments instead of by
full type_caster type.
2016-09-12 16:21:40 -04:00
Wenzel Jakob
f22683806e Merge pull request #400 from jagerman/add-ref-virtual-macros
Add a way to deal with copied value references
2016-09-12 06:32:39 +09:00
Jason Rhinelander
3e4fe6c0a8 Store a static type_caster rather than the basic type 2016-09-11 12:17:41 -04:00
Jason Rhinelander
f3f53e2b03 Removed unused/unwanted public ref_cast 2016-09-11 11:36:33 -04:00
Wenzel Jakob
b2eda9ac7c Merge pull request #408 from dean0x7d/exc-destructors
Fix Python C API calls in desctuctors triggered by error_already_set
2016-09-11 21:33:33 +09:00
Wenzel Jakob
e3c297f03e Merge pull request #407 from wjakob/fix_iterator
parameterize iterators by return value policy (fixes #388)
2016-09-11 20:02:32 +09:00
Jason Rhinelander
7dfb932e70 Update OVERLOAD macros to support ref/ptr return type overloads
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.
2016-09-11 01:21:53 -04:00
Ivan Smirnov
f2a0ad5855 array: add direct data access and indexing methods 2016-09-10 16:24:00 +01:00
Ivan Smirnov
91b3d681ad Expose some dtype/array attributes via NumPy C API 2016-09-10 16:24:00 +01:00
Dean Moldovan
f69071ca4b Make it easier to add new binding of builtin Python exceptions 2016-09-10 16:14:36 +02:00
Dean Moldovan
135ba8deaf Make error_already_set fetch and hold the Python error
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.
2016-09-10 12:08:32 +02:00
Wenzel Jakob
b212f6c416 parameterize iterators by return value policy (fixes #388) 2016-09-10 17:16:16 +09:00
Wenzel Jakob
720136bfa7 RAII wrapper for error state 2016-09-10 16:32:17 +09:00
Wenzel Jakob
1f2e417d8c Merge pull request #403 from jagerman/alias-initialization
Implement py::init_alias<>() constructors
2016-09-10 16:12:19 +09:00
Wenzel Jakob
382484ae56 operators should return NotImplemented given unsupported input (fixes #393) 2016-09-10 15:34:26 +09:00
Jason Rhinelander
ec62d977c4 Implement py::init_alias<>() constructors
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
86d825f330, 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.
2016-09-09 03:04:09 -04:00
Jason Rhinelander
5aa2cd5eb9 Template simplifications
Switch count_t to use constexpr_sum (under non-MSVC), and then make
all_of_t/any_of_t use it instead of doing the sum itself.

For MSVC, count_t is still done using template recursion, but
all_of_t/any_of_t can also make use of it.
2016-09-08 17:59:50 -04:00
Wenzel Jakob
260b26b3d6 Merge pull request #399 from jagerman/fix-alias-initialization
Fix type alias initialization
2016-09-09 00:39:43 +09:00
Jason Rhinelander
9c6859ee6e Fix type alias initialization
Type alias for alias classes with members didn't work properly: space
was only allocated for sizeof(type), but if we want to be able to put a
type_alias instance there, we need sizeof(type_alias), but
sizeof(type_alias) > sizeof(type) whenever type_alias has members.
2016-09-08 11:10:18 -04:00
Wenzel Jakob
9d7f7a38a7 fixed Py_None reference couting 2016-09-08 22:53:18 +09:00
Wenzel Jakob
5812d64ba2 Merge pull request #394 from jagerman/fix-ref-heap-casts
Fix ref heap casts
2016-09-08 09:05:15 +09:00
Wenzel Jakob
587aa328c6 Merge pull request #395 from aldanor/feature/error-already-set-message
error_already_set improvements
2016-09-08 09:03:41 +09:00
Ivan Smirnov
984c762485 Use handle::is_none() instead of raw ptrs 2016-09-07 21:16:26 +01:00
Ivan Smirnov
f5e8b6d9cb Add handle::is_none() method 2016-09-07 21:16:19 +01:00
Ivan Smirnov
67b54894b2 Set error if it's not set in error_already_set() 2016-09-07 21:10:16 +01:00
Jason Rhinelander
c03db9bad9 Fail static_assert when trying to reference non-referencable types
The previous commit to address #392 triggers a compiler warning about
returning a reference to a local variable, which is *not* a false alarm:
the following:

    py::cast<int &>(o)

(which happens internally in an overload declaration) really is
returning a reference to a local, because the cast operators for the
type_caster for numeric types returns a reference to its own member.

This commit adds a static_assert to make that a compilation failure
rather than returning a reference into about-to-be-freed memory.

Incidentally, this is also a fix for #219, which is exactly the same
issue: we can't reference numeric primitives that are cast from
wrappers around python numeric types.
2016-09-07 16:07:59 -04:00
Ivan Smirnov
392f16ccb8 Properly format type name in error_already_set() 2016-09-07 20:36:28 +01:00
Jason Rhinelander
56f717756b Fix type caster for heap reference types
Need to use the intrinsic type, not the raw type.

Fixes #392.
2016-09-07 14:14:11 -04:00
Wenzel Jakob
8706fb9085 Intel compiler 2017 fix 2016-09-07 23:49:16 +09:00
Wenzel Jakob
6fd3132e81 Merge pull request #385 from jagerman/relax-class-arguments
Allow arbitrary class_ template option ordering
2016-09-07 23:49:00 +09:00
Jason Rhinelander
6b52c838d7 Allow passing base types as a template parameter
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).
2016-09-06 20:34:24 -04:00
Jason Rhinelander
5fffe200e3 Allow arbitrary class_ template option ordering
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.
2016-09-06 12:22:13 -04:00
Wenzel Jakob
c84b37b577 fix bogus return value policy fallbacks (fixes #389) 2016-09-07 00:47:17 +09:00
Dean Moldovan
60b26802fd Make keyword argument hold a py::object instead of T*
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.
2016-09-06 16:41:50 +02:00
Dean Moldovan
8fe13b8896 Apply make_caster and intrinsic_t aliases everywhere 2016-09-06 16:41:50 +02:00
Dean Moldovan
56e86ed094 Workaround for py::dict() constructor on MSVC
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.
2016-09-06 16:41:50 +02:00
Dean Moldovan
16db1bfbd7 Remove superseded handle::operator() overloads
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`.
2016-09-06 16:41:50 +02:00
Dean Moldovan
15a112f8ff Add py::dict() keyword constructor 2016-09-06 16:41:50 +02:00
Dean Moldovan
66aa2728f4 Add py::str::format() method 2016-09-06 16:41:50 +02:00
Dean Moldovan
67990d9e19 Add py::print() function
Replicates Python API including keyword arguments.
2016-09-06 16:41:50 +02:00
Dean Moldovan
c743e1b1b4 Support keyword arguments and generalized unpacking in C++
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)
```
2016-09-06 16:41:50 +02:00
Dean Moldovan
317524ffad Make arg_t hold a pointer instead of a copy of the value 2016-09-06 14:39:30 +02:00
Wenzel Jakob
146397ecf4 allow iterators with different RV policies (fixes #388) 2016-09-06 13:06:31 +09:00
Wenzel Jakob
fe34241e50 minor doc & style fixes 2016-09-06 13:02:29 +09:00
Sergey Lyskov
7520418e26 Adding bind_map 2016-09-05 17:11:16 -04:00
Wenzel Jakob
8ac9715f84 enum serialization support (fixes #380) 2016-09-05 17:20:50 +09:00
Wenzel Jakob
614988c875 Merge pull request #384 from jagerman/unique-ptr-non-default-deleters
Make unique_ptr's with non-default deleters work
2016-09-05 08:26:34 +09:00
Wenzel Jakob
cc4e4065b3 .. and another one 2016-09-05 08:25:10 +09:00
Jason Rhinelander
a6495af87a Make unique_ptr's with non-default deleters work
Currently pybind11 only supports std::unique_ptr<T> holders by default
(other holders can, of course, be declared using the macro).  PR #368
added a `py::nodelete` that is intended to be used as:

    py::class_<Type, std::unique_ptr<Type, py::nodelete>> c("Type");

but this doesn't work out of the box.  (You could add an explicit
holder type declaration, but this doesn't appear to have been the
intention of the commit).

This commit fixes it by generalizing the unique_ptr type_caster to take
both the type and deleter as template arguments, so that *any*
unique_ptr instances are now automatically handled by pybind.  It also
adds a test to test_smart_ptr, testing both that py::nodelete (now)
works, and that the object is indeed not deleted as intended.
2016-09-04 18:23:55 -04:00
Wenzel Jakob
f3be07c661 minor code style fixes 2016-09-04 23:03:48 +09:00
Wenzel Jakob
987be18fee Merge pull request #379 from nevion/buffer_info
Buffer info improvements
2016-09-04 23:02:20 +09:00
Jason Newton
10d46e7f73 explicitly delete copy-ctor and assignment operator 2016-09-02 18:39:47 -04:00
Jason Newton
4764698069 add move ctor and move-assignment operator 2016-09-02 18:37:13 -04:00
Jason Newton
514c6dad70 add field for ownership 2016-09-02 17:10:50 -04:00
Jason Newton
3718c38e68 default all fields in all ctors 2016-09-02 17:10:02 -04:00
Jason Rhinelander
2097826346 Fix template trampoline overload lookup failure
Problem
=======

The template trampoline pattern documented in PR #322 has a problem with
virtual method overloads in intermediate classes in the inheritance
chain between the trampoline class and the base class.

For example, consider the following inheritance structure, where `B` is
the actual class, `PyB<B>` is the trampoline class, and `PyA<B>` is an
intermediate class adding A's methods into the trampoline:

    PyB<B> -> PyA<B> -> B -> A

Suppose PyA<B> has a method `some_method()` with a PYBIND11_OVERLOAD in
it to overload the virtual `A::some_method()`.  If a Python class `C` is
defined that inherits from the pybind11-registered `B` and tries to
provide an overriding `some_method()`, the PYBIND11_OVERLOADs declared
in PyA<B> fails to find this overloaded method, and thus never invoke it
(or, if pure virtual and not overridden in PyB<B>, raises an exception).

This happens because the base (internal) `PYBIND11_OVERLOAD_INT` macro
simply calls `get_overload(this, name)`; `get_overload()` then uses the
inferred type of `this` to do a type lookup in `registered_types_cpp`.
This is where it fails: `this` will be a `PyA<B> *`, but `PyA<B>` is
neither the base type (`B`) nor the trampoline type (`PyB<B>`).  As a
result, the overload fails and we get a failed overload lookup.

The fix
=======

The fix is relatively simple: we can cast `this` passed to
`get_overload()` to a `const B *`, which lets get_overload look up the
correct class.  Since trampoline classes should be derived from `B`
classes anyway, this cast should be perfectly safe.

This does require adding the class name as an argument to the
PYBIND11_OVERLOAD_INT macro, but leaves the public macro signatures
unchanged.
2016-08-29 19:41:44 -04:00
Wenzel Jakob
5e4e477b8b minor fixes to PR #368 2016-08-28 02:03:15 +02:00
Wenzel Jakob
a3906778eb minor: renamed argument in array constructor 2016-08-28 01:55:07 +02:00
Nickolai Belakovski
6333825350 Added support for exposing classes with private destructors and corresponding documentation 2016-08-27 15:09:15 -07:00
Wenzel Jakob
324c9c521b minor Intel compiler fix 2016-08-26 16:52:45 +02:00
Ivan Smirnov
d8b11b8708 Fix dtype::strip_padding() on Intel compiler 2016-08-25 21:52:52 +01:00
Wenzel Jakob
9a777a263d numpy.h: fix test suite issues on the Intel Compiler 2016-08-25 02:18:00 +02:00
Wenzel Jakob
89f2db4596 Merge pull request #353 from aldanor/feature/generalized-iterators
Add support for iterators with different begin/end types
2016-08-25 01:47:38 +02:00
Wenzel Jakob
1ffce7422d Get pybind11 test suite to compile on the Intel compiler (more or less..)
- ICPC can't handle the NCVirt trampoline which returns a non-copyable
  type, which is likely due to a constexpr/SFINAE issue. This disables
  the test on that compiler so that at least the rest can be tested.
2016-08-25 01:43:35 +02:00
Ivan Smirnov
1c8828fe8f Fix int_ shadowing problem in detail namespace
If operators.h is included, int_ function in the `detail`
namespace will shadow pybind11::int_ type, so the fully qualified
name has to be used.
2016-08-25 00:33:02 +01:00
Ivan Smirnov
2b308e01f7 Add support for iterators with differing end type 2016-08-24 23:29:04 +01:00
Ivan Smirnov
c5a1c8a6b9 Don't require operator-> for key iterators 2016-08-24 23:27:19 +01:00
Wenzel Jakob
8de0437e46 type_caster<std::function>: allow None values in both directions 2016-08-18 11:18:12 +02:00
Glen Walker
f45bb585c3 Support keep_alive where nurse may be None
For example keep_alive<0,1>() should work where the return value may sometimes be None. At present a "Could not allocate weak reference!" exception is thrown.
Update documentation to clarify behaviour of keep_alive when nurse is None or does not support weak references.
2016-08-18 09:09:41 +12:00
Ivan Smirnov
6956b655f0 Simplify code in eigen.h using new array ctors 2016-08-15 18:41:54 +01:00
Ivan Smirnov
67b3daeea4 Always decay type param of npy_format_descriptor 2016-08-15 18:41:54 +01:00
Ivan Smirnov
edbd4cb0a7 Decay const qualifiers in is_pod_struct<> 2016-08-15 18:41:54 +01:00
Ivan Smirnov
03fb488579 format_descriptor::format() now yields std::string
This is required since format descriptors for string types that
were using PYBIND11_DESCR were causing problems on C++14 on Linux.

Although this is technically a breaking change, it shouldn't cause
problems since the only use of format strings is passing them to
buffer_info constructor which expects std::string.

Note: for non-structured types, the const char * value is still
accessible via ::value for compatibility purpose.
2016-08-15 00:40:29 +01:00
Ivan Smirnov
6715736936 Add handle::repr() method 2016-08-14 13:43:31 +01:00
Ivan Smirnov
7dcbfe228e Add a missing bytes ctor from const char * 2016-08-13 20:00:15 +01:00
Ivan Smirnov
c22fe428ed Change str/bytes cast operators to ctors 2016-08-13 19:39:11 +01:00
Ivan Smirnov
89ec7f3e79 Add (const char *, size_t) ctors for str/bytes 2016-08-13 19:38:50 +01:00
Ivan Smirnov
fd6cede7e9 Avoid extra allocations in operator str/bytes 2016-08-13 15:46:46 +01:00
Ivan Smirnov
61e3b0bd15 Use builtin str type for recarray field names 2016-08-13 12:51:31 +01:00
Ivan Smirnov
1cdd171fbc Add PYBIND11_STR_TYPE to represent builtin str 2016-08-13 12:51:31 +01:00
Ivan Smirnov
006d8b6621 Add casting operators between py::str / py::bytes 2016-08-13 12:51:31 +01:00
Ivan Smirnov
3768b6abf9 Use fully qualified name in PYBIND11_DESCR macro 2016-08-13 12:43:16 +01:00
Ivan Smirnov
ad5ca6d4e6 Added dtype from const char pointer ctor 2016-08-13 12:43:16 +01:00
Ivan Smirnov
c6257f8641 Allow nullptr in array ctors wherever possible 2016-08-13 12:43:16 +01:00
Ivan Smirnov
98ba98c06b Add a simplified buffer_info ctor for 1-D case 2016-08-13 12:43:16 +01:00
Ivan Smirnov
6636ae9d4e Also add the new ctors to py::array_t 2016-08-13 12:43:16 +01:00
Ivan Smirnov
6bb0ee1186 Add all possible ctors for py::array 2016-08-13 12:43:16 +01:00
Ivan Smirnov
d77bc8c343 Add dtype(names, offsets, formats, itemsize) ctor 2016-08-13 12:43:16 +01:00
Ivan Smirnov
fc5620afa6 Fix a segfault where func object wasn't released 2016-08-13 12:43:16 +01:00
Ivan Smirnov
01f7409550 Initial implementation of py::dtype 2016-08-13 12:43:16 +01:00
Ivan Smirnov
05cb58ade2 Cleanup: move numpy API bindings out of py::array 2016-08-13 12:43:16 +01:00
Ivan Smirnov
afb07e7e92 Code reordering / cleanup only 2016-08-13 12:43:16 +01:00
Ivan Smirnov
f9c0defed7 Add numpy wrappers for char[] and std::array<char> 2016-08-13 12:43:16 +01:00
Ivan Smirnov
103d5eadc3 Remove redundant definition 2016-08-13 12:43:16 +01:00
Ivan Smirnov
098f9aef73 Replace 4096B format buffer with std::string 2016-08-13 12:43:16 +01:00
Ivan Smirnov
b37985ee0c Fix a comment and wrong indentation 2016-08-13 12:43:16 +01:00
Ivan Smirnov
bf2510ee86 Make buffer_info::as_pybuffer a memoryview ctor 2016-08-13 12:43:16 +01:00
Ivan Smirnov
41c3399021 Update npy_format_descriptor::name() 2016-08-13 12:43:16 +01:00
Ivan Smirnov
076b953ccd Restore dtype equivalence sanity check 2016-08-13 12:43:16 +01:00
Ivan Smirnov
8f2f7cd61c Various cleanup 2016-08-13 12:43:16 +01:00
Ivan Smirnov
8fa09cb871 Strip padding fields in dtypes, update the tests 2016-08-13 12:43:16 +01:00
Ivan Smirnov
13022f1b8c Bugfix: pass struct size as itemsize to descriptor
Without this, partially bound structs will have incorrect itemsize.
2016-08-13 12:43:16 +01:00
Ivan Smirnov
eeb4c043f9 Change field descriptor offset type to size_t 2016-08-13 12:43:16 +01:00
Ivan Smirnov
511401599c Use malloc insterad of calloc for numpy arrays 2016-08-13 12:43:16 +01:00
Ivan Smirnov
5412a05cf0 Rename PYBIND11_DTYPE to PYBIND11_NUMPY_DTYPE 2016-08-13 12:43:16 +01:00
Ivan Smirnov
872bd92575 Use proper type for an int literal 2016-08-13 12:43:16 +01:00
Ivan Smirnov
4c9a160a1d Exclude double type from is_pod_struct 2016-08-13 12:43:16 +01:00
Ivan Smirnov
3b803846d5 Add a few comments throughout numpy.h 2016-08-13 12:43:16 +01:00
Ivan Smirnov
2f01f01866 Always allocate at least one element 2016-08-13 12:43:16 +01:00
Ivan Smirnov
b38ca22e94 Add a few braces for clarity 2016-08-13 12:43:16 +01:00
Ivan Smirnov
95545e6256 Change PB11_IMPL prefix to PYBIND11, add comment 2016-08-13 12:43:16 +01:00
Ivan Smirnov
7bdd74a9fb Fix PYBIND11_DTYPE to work with MSVC compiler 2016-08-13 12:43:16 +01:00
Ivan Smirnov
5dc6c5445d Cosmetic: fix indentation 2016-08-13 12:43:16 +01:00
Ivan Smirnov
73f56830f8 Add detail::is_pod_struct<T> helper 2016-08-13 12:43:16 +01:00
Ivan Smirnov
a0e37f250e npy_format_descriptor::format() - fail if unbound 2016-08-13 12:43:16 +01:00
Ivan Smirnov
5a47a16e47 Revert accidental whitespace change 2016-08-13 12:43:16 +01:00
Ivan Smirnov
40eadfeb73 Make npy_format_descriptor backwards-compat
The typenum for non-structured types is still accessible at ::value,
and the dtype object for all types is accessible at ::dtype().
2016-08-13 12:43:16 +01:00
Ivan Smirnov
95e9b12322 Prefix the FIELD_DESCRIPTOR macro 2016-08-13 12:43:16 +01:00
Ivan Smirnov
5e71e17bdf Make changes to format_descriptor backwards-compat
The format strings that are known at compile time are now accessible
via both ::value and ::format(), and format strings for everything
else is accessible via ::format(). This makes it backwards compatible.
2016-08-13 12:43:16 +01:00
Ivan Smirnov
4f164217e4 Add dtype_of<T>() function, update the tests 2016-08-13 12:43:16 +01:00
Ivan Smirnov
036e8cd32f Remove erroneous py:: prefix in numpy.h 2016-08-13 12:43:16 +01:00
Ivan Smirnov
873d267471 Prefix all macros in numpy.h to avoid name clashes 2016-08-13 12:43:16 +01:00
Ivan Smirnov
1f54cd9209 Use object instead of ptrs in numpy descriptors 2016-08-13 12:43:16 +01:00
Ivan Smirnov
2a7acb6d55 Incref descriptors properly when creating arrays 2016-08-13 12:43:16 +01:00
Ivan Smirnov
f5b166d042 Simplify npy_format_descriptor slightly 2016-08-13 12:43:16 +01:00