Skip to content

Commit ddb1236

Browse files
committed
Begin transition away from handle<>
[SVN r14602]
1 parent 30ef9c6 commit ddb1236

9 files changed

Lines changed: 77 additions & 74 deletions

File tree

include/boost/python/class.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,19 @@ class class_ : public objects::class_base
181181
template <class D>
182182
self& def_readonly(char const* name, D T::*pm)
183183
{
184-
handle<> fget(make_getter(pm));
185-
this->add_property(name, fget);
184+
this->add_property(name, make_getter(pm));
186185
return *this;
187186
}
188187

189188
template <class D>
190189
self& def_readwrite(char const* name, D T::*pm)
191190
{
192-
handle<> fget(make_getter(pm));
193-
handle<> fset(make_setter(pm));
194-
return this->add_property(name, fget, fset);
191+
return this->add_property(name, make_getter(pm), make_setter(pm));
195192
}
196193

197194
// Property creation
198-
self& add_property(char const* name, handle<> const& fget);
199-
self& add_property(char const* name, handle<> const& fget, handle<> const& fset);
195+
self& add_property(char const* name, object const& fget);
196+
self& add_property(char const* name, object const& fget, object const& fset);
200197

201198
self& setattr(char const* name, handle<> const&);
202199

@@ -277,14 +274,14 @@ inline class_<T,X1,X2,X3>::class_(char const* name)
277274

278275

279276
template <class T, class X1, class X2, class X3>
280-
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::add_property(char const* name, handle<> const& fget)
277+
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::add_property(char const* name, object const& fget)
281278
{
282279
base::add_property(name, fget);
283280
return *this;
284281
}
285282

