Skip to content

Commit 366ee6d

Browse files
committed
reference<> => handle<>
[SVN r14136]
1 parent 0d58869 commit 366ee6d

36 files changed

+1264
-293
lines changed

Jamfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ dll bpl
2323
src/object/life_support.cpp
2424
src/errors.cpp
2525
src/module.cpp
26-
src/objects.cpp
26+
src/objects2.cpp
2727
src/converter/builtin_converters.cpp
2828
src/converter/callback.cpp
2929
src/object/iterator.cpp

include/boost/python/back_reference.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef BACK_REFERENCE_DWA2002510_HPP
77
# define BACK_REFERENCE_DWA2002510_HPP
88

9-
# include <boost/python/reference.hpp>
9+
# include <boost/python/handle.hpp>
1010

1111
namespace boost { namespace python {
1212

@@ -17,10 +17,10 @@ struct back_reference
1717
typedef T type;
1818

1919
back_reference(PyObject*, T);
20-
ref reference() const;
20+
handle<> reference() const;
2121
T get() const;
2222
private:
23-
ref m_reference;
23+
handle<> m_reference;
2424
T m_value;
2525
};
2626

@@ -75,13 +75,13 @@ class is_back_reference
7575
//
7676
template <class T>
7777
back_reference<T>::back_reference(PyObject* p, T x)
78-
: m_reference(p, ref::increment_count)
78+
: m_reference(python::borrow(p))
7979
, m_value(x)
8080
{
8181
}
8282

8383
template <class T>
84-
ref back_reference<T>::reference() const
84+
handle<> back_reference<T>::reference() const
8585
{
8686
return m_reference;
8787
}

include/boost/python/cast.hpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 CAST_DWA200269_HPP
7+
# define CAST_DWA200269_HPP
8+
9+
# include <boost/python/detail/wrap_python.hpp>
10+
# include <boost/type_traits/same_traits.hpp>
11+
# include <boost/type.hpp>
12+
13+
namespace boost { namespace python {
14+
15+
template <class T> struct base_type_traits;
16+
17+
template <>
18+
struct base_type_traits<PyObject>
19+
{
20+
typedef PyObject type;
21+
};
22+
23+
template <>
24+
struct base_type_traits<PyTypeObject>
25+
{
26+
typedef PyObject type;
27+
};
28+
29+
namespace detail
30+
{
31+
typedef char* yes_convertible;
32+
typedef int* no_convertible;
33+
34+
typedef char* yes_python_object;
35+
typedef int* no_python_object;
36+
37+
template <class Target>
38+
struct convertible
39+
{
40+
static inline yes_convertible check(Target) { return 0; }
41+
static inline no_convertible check(...) { return 0; }
42+
};
43+
44+
template <class Target>
45+
inline Target* upcast(Target* p, yes_convertible)
46+
{
47+
return p;
48+
}
49+
50+
template <class Target, class Source>
51+
inline Target* upcast(Source* p, no_convertible, boost::type<Target>* = 0)
52+
{
53+
typedef typename base_type_traits<Source>::type base;
54+
return detail::upcast<Target>((base*)p, convertible<Target*>::check((base*)0));
55+
}
56+
57+
58+
template <class Target, class Source>
59+
inline Target* downcast(Source* p, yes_convertible)
60+
{
61+
return static_cast<Target*>(p);
62+
}
63+
64+
template <class Target, class Source>
65+
inline Target* downcast(Source* p, no_convertible, boost::type<Target>* = 0)
66+
{
67+
typedef typename base_type_traits<Source>::type base;
68+
return (Target*)detail::downcast<base>(p, convertible<Source*>::check((base*)0));
69+
}
70+
71+
template <class T>
72+
inline void assert_castable(boost::type<T>* = 0)
73+
{
74+
typedef char must_be_a_complete_type[sizeof(T)];
75+
}
76+
}
77+
78+
template <class Target, class Source>
79+
inline Target* upcast(Source* x, Target* = 0)
80+
{
81+
detail::assert_castable<Source>();
82+
detail::assert_castable<Target>();
83+
return detail::upcast<Target>(x, detail::convertible<Target*>::check(x));
84+
}
85+
86+
template <class Target, class Source>
87+
inline Target* downcast(Source* x, Target* = 0)
88+
{
89+
detail::assert_castable<Source>();
90+
detail::assert_castable<Target>();
91+
return detail::downcast<Target>(x, detail::convertible<Source*>::check((Target*)0));
92+
}
93+
94+
}} // namespace boost::python
95+
96+
#endif // CAST_DWA200269_HPP

include/boost/python/class.hpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# include <boost/python/class_fwd.hpp>
1010
# include <boost/python/bases.hpp>
1111
# include <boost/python/args.hpp>
12-
# include <boost/python/reference.hpp>
12+
# include <boost/python/handle.hpp>
1313
# include <boost/python/object/class.hpp>
1414
# include <boost/python/type_id.hpp>
1515
# include <boost/python/detail/wrap_function.hpp>
@@ -46,14 +46,14 @@ namespace detail
4646
// to the type of holder that must be created. The 3rd argument is a
4747
// reference to the Python type object to be created.
4848
template <class T, class Holder>
49-
static inline void register_copy_constructor(mpl::bool_t<true> const&, Holder*, ref const& obj, T* = 0)
49+
static inline void register_copy_constructor(mpl::bool_t<true> const&, Holder*, handle<> const& obj, T* = 0)
5050
{
5151
objects::class_wrapper<T,Holder> x(obj);
5252
}
5353

5454
// Tag dispatched to have no effect.
5555
template <class T, class Holder>
56-
static inline void register_copy_constructor(mpl::bool_t<false> const&, Holder*, ref const&, T* = 0)
56+
static inline void register_copy_constructor(mpl::bool_t<false> const&, Holder*, handle<> const&, T* = 0)
5757
{
5858
}
5959
}
@@ -104,7 +104,7 @@ class class_ : public objects::class_base
104104
// appropriate.
105105
objects::function::add_to_namespace(
106106
this->object(), name,
107-
ref(detail::wrap_function(
107+
handle<>(detail::wrap_function(
108108
// This bit of nastiness casts F to a member function of T if possible.
109109
detail::member_function_cast<T,F>::stage1(f).stage2((T*)0).stage3(f)
110110
)));
@@ -132,7 +132,7 @@ class class_ : public objects::class_base
132132
// appropriate.
133133
objects::function::add_to_namespace(
134134
this->object(), op.name(),
135-
ref(detail::wrap_function(&op_t::template apply<T>::execute)));
135+
handle<>(detail::wrap_function(&op_t::template apply<T>::execute)));
136136
return *this;
137137
}
138138

