Commit Graph

228 Commits

Author SHA1 Message Date
Wenzel Jakob
2ac5044a05 moved processing of cpp_function arguments out of dispatch code
The cpp_function class accepts a variadic argument, which was formerly
processed twice -- once at registration time, and once in the dispatch
lambda function. This is not only unnecessarily slow but also leads to
code bloat since it adds to the object code generated for every bound
function. This change removes the second pass at dispatch time.

One noteworthy change of this commit is that default arguments are now
constructed (and converted to Python objects) right at declaration time.
Consider the following example:

py::class_<MyClass>("MyClass")
    .def("myFunction", py::arg("arg") = SomeType(123));

In this case, the change means that pybind11 must already be set up to
deal with values of the type 'SomeType', or an exception will be thrown.
Another change is that the "preview" of the default argument in the
function signature is generated using the __repr__ special method. If
it is not available in this type, the signature may not be very helpful,
i.e.:

|  myFunction(...)
|      Signature : (MyClass, arg : SomeType = <SomeType object at 0x101b7b080>) -> None

One workaround (other than defining SomeType.__repr__) is to specify the
human-readable preview of the default argument manually using the more
cumbersome arg_t notation:

py::class_<MyClass>("MyClass")
    .def("myFunction", py::arg_t<SomeType>("arg", SomeType(123), "SomeType(123)"));
2016-01-17 22:31:15 +01:00
Wenzel Jakob
f08a3f0622 Merge pull request #52 from tmiasko/const-correctness
Make handle and related classes const correct.
2016-01-10 21:34:55 +01:00
Wenzel Jakob
deadbbb671 Merge pull request #57 from tmiasko/conversion
Use object class to hold partially converted python objects.
2016-01-07 00:08:38 +01:00
Tomasz Miąsko
ca77130be8 Use object class to hold partially converted python objects.
Using object class to hold converted object automatically deallocates
object if an exception is thrown or scope is left before constructing
complete Python object.

