mirror of
https://github.com/boostorg/python.git
synced 2026-01-24 18:12:43 +00:00
handle<> -> object
[SVN r14603]
This commit is contained in:
@@ -195,7 +195,13 @@ class class_ : public objects::class_base
|
||||
self& add_property(char const* name, object const& fget);
|
||||
self& add_property(char const* name, object const& fget, object const& fset);
|
||||
|
||||
self& setattr(char const* name, handle<> const&);
|
||||
self& setattr(char const* name, object const&);
|
||||
|
||||
template <class T>
|
||||
self& bind(char const* name, T const& x)
|
||||
{
|
||||
return this->setattr(name, object(x));
|
||||
}
|
||||
|
||||
// Pickle support
|
||||
template <typename PickleSuiteType>
|
||||
@@ -288,7 +294,7 @@ inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::add_property(char const* name, ob
|
||||
}
|
||||
|
||||
template <class T, class X1, class X2, class X3>
|
||||
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::setattr(char const* name, handle<> const& x)
|
||||
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::setattr(char const* name, object const& x)
|
||||
{
|
||||
base::setattr(name, x);
|
||||
return *this;
|
||||
|
||||
@@ -38,7 +38,7 @@ struct BOOST_PYTHON_DECL class_base : python::api::object
|
||||
// Retrieve the underlying object
|
||||
void add_property(char const* name, object const& fget);
|
||||
void add_property(char const* name, object const& fget, object const& fset);
|
||||
void setattr(char const* name, handle<> const&);
|
||||
void setattr(char const* name, object const&);
|
||||
void enable_pickling(bool getstate_manages_dict);
|
||||
};
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ namespace detail
|
||||
|
||||
return class_<range_>(name)
|
||||
.def("__iter__", identity_function())
|
||||
.setattr("next", next_function)
|
||||
.bind("next", next_function)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
@@ -298,29 +298,36 @@ namespace objects
|
||||
|
||||
void class_base::add_property(char const* name, object const& fget)
|
||||
{
|
||||
handle<> property(PyObject_CallFunction((PyObject*)&PyProperty_Type, "O", fget.ptr()));
|
||||
setattr(name, property);
|
||||
object property(
|
||||
python::detail::new_reference(
|
||||
PyObject_CallFunction((PyObject*)&PyProperty_Type, "O", fget.ptr())));
|
||||
|
||||
this->setattr(name, property);
|
||||
}
|
||||
|
||||
void class_base::add_property(char const* name, object const& fget, object const& fset)
|
||||
{
|
||||
handle<> property(PyObject_CallFunction((PyObject*)&PyProperty_Type, "OO", fget.ptr(), fset.ptr()));
|
||||
setattr(name, property);
|
||||
object property(
|
||||
python::detail::new_reference(
|
||||
PyObject_CallFunction((PyObject*)&PyProperty_Type, "OO", fget.ptr(), fset.ptr())));
|
||||
|
||||
this->setattr(name, property);
|
||||
}
|
||||
|
||||
void class_base::setattr(char const* name, handle<> const& x)
|
||||
void class_base::setattr(char const* name, object const& x)
|
||||
{
|
||||
if (PyObject_SetAttrString(this->ptr(), const_cast<char*>(name), x.get()) < 0)
|
||||
if (PyObject_SetAttrString(this->ptr(), const_cast<char*>(name), x.ptr()) < 0)
|
||||
throw_error_already_set();
|
||||
}
|
||||
|
||||
void class_base::enable_pickling(bool getstate_manages_dict)
|
||||
{
|
||||
setattr("__reduce__", make_instance_reduce_function());
|
||||
handle<> one(PyInt_FromLong(1));
|
||||
setattr("__safe_for_unpickling__", one);
|
||||
if (getstate_manages_dict) {
|
||||
setattr("__getstate_manages_dict__", one);
|
||||
setattr("__reduce__", object(make_instance_reduce_function()));
|
||||
setattr("__safe_for_unpickling__", object(true));
|
||||
|
||||
if (getstate_manages_dict)
|
||||
{
|
||||
setattr("__getstate_manages_dict__", object(true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user