286283
template <class T, class X1, class X2, class X3>
287-
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::add_property(char const* name, handle<> const& fget, handle<> const& fset)
284+
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::add_property(char const* name, object const& fget, object const& fset)
288285
{
289286
base::add_property(name, fget, fset);
290287
return *this;

include/boost/python/data_members.hpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# include <boost/type_traits/cv_traits.hpp>
1414
# include <boost/python/return_value_policy.hpp>
1515
# include <boost/python/copy_non_const_reference.hpp>
16+
# include <boost/python/object/function_object.hpp>
1617

1718
namespace boost { namespace python {
1819

@@ -61,47 +62,45 @@ namespace detail
6162
}
6263

6364
template <class C, class D>
64-
objects::function* make_getter(D C::*pm)
65+
object make_getter(D C::*pm)
6566
{
6667
typedef return_value_policy<copy_non_const_reference> default_policy;
67-
return new objects::function(
68-
objects::py_function(
69-
::boost::bind(
70-
&detail::member<D,C,default_policy>::get, pm, _1, _2
71-
, default_policy()))
68+
69+
return objects::function_object(
70+
::boost::bind(
71+
&detail::member<D,C,default_policy>::get, pm, _1, _2
72+
, default_policy())
7273
, 1);
74+
7375
}
7476

7577
template <class C, class D, class Policies>
76-
objects::function* make_getter(D C::*pm, Policies const& policies)
78+
object make_getter(D C::*pm, Policies const& policies)
7779
{
78-
return new objects::function(
79-
objects::py_function(
80+
return objects::function_object(
8081
::boost::bind(
8182
&detail::member<D,C,Policies>::get, pm, _1, _2
82-
, policies))
83+
, policies)
8384
, 1);
8485
}
8586

8687
template <class C, class D>
87-
objects::function* make_setter(D C::*pm)
88+
object make_setter(D C::*pm)
8889
{
89-
return new objects::function(
90-
objects::py_function(
91-
::boost::bind(
92-
&detail::member<D,C,default_call_policies>::set, pm, _1, _2
93-
, default_call_policies()))
90+
return objects::function_object(
91+
::boost::bind(
92+
&detail::member<D,C,default_call_policies>::set, pm, _1, _2
93+
, default_call_policies())
9494
, 2);
9595
}
9696

9797
template <class C, class D, class Policies>
98-
objects::function* make_setter(D C::*pm, Policies const& policies)
98+
object make_setter(D C::*pm, Policies const& policies)
9999
{
100-
return new objects::function(
101-
objects::py_function(
102-
::boost::bind(
103-
&detail::member<D,C,Policies>::set, pm, _1, _2
104-
, policies))
100+
return objects::function_object(
101+
::boost::bind(
102+
&detail::member<D,C,Policies>::set, pm, _1, _2
103+
, policies)
105104
, 2);
106105
}
107106

include/boost/python/detail/wrap_function.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# include <boost/type_traits/transform_traits.hpp>
1313
# include <boost/python/detail/indirect_traits.hpp>
1414
# include <boost/mpl/select_type.hpp>
15+
# include <boost/python/object_core.hpp>
16+
# include <boost/python/refcount.hpp>
1517

1618
namespace boost { namespace python {
1719

@@ -28,13 +30,16 @@ namespace detail {
2830
// object.
2931

3032
template <class F>
31-
inline PyObject* wrap_function_aux(F f, PyObject*) { return f; }
33+
inline PyObject* wrap_function_aux(F const& f, PyObject*) { return f; }
3234

3335
template <class F, class T>
34-
inline PyObject* wrap_function_aux(F f, boost::python::handle<T> x) { return x.release(); }
36+
inline PyObject* wrap_function_aux(F const&, boost::python::handle<T> x) { return x.release(); }
3537

3638
template <class F>
37-
inline PyObject* wrap_function_aux(F f, ...) { return make_function(f); }
39+
inline PyObject* wrap_function_aux(F const&, object const& x) { return python::incref(x.ptr()); }
40+
41+
template <class F>
42+
inline PyObject* wrap_function_aux(F const& f, ...) { return make_function(f); }
3843

3944
template <class F>
4045
PyObject* wrap_function(F f)

include/boost/python/iterator.hpp

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,43 +69,28 @@ struct iterators
6969
// accessors. Deduce the Target type from the accessors. The iterator
7070
// returns copies of the inderlying elements.
7171
template <class Accessor1, class Accessor2>
72-
handle<> range(Accessor1 start, Accessor2 finish)
72+
object range(Accessor1 start, Accessor2 finish)
7373
{
74-
return handle<>(
75-
borrowed(allow_null(
76-
detail::make_iterator<objects::default_iterator_call_policies>(
74+
return detail::make_iterator<objects::default_iterator_call_policies>(
7775
start, finish
78-
, detail::target(start))
79-
.ptr()
80-
))
81-
);
76+
, detail::target(start));
8277
}
8378

8479
// Create an iterator-building function which uses the given accessors
8580
// and next() policies. Deduce the Target type.
8681
template <class NextPolicies, class Accessor1, class Accessor2>
87-
handle<> range(Accessor1 start, Accessor2 finish, NextPolicies* = 0)
82+
object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0)
8883
{
89-
return handle<>(
90-
borrowed(
91-
allow_null(
92-
detail::make_iterator<NextPolicies>(start, finish, detail::target(start))
93-
.ptr()
94-
)));
84+
return detail::make_iterator<NextPolicies>(start, finish, detail::target(start));
9585
}
9686

9787
// Create an iterator-building function which uses the given accessors
9888
// and next() policies, operating on the given Target type
9989
template <class NextPolicies, class Target, class Accessor1, class Accessor2>
100-
handle<> range(Accessor1 start, Accessor2 finish, NextPolicies* = 0, boost::type<Target>* = 0)
90+
object range(Accessor1 start, Accessor2 finish, NextPolicies* = 0, boost::type<Target>* = 0)
10191
{
10292
typedef typename add_reference<Target>::type target;
103-
return handle<>(
104-
borrowed(
105-
allow_null(
106-
detail::make_iterator<NextPolicies, target>(start, finish)
107-
.ptr()
108-
)));
93+
return detail::make_iterator<NextPolicies, target>(start, finish);
10994
}
11095

11196
// A Python callable object which produces an iterator traversing
@@ -114,11 +99,11 @@ handle<> range(Accessor1 start, Accessor2 finish, NextPolicies* = 0, boost::type
11499
// next() function.
115100
template <class Container
116101
, class NextPolicies = objects::default_iterator_call_policies>
117-
struct iterator : handle<>
102+
struct iterator : object
118103
{
119104
iterator()
120-
: handle<>(
121-
range<NextPolicies>(
105+
: object(
106+
python::range<NextPolicies>(
122107
&iterators<Container>::begin, &iterators<Container>::end
123108
))
124109
{

include/boost/python/object/class.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ struct BOOST_PYTHON_DECL class_base : python::api::object
3636
);
3737

3838
// Retrieve the underlying object
39-
void add_property(char const* name, handle<> const& fget);
40-
void add_property(char const* name, handle<> const& fget, handle<> const& fset);
39+
void add_property(char const* name, object const& fget);
40+
void add_property(char const* name, object const& fget, object const& fset);
4141
void setattr(char const* name, handle<> const&);
4242
void enable_pickling(bool getstate_manages_dict);
4343
};

include/boost/python/object/function.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@ struct BOOST_PYTHON_DECL function : PyObject
4141
function* m_overloads;
4242
};
4343

44-
//
45-
// implementations
46-
//
47-
4844
}}} // namespace boost::python::objects
4945

5046
#endif // FUNCTION_DWA20011214_HPP
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright David Abrahams 2002. Permission to copy, use,
2+
// modify, sell and distribute this software is granted provided this
3+
// copyright notice appears in all copies. This software is provided
4+
// "as is" without express or implied warranty, and with no claim as
5+
// to its suitability for any purpose.
6+
#ifndef FUNCTION_OBJECT_DWA2002725_HPP
7+
# define FUNCTION_OBJECT_DWA2002725_HPP
8+
# include <boost/python/object/function.hpp>
9+
# include <boost/python/object_core.hpp>
10+
11+
namespace boost { namespace python { namespace objects {
12+
13+
template <class F>
14+
inline object function_object(F const& f, unsigned min_args, unsigned max_args = 0)
15+
{
16+
return python::object(
17+
python::detail::new_non_null_reference(
18+
new function(objects::py_function(f), min_args, max_args)));
19+
}
20+
21+
}}} // namespace boost::python::object
22+
23+
#endif // FUNCTION_OBJECT_DWA2002725_HPP

src/object/class.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,15 @@ namespace objects
296296
extern DL_IMPORT(PyTypeObject) PyProperty_Type;
297297
}
298298

299-
void class_base::add_property(char const* name, handle<> const& fget)
299+
void class_base::add_property(char const* name, object const& fget)
300300
{
301-
handle<> property(PyObject_CallFunction((PyObject*)&PyProperty_Type, "O", fget.get()));
301+
handle<> property(PyObject_CallFunction((PyObject*)&PyProperty_Type, "O", fget.ptr()));
302302
setattr(name, property);
303303
}
304304

305-
void class_base::add_property(char const* name, handle<> const& fget, handle<> const& fset)
305+
void class_base::add_property(char const* name, object const& fget, object const& fset)
306306
{
307-
handle<> property(PyObject_CallFunction((PyObject*)&PyProperty_Type, "OO", fget.get(), fset.get()));
307+
handle<> property(PyObject_CallFunction((PyObject*)&PyProperty_Type, "OO", fget.ptr(), fset.ptr()));
308308
setattr(name, property);
309309
}
310310

src/object/function.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// "as is" without express or implied warranty, and with no claim as
55
// to its suitability for any purpose.
66

7-
#include <boost/python/object/function.hpp>
7+
#include <boost/python/object/function_object.hpp>
88
#include <numeric>
99
#include <boost/python/errors.hpp>
1010
#include <boost/python/str.hpp>
@@ -148,10 +148,8 @@ namespace
148148

149149
function* not_implemented_function()
150150
{
151-
static function* result = new function(py_function(&not_implemented_impl), 2, 3);
152-
static handle<> keeper(result);
153-
154-
return result;
151+
static object keeper(function_object(&not_implemented_impl, 2, 3));
152+
return (function*)keeper.ptr();
155153
}
156154
}
157155

0 commit comments

Comments
 (0)