From 5116b02e6806f7b9a025597c896d3928ed3a891e Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Sat, 5 Sep 2015 02:09:17 +0200 Subject: [PATCH] python 2.7 fix --- example/example2.cpp | 2 +- include/pybind/pybind.h | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/example/example2.cpp b/example/example2.cpp index c4a352e73..580fbc3d5 100644 --- a/example/example2.cpp +++ b/example/example2.cpp @@ -100,7 +100,7 @@ const int Example2::value2 = 5; void init_ex2(py::module &m) { /* No constructor is explicitly defined below. An exception is raised when trying to construct it directly from Python */ - py::class_(m, "Example2") + py::class_(m, "Example2", "Example 2 documentation") .def("get_dict", &Example2::get_dict, "Return a Python dictionary") .def("get_dict_2", &Example2::get_dict_2, "Return a C++ dictionary") .def("get_list", &Example2::get_list, "Return a Python list") diff --git a/include/pybind/pybind.h b/include/pybind/pybind.h index 45ce9e4c2..27c888e37 100644 --- a/include/pybind/pybind.h +++ b/include/pybind/pybind.h @@ -510,6 +510,11 @@ public: type->ht_type.tp_as_sequence = &type->as_sequence; type->ht_type.tp_as_mapping = &type->as_mapping; type->ht_type.tp_base = (PyTypeObject *) parent; + if (doc) { + size_t size = strlen(doc)+1; + type->ht_type.tp_doc = (char *)PyObject_MALLOC(size); + memcpy((void *) type->ht_type.tp_doc, doc, size); + } Py_XINCREF(parent); if (PyType_Ready(&type->ht_type) < 0) @@ -525,8 +530,6 @@ public: type_info.type_size = type_size; type_info.init_holder = init_holder; attr("__pybind__") = capsule(&type_info); - if (doc) - attr("__doc__") = pybind::str(doc); scope.attr(name) = *this; }