[C++-sig] Multiple registration safety and unit testing

David Sankel camior at gmail.com
Fri Jan 29 19:19:37 EST 2016


Hello all,

I'd like to allow a class to be registered more than once and wanted to get
your opinion if this change would be a good idea.

'boost::python::class_' always adds a class to the current scope and
registers it in the global registry. The global registry code (particularly
the 'insert' function in 'src/converter/registry.cpp') asserts that the
class hasn't been registered already. This, of course, prevents multiple
registrations of the same type.

There is a use case, though, where multiple registrations of the same type
is both necessary and safe. Generally, a c++ component which has a 'class_'
call may not know the name of the module it will eventually end up in. It
would still be desirable to write a unit test for this component. If we
write a unit test and put the 'class_' into some dummy module we run into a
problem where other unit tests might call 'class_' in another scope.

The safety of multiple 'class_' calls stems from always using the same
conversion function. Semantically everything is a-okay.

I'm proposing to change the precondition of the
'boost::python::converter::registry::insert' function from:

The behavior is undefined unless the specified 'type_info' object has not
already been registered.


to:

The behavior is undefined unless the specified 'type_info' object has not
already been registered with a semantically different converter

Any objections?

-- David Sankel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20160129/f6e8d453/attachment-0001.html>


More information about the Cplusplus-sig mailing list