Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Incompatibility with CppUTest MemoryLeakDecector Malloc Macros #39

Closed
avlec opened this issue Jul 20, 2022 · 3 comments
Closed

Incompatibility with CppUTest MemoryLeakDecector Malloc Macros #39

avlec opened this issue Jul 20, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@avlec
Copy link

avlec commented Jul 20, 2022

The library makes use of std::free which interferes with the way cpputest uses define macros to override the instances of free (see https://github.com/cpputest/cpputest/blob/master/include/CppUTest/MemoryLeakDetectorMallocMacros.h#L39). This will cause compilation errors to complain that std::cpputest_free_location doesn't exist (which it doesn't in that namespace).

Looking into seeing where the fix should go (here or a in CppUTest) the easiest is definitely here. So I looked to the implemenations to see if I could provide some evidence that dropping the std:: prefix was valid.

Looking into the implemenations for __cxa_demangle use (see https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/libiberty/cp-demangle.c#L6496). They seem to use the unprefixed variant.

@avlec avlec changed the title Incompatibility with CppUTest Incompatibility with CppUTest MemoryLeakDecector Malloc Macros Jul 20, 2022
@avlec
Copy link
Author

avlec commented Jul 20, 2022

The patch for this is very small. Possibly the addition of a header on top of this?

diff --git a/include/nameof.hpp b/include/nameof.hpp
index 3ca6752..8bec134 100644
--- a/include/nameof.hpp
+++ b/include/nameof.hpp
@@ -769,7 +769,7 @@ string nameof_type_rtti(const char* tn) {
   static_assert(nameof_type_rtti_supported<T>::value, "nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
   const auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr);
   const auto name = string{dmg};
-  std::free(dmg);
+  free(dmg);
   assert(name.size() > 0 && "Type does not have a name.");
 
   return name;
@@ -780,7 +780,7 @@ string nameof_full_type_rtti(const char* tn) {
 static_assert(nameof_type_rtti_supported<T>::value, "nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
   const auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr);
   auto name = string{dmg};
-  std::free(dmg);
+  free(dmg);
   assert(name.size() > 0 && "Type does not have a name.");
   if constexpr (std::is_const_v<std::remove_reference_t<T>>) {
     name = "const " + name;
@@ -803,7 +803,7 @@ string nameof_short_type_rtti(const char* tn) {
   static_assert(nameof_type_rtti_supported<T>::value, "nameof::nameof_type_rtti unsupported compiler (https://github.com/Neargye/nameof#compiler-compatibility).");
   const auto dmg = abi::__cxa_demangle(tn, nullptr, nullptr, nullptr);
   const auto name = string{pretty_name(dmg)};
-  std::free(dmg);
+  free(dmg);
   assert(name.size() > 0 && "Type does not have a short name.");
 
   return name;

@Neargye
Copy link
Owner

Neargye commented Jul 20, 2022

addition header for nameof_type_rtti?

@avlec
Copy link
Author

avlec commented Jul 20, 2022

Probably don't need the addition of a header for that change

@Neargye Neargye added the bug Something isn't working label Jul 21, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants