commit | 5a6aa491056046dc8d828d7234873fecbdae8492 | [log] [tgz] |
---|---|---|
author | Wenzel Jakob <wenzel.jakob@epfl.ch> | Wed Apr 13 22:48:05 2016 +0200 |
committer | Wenzel Jakob <wenzel.jakob@epfl.ch> | Wed Apr 13 22:48:05 2016 +0200 |
tree | 8f11344c639b6bc75682780ce93231546a139e3c | |
parent | 1a060fd70df0b9089c34b8f60fba6bb62349b498 [diff] |
Added len() function
diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 455d893..e23df9a 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h
@@ -461,4 +461,11 @@ } }; +inline size_t len(handle h) { + ssize_t result = PyObject_Length(h.ptr()); + if (result < 0) + pybind11_fail("Unable to compute length of object"); + return (size_t) result; +} + NAMESPACE_END(pybind11)