summaryrefslogtreecommitdiffstats
path: root/lldb/source/API/SBModule.cpp
diff options
context:
space:
mode:
authorGreg Clayton <gclayton@apple.com>2015-02-11 19:16:38 +0000
committerGreg Clayton <gclayton@apple.com>2015-02-11 19:16:38 +0000
commitf1be855a002ec3bf17a8c16a1d8a18786646e740 (patch)
treed0f78c0b7fdd188e4b17ba2a50a1c29bab694a68 /lldb/source/API/SBModule.cpp
parentc47edb51c68b399b1576b7306bad1b8cb7e39c28 (diff)
downloadbcm5719-llvm-f1be855a002ec3bf17a8c16a1d8a18786646e740.tar.gz
bcm5719-llvm-f1be855a002ec3bf17a8c16a1d8a18786646e740.zip
Fixed SBModule::GetUUIDString() to not use a static character buffer.
Rules for returning "const char *" from functions in the public lldb::SB* API are that you must constify the string using "ConstString(cstr).GetCString()" and return that. This puts the string into a string pool that never goes away. This is only when there is nothing that can hold onto the string. It is OK to specify that a string value lives as long as its SB class counterpart, but this should be made clear in the API if this is done. Many classes already constify their strings (symbol mangled and demangled names, variable names, type names, etc), so be sure to verify you string isn't already constified before you re-constify it. It won't do any harm to re-constify it, it will just cause you a little performance by having to rehash the string. llvm-svn: 228867
Diffstat (limited to 'lldb/source/API/SBModule.cpp')
-rw-r--r--lldb/source/API/SBModule.cpp36
1 files changed, 15 insertions, 21 deletions
diff --git a/lldb/source/API/SBModule.cpp b/lldb/source/API/SBModule.cpp
index 0d7dda1aa1f..2d89b903037 100644
--- a/lldb/source/API/SBModule.cpp
+++ b/lldb/source/API/SBModule.cpp
@@ -211,34 +211,28 @@ SBModule::GetUUIDString () const
{
Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
- static char uuid_string_buffer[80];
- const char *uuid_c_string = NULL;
- std::string uuid_string;
+ const char *uuid_cstr = NULL;
ModuleSP module_sp (GetSP ());
if (module_sp)
- uuid_string = module_sp->GetUUID().GetAsString();
-
- if (!uuid_string.empty())
{
- strncpy (uuid_string_buffer, uuid_string.c_str(), sizeof (uuid_string_buffer));
- uuid_string_buffer[sizeof (uuid_string_buffer) - 1] = '\0';
- uuid_c_string = uuid_string_buffer;
+ // We are going to return a "const char *" value through the public
+ // API, so we need to constify it so it gets added permanently the the
+ // string pool and then we don't need to worry about the lifetime of the
+ // string as it will never go away once it has been put into the ConstString
+ // string pool
+ uuid_cstr = ConstString(module_sp->GetUUID().GetAsString()).GetCString();
}
- if (log)
+ if (uuid_cstr && uuid_cstr[0])
{
- if (!uuid_string.empty())
- {
- StreamString s;
- module_sp->GetUUID().Dump (&s);
- log->Printf ("SBModule(%p)::GetUUIDString () => %s",
- static_cast<void*>(module_sp.get()), s.GetData());
- }
- else
- log->Printf ("SBModule(%p)::GetUUIDString () => NULL",
- static_cast<void*>(module_sp.get()));
+ if (log)
+ log->Printf ("SBModule(%p)::GetUUIDString () => %s", static_cast<void*>(module_sp.get()), uuid_cstr);
+ return uuid_cstr;
}
- return uuid_c_string;
+
+ if (log)
+ log->Printf ("SBModule(%p)::GetUUIDString () => NULL", static_cast<void*>(module_sp.get()));
+ return NULL;
}
OpenPOWER on IntegriCloud