Commit 4e1ee699 authored by Kevin Modzelewski's avatar Kevin Modzelewski

sys.maxunicode, int subcls ops, set.issuperclass(non-set)

parent cc3a1cc3
...@@ -474,6 +474,11 @@ void setupSys() { ...@@ -474,6 +474,11 @@ void setupSys() {
ADD(optimize); ADD(optimize);
#undef ADD #undef ADD
#define SET_SYS_FROM_STRING(key, value) sys_module->giveAttr((key), (value))
#ifdef Py_USING_UNICODE
SET_SYS_FROM_STRING("maxunicode", PyInt_FromLong(PyUnicode_GetMax()));
#endif
sys_flags_cls->tp_mro = BoxedTuple::create({ sys_flags_cls, object_cls }); sys_flags_cls->tp_mro = BoxedTuple::create({ sys_flags_cls, object_cls });
sys_flags_cls->freeze(); sys_flags_cls->freeze();
......
...@@ -428,7 +428,7 @@ extern "C" Box* intAnd(BoxedInt* lhs, Box* rhs) { ...@@ -428,7 +428,7 @@ extern "C" Box* intAnd(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls)) if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__and__' requires a 'int' object but received a '%s'", getTypeName(lhs)); raiseExcHelper(TypeError, "descriptor '__and__' requires a 'int' object but received a '%s'", getTypeName(lhs));
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
...@@ -445,7 +445,7 @@ extern "C" Box* intOr(BoxedInt* lhs, Box* rhs) { ...@@ -445,7 +445,7 @@ extern "C" Box* intOr(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls)) if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__or__' requires a 'int' object but received a '%s'", getTypeName(lhs)); raiseExcHelper(TypeError, "descriptor '__or__' requires a 'int' object but received a '%s'", getTypeName(lhs));
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
...@@ -462,7 +462,7 @@ extern "C" Box* intXor(BoxedInt* lhs, Box* rhs) { ...@@ -462,7 +462,7 @@ extern "C" Box* intXor(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls)) if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__xor__' requires a 'int' object but received a '%s'", getTypeName(lhs)); raiseExcHelper(TypeError, "descriptor '__xor__' requires a 'int' object but received a '%s'", getTypeName(lhs));
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
...@@ -590,7 +590,7 @@ extern "C" Box* intNe(BoxedInt* lhs, Box* rhs) { ...@@ -590,7 +590,7 @@ extern "C" Box* intNe(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls)) if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__ne__' requires a 'int' object but received a '%s'", getTypeName(lhs)); raiseExcHelper(TypeError, "descriptor '__ne__' requires a 'int' object but received a '%s'", getTypeName(lhs));
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
...@@ -607,7 +607,7 @@ extern "C" Box* intLt(BoxedInt* lhs, Box* rhs) { ...@@ -607,7 +607,7 @@ extern "C" Box* intLt(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls)) if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__lt__' requires a 'int' object but received a '%s'", getTypeName(lhs)); raiseExcHelper(TypeError, "descriptor '__lt__' requires a 'int' object but received a '%s'", getTypeName(lhs));
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
...@@ -624,7 +624,7 @@ extern "C" Box* intLe(BoxedInt* lhs, Box* rhs) { ...@@ -624,7 +624,7 @@ extern "C" Box* intLe(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls)) if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__le__' requires a 'int' object but received a '%s'", getTypeName(lhs)); raiseExcHelper(TypeError, "descriptor '__le__' requires a 'int' object but received a '%s'", getTypeName(lhs));
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
...@@ -641,7 +641,7 @@ extern "C" Box* intGt(BoxedInt* lhs, Box* rhs) { ...@@ -641,7 +641,7 @@ extern "C" Box* intGt(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls)) if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__gt__' requires a 'int' object but received a '%s'", getTypeName(lhs)); raiseExcHelper(TypeError, "descriptor '__gt__' requires a 'int' object but received a '%s'", getTypeName(lhs));
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
...@@ -658,7 +658,7 @@ extern "C" Box* intGe(BoxedInt* lhs, Box* rhs) { ...@@ -658,7 +658,7 @@ extern "C" Box* intGe(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls)) if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__ge__' requires a 'int' object but received a '%s'", getTypeName(lhs)); raiseExcHelper(TypeError, "descriptor '__ge__' requires a 'int' object but received a '%s'", getTypeName(lhs));
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
...@@ -689,7 +689,7 @@ extern "C" Box* intLShift(BoxedInt* lhs, Box* rhs) { ...@@ -689,7 +689,7 @@ extern "C" Box* intLShift(BoxedInt* lhs, Box* rhs) {
if (rhs->cls == long_cls) if (rhs->cls == long_cls)
return longLshift(boxLong(lhs->n), rhs); return longLshift(boxLong(lhs->n), rhs);
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
...@@ -706,7 +706,7 @@ extern "C" Box* intMod(BoxedInt* lhs, Box* rhs) { ...@@ -706,7 +706,7 @@ extern "C" Box* intMod(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls)) if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__mod__' requires a 'int' object but received a '%s'", getTypeName(lhs)); raiseExcHelper(TypeError, "descriptor '__mod__' requires a 'int' object but received a '%s'", getTypeName(lhs));
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
...@@ -812,7 +812,7 @@ extern "C" Box* intRShift(BoxedInt* lhs, Box* rhs) { ...@@ -812,7 +812,7 @@ extern "C" Box* intRShift(BoxedInt* lhs, Box* rhs) {
if (rhs->cls == long_cls) if (rhs->cls == long_cls)
return longRshift(boxLong(lhs->n), rhs); return longRshift(boxLong(lhs->n), rhs);
if (rhs->cls != int_cls) { if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented; return NotImplemented;
} }
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
......
...@@ -292,7 +292,11 @@ static BoxedSet* setIntersection2(BoxedSet* self, Box* container) { ...@@ -292,7 +292,11 @@ static BoxedSet* setIntersection2(BoxedSet* self, Box* container) {
static Box* setIssubset(BoxedSet* self, Box* container) { static Box* setIssubset(BoxedSet* self, Box* container) {
assert(self->cls == set_cls); assert(self->cls == set_cls);
RELEASE_ASSERT(container->cls == set_cls, "");
if (container->cls != set_cls && container->cls != frozenset_cls) {
container = setNew(set_cls, container);
}
assert(container->cls == set_cls || container->cls == frozenset_cls);
BoxedSet* rhs = static_cast<BoxedSet*>(container); BoxedSet* rhs = static_cast<BoxedSet*>(container);
for (auto e : self->s) { for (auto e : self->s) {
...@@ -304,7 +308,11 @@ static Box* setIssubset(BoxedSet* self, Box* container) { ...@@ -304,7 +308,11 @@ static Box* setIssubset(BoxedSet* self, Box* container) {
static Box* setIssuperset(BoxedSet* self, Box* container) { static Box* setIssuperset(BoxedSet* self, Box* container) {
assert(self->cls == set_cls); assert(self->cls == set_cls);
RELEASE_ASSERT(container->cls == set_cls, "");
if (container->cls != set_cls && container->cls != frozenset_cls) {
container = setNew(set_cls, container);
}
assert(container->cls == set_cls || container->cls == frozenset_cls);
BoxedSet* rhs = static_cast<BoxedSet*>(container); BoxedSet* rhs = static_cast<BoxedSet*>(container);
for (auto e : rhs->s) { for (auto e : rhs->s) {
......
...@@ -101,6 +101,9 @@ void raiseRaw(const ExcInfo& e) { ...@@ -101,6 +101,9 @@ void raiseRaw(const ExcInfo& e) {
assert(e.type); assert(e.type);
assert(e.value); assert(e.value);
assert(e.traceback); assert(e.traceback);
assert(gc::isValidGCObject(e.type));
assert(gc::isValidGCObject(e.value));
assert(gc::isValidGCObject(e.traceback));
// Using libgcc: // Using libgcc:
throw e; throw e;
......
...@@ -79,3 +79,11 @@ for b in range(26): ...@@ -79,3 +79,11 @@ for b in range(26):
print int(u'123', b) print int(u'123', b)
except ValueError as e: except ValueError as e:
print e print e
class I(int):
pass
for i1 in [1, I(2), 3, I(4)]:
for i2 in [1, I(2), 3, I(4)]:
print -i1, +i1, ~i1, i1 < i2, i1 <= i2, i1 == i2, i1 > i2, i1 >= i2, i1 != i2, i1 | i2, i1 ^ i2, i1 & i2, i1 * i2, i1 + i2, i1 / i2, i1 - i2, i1 ** i2, i1 // i2
...@@ -107,4 +107,4 @@ print s ...@@ -107,4 +107,4 @@ print s
s = set(range(5)) s = set(range(5))
for i in xrange(10): for i in xrange(10):
s2 = set(range(i)) s2 = set(range(i))
print s.issubset(s2), s.issuperset(s2), s == s2, s != s2, s.difference(s2) print s.issubset(s2), s.issuperset(s2), s == s2, s != s2, s.difference(s2), s.issubset(range(i)), s.issuperset(range(i))
...@@ -152,3 +152,6 @@ for m in str.strip, str.lstrip, str.rstrip: ...@@ -152,3 +152,6 @@ for m in str.strip, str.lstrip, str.rstrip:
print repr(m(s, *args)) print repr(m(s, *args))
print "".join([u"\xB2", u"\xB3"]) print "".join([u"\xB2", u"\xB3"])
import sys
print type(sys.maxunicode)
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