|
17 | 17 | # include <boost/mpl/apply.hpp> |
18 | 18 | # include <boost/bind.hpp> |
19 | 19 | # include <boost/bind/protect.hpp> |
| 20 | +# include <boost/python/detail/raw_pyobject.hpp> |
20 | 21 |
|
21 | 22 | namespace boost { namespace python { namespace objects { |
22 | 23 |
|
@@ -113,30 +114,28 @@ namespace detail |
113 | 114 | // policies, creating it if neccessary. Requires: NextPolicies is |
114 | 115 | // default-constructible. |
115 | 116 | template <class Iterator, class NextPolicies> |
116 | | - handle<> demand_iterator_class(char const* name, Iterator* = 0, NextPolicies const& policies = NextPolicies()) |
| 117 | + object demand_iterator_class(char const* name, Iterator* = 0, NextPolicies const& policies = NextPolicies()) |
117 | 118 | { |
118 | 119 | typedef iterator_range<NextPolicies,Iterator> range_; |
119 | 120 |
|
120 | 121 | // Check the registry. If one is already registered, return it. |
121 | | - handle<> result( |
| 122 | + handle<> class_obj( |
122 | 123 | objects::registered_class_object(python::type_id<range_>())); |
123 | 124 |
|
124 | | - if (result.get() == 0) |
125 | | - { |
126 | | - // Make a callable object which can be used as the iterator's next() function. |
127 | | - handle<> next_function( |
128 | | - new objects::function( |
129 | | - objects::py_function( |
130 | | - bind(&detail::iterator_next<Iterator,NextPolicies>::execute, _1, _2, policies)) |
131 | | - , 1)); |
| 125 | + if (class_obj.get() != 0) |
| 126 | + return object(class_obj); |
| 127 | + |
| 128 | + // Make a callable object which can be used as the iterator's next() function. |
| 129 | + handle<> next_function( |
| 130 | + new objects::function( |
| 131 | + objects::py_function( |
| 132 | + bind(&detail::iterator_next<Iterator,NextPolicies>::execute, _1, _2, policies)) |
| 133 | + , 1)); |
132 | 134 |
|
133 | | - result = class_<range_>(name) |
134 | | - .def("__iter__", identity_function()) |
135 | | - .setattr("next", next_function) |
136 | | - .object(); |
137 | | - |
138 | | - } |
139 | | - return result; |
| 135 | + return class_<range_>(name) |
| 136 | + .def("__iter__", identity_function()) |
| 137 | + .setattr("next", next_function) |
| 138 | + ; |
140 | 139 | } |
141 | 140 |
|
142 | 141 | // This class template acts as a generator for an ordinary function |
@@ -187,22 +186,23 @@ namespace detail |
187 | 186 | // iterators for the range, and an instance of NextPolicies is used as |
188 | 187 | // CallPolicies for the Python iterator's next() function. |
189 | 188 | template <class NextPolicies, class Target, class Accessor1, class Accessor2> |
190 | | -inline handle<> make_iterator_function( |
| 189 | +inline object make_iterator_function( |
191 | 190 | Accessor1 const& get_start, Accessor2 const& get_finish |
192 | 191 | , boost::type<Target>* = 0, NextPolicies* = 0) |
193 | 192 | { |
194 | 193 | typedef typename Accessor1::result_type result_type; |
195 | 194 |
|
196 | | - return handle<>( |
197 | | - new objects::function( |
198 | | - objects::py_function( |
199 | | - boost::bind( |
200 | | - &detail::make_iterator_help< |
201 | | - Target,result_type,Accessor1,Accessor2,NextPolicies |
202 | | - >::create |
203 | | - , get_start, get_finish, _1, _2) |
204 | | - ) |
205 | | - ,1 )); |
| 195 | + return object( |
| 196 | + python::detail::new_non_null_reference( |
| 197 | + new objects::function( |
| 198 | + objects::py_function( |
| 199 | + boost::bind( |
| 200 | + &detail::make_iterator_help< |
| 201 | + Target,result_type,Accessor1,Accessor2,NextPolicies |
| 202 | + >::create |
| 203 | + , get_start, get_finish, _1, _2)) |
| 204 | + ,1 )) |
| 205 | + ); |
206 | 206 | } |
207 | 207 |
|
208 | 208 | // |
|
0 commit comments