@@ -51,6 +51,7 @@ NAMESPACE_BEGIN(PYBIND11_NAMESPACE)
51
51
class cpp_function : public function {
52
52
public:
53
53
cpp_function () { }
54
+ cpp_function (std::nullptr_t ) { }
54
55
55
56
// / Construct a cpp_function from a vanilla function pointer
56
57
template <typename Return, typename ... Args, typename ... Extra>
@@ -951,18 +952,18 @@ class generic_type : public object {
951
952
tinfo->get_buffer_data = get_buffer_data;
952
953
}
953
954
955
+ // rec_func must be set for either fget or fset.
954
956
void def_property_static_impl (const char *name,
955
957
handle fget, handle fset,
956
- detail::function_record *rec_fget) {
957
- const auto is_static = !(rec_fget->is_method && rec_fget->scope );
958
- const auto has_doc = rec_fget->doc && pybind11::options::show_user_defined_docstrings ();
959
-
958
+ detail::function_record *rec_func) {
959
+ const auto is_static = rec_func && !(rec_func->is_method && rec_func->scope );
960
+ const auto has_doc = rec_func && rec_func->doc && pybind11::options::show_user_defined_docstrings ();
960
961
auto property = handle ((PyObject *) (is_static ? get_internals ().static_property_type
961
962
: &PyProperty_Type));
962
963
attr (name) = property (fget.ptr () ? fget : none (),
963
964
fset.ptr () ? fset : none (),
964
965
/* deleter*/ none (),
965
- pybind11::str (has_doc ? rec_fget ->doc : " " ));
966
+ pybind11::str (has_doc ? rec_func ->doc : " " ));
966
967
}
967
968
};
968
969
@@ -1196,7 +1197,7 @@ class class_ : public detail::generic_type {
1196
1197
// / Uses cpp_function's return_value_policy by default
1197
1198
template <typename ... Extra>
1198
1199
class_ &def_property_readonly (const char *name, const cpp_function &fget, const Extra& ...extra) {
1199
- return def_property (name, fget, cpp_function () , extra...);
1200
+ return def_property (name, fget, nullptr , extra...);
1200
1201
}
1201
1202
1202
1203
// / Uses return_value_policy::reference by default
@@ -1208,7 +1209,7 @@ class class_ : public detail::generic_type {
1208
1209
// / Uses cpp_function's return_value_policy by default
1209
1210
template <typename ... Extra>
1210
1211
class_ &def_property_readonly_static (const char *name, const cpp_function &fget, const Extra& ...extra) {
1211
- return def_property_static (name, fget, cpp_function () , extra...);
1212
+ return def_property_static (name, fget, nullptr , extra...);
1212
1213
}
1213
1214
1214
1215
// / Uses return_value_policy::reference_internal by default
@@ -1238,21 +1239,25 @@ class class_ : public detail::generic_type {
1238
1239
template <typename ... Extra>
1239
1240
class_ &def_property_static (const char *name, const cpp_function &fget, const cpp_function &fset, const Extra& ...extra) {
1240
1241
auto rec_fget = get_function_record (fget), rec_fset = get_function_record (fset);
1241
- char *doc_prev = rec_fget->doc ; /* 'extra' field may include a property-specific documentation string */
1242
- detail::process_attributes<Extra...>::init (extra..., rec_fget);
1243
- if (rec_fget->doc && rec_fget->doc != doc_prev) {
1244
- free (doc_prev);
1245
- rec_fget->doc = strdup (rec_fget->doc );
1242
+ auto *rec_active = rec_fget;
1243
+ if (rec_fget) {
1244
+ char *doc_prev = rec_fget->doc ; /* 'extra' field may include a property-specific documentation string */
1245
+ detail::process_attributes<Extra...>::init (extra..., rec_fget);
1246
+ if (rec_fget->doc && rec_fget->doc != doc_prev) {
1247
+ free (doc_prev);
1248
+ rec_fget->doc = strdup (rec_fget->doc );
1249
+ }
1246
1250
}
1247
1251
if (rec_fset) {
1248
- doc_prev = rec_fset->doc ;
1252
+ char * doc_prev = rec_fset->doc ;
1249
1253
detail::process_attributes<Extra...>::init (extra..., rec_fset);
1250
1254
if (rec_fset->doc && rec_fset->doc != doc_prev) {
1251
1255
free (doc_prev);
1252
1256
rec_fset->doc = strdup (rec_fset->doc );
1253
1257
}
1258
+ if (! rec_active) rec_active = rec_fset;
1254
1259
}
1255
- def_property_static_impl (name, fget, fset, rec_fget );
1260
+ def_property_static_impl (name, fget, fset, rec_active );
1256
1261
return *this ;
1257
1262
}
1258
1263
0 commit comments