@@ -269,7 +269,6 @@ BOOST_PYTHON_MODULE_INIT(m1)
269269 using boost::python::module ;
270270 using boost::python::class_;
271271
272- module m1 (" m1" );
273272 // Create the converters; they are self-registering/unregistering.
274273 static int_wrapper wrap_int;
275274 static simple_wrapper wrap_simple;
@@ -280,56 +279,66 @@ BOOST_PYTHON_MODULE_INIT(m1)
280279 static simple_const_ref_unwrapper unwrap_simple_const_ref;
281280 static simple_ref_wrapper wrap_simple_ref;
282281
283- // This unwrapper extracts pointers and references to the "complicated" class.
284- // static boost::python::converter::class_unwrapper<complicated> unwrap_complicated;
285-
286- // Insert the extension metaclass object
287- m1.add (
288- boost::python::objects::class_metatype ()
289- , " xclass" );
290-
291- // Insert the base class for all extension classes
292- m1.add (boost::python::objects::class_type ()
293- , " xinst" );
282+ module m1 (" m1" );
294283
295- m1.def (new_noddy, " new_noddy" );
296- m1.def (new_simple, " new_simple" );
284+ m1
285+ // Insert the metaclass for all extension classes
286+ .setattr (" xclass" , boost::python::objects::class_metatype ())
297287
298- // Expose f()
299- m1. def (f, " f " );
288+ // Insert the base class for all extension classes
289+ . setattr ( " xinst " , boost::python::objects::class_type ())
300290
301- // Expose g( )
302- m1 .def (g, " g " );
291+ . def ( " new_noddy " , new_noddy )
292+ .def (" new_simple " , new_simple)
303293
304- m1.def (take_a, " take_a" );
305- m1.def (take_b, " take_b" );
306- m1.def (take_c, " take_c" );
307- m1.def (take_d, " take_d" );
294+ // Expose f()
295+ .def (" f" , f)
308296
309- class_<A>(m1, " A" )
310- .def_init ()
311- .def (&A::name, " name" )
312- ;
313-
314- class_<B,bases<A> >(m1, " B" )
315- .def_init ()
316- .def (&B::name, " name" )
317- ;
318-
319- class_<C,bases<A> >(m1, " C" )
320- .def_init ()
321- .def (&C::name, " name" )
297+ // Expose g()
298+ .def (" g" , g)
299+
300+ .def (" take_a" , take_a)
301+ .def (" take_b" , take_b)
302+ .def (" take_c" , take_c)
303+ .def (" take_d" , take_d)
304+
305+ .add (
306+ class_<A>(" A" )
307+ .def_init ()
308+ .def (" name" , &A::name)
309+ )
310+
322311 ;
323312
324- class_<D,bases<B,C> >(m1, " D" )
325- .def_init ()
326- .def (&D::name, " name" )
313+ // sequence points don't ensure that "A" is constructed before "B"
314+ // or "C" below if we make them part of the same chain
315+ m1
316+ .add (
317+ class_<B,bases<A> >(" B" )
318+ .def_init ()
319+ .def (" name" , &B::name)
320+ )
321+
322+ .add (
323+ class_<C,bases<A> >(" C" )
324+ .def_init ()
325+ .def (" name" , &C::name)
326+ )
327327 ;
328328
329- class_<complicated>(m1, " complicated" )
330- .def_init (args<simple const &,int >())
331- .def_init (args<simple const &>())
332- .def (&complicated::get_n, " get_n" )
329+ m1
330+ .add (
331+ class_<D,bases<B,C> >(" D" )
332+ .def_init ()
333+ .def (" name" , &D::name)
334+ )
335+
336+ .add (
337+ class_<complicated>(" complicated" )
338+ .def_init (args<simple const &,int >())
339+ .def_init (args<simple const &>())
340+ .def (" get_n" , &complicated::get_n)
341+ )
333342 ;
334343}
335344
0 commit comments