[C++-sig] BPL v2: Auto initialization/massive code breakage!!!

David Abrahams dave at boost-consulting.com
Wed Aug 14 01:50:06 CEST 2002


I've just implemented an auto_initialization feature as described in the
"Automatic C++ Object Initialization" section at
http://www.python.org/sigs/c++-sig, and pretty much all of the test files
had to be changed to accomodate it.

Okay, calm down -- the code breakage is not all that massive ;-)

What happened is that essentially, the argument(s) to a class_<> instance's
first def_init() function got added to its constructor. If the class had no
def_init(...) calls, you now must pass python::no_init instead. On the
upside, you never need to call def_init() with no arguments, since that's
the default. So:

OLD WAY                                 NEW WAY

class_<A>("A")                          class_<A>("A")
    .def_init()                             .def_init(args<int, int>())
    .def_init(args<int, int>())             .def(...)
    .def(...)                               ;
    ;

class_<B>("B")                          class_<B>("B", args<int, int>())
    .def_init(args<int, int>())             .def(...)
    .def(...)                               ;
    ;

class_<C>("C", "C's docstring")         class_<C>("C", "C's docstring"
    .def_init(args<int, int>())                   , args<int, int>())
    .def(...)                               .def(...)
    ;                                       ;

class_<D>("D", "D's docstring")         class_<D>("D", "D's docstring"
    .def_init(args<int, int>(), "doc")            , args<int, int>(),
"doc")
    .def(...)                               .def(...)
    ;                                       ;


class_<E>("E")                          class_<E>("E", no_init)
    .def(...)                                   .def(...)
    ;                                           ;

class_<F>("F")                          class_<F>("F", no_init)
    .def(...)                                   .def(...)
    ;

class_<G>("G", "G's docstring")         class_<G>("G", "G's docstring",
no_init)
    .def(...)                               .def(...)
    ;                                       ;


I plan to check this stuff in later this evening. I just wanted everyone to
be aware of what's coming.

Regards,
Dave

-----------------------------------------------------------
           David Abrahams * Boost Consulting
dave at boost-consulting.com * http://www.boost-consulting.com







More information about the Cplusplus-sig mailing list