Skip to content
Snippets Groups Projects
Commit d769287d authored by Florent Lamiraux's avatar Florent Lamiraux
Browse files

When registering a type, store pointer to type_info in a map

     * include/dynamic-graph/signal-caster.h,
     * src/signal/signal-caster.cpp: if a typename is registered several times,
     throw only if pointers to type_info differ. When loading python modules,
     for some reason, global variables are constructed several times.
parent 80efeca1
Branches
Tags
No related merge requests found
...@@ -74,6 +74,7 @@ private: ...@@ -74,6 +74,7 @@ private:
* using boost::function with 'compatible' syntax * using boost::function with 'compatible' syntax
*/ */
std::map<std::string, cast_functions_type> functions_; std::map<std::string, cast_functions_type> functions_;
std::map<std::string, const std::type_info*> type_info_;
}; };
......
...@@ -43,13 +43,22 @@ SignalCaster::~SignalCaster() { ...@@ -43,13 +43,22 @@ SignalCaster::~SignalCaster() {
void SignalCaster::registerCast(const type_info& type, SignalCaster::displayer_type displayer, void SignalCaster::registerCast(const type_info& type, SignalCaster::displayer_type displayer,
SignalCaster::caster_type caster, SignalCaster::tracer_type tracer) { SignalCaster::caster_type caster, SignalCaster::tracer_type tracer) {
if ( existsCast(type) ) { if ( existsCast(type) ) {
std::string typeName(type.name()); // If type name has already been registered for same type, do not throw.
std::ostringstream os; if ( type_info_[type.name()] != &type) {
os << "cast already registered for type " << typeName << "."; std::string typeName(type.name());
throw ExceptionSignal(ExceptionSignal::GENERIC, std::ostringstream os;
os.str()); //TODO: throw "cast already registered for type" exception os << "cast already registered for typename " << typeName << "\n"
<< "and types differ: " << &type << " != " << type_info_[type.name()]
<< ".\n"
<< "A possible reason is that the dynamic library defining this type\n"
<< "has been loaded several times, defining different symbols"
<< " for the same type.";
throw ExceptionSignal(ExceptionSignal::GENERIC,
os.str());
}
} }
functions_[type.name()] = cast_functions_type(displayer,caster, tracer); functions_[type.name()] = cast_functions_type(displayer,caster, tracer);
type_info_[type.name()] = &type;
} }
void SignalCaster::unregisterCast(const std::type_info& type) { void SignalCaster::unregisterCast(const std::type_info& type) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment