Remove uses of scoped_ptr_malloc.
Change-Id: I355fcfc93e8d689bea8b9388423ca12cb3e6566f
diff --git a/src/common_test.h b/src/common_test.h
index afe0c0f..4fcf44d 100644
--- a/src/common_test.h
+++ b/src/common_test.h
@@ -33,24 +33,21 @@
class ScratchFile {
public:
ScratchFile() {
- std::string filename_template;
- filename_template = getenv("ANDROID_DATA");
- filename_template += "/TmpFile-XXXXXX";
- filename_.reset(strdup(filename_template.c_str()));
- CHECK(filename_ != NULL);
- fd_ = mkstemp(filename_.get());
+ filename_ = getenv("ANDROID_DATA");
+ filename_ += "/TmpFile-XXXXXX";
+ fd_ = mkstemp(&filename_[0]);
CHECK_NE(-1, fd_);
}
~ScratchFile() {
- int unlink_result = unlink(filename_.get());
+ int unlink_result = unlink(filename_.c_str());
CHECK_EQ(0, unlink_result);
int close_result = close(fd_);
CHECK_EQ(0, close_result);
}
const char* GetFilename() const {
- return filename_.get();
+ return filename_.c_str();
}
int GetFd() const {
@@ -58,7 +55,7 @@
}
private:
- scoped_ptr_malloc<char> filename_;
+ std::string filename_;
int fd_;
};
@@ -76,13 +73,10 @@
setenv("ANDROID_ROOT", root.c_str(), 1);
}
- android_data_.reset(strdup(is_host_ ? "/tmp/art-data-XXXXXX" : "/sdcard/art-data-XXXXXX"));
- ASSERT_TRUE(android_data_ != NULL);
- const char* android_data_modified = mkdtemp(android_data_.get());
- // note that mkdtemp side effects android_data_ as well
- ASSERT_TRUE(android_data_modified != NULL);
- setenv("ANDROID_DATA", android_data_modified, 1);
- art_cache_.append(android_data_.get());
+ android_data_ = (is_host_ ? "/tmp/art-data-XXXXXX" : "/sdcard/art-data-XXXXXX");
+ ASSERT_TRUE(mkdtemp(&android_data_[0]) != NULL);
+ setenv("ANDROID_DATA", android_data_.c_str(), 1);
+ art_cache_.append(android_data_.c_str());
art_cache_.append("/art-cache");
int mkdir_result = mkdir(art_cache_.c_str(), 0700);
ASSERT_EQ(mkdir_result, 0);
@@ -121,7 +115,7 @@
closedir(dir);
int rmdir_cache_result = rmdir(art_cache_.c_str());
ASSERT_EQ(0, rmdir_cache_result);
- int rmdir_data_result = rmdir(android_data_.get());
+ int rmdir_data_result = rmdir(android_data_.c_str());
ASSERT_EQ(0, rmdir_data_result);
// icu4c has a fixed 10-element array "gCommonICUDataArray".
@@ -172,7 +166,7 @@
}
bool is_host_;
- scoped_ptr_malloc<char> android_data_;
+ std::string android_data_;
std::string art_cache_;
scoped_ptr<const DexFile> java_lang_dex_file_;
std::vector<const DexFile*> boot_class_path_;
@@ -181,3 +175,21 @@
};
} // namespace art
+
+namespace std {
+
+// TODO: isn't gtest supposed to be able to print STL types for itself?
+template <typename T>
+std::ostream& operator<<(std::ostream& os, const std::vector<T>& rhs) {
+ os << "[";
+ for (size_t i = 0; i < rhs.size(); ++i) {
+ os << rhs[i];
+ if (i < rhs.size() - 1) {
+ os << ", ";
+ }
+ }
+ os << "]";
+ return os;
+}
+
+} // namespace std
diff --git a/src/runtime.cc b/src/runtime.cc
index 33b372b..e628f2c 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -61,34 +61,6 @@
// notreached
}
-// Splits a C string using the given delimiter characters into a vector of
-// strings. Empty strings will be omitted.
-void Split(const char* str, const char* delim, std::vector<std::string>& vec) {
- DCHECK(str != NULL);
- DCHECK(delim != NULL);
- scoped_ptr_malloc<char> tmp(strdup(str));
- char* full = tmp.get();
- char* p = full;
- while (p != NULL) {
- p = strpbrk(full, delim);
- if (p != NULL) {
- p[0] = '\0';
- }
- if (full[0] != '\0') {
- vec.push_back(std::string(full));
- }
- if (p != NULL) {
- full = p + 1;
- }
- }
-}
-
-// Splits a colon delimited list of pathname elements into a vector of
-// strings. Empty strings will be omitted.
-void ParseClassPath(const char* class_path, std::vector<std::string>& vec) {
- Split(class_path, ":", vec);
-}
-
// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
// [gG] gigabytes.
@@ -182,7 +154,7 @@
std::vector<const DexFile*>& boot_class_path_vector) {
CHECK(boot_class_path_cstr != NULL);
std::vector<std::string> parsed;
- ParseClassPath(boot_class_path_cstr, parsed);
+ Split(boot_class_path_cstr, ':', parsed);
for (size_t i = 0; i < parsed.size(); ++i) {
const DexFile* dex_file = Open(parsed[i]);
if (dex_file != NULL) {
@@ -268,7 +240,7 @@
parsed->properties_.push_back(option.substr(strlen("-D")).data());
} else if (option.starts_with("-verbose:")) {
std::vector<std::string> verbose_options;
- Split(option.substr(strlen("-verbose:")).data(), ",", verbose_options);
+ Split(option.substr(strlen("-verbose:")).data(), ',', verbose_options);
for (size_t i = 0; i < verbose_options.size(); ++i) {
parsed->verbose_.insert(verbose_options[i]);
}
diff --git a/src/runtime_linux.cc b/src/runtime_linux.cc
index 9b9cc07..c87825c 100644
--- a/src/runtime_linux.cc
+++ b/src/runtime_linux.cc
@@ -6,7 +6,6 @@
#include <execinfo.h>
#include "logging.h"
-#include "scoped_ptr.h"
#include "stringprintf.h"
namespace art {
@@ -18,9 +17,11 @@
// http://gcc.gnu.org/onlinedocs/libstdc++/manual/ext_demangling.html
int status;
- scoped_ptr_malloc<char> result(abi::__cxa_demangle(mangled_name.c_str(), NULL, NULL, &status));
- if (result != NULL) {
- return result.get();
+ char* name(abi::__cxa_demangle(mangled_name.c_str(), NULL, NULL, &status));
+ if (name != NULL) {
+ std::string result(name);
+ free(name);
+ return result;
}
return mangled_name + "()";
@@ -35,7 +36,7 @@
size_t frame_count = backtrace(frames, MAX_STACK_FRAMES);
// Turn them into something human-readable with symbols.
- scoped_ptr_malloc<char*> symbols(backtrace_symbols(frames, frame_count));
+ char** symbols = backtrace_symbols(frames, frame_count);
if (symbols == NULL) {
PLOG(ERROR) << "backtrace_symbols failed";
return;
@@ -48,7 +49,7 @@
// libartd.so:-1] #00 art::Runtime::PlatformAbort(char const*, int) +0x15b [0xf770dd51]
for (size_t i = 0; i < frame_count; ++i) {
- std::string text(symbols.get()[i]);
+ std::string text(symbols[i]);
size_t index = text.find('(');
std::string filename(text.substr(0, index));
@@ -63,6 +64,8 @@
std::string log_line(StringPrintf("\t#%02d ", i) + function_name + text);
LogMessage(filename.c_str(), -1, ERROR, -1).stream() << log_line;
}
+
+ free(symbols);
}
} // namespace art
diff --git a/src/runtime_test.cc b/src/runtime_test.cc
index 75c003b..59e39d6 100644
--- a/src/runtime_test.cc
+++ b/src/runtime_test.cc
@@ -4,66 +4,9 @@
#include "common_test.h"
namespace art {
-void ParseClassPath(const char* class_path, std::vector<std::string>& vec);
class RuntimeTest : public CommonTest {};
-TEST_F(RuntimeTest, ParseClassPath) {
- std::vector<std::string> vec;
-
- art::ParseClassPath("", vec);
- EXPECT_EQ(0U, vec.size());
- vec.clear();
-
- art::ParseClassPath(":", vec);
- EXPECT_EQ(0U, vec.size());
- vec.clear();
-
- art::ParseClassPath(":foo", vec);
- EXPECT_EQ(1U, vec.size());
- vec.clear();
-
- art::ParseClassPath("foo:", vec);
- EXPECT_EQ(1U, vec.size());
- vec.clear();
-
- art::ParseClassPath(":foo:", vec);
- EXPECT_EQ(1U, vec.size());
- vec.clear();
-
- art::ParseClassPath("foo:bar", vec);
- EXPECT_EQ(2U, vec.size());
- vec.clear();
-
- art::ParseClassPath(":foo:bar", vec);
- EXPECT_EQ(2U, vec.size());
- vec.clear();
-
- art::ParseClassPath("foo:bar:", vec);
- EXPECT_EQ(2U, vec.size());
- vec.clear();
-
- art::ParseClassPath(":foo:bar:", vec);
- EXPECT_EQ(2U, vec.size());
- vec.clear();
-
- art::ParseClassPath("foo:bar:baz", vec);
- EXPECT_EQ(3U, vec.size());
- vec.clear();
-
- art::ParseClassPath(":foo:bar:baz", vec);
- EXPECT_EQ(3U, vec.size());
- vec.clear();
-
- art::ParseClassPath("foo:bar:baz:", vec);
- EXPECT_EQ(3U, vec.size());
- vec.clear();
-
- art::ParseClassPath(":foo:bar:baz:", vec);
- EXPECT_EQ(3U, vec.size());
- vec.clear();
-}
-
TEST_F(RuntimeTest, ParsedOptions) {
void* test_vfprintf = reinterpret_cast<void*>(0xa);
void* test_abort = reinterpret_cast<void*>(0xb);
diff --git a/src/utils.cc b/src/utils.cc
index 695cbb3..b908c4d 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -189,4 +189,20 @@
return long_name;
}
+void Split(const std::string& s, char delim, std::vector<std::string>& result) {
+ const char* p = s.data();
+ const char* end = p + s.size();
+ while (p != end) {
+ if (*p == delim) {
+ ++p;
+ } else {
+ const char* start = p;
+ while (++p != end && *p != delim) {
+ // Skip to the next occurrence of the delimiter.
+ }
+ result.push_back(std::string(start, p - start));
+ }
+ }
+}
+
} // namespace art
diff --git a/src/utils.h b/src/utils.h
index 4b3e57e..3a6f404 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -8,6 +8,9 @@
#include "stringpiece.h"
#include "stringprintf.h"
+#include <string>
+#include <vector>
+
namespace art {
class Field;
@@ -170,6 +173,10 @@
// Returns the current date in ISO yyyy-mm-dd hh:mm:ss format.
std::string GetIsoDate();
+// Splits a string using the given delimiter character into a vector of
+// strings. Empty strings will be omitted.
+void Split(const std::string& s, char delim, std::vector<std::string>& result);
+
} // namespace art
#endif // ART_SRC_UTILS_H_
diff --git a/src/utils_test.cc b/src/utils_test.cc
index 769dec5..3d53c35 100644
--- a/src/utils_test.cc
+++ b/src/utils_test.cc
@@ -103,4 +103,70 @@
EXPECT_EQ("Java_java_lang_String_copyValueOf___3CII", JniLongName(m));
}
+TEST_F(UtilsTest, Split) {
+ std::vector<std::string> actual;
+ std::vector<std::string> expected;
+
+ expected.clear();
+
+ actual.clear();
+ Split("", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ actual.clear();
+ Split(":", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ expected.clear();
+ expected.push_back("foo");
+
+ actual.clear();
+ Split(":foo", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ actual.clear();
+ Split("foo:", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ actual.clear();
+ Split(":foo:", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ expected.push_back("bar");
+
+ actual.clear();
+ Split("foo:bar", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ actual.clear();
+ Split(":foo:bar", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ actual.clear();
+ Split("foo:bar:", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ actual.clear();
+ Split(":foo:bar:", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ expected.push_back("baz");
+
+ actual.clear();
+ Split("foo:bar:baz", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ actual.clear();
+ Split(":foo:bar:baz", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ actual.clear();
+ Split("foo:bar:baz:", ':', actual);
+ EXPECT_EQ(expected, actual);
+
+ actual.clear();
+ Split(":foo:bar:baz:", ':', actual);
+ EXPECT_EQ(expected, actual);
+}
+
} // namespace art