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

This commit is contained in:
saleelk
2019-12-23 05:41:40 -08:00
committed by Maneesh Gupta
vanhempi 150e690a3a
commit 1ca75e5f6d
2 muutettua tiedostoa jossa 14 lisäystä ja 13 poistoa
@@ -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,8 +102,9 @@ 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;
} }
+8 -8
Näytä tiedosto
@@ -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.