Don't allow direct access to StreamString's internal buffer.
This is a large API change that removes the two functions from
StreamString that return a std::string& and a const std::string&,
and instead provide one function which returns a StringRef.
Direct access to the underlying buffer violates the concept of
a "stream" which is intended to provide forward only access,
and makes porting to llvm::raw_ostream more difficult in the
future.
Differential Revision: https://reviews.llvm.org/D26698
llvm-svn: 287152
diff --git a/lldb/source/API/SBCommandReturnObject.cpp b/lldb/source/API/SBCommandReturnObject.cpp
index 51e6781..41d5147 100644
--- a/lldb/source/API/SBCommandReturnObject.cpp
+++ b/lldb/source/API/SBCommandReturnObject.cpp
@@ -59,12 +59,14 @@
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
if (m_opaque_ap) {
+ llvm::StringRef output = m_opaque_ap->GetOutputData();
+ ConstString result(output.empty() ? llvm::StringRef("") : output);
+
if (log)
log->Printf("SBCommandReturnObject(%p)::GetOutput () => \"%s\"",
- static_cast<void *>(m_opaque_ap.get()),
- m_opaque_ap->GetOutputData());
+ static_cast<void *>(m_opaque_ap.get()), result.AsCString());
- return m_opaque_ap->GetOutputData();
+ return result.AsCString();
}
if (log)
@@ -78,12 +80,13 @@
Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
if (m_opaque_ap) {
+ llvm::StringRef output = m_opaque_ap->GetErrorData();
+ ConstString result(output.empty() ? llvm::StringRef("") : output);
if (log)
log->Printf("SBCommandReturnObject(%p)::GetError () => \"%s\"",
- static_cast<void *>(m_opaque_ap.get()),
- m_opaque_ap->GetErrorData());
+ static_cast<void *>(m_opaque_ap.get()), result.AsCString());
- return m_opaque_ap->GetErrorData();
+ return result.AsCString();
}
if (log)
@@ -94,11 +97,11 @@
}
size_t SBCommandReturnObject::GetOutputSize() {
- return (m_opaque_ap ? strlen(m_opaque_ap->GetOutputData()) : 0);
+ return (m_opaque_ap ? m_opaque_ap->GetOutputData().size() : 0);
}
size_t SBCommandReturnObject::GetErrorSize() {
- return (m_opaque_ap ? strlen(m_opaque_ap->GetErrorData()) : 0);
+ return (m_opaque_ap ? m_opaque_ap->GetErrorData().size() : 0);
}
size_t SBCommandReturnObject::PutOutput(FILE *fh) {
diff --git a/lldb/source/API/SBFrame.cpp b/lldb/source/API/SBFrame.cpp
index 31ac0a7..1845b12 100644
--- a/lldb/source/API/SBFrame.cpp
+++ b/lldb/source/API/SBFrame.cpp
@@ -1295,7 +1295,7 @@
"SBFrame::EvaluateExpression (expr = \"%s\", fetch_dynamic_value "
"= %u) %s",
expr, options.GetFetchDynamicValue(),
- frame_description.GetString().c_str());
+ frame_description.GetData());
}
exe_results = target->EvaluateExpression(expr, frame, expr_value_sp,
diff --git a/lldb/source/API/SBStream.cpp b/lldb/source/API/SBStream.cpp
index 0ade453..858e949 100644
--- a/lldb/source/API/SBStream.cpp
+++ b/lldb/source/API/SBStream.cpp
@@ -63,8 +63,7 @@
// See if we have any locally backed data. If so, copy it so we can then
// redirect it to the file so we don't lose the data
if (!m_is_file)
- local_data.swap(
- static_cast<StreamString *>(m_opaque_ap.get())->GetString());
+ local_data = static_cast<StreamString *>(m_opaque_ap.get())->GetString();
}
StreamFile *stream_file = new StreamFile;
uint32_t open_options = File::eOpenOptionWrite | File::eOpenOptionCanCreate;
@@ -97,8 +96,7 @@
// See if we have any locally backed data. If so, copy it so we can then
// redirect it to the file so we don't lose the data
if (!m_is_file)
- local_data.swap(
- static_cast<StreamString *>(m_opaque_ap.get())->GetString());
+ local_data = static_cast<StreamString *>(m_opaque_ap.get())->GetString();
}
m_opaque_ap.reset(new StreamFile(fh, transfer_fh_ownership));
@@ -119,8 +117,7 @@
// See if we have any locally backed data. If so, copy it so we can then
// redirect it to the file so we don't lose the data
if (!m_is_file)
- local_data.swap(
- static_cast<StreamString *>(m_opaque_ap.get())->GetString());
+ local_data = static_cast<StreamString *>(m_opaque_ap.get())->GetString();
}
m_opaque_ap.reset(new StreamFile(::fdopen(fd, "w"), transfer_fh_ownership));
@@ -152,6 +149,6 @@
if (m_is_file)
m_opaque_ap.reset();
else
- static_cast<StreamString *>(m_opaque_ap.get())->GetString().clear();
+ static_cast<StreamString *>(m_opaque_ap.get())->Clear();
}
}
diff --git a/lldb/source/API/SBTarget.cpp b/lldb/source/API/SBTarget.cpp
index 7515343..fa58e72 100644
--- a/lldb/source/API/SBTarget.cpp
+++ b/lldb/source/API/SBTarget.cpp
@@ -2133,7 +2133,7 @@
"SBTarget::EvaluateExpression (expr = \"%s\", fetch_dynamic_value = "
"%u) %s",
expr, options.GetFetchDynamicValue(),
- frame_description.GetString().c_str());
+ frame_description.GetString().str().c_str());
#endif
exe_results =
target->EvaluateExpression(expr, frame, expr_value_sp, options.ref());