<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Jan 30, 2016 at 7:30 AM, Stefan Seefeld <span dir="ltr"><<a href="mailto:stefan@seefeld.name" target="_blank">stefan@seefeld.name</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class=""><div class="h5">On 29.01.2016 19:19, David Sankel wrote:<br>
> Hello all,<br>
><br>
> I'd like to allow a class to be registered more than once and wanted<br>
> to get your opinion if this change would be a good idea.<br>
><br>
> 'boost::python::class_' always adds a class to the current scope and<br>
> registers it in the global registry. The global registry code<br>
> (particularly the 'insert' function in 'src/converter/registry.cpp')<br>
> asserts that the class hasn't been registered already. This, of<br>
> course, prevents multiple registrations of the same type.<br>
><br>
> There is a use case, though, where multiple registrations of the same<br>
> type is both necessary and safe. Generally, a c++ component which has<br>
> a 'class_' call may not know the name of the module it will eventually<br>
> end up in. It would still be desirable to write a unit test for this<br>
> component. If we write a unit test and put the 'class_' into some<br>
> dummy module we run into a problem where other unit tests might call<br>
> 'class_' in another scope.<br>
><br>
> The safety of multiple 'class_' calls stems from always using the same<br>
> conversion function. Semantically everything is a-okay.<br>
><br>
> I'm proposing to change the precondition of the<br>
> 'boost::python::converter::registry::insert' function from:<br>
><br>
> The behavior is undefined unless the specified 'type_info' object<br>
> has not already been registered.<br>
><br>
><br>
> to:<br>
><br>
> The behavior is undefined unless the specified 'type_info' object<br>
> has not already been registered with a semantically different<br>
> converter<br>
><br>
> Any objections?<br>
<br>
</div></div>Yes. Can you describe your use-case ? And what do you mean exactly by<br>
"semantically different" ? :-)<br></blockquote><div><br></div><div>In one '.cpp' file I have something like:</div></div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_extra"><div class="gmail_quote"><div><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>void addFooAssets()</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>{</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div> boost::python::class_< Foo > ( /* etc. */ )</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div> .def( /* etc */ );</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>}</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>// testing code follows.</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>BOOST_PYTHON_MODULE( fooTest )</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>{</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div> addFooAssets();</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><div>}</div></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div><br></div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>BOOST_AUTO_TEST_CASE( fooAssets ) {</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div> // import 'fooTest' and check that all is good.</div></div></div><div class="gmail_extra"><div class="gmail_quote"><div>}</div><div><br></div></div></div></blockquote>In another '.cpp' file, I have something like:<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>void initBarPackage()</div><div>{</div><div><div> boost::python::object barPackage = boost::python::scope();</div></div><div><div> barPackage.attr( "__path__" ) = "bar";</div></div><div><br></div><div><div> boost::python::object barFooPackage(</div></div><div><div> boost::python::handle<>( boost::python::borrowed(::PyImport_AddModule( "bar.foo" ) ) ) );</div></div><div><div> barPackage.attr( "foo" ) = barFooPackage;</div></div><div><div><br></div></div><div><div> {</div></div><div><div> const boost::python::scope fooScope( barFooPackage );</div></div><div><div> addFooAssets();</div></div><div><div> }</div></div><div>}</div><div><br></div><div>// testing code follows</div></blockquote><br><div>If I run the unit test for "foo" and that for "bar" in the same test run, then I'll get 'class_' called twice. It is harmless to call it twice though since the registration is identical for both calls.</div><div><br></div><div>When I say "semantically" the same, I mean that something like the 'to_python' member could point to a different function as long as they "do" the same thing.</div><div><br></div><div>-- David Sankel</div></div>