mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-01-31 12:03:22 +08:00
fixed a terrible bug in def_property_static and switched to the faster PyObject_CallFunctionObjArgs API call
This commit is contained in:
parent
678d787ca4
commit
ba0732e7dc
@ -975,9 +975,9 @@ public:
|
|||||||
class_ &def_property(const char *name, const cpp_function &fget, const cpp_function &fset, const char *doc = nullptr) {
|
class_ &def_property(const char *name, const cpp_function &fget, const cpp_function &fset, const char *doc = nullptr) {
|
||||||
object doc_obj = doc ? pybind11::str(doc) : (object) const_cast<cpp_function&>(fget).attr("__doc__");
|
object doc_obj = doc ? pybind11::str(doc) : (object) const_cast<cpp_function&>(fget).attr("__doc__");
|
||||||
object property(
|
object property(
|
||||||
PyObject_CallFunction((PyObject *)&PyProperty_Type,
|
PyObject_CallFunctionObjArgs((PyObject *) &PyProperty_Type,
|
||||||
const_cast<char *>("OOOO"), fget.ptr() ? fget.ptr() : Py_None,
|
fget.ptr() ? fget.ptr() : Py_None,
|
||||||
fset.ptr() ? fset.ptr() : Py_None, Py_None, doc_obj.ptr()), false);
|
fset.ptr() ? fset.ptr() : Py_None, Py_None, doc_obj.ptr(), nullptr), false);
|
||||||
attr(name) = property;
|
attr(name) = property;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -985,9 +985,9 @@ public:
|
|||||||
class_ &def_property_static(const char *name, const cpp_function &fget, const cpp_function &fset, const char *doc = nullptr) {
|
class_ &def_property_static(const char *name, const cpp_function &fget, const cpp_function &fset, const char *doc = nullptr) {
|
||||||
object doc_obj = doc ? pybind11::str(doc) : (object) const_cast<cpp_function&>(fget).attr("__doc__");
|
object doc_obj = doc ? pybind11::str(doc) : (object) const_cast<cpp_function&>(fget).attr("__doc__");
|
||||||
object property(
|
object property(
|
||||||
PyObject_CallFunction((PyObject *)&PyProperty_Type,
|
PyObject_CallFunctionObjArgs((PyObject *) &PyProperty_Type,
|
||||||
const_cast<char *>("OOOs"), fget.ptr() ? fget.ptr() : Py_None,
|
fget.ptr() ? fget.ptr() : Py_None,
|
||||||
fset.ptr() ? fset.ptr() : Py_None, Py_None, doc_obj.ptr()), false);
|
fset.ptr() ? fset.ptr() : Py_None, Py_None, doc_obj.ptr(), nullptr), false);
|
||||||
metaclass().attr(name) = property;
|
metaclass().attr(name) = property;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user