diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index 61ac1502e..ad7367218 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -467,6 +467,9 @@ protected: holder_type holder; }; +template struct handle_type_name { static PYBIND11_DESCR name() { return _(); } }; +template <> struct handle_type_name { static PYBIND11_DESCR name() { return _(PYBIND11_BYTES_NAME); } }; + template struct type_caster::value>::type> { public: @@ -477,10 +480,9 @@ public: bool load(PyObject *src, bool /* convert */) { value = type(src, true); return value.check(); } static PyObject *cast(const handle &src, return_value_policy /* policy */, PyObject * /* parent */) { - src.inc_ref(); - return (PyObject *) src.ptr(); + src.inc_ref(); return (PyObject *) src.ptr(); } - PYBIND11_TYPE_CASTER(type, _()); + PYBIND11_TYPE_CASTER(type, handle_type_name::name()); }; NAMESPACE_END(detail) diff --git a/include/pybind11/common.h b/include/pybind11/common.h index 43b365778..c6e62910e 100644 --- a/include/pybind11/common.h +++ b/include/pybind11/common.h @@ -94,6 +94,7 @@ #define PYBIND11_LONG_CHECK(o) PyLong_Check(o) #define PYBIND11_LONG_AS_LONGLONG(o) PyLong_AsLongLong(o) #define PYBIND11_LONG_AS_UNSIGNED_LONGLONG(o) PyLong_AsUnsignedLongLong(o) +#define PYBIND11_BYTES_NAME "bytes" #define PYBIND11_STRING_NAME "str" #define PYBIND11_SLICE_OBJECT PyObject #else @@ -105,6 +106,7 @@ #define PYBIND11_LONG_CHECK(o) (PyInt_Check(o) || PyLong_Check(o)) #define PYBIND11_LONG_AS_LONGLONG(o) (PyInt_Check(o) ? (long long) PyLong_AsLong(o) : PyLong_AsLongLong(o)) #define PYBIND11_LONG_AS_UNSIGNED_LONGLONG(o) (PyInt_Check(o) ? (unsigned long long) PyLong_AsUnsignedLong(o) : PyLong_AsUnsignedLongLong(o)) +#define PYBIND11_BYTES_NAME "str" #define PYBIND11_STRING_NAME "unicode" #define PYBIND11_SLICE_OBJECT PySliceObject #endif diff --git a/include/pybind11/numpy.h b/include/pybind11/numpy.h index 094f31759..4b105323a 100644 --- a/include/pybind11/numpy.h +++ b/include/pybind11/numpy.h @@ -150,6 +150,10 @@ DECL_FMT(std::complex, NPY_CDOUBLE); NAMESPACE_BEGIN(detail) +template struct handle_type_name> { + static PYBIND11_DESCR name() { return _("array[") + type_caster::name() + _("]"); } +}; + template struct vectorize_helper { typename std::remove_reference::type f;