Commit 56f2d23f authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #546 from tjhance/clean-boxed-string

remove the llvm::StringRef from BoxedString
parents 9f318d52 283f90df
......@@ -59,14 +59,14 @@ bool containsYield(AST* ast) {
BoxedString* mangleNameBoxedString(BoxedString* id, BoxedString* private_name) {
assert(id);
assert(private_name);
int len = id->s.size();
if (len < 2 || id->s[0] != '_' || id->s[1] != '_')
int len = id->size();
if (len < 2 || id->s()[0] != '_' || id->s()[1] != '_')
return id;
if ((id->s[len - 2] == '_' && id->s[len - 1] == '_') || id->s.find('.') != llvm::StringRef::npos)
if ((id->s()[len - 2] == '_' && id->s()[len - 1] == '_') || id->s().find('.') != llvm::StringRef::npos)
return id;
const char* p = private_name->s.data();
const char* p = private_name->data();
while (*p == '_') {
p++;
len--;
......@@ -74,7 +74,7 @@ BoxedString* mangleNameBoxedString(BoxedString* id, BoxedString* private_name) {
if (*p == '\0')
return id;
return static_cast<BoxedString*>(boxStringTwine("_" + (p + id->s)));
return static_cast<BoxedString*>(boxStringTwine("_" + (p + id->s())));
}
static void mangleNameInPlace(InternedString& id, const std::string* private_name,
......
......@@ -421,9 +421,9 @@ extern "C" PyObject* PyObject_SelfIter(PyObject* obj) noexcept {
extern "C" int PyObject_GenericSetAttr(PyObject* obj, PyObject* name, PyObject* value) noexcept {
try {
if (value == NULL)
delattrGeneric(obj, std::string(static_cast<BoxedString*>(name)->s), NULL);
delattrGeneric(obj, std::string(static_cast<BoxedString*>(name)->s()), NULL);
else
setattrGeneric(obj, std::string(static_cast<BoxedString*>(name)->s), value, NULL);
setattrGeneric(obj, std::string(static_cast<BoxedString*>(name)->s()), value, NULL);
} catch (ExcInfo e) {
setCAPIException(e);
return -1;
......@@ -445,9 +445,9 @@ extern "C" int PyObject_SetAttr(PyObject* obj, PyObject* name, PyObject* value)
try {
if (value == NULL)
delattr(obj, static_cast<BoxedString*>(name)->s.data());
delattr(obj, static_cast<BoxedString*>(name)->data());
else
setattr(obj, static_cast<BoxedString*>(name)->s.data(), value);
setattr(obj, static_cast<BoxedString*>(name)->data(), value);
} catch (ExcInfo e) {
setCAPIException(e);
return -1;
......
......@@ -1303,7 +1303,7 @@ Box* astInterpretFrom(CompiledFunction* cf, AST_expr* after_expr, AST_stmt* encl
for (const auto& p : frame_state.locals->d) {
assert(p.first->cls == str_cls);
auto& name = static_cast<BoxedString*>(p.first)->s;
auto name = static_cast<BoxedString*>(p.first)->s();
if (name == PASSED_GENERATOR_NAME) {
interpreter.setGenerator(p.second);
} else if (name == PASSED_CLOSURE_NAME) {
......
......@@ -457,8 +457,8 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
}
RELEASE_ASSERT(isSubclass(type->cls, str_cls), "");
llvm::StringRef filename_str = static_cast<BoxedString*>(fn)->s;
llvm::StringRef type_str = static_cast<BoxedString*>(type)->s;
llvm::StringRef filename_str = static_cast<BoxedString*>(fn)->s();
llvm::StringRef type_str = static_cast<BoxedString*>(type)->s();
if (iflags & ~(/*PyCF_MASK | PyCF_MASK_OBSOLETE | PyCF_DONT_IMPLY_DEDENT | */ PyCF_ONLY_AST)) {
raiseExcHelper(ValueError, "compile(): unrecognised flags");
......@@ -474,7 +474,7 @@ Box* compile(Box* source, Box* fn, Box* type, Box** _args) {
parsed = unboxAst(source);
} else {
RELEASE_ASSERT(isSubclass(source->cls, str_cls), "");
llvm::StringRef source_str = static_cast<BoxedString*>(source)->s;
llvm::StringRef source_str = static_cast<BoxedString*>(source)->s();
if (type_str == "exec") {
parsed = parseExec(source_str);
......@@ -543,7 +543,7 @@ Box* eval(Box* boxedCode, Box* globals, Box* locals) {
CLFunction* cl;
if (boxedCode->cls == str_cls) {
AST_Expression* parsed = parseEval(static_cast<BoxedString*>(boxedCode)->s);
AST_Expression* parsed = parseEval(static_cast<BoxedString*>(boxedCode)->s());
cl = compileEval(parsed, "<string>");
} else if (boxedCode->cls == code_cls) {
cl = clfunctionFromCode(boxedCode);
......@@ -610,7 +610,7 @@ Box* exec(Box* boxedCode, Box* globals, Box* locals) {
CLFunction* cl;
if (boxedCode->cls == str_cls) {
AST_Suite* parsed = parseExec(static_cast<BoxedString*>(boxedCode)->s);
AST_Suite* parsed = parseExec(static_cast<BoxedString*>(boxedCode)->s());
cl = compileExec(parsed, "<string>");
} else if (boxedCode->cls == code_cls) {
cl = clfunctionFromCode(boxedCode);
......
......@@ -932,7 +932,7 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
BoxedString* str_utf8 = (BoxedString*)PyUnicode_AsUTF8String(str);
assert(str_utf8->cls == str_cls);
checkAndThrowCAPIException();
return str_utf8->s.str();
return str_utf8->s().str();
}
bool need_encoding = encoding != "utf-8" && encoding != "iso-8859-1";
......@@ -943,7 +943,7 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
throwCAPIException();
BoxedString* str = (BoxedString*)PyUnicode_AsEncodedString(u, encoding.c_str(), NULL);
assert(str->cls == str_cls);
return str->s.str();
return str->s().str();
} else {
return s;
}
......@@ -954,12 +954,12 @@ pypa::String pypaEscapeDecoder(const pypa::String& s, const pypa::String& encodi
if (!decoded)
throwCAPIException();
assert(decoded->cls == str_cls);
return decoded->s.str();
return decoded->s().str();
} catch (ExcInfo e) {
error = true;
BoxedString* error_message = str(e.value);
if (error_message && error_message->cls == str_cls)
return std::string(error_message->s);
return std::string(error_message->s());
return "Encountered an unknown error inside pypaEscapeDecoder";
}
}
......@@ -1080,7 +1080,7 @@ std::string PystonSourceReader::get_line() {
if (!line->size())
is_eof = true;
++line_number;
return line->s;
return line->s();
}
AST_Module* pypa_parse(char const* file_path) {
......
......@@ -2479,7 +2479,7 @@ CFG* computeCFG(SourceInfo* source, std::vector<AST_stmt*> body) {
if (source->scoping->areGlobalsFromModule()) {
Box* module_name = source->parent_module->getattr("__name__", NULL);
assert(module_name->cls == str_cls);
module_assign->value = new AST_Str(static_cast<BoxedString*>(module_name)->s);
module_assign->value = new AST_Str(static_cast<BoxedString*>(module_name)->s());
} else {
module_assign->value
= new AST_Name(source->getInternedStrings().get("__name__"), AST_TYPE::Load, source->ast->lineno);
......
......@@ -402,7 +402,7 @@ Box* bltinImport(Box* name, Box* globals, Box* locals, Box** args) {
raiseExcHelper(TypeError, "an integer is required");
}
std::string _name = static_cast<BoxedString*>(name)->s;
std::string _name = static_cast<BoxedString*>(name)->s();
return importModuleLevel(_name, globals, fromlist, ((BoxedInt*)level)->n);
}
......@@ -412,7 +412,7 @@ Box* delattrFunc(Box* obj, Box* _str) {
if (_str->cls != str_cls)
raiseExcHelper(TypeError, "attribute name must be string, not '%s'", getTypeName(_str));
BoxedString* str = static_cast<BoxedString*>(_str);
delattr(obj, str->s.data());
delattr(obj, str->data());
return None;
}
......@@ -427,7 +427,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
Box* rtn = NULL;
try {
rtn = getattr(obj, str->s.data());
rtn = getattr(obj, str->data());
} catch (ExcInfo e) {
if (!e.matches(AttributeError))
throw e;
......@@ -437,7 +437,7 @@ Box* getattrFunc(Box* obj, Box* _str, Box* default_value) {
if (default_value)
return default_value;
else
raiseExcHelper(AttributeError, "'%s' object has no attribute '%s'", getTypeName(obj), str->s.data());
raiseExcHelper(AttributeError, "'%s' object has no attribute '%s'", getTypeName(obj), str->data());
}
return rtn;
......@@ -451,7 +451,7 @@ Box* setattrFunc(Box* obj, Box* _str, Box* value) {
}
BoxedString* str = static_cast<BoxedString*>(_str);
setattr(obj, str->s.data(), value);
setattr(obj, str->data(), value);
return None;
}
......@@ -465,7 +465,7 @@ Box* hasattr(Box* obj, Box* _str) {
BoxedString* str = static_cast<BoxedString*>(_str);
Box* attr;
try {
attr = getattrInternal(obj, str->s, NULL);
attr = getattrInternal(obj, str->s(), NULL);
} catch (ExcInfo e) {
if (e.matches(Exception))
return False;
......@@ -672,7 +672,7 @@ Box* exceptionRepr(Box* b) {
assert(message->cls == str_cls);
BoxedString* message_s = static_cast<BoxedString*>(message);
return boxStringTwine(llvm::Twine(getTypeName(b)) + "(" + message_s->s + ",)");
return boxStringTwine(llvm::Twine(getTypeName(b)) + "(" + message_s->s() + ",)");
}
static BoxedClass* makeBuiltinException(BoxedClass* base, const char* name, int size = 0) {
......@@ -833,14 +833,14 @@ Box* execfile(Box* _fn) {
#endif
#else
bool exists = llvm::sys::fs::exists(std::string(fn->s));
bool exists = llvm::sys::fs::exists(std::string(fn->s()));
#endif
if (!exists)
raiseExcHelper(IOError, "No such file or directory: '%s'", fn->s.data());
raiseExcHelper(IOError, "No such file or directory: '%s'", fn->data());
// Run directly inside the current module:
AST_Module* ast = caching_parse_file(fn->s.data());
AST_Module* ast = caching_parse_file(fn->data());
ASSERT(getExecutionPoint().cf->clfunc->source->scoping->areGlobalsFromModule(), "need to pass custom globals in");
compileAndRunModule(ast, getCurrentModule());
......
......@@ -30,7 +30,7 @@ static Box* setOption(Box* option, Box* value) {
int n = ((BoxedInt*)value)->n;
#define CHECK(_s) \
if (option_string->s == STRINGIFY(_s)) \
if (option_string->s() == STRINGIFY(_s)) \
_s = n
// :)
......@@ -43,7 +43,7 @@ static Box* setOption(Box* option, Box* value) {
else CHECK(REOPT_THRESHOLD_BASELINE);
else CHECK(OSR_THRESHOLD_BASELINE);
else CHECK(SPECULATION_THRESHOLD);
else raiseExcHelper(ValueError, "unknown option name '%s", option_string->s.data());
else raiseExcHelper(ValueError, "unknown option name '%s", option_string->data());
return None;
}
......
......@@ -168,7 +168,7 @@ public:
}
static Box* setattrPyston(Box* obj, Box* name, Box* val) noexcept {
if (isSubclass(name->cls, str_cls) && static_cast<BoxedString*>(name)->s == "__dict__") {
if (isSubclass(name->cls, str_cls) && static_cast<BoxedString*>(name)->s() == "__dict__") {
raiseExcHelper(AttributeError, "'%.50s' object attribute '__dict__' is read-only", Py_TYPE(obj)->tp_name);
}
......@@ -189,7 +189,7 @@ public:
static Box* getattro(Box* obj, Box* name) noexcept {
assert(name->cls == str_cls);
llvm::StringRef s = static_cast<BoxedString*>(name)->s;
llvm::StringRef s = static_cast<BoxedString*>(name)->s();
Box* tls_obj = getThreadLocalObject(obj);
if (s == "__dict__")
......
......@@ -258,7 +258,7 @@ extern "C" PyObject* PyObject_GetAttr(PyObject* o, PyObject* attr_name) noexcept
extern "C" PyObject* PyObject_GenericGetAttr(PyObject* o, PyObject* name) noexcept {
try {
Box* r = getattrInternalGeneric(o, static_cast<BoxedString*>(name)->s.data(), NULL, false, false, NULL, NULL);
Box* r = getattrInternalGeneric(o, static_cast<BoxedString*>(name)->data(), NULL, false, false, NULL, NULL);
if (!r)
PyErr_Format(PyExc_AttributeError, "'%.50s' object has no attribute '%.400s'", o->cls->tp_name,
PyString_AS_STRING(name));
......@@ -868,7 +868,7 @@ extern "C" PyObject* PyImport_Import(PyObject* module_name) noexcept {
RELEASE_ASSERT(module_name->cls == str_cls, "");
try {
std::string _module_name = static_cast<BoxedString*>(module_name)->s;
std::string _module_name = static_cast<BoxedString*>(module_name)->s();
return importModuleLevel(_module_name, None, None, -1);
} catch (ExcInfo e) {
fatalOrError(PyExc_NotImplementedError, "unimplemented");
......
......@@ -104,7 +104,7 @@ Box* classobjNew(Box* _cls, Box* _name, Box* _bases, Box** _args) {
for (auto& p : dict->d) {
RELEASE_ASSERT(p.first->cls == str_cls, "");
made->setattr(std::string(static_cast<BoxedString*>(p.first)->s), p.second, NULL);
made->setattr(std::string(static_cast<BoxedString*>(p.first)->s()), p.second, NULL);
}
// Note: make sure to do this after assigning the attrs, since it will overwrite any defined __name__
......@@ -148,21 +148,21 @@ static Box* classobjGetattribute(Box* _cls, Box* _attr) {
BoxedString* attr = static_cast<BoxedString*>(_attr);
// These are special cases in CPython as well:
if (attr->s[0] == '_' && attr->s[1] == '_') {
if (attr->s == "__dict__")
if (attr->s()[0] == '_' && attr->s()[1] == '_') {
if (attr->s() == "__dict__")
return cls->getAttrWrapper();
if (attr->s == "__bases__")
if (attr->s() == "__bases__")
return cls->bases;
if (attr->s == "__name__") {
if (attr->s() == "__name__") {
if (cls->name)
return cls->name;
return None;
}
}
Box* r = classLookup(cls, std::string(attr->s));
Box* r = classLookup(cls, std::string(attr->s()));
if (!r)
raiseExcHelper(AttributeError, "class %s has no attribute '%s'", cls->name->data(), attr->data());
......@@ -206,7 +206,7 @@ static void classobjSetattr(Box* _cls, Box* _attr, Box* _value) {
RELEASE_ASSERT(_attr->cls == str_cls, "");
BoxedString* attr = static_cast<BoxedString*>(_attr);
if (attr->s == "__bases__") {
if (attr->s() == "__bases__") {
const char* error_str = set_bases((PyClassObject*)cls, _value);
if (error_str && error_str[0] != '\0')
raiseExcHelper(TypeError, "%s", error_str);
......@@ -242,7 +242,7 @@ Box* classobjStr(Box* _obj) {
Box* _mod = cls->getattr("__module__");
RELEASE_ASSERT(_mod, "");
RELEASE_ASSERT(_mod->cls == str_cls, "");
return boxStringTwine(llvm::Twine(static_cast<BoxedString*>(_mod)->s) + "." + cls->name->s);
return boxStringTwine(llvm::Twine(static_cast<BoxedString*>(_mod)->s()) + "." + cls->name->s());
}
static Box* _instanceGetattribute(Box* _inst, Box* _attr, bool raise_on_missing) {
......@@ -253,19 +253,19 @@ static Box* _instanceGetattribute(Box* _inst, Box* _attr, bool raise_on_missing)
BoxedString* attr = static_cast<BoxedString*>(_attr);
// These are special cases in CPython as well:
if (attr->s[0] == '_' && attr->s[1] == '_') {
if (attr->s == "__dict__")
if (attr->s()[0] == '_' && attr->s()[1] == '_') {
if (attr->s() == "__dict__")
return inst->getAttrWrapper();
if (attr->s == "__class__")
if (attr->s() == "__class__")
return inst->inst_cls;
}
Box* r = inst->getattr(attr->s);
Box* r = inst->getattr(attr->s());
if (r)
return r;
r = classLookup(inst->inst_cls, attr->s);
r = classLookup(inst->inst_cls, attr->s());
if (r) {
return processDescriptor(r, inst, inst->inst_cls);
}
......@@ -308,11 +308,11 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
assert(value);
// These are special cases in CPython as well:
if (attr->s[0] == '_' && attr->s[1] == '_') {
if (attr->s == "__dict__")
if (attr->s()[0] == '_' && attr->s()[1] == '_') {
if (attr->s() == "__dict__")
Py_FatalError("unimplemented");
if (attr->s == "__class__") {
if (attr->s() == "__class__") {
if (value->cls != classobj_cls)
raiseExcHelper(TypeError, "__class__ must be set to a class");
......@@ -329,7 +329,7 @@ Box* instanceSetattr(Box* _inst, Box* _attr, Box* value) {
return runtimeCall(setattr, ArgPassSpec(2), _attr, value, NULL, NULL, NULL);
}
_inst->setattr(attr->s, value, NULL);
_inst->setattr(attr->s(), value, NULL);
return None;
}
......@@ -341,11 +341,11 @@ Box* instanceDelattr(Box* _inst, Box* _attr) {
BoxedString* attr = static_cast<BoxedString*>(_attr);
// These are special cases in CPython as well:
if (attr->s[0] == '_' && attr->s[1] == '_') {
if (attr->s == "__dict__")
if (attr->s()[0] == '_' && attr->s()[1] == '_') {
if (attr->s() == "__dict__")
raiseExcHelper(TypeError, "__dict__ must be set to a dictionary");
if (attr->s == "__class__")
if (attr->s() == "__class__")
raiseExcHelper(TypeError, "__class__ must be set to a class");
}
......@@ -357,7 +357,7 @@ Box* instanceDelattr(Box* _inst, Box* _attr) {
return runtimeCall(delattr, ArgPassSpec(1), _attr, NULL, NULL, NULL, NULL);
}
_inst->delattr(attr->s, NULL);
_inst->delattr(attr->s(), NULL);
return None;
}
......
......@@ -38,10 +38,10 @@ Box* dictRepr(BoxedDict* self) {
BoxedString* k = static_cast<BoxedString*>(repr(p.first));
BoxedString* v = static_cast<BoxedString*>(repr(p.second));
chars.insert(chars.end(), k->s.begin(), k->s.end());
chars.insert(chars.end(), k->s().begin(), k->s().end());
chars.push_back(':');
chars.push_back(' ');
chars.insert(chars.end(), v->s.begin(), v->s.end());
chars.insert(chars.end(), v->s().begin(), v->s().end());
}
chars.push_back('}');
return boxString(llvm::StringRef(&chars[0], chars.size()));
......
......@@ -971,7 +971,7 @@ Box* fileNew(BoxedClass* cls, Box* s, Box* m, Box** args) {
abort(); // unreachable;
}
auto file = new BoxedFile(f, fn->s, PyString_AsString(m));
auto file = new BoxedFile(f, fn->s(), PyString_AsString(m));
PyFile_SetBufSize(file, buffering->n);
return file;
}
......@@ -1110,7 +1110,7 @@ error:
Box* fileIterNext(BoxedFile* s) {
Box* rtn = fileReadline1(s);
assert(!rtn || rtn->cls == str_cls);
if (!rtn || ((BoxedString*)rtn)->s.empty())
if (!rtn || ((BoxedString*)rtn)->s().empty())
raiseExcHelper(StopIteration, "");
return rtn;
}
......
......@@ -627,7 +627,7 @@ BoxedFloat* _floatNew(Box* a) {
} else if (isSubclass(a->cls, int_cls)) {
return new BoxedFloat(static_cast<BoxedInt*>(a)->n);
} else if (a->cls == str_cls) {
const std::string& s = static_cast<BoxedString*>(a)->s;
const std::string& s = static_cast<BoxedString*>(a)->s();
if (s == "nan")
return new BoxedFloat(NAN);
if (s == "-nan")
......
......@@ -220,7 +220,7 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B
BoxedString* p = static_cast<BoxedString*>(_p);
joined_path.clear();
llvm::sys::path::append(joined_path, std::string(p->s), name);
llvm::sys::path::append(joined_path, std::string(p->s()), name);
std::string dn(joined_path.str());
llvm::sys::path::append(joined_path, "__init__.py");
......@@ -242,14 +242,14 @@ SearchResult findModule(const std::string& name, const std::string& full_name, B
return SearchResult(std::move(dn), SearchResult::PKG_DIRECTORY);
joined_path.clear();
llvm::sys::path::append(joined_path, std::string(p->s), name + ".py");
llvm::sys::path::append(joined_path, std::string(p->s()), name + ".py");
fn = joined_path.str();
if (pathExists(fn))
return SearchResult(std::move(fn), SearchResult::PY_SOURCE);
joined_path.clear();
llvm::sys::path::append(joined_path, p->s, name + ".pyston.so");
llvm::sys::path::append(joined_path, p->s(), name + ".pyston.so");
fn = joined_path.str();
if (pathExists(fn))
......@@ -291,7 +291,7 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
if (len > PATH_MAX) {
raiseExcHelper(ValueError, "Package name too long");
}
buf += pkgname->s;
buf += pkgname->s();
} else {
/* __package__ not set, so figure it out and set it */
BoxedString* modname = static_cast<BoxedString*>(getFromGlobals(globals, name_str));
......@@ -305,11 +305,11 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
if (modname->size() > PATH_MAX) {
raiseExcHelper(ValueError, "Module name too long");
}
buf += modname->s;
buf += modname->s();
setGlobal(globals, package_str, modname);
} else {
/* Normal module, so work out the package name if any */
size_t lastdot = modname->s.rfind('.');
size_t lastdot = modname->s().rfind('.');
if (lastdot == std::string::npos && level > 0) {
raiseExcHelper(ValueError, "Attempted relative import in non-package");
}
......@@ -321,7 +321,7 @@ static Box* getParent(Box* globals, int level, std::string& buf) {
raiseExcHelper(ValueError, "Module name too long");
}
buf = std::string(modname->s, 0, lastdot);
buf = std::string(modname->s(), 0, lastdot);
setGlobal(globals, package_str, boxStringPtr(&buf));
}
}
......@@ -562,7 +562,7 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re
assert(_s->cls == str_cls);
BoxedString* s = static_cast<BoxedString*>(_s);
if (s->s[0] == '*') {
if (s->s()[0] == '*') {
// If __all__ contains a '*', just skip it:
if (recursive)
continue;
......@@ -574,12 +574,12 @@ static void ensureFromlist(Box* module, Box* fromlist, std::string& buf, bool re
continue;
}
Box* attr = getattrInternal(module, s->s, NULL);
Box* attr = getattrInternal(module, s->s(), NULL);
if (attr != NULL)
continue;
// Just want to import it and add it to the modules list for now:
importSub(s->s, (llvm::Twine(buf) + "." + s->s).str(), module);
importSub(s->s(), (llvm::Twine(buf) + "." + s->s()).str(), module);
}
}
......@@ -651,7 +651,7 @@ Box* nullImporterInit(Box* self, Box* _path) {
raiseExcHelper(TypeError, "must be string, not %s", getTypeName(_path));
BoxedString* path = (BoxedString*)_path;
if (path->s.empty())
if (path->s().empty())
raiseExcHelper(ImportError, "empty pathname");
if (isdir(path->data()))
......@@ -676,7 +676,7 @@ Box* impFindModule(Box* _name, BoxedList* path) {
BoxedString* name = static_cast<BoxedString*>(_name);
BoxedList* path_list = path && path != None ? path : getSysPath();
SearchResult sr = findModule(name->s, name->s, path_list);
SearchResult sr = findModule(name->s(), name->s(), path_list);
if (sr.type == SearchResult::SEARCH_ERROR)
raiseExcHelper(ImportError, "%s", name->data());
......@@ -726,13 +726,13 @@ Box* impLoadModule(Box* _name, Box* _file, Box* _pathname, Box** args) {
if (type->n == SearchResult::PKG_DIRECTORY) {
RELEASE_ASSERT(suffix->cls == str_cls, "");
RELEASE_ASSERT(suffix->s.empty(), "");
RELEASE_ASSERT(mode->s.empty(), "");
RELEASE_ASSERT(suffix->s().empty(), "");
RELEASE_ASSERT(mode->s().empty(), "");
RELEASE_ASSERT(_file == None, "");
return createAndRunModule(name->s, (llvm::Twine(pathname->s) + "/__init__.py").str(), pathname->s);
return createAndRunModule(name->s(), (llvm::Twine(pathname->s()) + "/__init__.py").str(), pathname->s());
} else if (type->n == SearchResult::PY_SOURCE) {
RELEASE_ASSERT(_file->cls == file_cls, "");
return createAndRunModule(name->s, pathname->s);
return createAndRunModule(name->s(), pathname->s());
}
Py_FatalError("unimplemented");
......@@ -744,7 +744,7 @@ Box* impLoadSource(Box* _name, Box* _pathname, Box* _file) {
RELEASE_ASSERT(_name->cls == str_cls, "");
RELEASE_ASSERT(_pathname->cls == str_cls, "");
return createAndRunModule(static_cast<BoxedString*>(_name)->s, static_cast<BoxedString*>(_pathname)->s);
return createAndRunModule(static_cast<BoxedString*>(_name)->s(), static_cast<BoxedString*>(_pathname)->s());
}
Box* impLoadDynamic(Box* _name, Box* _pathname, Box* _file) {
......@@ -755,16 +755,16 @@ Box* impLoadDynamic(Box* _name, Box* _pathname, Box* _file) {
BoxedString* name = (BoxedString*)_name;
BoxedString* pathname = (BoxedString*)_pathname;
const char* lastdot = strrchr(name->s.data(), '.');
const char* lastdot = strrchr(name->s().data(), '.');
const char* shortname;
if (lastdot == NULL) {
shortname = name->s.data();
shortname = name->s().data();
} else {
shortname = lastdot + 1;
}
return importCExtension(name->s, shortname, pathname->s);
return importCExtension(name->s(), shortname, pathname->s());
}
Box* impGetSuffixes() {
......
......@@ -76,7 +76,7 @@ extern "C" Box* listRepr(BoxedList* self) {
assert(r->cls == str_cls);
BoxedString* s = static_cast<BoxedString*>(r);
os << s->s;
os << s->s();
}
os << ']';
return boxString(os.str());
......
......@@ -612,7 +612,7 @@ BoxedLong* _longNew(Box* val, Box* _base) {
raiseExcHelper(TypeError, "long() can't convert non-string with explicit base");
BoxedString* s = static_cast<BoxedString*>(val);
rtn = (BoxedLong*)PyLong_FromString(s->s.str().c_str(), NULL, base);
rtn = (BoxedLong*)PyLong_FromString(s->data(), NULL, base);
checkAndThrowCAPIException();
} else {
if (isSubclass(val->cls, long_cls)) {
......@@ -625,7 +625,7 @@ BoxedLong* _longNew(Box* val, Box* _base) {
} else if (isSubclass(val->cls, int_cls)) {
mpz_init_set_si(rtn->n, static_cast<BoxedInt*>(val)->n);
} else if (val->cls == str_cls) {
const std::string& s = static_cast<BoxedString*>(val)->s;
const std::string& s = static_cast<BoxedString*>(val)->s();
int r = mpz_init_set_str(rtn->n, s.c_str(), 10);
RELEASE_ASSERT(r == 0, "");
} else if (val->cls == float_cls) {
......
......@@ -146,7 +146,7 @@ bool PyEq::operator()(Box* lhs, Box* rhs) const {
if (lhs->cls == rhs->cls) {
if (lhs->cls == str_cls) {
return static_cast<BoxedString*>(lhs)->s == static_cast<BoxedString*>(rhs)->s;
return static_cast<BoxedString*>(lhs)->s() == static_cast<BoxedString*>(rhs)->s();
}
}
......@@ -464,7 +464,7 @@ std::string getFullNameOfClass(BoxedClass* cls) {
BoxedString* module = static_cast<BoxedString*>(b);
return (llvm::Twine(module->s) + "." + cls->tp_name).str();
return (llvm::Twine(module->s()) + "." + cls->tp_name).str();
}
std::string getFullTypeName(Box* o) {
......@@ -3104,7 +3104,7 @@ Box* callFunc(BoxedFunctionBase* func, CallRewriteArgs* rewrite_args, ArgPassSpe
if (param_names.takes_param_names) {
assert(!rewrite_args && "would need to make sure that this didn't need to go into r_kwargs");
placeKeyword(param_names, params_filled, s->s, p.second, oarg1, oarg2, oarg3, oargs, okwargs, f);
placeKeyword(param_names, params_filled, s->s(), p.second, oarg1, oarg2, oarg3, oargs, okwargs, f);
} else {
assert(!rewrite_args && "would need to make sure that this didn't need to go into r_kwargs");
assert(okwargs);
......@@ -4261,14 +4261,14 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
Box* tmp = slots[i];
assertValidSlotIdentifier(tmp);
assert(PyString_Check(tmp));
if (static_cast<BoxedString*>(tmp)->s == "__dict__") {
if (static_cast<BoxedString*>(tmp)->s() == "__dict__") {
if (!may_add_dict || add_dict) {
raiseExcHelper(TypeError, "__dict__ slot disallowed: "
"we already got one");
}
add_dict++;
continue;
} else if (static_cast<BoxedString*>(tmp)->s == "__weakref__") {
} else if (static_cast<BoxedString*>(tmp)->s() == "__weakref__") {
if (!may_add_weak || add_weak) {
raiseExcHelper(TypeError, "__weakref__ slot disallowed: "
"either we already got one, "
......@@ -4356,7 +4356,7 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
// Add the member descriptors
size_t offset = base->tp_basicsize;
for (size_t i = 0; i < final_slot_names.size(); i++) {
made->giveAttr(static_cast<BoxedString*>(slotsTuple->elts[i])->s.data(),
made->giveAttr(static_cast<BoxedString*>(slotsTuple->elts[i])->data(),
new BoxedMemberDescriptor(BoxedMemberDescriptor::OBJECT_EX, offset, false /* read only */));
slot_offsets[i] = offset;
offset += sizeof(Box*);
......@@ -4381,7 +4381,7 @@ Box* typeNew(Box* _cls, Box* arg1, Box* arg2, Box** _args) {
auto k = coerceUnicodeToStr(p.first);
RELEASE_ASSERT(k->cls == str_cls, "");
made->setattr(static_cast<BoxedString*>(k)->s, p.second, NULL);
made->setattr(static_cast<BoxedString*>(k)->s(), p.second, NULL);
}
if (!made->hasattr("__module__")) {
......@@ -4911,11 +4911,11 @@ extern "C" Box* importStar(Box* _from_module, Box* to_globals) {
raiseExcHelper(TypeError, "attribute name must be string, not '%s'", getTypeName(attr_name));
BoxedString* casted_attr_name = static_cast<BoxedString*>(attr_name);
Box* attr_value = from_module->getattr(casted_attr_name->s);
Box* attr_value = from_module->getattr(casted_attr_name->s());
if (!attr_value)
raiseExcHelper(AttributeError, "'module' object has no attribute '%s'", casted_attr_name->data());
setGlobal(to_globals, casted_attr_name->s, attr_value);
setGlobal(to_globals, casted_attr_name->s(), attr_value);
}
return None;
}
......
......@@ -106,7 +106,7 @@ static Box* _setRepr(BoxedSet* self, const char* type_name) {
if (!first) {
os << ", ";
}
os << static_cast<BoxedString*>(repr(elt))->s;
os << static_cast<BoxedString*>(repr(elt))->s();
first = false;
}
os << "])";
......
This diff is collapsed.
......@@ -64,7 +64,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
if (!skip) {
// Looks like __class__ is supposed to be "super", not the class of the the proxied object.
skip = (attr->s == class_str);
skip = (attr->s() == class_str);
}
if (!skip) {
......@@ -101,7 +101,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
continue;
res = PyDict_GetItem(dict, name);
#endif
res = tmp->getattr(std::string(attr->s));
res = tmp->getattr(std::string(attr->s()));
if (res != NULL) {
// Pyston change:
......@@ -128,7 +128,7 @@ Box* superGetattribute(Box* _s, Box* _attr) {
}
}
Box* r = typeLookup(s->cls, std::string(attr->s), NULL);
Box* r = typeLookup(s->cls, std::string(attr->s()), NULL);
// TODO implement this
RELEASE_ASSERT(r, "should call the equivalent of objectGetattr here");
return processDescriptor(r, s, s->cls);
......
......@@ -215,7 +215,7 @@ Box* tupleRepr(BoxedTuple* t) {
os << ", ";
BoxedString* elt_repr = static_cast<BoxedString*>(repr(t->elts[i]));
os << elt_repr->s;
os << elt_repr->s();
}
if (n == 1)
os << ",";
......@@ -376,7 +376,7 @@ extern "C" Box* tupleNew(Box* _cls, BoxedTuple* args, BoxedDict* kwargs) {
auto const seq = *(kwargs->d.begin());
auto const kw = static_cast<BoxedString*>(seq.first);
if (kw->s == "sequence")
if (kw->s() == "sequence")
elements = seq.second;
else
raiseExcHelper(TypeError, "'%s' is an invalid keyword argument for this function", kw->data());
......
......@@ -401,7 +401,7 @@ std::string BoxedModule::name() {
return "?";
} else {
BoxedString* sname = static_cast<BoxedString*>(name);
return sname->s;
return sname->s();
}
}
......@@ -1038,7 +1038,7 @@ Box* sliceRepr(BoxedSlice* self) {
BoxedString* start = static_cast<BoxedString*>(repr(self->start));
BoxedString* stop = static_cast<BoxedString*>(repr(self->stop));
BoxedString* step = static_cast<BoxedString*>(repr(self->step));
return boxStringTwine(llvm::Twine("slice(") + start->s + ", " + stop->s + ", " + step->s + ")");
return boxStringTwine(llvm::Twine("slice(") + start->s() + ", " + stop->s() + ", " + step->s() + ")");
}
extern "C" int PySlice_GetIndices(PySliceObject* r, Py_ssize_t length, Py_ssize_t* start, Py_ssize_t* stop,
......@@ -1150,8 +1150,8 @@ Box* typeRepr(BoxedClass* self) {
Box* m = self->getattr("__module__");
if (m && m->cls == str_cls) {
BoxedString* sm = static_cast<BoxedString*>(m);
if (sm->s != "__builtin__")
os << sm->s << '.';
if (sm->s() != "__builtin__")
os << sm->s() << '.';
}
os << self->tp_name;
......@@ -1347,7 +1347,7 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key);
self->b->setattr(key->s, value, NULL);
self->b->setattr(key->s(), value, NULL);
return None;
}
......@@ -1360,10 +1360,10 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key);
Box* cur = self->b->getattr(key->s);
Box* cur = self->b->getattr(key->s());
if (cur)
return cur;
self->b->setattr(key->s, value, NULL);
self->b->setattr(key->s(), value, NULL);
return value;
}
......@@ -1376,7 +1376,7 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key);
Box* r = self->b->getattr(key->s);
Box* r = self->b->getattr(key->s());
if (!r)
return def;
return r;
......@@ -1391,7 +1391,7 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, "%s", _key->cls->tp_name);
BoxedString* key = static_cast<BoxedString*>(_key);
Box* r = self->b->getattr(key->s);
Box* r = self->b->getattr(key->s());
if (!r)
raiseExcHelper(KeyError, "'%s'", key->data());
return r;
......@@ -1405,9 +1405,9 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key);
Box* r = self->b->getattr(key->s);
Box* r = self->b->getattr(key->s());
if (r) {
self->b->delattr(key->s, NULL);
self->b->delattr(key->s(), NULL);
return r;
} else {
if (default_)
......@@ -1425,8 +1425,8 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, "%s", _key->cls->tp_name);
BoxedString* key = static_cast<BoxedString*>(_key);
if (self->b->getattr(key->s))
self->b->delattr(key->s, NULL);
if (self->b->getattr(key->s()))
self->b->delattr(key->s(), NULL);
else
raiseExcHelper(KeyError, "'%s'", key->data());
return None;
......@@ -1450,7 +1450,7 @@ public:
first = false;
BoxedString* v = attrs->attr_list->attrs[p.second]->reprICAsString();
os << p.first().str() << ": " << v->s;
os << p.first().str() << ": " << v->s();
}
os << "})";
return boxString(os.str());
......@@ -1464,7 +1464,7 @@ public:
RELEASE_ASSERT(_key->cls == str_cls, "");
BoxedString* key = static_cast<BoxedString*>(_key);
Box* r = self->b->getattr(key->s);
Box* r = self->b->getattr(key->s());
return r ? True : False;
}
......@@ -1728,7 +1728,7 @@ Box* objectSetattr(Box* obj, Box* attr, Box* value) {
}
BoxedString* attr_str = static_cast<BoxedString*>(attr);
setattrGeneric(obj, attr_str->s, value, NULL);
setattrGeneric(obj, attr_str->s(), value, NULL);
return None;
}
......
......@@ -427,11 +427,14 @@ public:
class BoxedString : public BoxVar {
public:
llvm::StringRef s;
// llvm::StringRef is basically just a pointer and a length, so with proper compiler
// optimizations and inlining, creating a new one each time shouldn't have any cost.
llvm::StringRef s() const { return llvm::StringRef(s_data, ob_size); };
char interned_state;
char* data() { return const_cast<char*>(s.data()); }
size_t size() { return s.size(); }
char* data() { return s_data; }
size_t size() { return this->ob_size; }
// DEFAULT_CLASS_VAR_SIMPLE doesn't work because of the +1 for the null byte
void* operator new(size_t size, BoxedClass* cls, size_t nitems) __attribute__((visibility("default"))) {
......@@ -465,11 +468,9 @@ public:
explicit BoxedString(llvm::StringRef lhs, llvm::StringRef rhs) __attribute__((visibility("default")));
private:
// used only in ctors to give our llvm::StringRef the proper pointer
// Note: sizeof(BoxedString) = str_cls->tp_basicsize - 1
char* storage() { return (char*)this + sizeof(BoxedString); }
void* operator new(size_t size) = delete;
char s_data[0];
};
template <typename T> struct StringHash {
......
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