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