Commit e9152be5 authored by Marius Wachtler's avatar Marius Wachtler

Merge pull request #1062 from undingen/minor_compat3

Fix minor compatibility issues
parents b0991a74 9dec82ed
......@@ -217,7 +217,7 @@ 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->data()[0] == '_' && attr->data()[1] == '_') {
if (attr->s() == "__dict__")
return cls->getAttrWrapper();
......@@ -448,7 +448,7 @@ static Box* _instanceGetattribute(Box* _inst, BoxedString* attr_str, bool raise_
BoxedInstance* inst = static_cast<BoxedInstance*>(_inst);
// These are special cases in CPython as well:
if (attr_str->s()[0] == '_' && attr_str->s()[1] == '_') {
if (attr_str->data()[0] == '_' && attr_str->data()[1] == '_') {
if (attr_str->s() == "__dict__")
return inst->getAttrWrapper();
......@@ -510,7 +510,7 @@ Box* instanceSetattroInternal(Box* _inst, Box* _attr, Box* value, SetattrRewrite
assert(value);
// These are special cases in CPython as well:
if (attr->s()[0] == '_' && attr->s()[1] == '_') {
if (attr->data()[0] == '_' && attr->data()[1] == '_') {
if (attr->s() == "__dict__")
Py_FatalError("unimplemented");
......@@ -571,7 +571,7 @@ 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->data()[0] == '_' && attr->data()[1] == '_') {
if (attr->s() == "__dict__")
raiseExcHelper(TypeError, "__dict__ must be set to a dictionary");
......
......@@ -1129,7 +1129,7 @@ template <ExceptionStyle S> static Box* _intNew(Box* val, Box* _base) noexcept(S
return NULL;
}
if (val == None) {
if (val == NULL) {
PyErr_SetString(PyExc_TypeError, "int() missing string argument");
return NULL;
}
......@@ -1142,7 +1142,7 @@ template <ExceptionStyle S> static Box* _intNew(Box* val, Box* _base) noexcept(S
if (!PyInt_Check(_base))
raiseExcHelper(TypeError, "an integer is required");
if (val == None)
if (val == NULL)
raiseExcHelper(TypeError, "int() missing string argument");
if (!PyString_Check(val) && !PyUnicode_Check(val))
......@@ -1150,7 +1150,7 @@ template <ExceptionStyle S> static Box* _intNew(Box* val, Box* _base) noexcept(S
}
base = static_cast<BoxedInt*>(_base)->n;
} else {
if (val == None)
if (val == NULL)
return PyInt_FromLong(0L);
Box* r = PyNumber_Int(val);
......@@ -1441,7 +1441,7 @@ void setupInt() {
auto int_new = FunctionMetadata::create((void*)intNew<CXX>, UNKNOWN, 3, false, false,
ParamNames({ "", "x", "base" }, "", ""), CXX);
int_new->addVersion((void*)intNew<CAPI>, UNKNOWN, CAPI);
int_cls->giveAttr("__new__", new BoxedFunction(int_new, { None, NULL }));
int_cls->giveAttr("__new__", new BoxedFunction(int_new, { NULL, NULL }));
int_cls->giveAttr("bit_length", new BoxedFunction(FunctionMetadata::create((void*)intBitLength, BOXED_INT, 1)));
......
......@@ -783,6 +783,11 @@ Box* listIAdd(BoxedList* self, Box* _rhs) {
return self;
}
Box* listExtend(BoxedList* self, Box* _rhs) {
listIAdd(self, _rhs);
return None;
}
Box* listAdd(BoxedList* self, Box* _rhs) {
if (!PyList_Check(_rhs)) {
return NotImplemented;
......@@ -1344,7 +1349,7 @@ void setupList() {
new BoxedFunction(FunctionMetadata::create((void*)listPop, UNKNOWN, 2, false, false), { None }));
list_cls->giveAttr("append", new BoxedFunction(FunctionMetadata::create((void*)listAppend, NONE, 2)));
list_cls->giveAttr("extend", new BoxedFunction(FunctionMetadata::create((void*)listIAdd, UNKNOWN, 2)));
list_cls->giveAttr("extend", new BoxedFunction(FunctionMetadata::create((void*)listExtend, NONE, 2)));
list_cls->giveAttr("insert", new BoxedFunction(FunctionMetadata::create((void*)listInsert, NONE, 3)));
list_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)listMul, UNKNOWN, 2)));
......
......@@ -63,6 +63,10 @@ print type(int(2**100))
print type(int(2L))
print type(int.__new__(int, 2**100))
print type(int.__new__(int, 2L))
try:
print int(None)
except TypeError, e:
print e
try:
print type(int.__new__(C, 2**100))
except OverflowError, e:
......
......@@ -85,7 +85,7 @@ while l:
del l[0]
l = range(5)
l.extend(range(5))
print l.extend(range(5))
print l
# Repeating a list
......
......@@ -511,3 +511,19 @@ for i in range(500):
if i == 150:
C.__bases__ = tuple()
print s1, s2
# we used to have problems with this
for i in range(2):
try:
C._
except AttributeError, e:
print e
try:
C()._
except AttributeError, e:
print e
try:
print C()._()
except AttributeError, e:
print e
C._ = (lambda s: 42)
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