@@ -176,24 +176,24 @@ class class_ : public objects::class_base
176176
template <class D>
177177
self& def_readonly(char const* name, D T::*pm)
178178
{
179-
ref fget(make_getter(pm));
179+
handle<> fget(make_getter(pm));
180180
this->add_property(name, fget);
181181
return *this;
182182
}
183183

184184
template <class D>
185185
self& def_readwrite(char const* name, D T::*pm)
186186
{
187-
ref fget(make_getter(pm));
188-
ref fset(make_setter(pm));
187+
handle<> fget(make_getter(pm));
188+
handle<> fset(make_setter(pm));
189189
return this->add_property(name, fget, fset);
190190
}
191191

192192
// Property creation
193-
self& add_property(char const* name, ref const& fget);
194-
self& add_property(char const* name, ref const& fget, ref const& fset);
193+
self& add_property(char const* name, handle<> const& fget);
194+
self& add_property(char const* name, handle<> const& fget, handle<> const& fset);
195195

196-
self& setattr(char const* name, ref const&);
196+
self& setattr(char const* name, handle<> const&);
197197

198198
private: // types
199199
typedef objects::class_id class_id;
@@ -258,21 +258,21 @@ inline class_<T,X1,X2,X3>::class_(char const* name)
258258

259259

260260
template <class T, class X1, class X2, class X3>
261-
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::add_property(char const* name, ref const& fget)
261+
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::add_property(char const* name, handle<> const& fget)
262262
{
263263
base::add_property(name, fget);
264264
return *this;
265265
}
266266

267267
template <class T, class X1, class X2, class X3>
268-
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::add_property(char const* name, ref const& fget, ref const& fset)
268+
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::add_property(char const* name, handle<> const& fget, handle<> const& fset)
269269
{
270270
base::add_property(name, fget, fset);
271271
return *this;
272272
}
273273

