Commit 2748c606 authored by Chris Toshok's avatar Chris Toshok

fix bug introduced on colocation branch for empty string/list passed to strJoin

parent e871f4ef
...@@ -47,6 +47,7 @@ extern "C" PyObject* string_splitlines(PyStringObject* self, PyObject* args) noe ...@@ -47,6 +47,7 @@ extern "C" PyObject* string_splitlines(PyStringObject* self, PyObject* args) noe
namespace pyston { namespace pyston {
BoxedString::BoxedString(const char* s, size_t n) : s(storage(), n) { BoxedString::BoxedString(const char* s, size_t n) : s(storage(), n) {
RELEASE_ASSERT(n != llvm::StringRef::npos, "");
if (s) { if (s) {
memmove(data(), s, n); memmove(data(), s, n);
data()[n] = 0; data()[n] = 0;
...@@ -56,17 +57,20 @@ BoxedString::BoxedString(const char* s, size_t n) : s(storage(), n) { ...@@ -56,17 +57,20 @@ BoxedString::BoxedString(const char* s, size_t n) : s(storage(), n) {
} }
BoxedString::BoxedString(llvm::StringRef lhs, llvm::StringRef rhs) : s(storage(), lhs.size() + rhs.size()) { BoxedString::BoxedString(llvm::StringRef lhs, llvm::StringRef rhs) : s(storage(), lhs.size() + rhs.size()) {
RELEASE_ASSERT(lhs.size() + rhs.size() != llvm::StringRef::npos, "");
memmove(data(), lhs.data(), lhs.size()); memmove(data(), lhs.data(), lhs.size());
memmove(data() + lhs.size(), rhs.data(), rhs.size()); memmove(data() + lhs.size(), rhs.data(), rhs.size());
data()[lhs.size() + rhs.size()] = 0; data()[lhs.size() + rhs.size()] = 0;
} }
BoxedString::BoxedString(llvm::StringRef s) : s(storage(), s.size()) { BoxedString::BoxedString(llvm::StringRef s) : s(storage(), s.size()) {
RELEASE_ASSERT(s.size() != llvm::StringRef::npos, "");
memmove(data(), s.data(), s.size()); memmove(data(), s.data(), s.size());
data()[s.size()] = 0; data()[s.size()] = 0;
} }
BoxedString::BoxedString(size_t n, char c) : s(storage(), n) { BoxedString::BoxedString(size_t n, char c) : s(storage(), n) {
RELEASE_ASSERT(n != llvm::StringRef::npos, "");
memset(data(), c, n); memset(data(), c, n);
data()[n] = 0; data()[n] = 0;
} }
...@@ -1694,6 +1698,9 @@ Box* strJoin(BoxedString* self, Box* rhs) { ...@@ -1694,6 +1698,9 @@ Box* strJoin(BoxedString* self, Box* rhs) {
int i = 0; int i = 0;
if (rhs->cls == str_cls) { if (rhs->cls == str_cls) {
BoxedString* srhs = static_cast<BoxedString*>(rhs); BoxedString* srhs = static_cast<BoxedString*>(rhs);
if (srhs->size() == 0)
return EmptyString;
size_t rtn_len = self->size() * (srhs->size() - 1) + srhs->size(); size_t rtn_len = self->size() * (srhs->size() - 1) + srhs->size();
BoxedString* rtn = new (rtn_len) BoxedString(nullptr, rtn_len); BoxedString* rtn = new (rtn_len) BoxedString(nullptr, rtn_len);
char* p = rtn->data(); char* p = rtn->data();
...@@ -1708,6 +1715,9 @@ Box* strJoin(BoxedString* self, Box* rhs) { ...@@ -1708,6 +1715,9 @@ Box* strJoin(BoxedString* self, Box* rhs) {
return rtn; return rtn;
} else if (rhs->cls == list_cls) { } else if (rhs->cls == list_cls) {
BoxedList* lrhs = static_cast<BoxedList*>(rhs); BoxedList* lrhs = static_cast<BoxedList*>(rhs);
if (lrhs->size == 0)
return EmptyString;
size_t rtn_len = self->size() * (lrhs->size - 1); size_t rtn_len = self->size() * (lrhs->size - 1);
for (int l = 0; l < lrhs->size; l++) { for (int l = 0; l < lrhs->size; l++) {
......
print "-".join(["hello", "world"]) print "-".join(["hello", "world"])
print "-".join(("hello", "world")) print "-".join(("hello", "world"))
print "hi".join("")
print "hi".join([])
print "hi".join(())
print repr(chr(0) + chr(180)) print repr(chr(0) + chr(180))
print repr('"') print repr('"')
# print repr("'") // don't feel like handling this right now; this should print out (verbatim) "'", ie realize it can use double quotes # print repr("'") // don't feel like handling this right now; this should print out (verbatim) "'", ie realize it can use double quotes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment