From 19036c14f531652e8cf47869bbff7970284903e0 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 25 Jul 2002 18:07:25 +0000 Subject: [PATCH] handle<> -> object [SVN r14603] --- include/boost/python/class.hpp | 10 ++++++-- include/boost/python/object/class.hpp | 2 +- include/boost/python/object/iterator.hpp | 2 +- src/object/class.cpp | 29 +++++++++++++++--------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index b2d960b0..d7a01edd 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -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 + self& bind(char const* name, T const& x) + { + return this->setattr(name, object(x)); + } // Pickle support template @@ -288,7 +294,7 @@ inline class_& class_::add_property(char const* name, ob } template -inline class_& class_::setattr(char const* name, handle<> const& x) +inline class_& class_::setattr(char const* name, object const& x) { base::setattr(name, x); return *this; diff --git a/include/boost/python/object/class.hpp b/include/boost/python/object/class.hpp index 1367337b..d6af07e1 100644 --- a/include/boost/python/object/class.hpp +++ b/include/boost/python/object/class.hpp @@ -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); }; diff --git a/include/boost/python/object/iterator.hpp b/include/boost/python/object/iterator.hpp index 124759d6..8590d531 100644 --- a/include/boost/python/object/iterator.hpp +++ b/include/boost/python/object/iterator.hpp @@ -134,7 +134,7 @@ namespace detail return class_(name) .def("__iter__", identity_function()) - .setattr("next", next_function) + .bind("next", next_function) ; } diff --git a/src/object/class.cpp b/src/object/class.cpp index b3c6c5e0..d5d854dd 100644 --- a/src/object/class.cpp +++ b/src/object/class.cpp @@ -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(name), x.get()) < 0) + if (PyObject_SetAttrString(this->ptr(), const_cast(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)); } }