Skip to content
Snippets Groups Projects
Commit 06b1f008 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

fix another memory leak

parent 0d974f49
No related branches found
No related tags found
No related merge requests found
......@@ -34,7 +34,7 @@ struct castApi {
std::map < std::type_index, std::function < alib::Object ( const alib::ObjectBase & ) > >::iterator res = castFunctions.find ( std::type_index ( typeid ( from ) ) );
 
if ( res == castFunctions.end ( ) ) {
std::string fromType = std::cstringToString ( std::type_name ( typeid ( from ) ) );
std::string fromType = std::type_name ( typeid ( from ) );
 
throw exception::CommonException ( "Bad cast: From: " + fromType + " To: " + toType ( ) );
}
......@@ -69,7 +69,7 @@ struct castApi {
}
 
std::string toType ( ) {
return std::cstringToString ( std::type_name < To > ( ) );
return std::type_name < To > ( );
}
 
};
......@@ -125,7 +125,7 @@ public:
std::map < std::type_index, CastPoolBase * >::iterator res = castFunctionsById ( ).find ( typeId );
 
if ( res == castFunctionsById ( ).end ( ) ) {
std::string toType = std::cstringToString ( std::type_name ( typeId ) );
std::string toType = std::type_name ( typeId );
 
throw exception::CommonException ( "Casting to type " + toType + " not available." );
} else {
......
......@@ -53,9 +53,9 @@ public:
RegistratorWrapper ( RealReturnType ( * callback ) ( FrontStaticParamTypes ..., typename std::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type && ..., BackStaticParamTypes ... ) ) : m_callback ( callback ) {
if ( !getInstance ( ).registeredFunctions.insert ( std::make_pair ( std::make_tuple ( std::type_index ( typeid ( typename std::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type ) ) ... ), this ) ).second ) {
std::stringstream ss;
( void ) initializer_list < int > { ( ss << cstringToString ( std::type_name < typename std::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type > ( ) ), 0 ) ... };
( void ) initializer_list < int > { ( ss << std::type_name < typename std::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type > ( ), 0 ) ... };
 
std::string classType = cstringToString ( std::type_name < Algorithm > ( ) );
std::string classType = std::type_name < Algorithm > ( );
 
throw::exception::CommonException ( "Callback for " + ss.str ( ) + " already registered on " + classType + "." );
}
......@@ -68,9 +68,9 @@ public:
 
if ( callback == getInstance ( ).registeredFunctions.end ( ) ) {
std::stringstream ss;
( void ) initializer_list < int > { ( ss << cstringToString ( std::type_name ( typeid ( dispatched ) ) ), 0 ) ... };
( void ) initializer_list < int > { ( ss << std::type_name ( typeid ( dispatched ) ), 0 ) ... };
 
std::string classType = cstringToString ( std::type_name < Algorithm > ( ) );
std::string classType = std::type_name < Algorithm > ( );
 
throw::exception::CommonException ( "Callback for " + ss.str ( ) + " not registered on " + classType + "." );
}
......@@ -146,9 +146,9 @@ public:
 
RegistratorWrapper ( RealReturnType ( * callback ) ( RealParametersType &&, RealParametersType && ) ) : m_callback ( callback ) {
if ( !getInstance ( ).registeredFunctions.insert ( std::make_pair ( std::type_index ( typeid ( RealParametersType ) ), this ) ).second ) {
std::string paramsType = std::cstringToString ( std::type_name < RealParametersType > ( ) );
std::string paramsType = std::type_name < RealParametersType > ( );
 
std::string classType = std::cstringToString ( std::type_name < Algorithm > ( ) );
std::string classType = std::type_name < Algorithm > ( );
 
throw::exception::CommonException ( "Callback for " + paramsType + " already registered on " + classType + "." );
}
......@@ -167,11 +167,11 @@ public:
if ( ( callback != getInstance ( ).registeredFunctions.end ( ) ) && callback->second->available ( false, std::type_index ( typeid ( first ) ), std::type_index ( typeid ( second ) ) ) )
return callback->second->eval ( false, std::forward < ParametersType > ( first ), std::forward < ParametersType > ( second ) );
 
std::string firstType = std::cstringToString ( std::type_name ( typeid ( first ) ) );
std::string firstType = std::type_name ( typeid ( first ) );
 
std::string secondType = std::cstringToString ( std::type_name ( typeid ( second ) ) );
std::string secondType = std::type_name ( typeid ( second ) );
 
std::string classType = std::cstringToString ( std::type_name < Algorithm > ( ) );
std::string classType = std::type_name < Algorithm > ( );
 
throw::exception::CommonException ( "Callback for (" + firstType + ", " + secondType + ") (promoting) not registered on " + classType + "." );
}
......
......@@ -9,15 +9,16 @@
 
namespace std {
 
char* type_name(const std::type_info& type) {
int status;
return abi::__cxa_demangle(type.name(), 0, 0, &status);
string type_name(const std::type_info& type) {
return type_name ( type_index ( type ) );
}
 
char* type_name(const std::type_index& type) {
string type_name(const std::type_index& type) {
int status;
 
return abi::__cxa_demangle(type.name(), 0, 0, &status);
char* demangled = abi::__cxa_demangle(type.name(), 0, 0, &status);
string res ( demangled );
free ( demangled );
return res;
}
} /* namespace std */
......@@ -10,11 +10,11 @@
 
namespace std {
 
char* type_name(const std::type_info& type);
char* type_name(const std::type_index& type);
string type_name(const std::type_info& type);
string type_name(const std::type_index& type);
 
template <class T>
char* type_name() {
string type_name() {
return type_name(typeid(T));
}
 
......@@ -22,9 +22,8 @@ namespace std {
bool is_same_type(const char* name) {
char namespaceId[100];
char classId[100];
char* ret = type_name<T>();
sscanf(ret, "%[a-zA-Z]::%[a-zA-Z]", namespaceId, classId);
free( ret );
string ret = type_name<T>();
sscanf(ret.c_str(), "%[a-zA-Z]::%[a-zA-Z]", namespaceId, classId);
 
if(strcmp(classId, name) == 0) {
return true;
......
......@@ -7,6 +7,7 @@
#include <cstring>
#include <cxxabi.h>
#include "typeindex"
#include <string>
#include "extensions/typeinfo.hpp"
 
#endif /* __TYPEINFO_HEADER_WRAPPER_ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment