Skip to content

Commit 34c9d89

Browse files
committed
Relaxed rules for using scope()
[SVN r16476]
1 parent bf8bb83 commit 34c9d89

5 files changed

Lines changed: 29 additions & 13 deletions

File tree

doc/tutorial/doc/enums.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@
6767
where my_module is the module where the enum is declared. You can also
6868
create a new scope around a class:</p>
6969
<code><pre>
70-
<span class=identifier>scope </span><span class=identifier>in_X</span><span class=special>(</span><span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>X</span><span class=special>&gt;(</span><span class=string>&quot;X&quot;</span><span class=special>)
70+
<span class=identifier>scope </span><span class=identifier>in_X</span> <span class=special>=</span> <span class=identifier>class_</span><span class=special>&lt;</span><span class=identifier>X</span><span class=special>&gt;(</span><span class=string>&quot;X&quot;</span><span class=special>)
7171
</span><span class=special>.</span><span class=identifier>def</span><span class=special>( </span><span class=special>... </span><span class=special>)
7272
</span><span class=special>.</span><span class=identifier>def</span><span class=special>( </span><span class=special>... </span><span class=special>)
73-
</span><span class=special>);
73+
</span><span class=special>;
7474

7575
</span><span class=comment>// Expose X::nested as X.nested
7676
</span><span class=identifier>enum_</span><span class=special>&lt;</span><span class=identifier>X</span><span class=special>::</span><span class=identifier>nested</span><span class=special>&gt;(</span><span class=string>&quot;nested&quot;</span><span class=special>)

doc/tutorial/doc/quickstart.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,10 +1148,10 @@ You can access those values in Python as
11481148
where my_module is the module where the enum is declared. You can also
11491149
create a new scope around a class:
11501150

1151-
scope in_X(class_<X>("X")
1151+
scope in_X = class_<X>("X")
11521152
.def( ... )
11531153
.def( ... )
1154-
);
1154+
;
11551155

11561156
// Expose X::nested as X.nested
11571157
enum_<X::nested>("nested")

doc/v2/scope.html

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,23 @@ <h4><a name="scope-spec-synopsis"></a>Class <code>scope</code>
8181
namespace boost { namespace python
8282
{
8383
class scope : public <a href=
84-
"object.html#object-spec">object</a>, private <a href=
85-
"../../../utility/utility.htm#Class noncopyable">noncopyable</a>
84+
"object.html#object-spec">object</a>
8685
{
8786
public:
88-
explicit scope(object const&amp;);
87+
scope(scope const&amp;);
88+
scope(object const&amp;);
8989
scope();
9090
~scope()
91+
private:
92+
void operator=(scope const&amp;);
9193
};
9294
}}
9395
</pre>
9496

9597
<h4><a name="scope-spec-ctors"></a>Class <code>scope</code> constructors
9698
and destructor</h4>
9799
<pre>
100+
explicit scope(scope const&amp; x);
98101
explicit scope(object const&amp; x);
99102
</pre>
100103
Stores a reference to the current associated scope object, and sets the

include/boost/python/scope.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@
1313
namespace boost { namespace python {
1414

1515
class BOOST_PYTHON_DECL scope
16-
: public object, private noncopyable
16+
: public object
1717
{
1818
public:
19-
explicit inline scope(object const&);
19+
inline scope(scope const&);
20+
inline scope(object const&);
2021
inline scope();
2122
inline ~scope();
2223

2324
private: // data members
2425
PyObject* m_previous_scope;
2526

27+
private: // unimplemented functions
28+
void operator=(scope const&);
29+
2630
private: // static members
2731

2832
// Use a PyObject* to avoid problems with static destruction after Py_Finalize
@@ -59,6 +63,14 @@ namespace converter
5963
};
6064
}
6165

66+
// Placing this after the specialization above suppresses a CWPro8.3 bug
67+
inline scope::scope(scope const& new_scope)
68+
: object(new_scope)
69+
, m_previous_scope(current_scope)
70+
{
71+
current_scope = python::incref(new_scope.ptr());
72+
}
73+
6274
}} // namespace boost::python
6375

6476
#endif // SCOPE_DWA2002724_HPP

test/nested.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ BOOST_PYTHON_MODULE(nested_ext)
3333
using namespace boost::python;
3434

3535
// Establish X as the current scope.
36-
scope x_class(
37-
class_<X>("X", init<int>())
38-
.def(str(self))
39-
);
36+
scope x_class
37+
= class_<X>("X", init<int>())
38+
.def(str(self))
39+
;
40+
4041

4142
// Y will now be defined in the current scope
4243
class_<Y>("Y", init<int>())

0 commit comments

Comments
 (0)