Commit c2b6a32a authored by Kevin Modzelewski's avatar Kevin Modzelewski

fix up typeRepr handling

parent a1e85219
......@@ -352,6 +352,8 @@ BoxedClass::BoxedClass(BoxedClass* metaclass, BoxedClass* base, gcvisit_func gc_
memset(&tp_name, 0, (char*)(&tp_version_tag + 1) - (char*)(&tp_name));
tp_basicsize = instance_size;
tp_flags |= Py_TPFLAGS_HEAPTYPE;
if (metaclass == NULL) {
assert(type_cls == NULL);
} else {
......
......@@ -607,31 +607,27 @@ extern "C" int PySlice_GetIndicesEx(PySliceObject* r, Py_ssize_t length, Py_ssiz
}
Box* typeRepr(BoxedClass* self) {
if (isUserDefined(self)) {
std::ostringstream os;
std::ostringstream os;
if ((self->tp_flags & Py_TPFLAGS_HEAPTYPE) && isUserDefined(self))
os << "<class '";
else
os << "<type '";
Box* m = self->getattr("__module__");
RELEASE_ASSERT(m, "");
if (m->cls == str_cls) {
BoxedString* sm = static_cast<BoxedString*>(m);
os << sm->s << '.';
}
Box* m = self->getattr("__module__");
if (m && m->cls == str_cls) {
BoxedString* sm = static_cast<BoxedString*>(m);
os << sm->s << '.';
}
Box* n = self->getattr("__name__");
RELEASE_ASSERT(n, "");
RELEASE_ASSERT(n->cls == str_cls, "should have prevented you from setting __name__ to non-string");
BoxedString* sn = static_cast<BoxedString*>(n);
os << sn->s;
Box* n = self->getattr("__name__");
RELEASE_ASSERT(n, "");
RELEASE_ASSERT(n->cls == str_cls, "should have prevented you from setting __name__ to non-string");
BoxedString* sn = static_cast<BoxedString*>(n);
os << sn->s;
os << "'>";
os << "'>";
return boxString(os.str());
} else {
char buf[80];
snprintf(buf, 80, "<type '%s'>", getNameOfClass(self)->c_str());
return boxStrConstant(buf);
}
return boxString(os.str());
}
Box* typeHash(BoxedClass* self) {
......
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