mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 13:15:12 +00:00
fix segfault when passing a docstring to def_property* (fixes #222)
This commit is contained in:
parent
9767c4803d
commit
7c99ff2a00
@ -860,9 +860,20 @@ public:
|
||||
template <typename... Extra>
|
||||
class_ &def_property_static(const char *name, const cpp_function &fget, const cpp_function &fset, const Extra& ...extra) {
|
||||
auto rec_fget = get_function_record(fget), rec_fset = get_function_record(fset);
|
||||
char *doc_prev = rec_fget->doc; /* 'extra' field may include a property-specific documentation string */
|
||||
detail::process_attributes<Extra...>::init(extra..., rec_fget);
|
||||
if (rec_fset)
|
||||
if (rec_fget->doc && rec_fget->doc != doc_prev) {
|
||||
free(doc_prev);
|
||||
rec_fget->doc = strdup(rec_fget->doc);
|
||||
}
|
||||
if (rec_fset) {
|
||||
doc_prev = rec_fset->doc;
|
||||
detail::process_attributes<Extra...>::init(extra..., rec_fset);
|
||||
if (rec_fset->doc && rec_fset->doc != doc_prev) {
|
||||
free(doc_prev);
|
||||
rec_fset->doc = strdup(rec_fset->doc);
|
||||
}
|
||||
}
|
||||
pybind11::str doc_obj = pybind11::str(rec_fget->doc ? rec_fget->doc : "");
|
||||
object property(
|
||||
PyObject_CallFunctionObjArgs((PyObject *) &PyProperty_Type, fget.ptr() ? fget.ptr() : Py_None,
|
||||
|
Loading…
Reference in New Issue
Block a user