Additionally added method object::release() that allows to release
ownership of python object without decreasing its reference count.
2016-01-02 21:07:18 +01:00
Wenzel Jakob
3367cecc6b detect unreferenced keyword arguments in function calls 2015-12-30 18:48:20 +01:00
Tomasz Miąsko
5d53ac4cbf Clean the type name alone, not the whole message. 2015-12-28 08:49:17 +01:00
Tomasz Miąsko
875df5528d Make handle and related classes const correct.
This gives handle classes a typical pointer semantics with respects to
constness.
2015-12-28 08:11:16 +01:00
Wenzel Jakob
45f7c65594 Merge pull request #50 from tmiasko/handle_cast_const
Add const modifier to handle::cast.
2015-12-27 17:29:24 +01:00
Tomasz Miąsko
c83e062263 Create an empty python tuple in pybind::tuple default constructor.
Follow the same semantics as constructors of dict, list, and set by
creating valid Python object in default constructor of a tuple class.
2015-12-27 09:05:25 +01:00
Tomasz Miąsko
cc39b2f37f Add const modifier to handle::cast. 2015-12-26 19:01:28 +01:00
Wenzel Jakob
dd57a34e2d improved error handling at module import time 2015-12-26 14:04:52 +01:00
Wenzel Jakob
9d573f44b9 stl.h fix for std::map (see PR #43) 2015-12-26 13:37:59 +01:00
Wenzel Jakob
4b279327a3 stl.h bugfix for std::set, misc. cleanups 2015-12-18 18:41:36 +01:00
Wenzel Jakob
d1a24823bc considerable simplifications to the Python type casters 2015-12-16 12:17:46 +01:00
Wenzel Jakob
9b0b40e0b0 add converter for nullptr_t 2015-12-16 11:41:53 +01:00
Wenzel Jakob
6621c17f10 Merge pull request #38 from adler-j/issue-37__convert_exception
ENH: add more error conversions
2015-12-15 12:25:12 +01:00
Jonas Adler
2b9fdbe7c9 ENH: add more error conversions 2015-12-15 11:56:12 +01:00
Jan Dohl
ab92eb3765 Fixed py:array constructor from failing for complex types
The array(const buffer_info &info) constructor fails when given
complex types since their format string is 'Zd' or 'Zf' which has
a length of two and causes an error here:

if (info.format.size() != 1)
    throw std::runtime_error("Unsupported buffer format!");

Fixed by allowing format sizes of one and two.
2015-12-15 04:16:49 +01:00
Wenzel Jakob
62127a27b0 don't allow 'void' or 'void*' as a function argument 2015-12-13 13:09:42 +01:00
Wenzel Jakob
60c36db1c9 generic integer type handling 2015-11-30 12:45:34 +01:00
Wenzel Jakob
7f8d1c20f1 improved int_ constructor 2015-11-29 13:48:16 +01:00
Wenzel Jakob
4ee0f2a19e add missing instructor for bool_ 2015-11-29 13:47:10 +01:00
Wenzel Jakob
e1b113b0d9 ifdef WIN32 -> _WIN32 2015-11-28 14:20:38 +01:00
Wenzel Jakob
6e213c9ca0 improved shared pointer support (fixes #14) 2015-11-24 23:18:32 +01:00
Wenzel Jakob
eb7c0b82ec functional.h: support more kinds of Python functions 2015-11-16 18:39:43 +01:00
Wenzel Jakob
3ee91b2f0a renamed pybind11::set::insert -> add to match C api naming 2015-11-15 13:03:07 +01:00
Wenzel Jakob
333e889ef2 Improved STL support, support for std::set 2015-11-14 19:04:49 +01:00
Wenzel Jakob
723bc65b27 fix for std::shared_ptr proposed by Vayu (fixes #8) 2015-11-12 23:27:20 +01:00
Wenzel Jakob
54289302bc minor cleanups 2015-10-26 20:10:24 +01:00
Wenzel Jakob
5db63fb746 work around weird macro substitution issue on GCC (fixes issue #7) 2015-10-22 21:38:32 +02:00
Wenzel Jakob
fa1bfb2ec7 do a fallback search over types to handle incompatible std::type_info* across module boundaries (fixes issue #4) 2015-10-22 16:04:53 +02:00
Wenzel Jakob
3419ee909f fix linux 32 bit builds 2015-10-21 11:07:48 +02:00
Wenzel Jakob
ad7bc01d51 fix build on linux 2015-10-20 01:11:17 +02:00
Wenzel Jakob
0fb8528edf factored out some common functionality to a non-templated parent class 2015-10-19 23:53:22 +02:00
Wenzel Jakob
b1b714023a consistent macro naming throughout the project 2015-10-18 16:48:30 +02:00
Wenzel Jakob
8f4eb00690 last breaking change: be consistent about the project name 2015-10-15 18:23:56 +02:00
Wenzel Jakob
db028d685c added module::import statement 2015-10-13 23:44:25 +02:00
Wenzel Jakob
b50872acf2 A few breaking changes for consistency just before the 1.0 release
1. Renamed PYTHON_* to PYBIND_* everywhere

2. Renamed pybind::array_dtype<> to pybind::array_t<>
2015-10-13 17:46:31 +02:00
Wenzel Jakob
19208fe9a4 install a cleanup handler for nontrivial lambda closures 2015-10-13 17:46:27 +02:00
Wenzel Jakob
8456a4dca2 minor enum_ improvement (use __repr__ instead of __str__) 2015-10-13 03:03:06 +02:00
Wenzel Jakob
215fc6a4ce simplified string casters, removed wide char support (inconsistent across platforms, better to use utf8 in any case..) 2015-10-13 03:03:01 +02:00
Wenzel Jakob
d2a902bd45 quench a warning on windows 2015-10-04 20:24:20 +02:00
Wenzel Jakob
b3ee3eaf81 emit a more useful error message when a return value can't be converted to a Python type 2015-10-04 15:17:34 +02:00
Wenzel Jakob
edbdef7ccf fixed pybind::call value policy 2015-10-02 09:33:53 +02:00
Wenzel Jakob
6a32620db3 convenience function to create a pybind::handle<> to the python version of a C++ type 2015-10-02 00:42:33 +02:00
Wenzel Jakob
6918922332 allow enums values to be cast to integers 2015-10-01 21:32:23 +02:00
Wenzel Jakob
ac0fde988a don't throw an exception when python deallocates an object which still exists on the C++ side 2015-10-01 18:49:37 +02:00
Wenzel Jakob
6c698fec59 Fix usage of WIN32 define 2015-10-01 17:13:38 +02:00
Wenzel Jakob
a2f6fde0dc support for overriding virtual functions 2015-10-01 17:13:35 +02:00
Wenzel Jakob
04358b02ed Always record the __module__ in newly created Python types 2015-10-01 16:45:28 +02:00
Wenzel Jakob
96c10530aa A few convenience functions for working with Python types
- Get a descriptive string after a Python exception (without changing the exception status)
- Convenience function to map from a C++ object to a Python handle
- Convenience to check if a pybind::function is defined by an underlying
  C++ implementation
- Get the type object of a pybind::handle
2015-10-01 16:44:30 +02:00
Wenzel Jakob
5257330e6a keyword processing bugfix 2015-09-14 16:38:47 +02:00
Wenzel Jakob
73a50a0441 Fix for radd/rsub/rmul/rdiv operator convenience wrappers 2015-09-11 17:09:47 +02:00
Wenzel Jakob
38ffb5232f handle errors in callbacks 2015-09-11 17:01:21 +02:00
Wenzel Jakob
5116b02e68 python 2.7 fix 2015-09-05 02:14:39 +02:00
Wenzel Jakob
570822102c support for ancient Python versions (2.7.x) 2015-09-04 23:49:23 +02:00
Wenzel Jakob
2b0339f44e refcounting fix 2015-09-01 22:51:03 +02:00
Wenzel Jakob
c47fc488d3 win32 build fix 2015-08-30 01:01:47 +02:00
Wenzel Jakob
a750031795 support strongly typed enum 2015-08-29 02:08:32 +02:00
Wenzel Jakob
bce10fae38 windows fixes 2015-08-28 17:58:24 +02:00
Wenzel Jakob
a9ee25a97e various minor compilation fixes 2015-08-28 17:53:31 +02:00
Wenzel Jakob
5d4d83da11 Merge branch 'master' of https://github.com/wjakob/pybind11 2015-08-28 17:49:27 +02:00
Wenzel Jakob
7b8e032c26 added a few basic number types 2015-08-28 17:49:15 +02:00
Wenzel Jakob
328aa14e0a linux compilation fixes 2015-08-26 17:23:23 +02:00
Wenzel Jakob
43dbdfd0e7 Merge branch 'master' of https://github.com/wjakob/pybind11 2015-08-24 15:32:50 +02:00
Wenzel Jakob
f5fae929a3 avoid std::string when creating signatures, and make nicer type names. binary size reduced by ~10% 2015-08-24 15:31:24 +02:00
Wenzel Jakob
d3a4a50207 Merge branch 'master' of https://github.com/wjakob/pybind11 2015-08-04 18:55:07 +02:00
Wenzel Jakob
efd9e987f5 windows fixes 2015-08-04 18:53:18 +02:00
Wenzel Jakob
cd5cda715b cleaned up handling of warnings on clang 2015-08-03 12:17:54 +02:00
Wenzel Jakob
281aa0e668 nicer code separation, cleanup logic, std::function type caster 2015-07-31 04:10:38 +02:00
Wenzel Jakob
a576e6a8ca keyword argument support, removed last traces of std::function<> usage 2015-07-29 23:39:11 +02:00
Wenzel Jakob
71867830f5 switched cpp_function to use variadic arguments 2015-07-29 17:50:57 +02:00
Wenzel Jakob
fbe82bf94d code size reduction 2015-07-28 16:12:29 +02:00
Wenzel Jakob
43398a8548 complex number support 2015-07-28 16:12:20 +02:00
Wenzel Jakob
d4258bafef generate more compact binaries 2015-07-28 03:10:15 +02:00
Wenzel Jakob
2ac80e77aa Better NumPy support 2015-07-22 01:00:06 +02:00
Wenzel Jakob
bd4a529319 more flexible function creation syntax 2015-07-11 18:55:41 +02:00
Wenzel Jakob
38bd71134a Initial commit 2015-07-09 15:27:32 +02:00