Index: runtime/vm/os_linux.cc |
diff --git a/runtime/vm/os_linux.cc b/runtime/vm/os_linux.cc |
index 288db46c139081729e30ea1eb31858fd6928121c..73fc0ea15e7669c9d1dec6c07ea5f66ce045fb9c 100644 |
--- a/runtime/vm/os_linux.cc |
+++ b/runtime/vm/os_linux.cc |
@@ -49,13 +49,10 @@ class PerfCodeObserver : public CodeObserver { |
if (file_open == NULL) { |
return; |
} |
- const char* format = "/tmp/perf-%" Pd ".map"; |
intptr_t pid = getpid(); |
- intptr_t len = OS::SNPrint(NULL, 0, format, pid); |
- char* filename = new char[len + 1]; |
- OS::SNPrint(filename, len + 1, format, pid); |
+ char* filename = OS::SCreate(NULL, "/tmp/perf-%" Pd ".map", pid); |
out_file_ = (*file_open)(filename, true); |
- delete[] filename; |
+ free(filename); |
} |
~PerfCodeObserver() { |
@@ -79,14 +76,12 @@ class PerfCodeObserver : public CodeObserver { |
if ((file_write == NULL) || (out_file_ == NULL)) { |
return; |
} |
- const char* format = "%" Px " %" Px " %s%s\n"; |
const char* marker = optimized ? "*" : ""; |
- intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name); |
- char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); |
- OS::SNPrint(buffer, len + 1, format, base, size, marker, name); |
+ char* buffer = OS::SCreate(Thread::Current()->zone(), |
+ "%" Px " %" Px " %s%s\n", base, size, marker, name); |
{ |
MutexLocker ml(CodeObservers::mutex()); |
- (*file_write)(buffer, len, out_file_); |
+ (*file_write)(buffer, strlen(buffer), out_file_); |
} |
} |
@@ -116,10 +111,8 @@ class GdbCodeObserver : public CodeObserver { |
// the prologue sequence is not the first instruction: |
// <name>_entry is used for code preceding the prologue sequence. |
// <name> for rest of the code (first instruction is prologue sequence). |
- const char* kFormat = "%s_%s"; |
- intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry"); |
- char* pname = Thread::Current()->zone()->Alloc<char>(len + 1); |
- OS::SNPrint(pname, (len + 1), kFormat, name, "entry"); |
+ char* pname = OS::SCreate(Thread::Current()->zone(), |
+ "%s_%s", name, "entry"); |
DebugInfo::RegisterSection(pname, base, size); |
DebugInfo::RegisterSection(name, |
(base + prologue_offset), |
@@ -245,12 +238,8 @@ class JitdumpCodeObserver : public CodeObserver { |
}; |
const char* GenerateCodeName(const char* name, bool optimized) { |
- const char* format = "%s%s"; |
const char* marker = optimized ? "*" : ""; |
- intptr_t len = OS::SNPrint(NULL, 0, format, marker, name); |
- char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); |
- OS::SNPrint(buffer, len + 1, format, marker, name); |
- return buffer; |
+ return OS::SCreate(Thread::Current()->zone(), "%s%s", marker, name); |
} |
uint32_t GetElfMach() { |
@@ -549,6 +538,39 @@ int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
} |
+char* OS::SCreate(Zone* zone, const char* format, ...) { |
+ va_list args; |
+ va_start(args, format); |
+ char* buffer = VSCreate(zone, format, args); |
+ va_end(args); |
+ return buffer; |
+} |
+ |
+ |
+char* OS::VSCreate(Zone* zone, const char* format, va_list args) { |
+ // Measure. |
+ va_list measure_args; |
+ va_copy(measure_args, args); |
+ intptr_t len = VSNPrint(NULL, 0, format, measure_args); |
+ va_end(measure_args); |
+ |
+ char* buffer; |
+ if (zone) { |
+ buffer = zone->Alloc<char>(len + 1); |
+ } else { |
+ buffer = reinterpret_cast<char*>(malloc(len + 1)); |
+ } |
+ ASSERT(buffer != NULL); |
+ |
+ // Print. |
+ va_list print_args; |
+ va_copy(print_args, args); |
+ VSNPrint(buffer, len + 1, format, print_args); |
+ va_end(print_args); |
+ return buffer; |
+} |
+ |
+ |
bool OS::StringToInt64(const char* str, int64_t* value) { |
ASSERT(str != NULL && strlen(str) > 0 && value != NULL); |
int32_t base = 10; |