274274
template <class T, class X1, class X2, class X3>
275-
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::setattr(char const* name, ref const& x)
275+
inline class_<T,X1,X2,X3>& class_<T,X1,X2,X3>::setattr(char const* name, handle<> const& x)
276276
{
277277
base::setattr(name, x);
278278
return *this;

include/boost/python/converter/arg_to_python.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# include <boost/python/converter/pointee_to_python_function.hpp>
1212
# include <boost/python/converter/arg_to_python_base.hpp>
1313
# include <boost/python/to_python_indirect.hpp>
14+
// Bring in specializations
15+
# include <boost/python/converter/builtin_converters.hpp>
1416

1517
namespace boost { namespace python { namespace converter {
1618

@@ -19,7 +21,7 @@ namespace detail
1921
BOOST_PYTHON_DECL void throw_no_class_registered();
2022

2123
template <class T>
22-
struct reference_arg_to_python : arg_to_python_holder
24+
struct reference_arg_to_python : handle<>
2325
{
2426
reference_arg_to_python(T& x);
2527
private:
@@ -41,7 +43,7 @@ namespace detail
4143
};
4244

4345
template <class Ptr>
44-
struct pointer_shallow_arg_to_python : arg_to_python_holder
46+
struct pointer_shallow_arg_to_python : handle<>
4547
{
4648
// Throw an exception if the conversion can't succeed
4749
pointer_shallow_arg_to_python(Ptr);
@@ -129,13 +131,13 @@ namespace detail
129131

130132
template <class T>
131133
inline reference_arg_to_python<T>::reference_arg_to_python(T& x)
132-
: arg_to_python_holder(get_object(x))
134+
: handle<>(get_object(x))
133135
{
134136
}
135137

136138
template <class Ptr>
137139
inline pointer_shallow_arg_to_python<Ptr>::pointer_shallow_arg_to_python(Ptr x)
138-
: arg_to_python_holder(get_object(x))
140+
: handle<>(get_object(x))
139141
{}
140142

141143
template <class Ptr>

include/boost/python/converter/arg_to_python_base.hpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,16 @@
77
# define ARG_TO_PYTHON_BASE_DWA200237_HPP
88
# include <boost/python/converter/to_python_function_type.hpp>
99
# include <boost/python/detail/wrap_python.hpp>
10-
# include <boost/python/reference.hpp>
10+
# include <boost/python/handle.hpp>
1111

1212
namespace boost { namespace python { namespace converter {
1313

1414
namespace detail
1515
{
16-
struct arg_to_python_holder
17-
{
18-
arg_to_python_holder(PyObject* obj);
19-
PyObject* get() const;
20-
PyObject* get_incref() const;
21-
private:
22-
ref m_held;
23-
};
24-
25-
struct BOOST_PYTHON_DECL arg_to_python_base : arg_to_python_holder
16+
struct BOOST_PYTHON_DECL arg_to_python_base : handle<>
2617
{
2718
arg_to_python_base(void const volatile* source, to_python_function_t);
2819
};
29-
30-
//
31-
// implmentation
32-
//
33-
inline arg_to_python_holder::arg_to_python_holder(PyObject* obj)
34-
: m_held(obj)
35-
{
36-
}
37-
38-
inline PyObject* arg_to_python_holder::get() const
39-
{
40-
return m_held.get();
41-
}
42-
43-
inline PyObject* arg_to_python_holder::get_incref() const
44-
{
45-
PyObject* result = m_held.get();
46-
Py_XINCREF(result);
47-
return result;
48-
}
4920
}
5021

5122
}}} // namespace boost::python::converter

include/boost/python/converter/builtin_converters.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
# define BUILTIN_CONVERTERS_DWA2002124_HPP
88
# include <boost/python/detail/wrap_python.hpp>
99
# include <boost/python/detail/none.hpp>
10-
# include <boost/python/reference.hpp>
11-
# include <boost/python/converter/arg_to_python_base.hpp>
10+
# include <boost/python/handle.hpp>
1211
# include <string>
1312
# include <complex>
1413

@@ -65,10 +64,10 @@ namespace detail
6564
namespace converter \
6665
{ \
6766
template <> struct arg_to_python< T > \
68-
: detail::arg_to_python_holder \
67+
: handle<> \
6968
{ \
7069
arg_to_python(T const& x) \
71-
: detail::arg_to_python_holder(expr) {} \
70+
: python::handle<>(expr) {} \
7271
}; \
7372
}
7473

0 commit comments

Comments
 (0)