Fix the return type of demangle function so that its compatible across ABIs (#1744)

Este commit está contenido en:
saleelk
2019-12-23 05:41:40 -08:00
cometido por Maneesh Gupta
padre 150e690a3a
commit 1ca75e5f6d
Se han modificado 2 ficheros con 14 adiciones y 13 borrados
+5 -4
Ver fichero
@@ -84,7 +84,7 @@ hiprtcResult hiprtcGetCodeSize(hiprtcProgram prog, std::size_t* codeSizeRet);
namespace hip_impl namespace hip_impl
{ {
std::string demangle(const char* mangled_expression); char* demangle(const char* mangled_expression);
} }
#if defined(HIPRTC_GET_TYPE_NAME) #if defined(HIPRTC_GET_TYPE_NAME)
@@ -102,10 +102,11 @@ namespace hip_impl
{ {
if (!result) return HIPRTC_ERROR_INVALID_INPUT; if (!result) return HIPRTC_ERROR_INVALID_INPUT;
*result = hip_impl::demangle(typeid(T).name()); char * res= hip_impl::demangle(typeid(T).name());
result->assign(res == nullptr ? "" : res);
std::free(res);
return (result->empty()) ? HIPRTC_ERROR_INTERNAL_ERROR : return (result->empty()) ? HIPRTC_ERROR_INTERNAL_ERROR :
HIPRTC_SUCCESS; HIPRTC_SUCCESS;
} }
#endif #endif
#endif #endif
+9 -9
Ver fichero
@@ -143,7 +143,9 @@ struct _hiprtcProgram {
{ {
using namespace std; using namespace std;
name = hip_impl::demangle(name.c_str()); char* demangled = hip_impl::demangle(name.c_str());
name.assign(demangled == nullptr ? "" : demangled);
free(demangled);
if (name.empty()) return name; if (name.empty()) return name;
@@ -392,18 +394,16 @@ namespace
namespace hip_impl namespace hip_impl
{ {
inline char* demangle(const char* x)
std::string demangle(const char* x)
{ {
if (!x) return {}; if (!x) return nullptr;
int s{}; int s{};
std::unique_ptr<char, decltype(std::free)*> tmp{ char* tmp = abi::__cxa_demangle(x, nullptr, nullptr, &s);
abi::__cxa_demangle(x, nullptr, nullptr, &s), std::free};
if (s != 0) return {}; if (s != 0) return nullptr;
return tmp.get(); return tmp;
} }
} // Namespace hip_impl. } // Namespace hip_impl.
@@ -598,4 +598,4 @@ hiprtcResult hiprtcGetCodeSize(hiprtcProgram p, std::size_t* sz)
*sz = p->elf.size(); *sz = p->elf.size();
return HIPRTC_SUCCESS; return HIPRTC_SUCCESS;
} }