Commit d849bb93 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge commit '68b2ed' into refcounting

parents 1a949369 68b2ed7a
......@@ -717,9 +717,15 @@ extern "C" int PyList_Insert(PyObject* op, Py_ssize_t where, PyObject* newitem)
}
Box* listMul(BoxedList* self, Box* rhs) {
Py_ssize_t n = PyNumber_AsSsize_t(rhs, PyExc_IndexError);
if (n == -1 && PyErr_Occurred())
throwCAPIException();
Py_ssize_t n;
if (PyIndex_Check(rhs)) {
n = PyNumber_AsSsize_t(rhs, PyExc_OverflowError);
if (n == -1 && PyErr_Occurred())
throwCAPIException();
} else {
return incref(NotImplemented);
}
int s = self->size;
......@@ -739,9 +745,15 @@ Box* listMul(BoxedList* self, Box* rhs) {
}
Box* listImul(BoxedList* self, Box* rhs) {
Py_ssize_t n = PyNumber_AsSsize_t(rhs, PyExc_IndexError);
if (n == -1 && PyErr_Occurred())
throwCAPIException();
Py_ssize_t n;
if (PyIndex_Check(rhs)) {
n = PyNumber_AsSsize_t(rhs, PyExc_OverflowError);
if (n == -1 && PyErr_Occurred())
throwCAPIException();
} else {
return incref(NotImplemented);
}
int s = self->size;
......
......@@ -171,16 +171,7 @@ Box* tupleAdd(BoxedTuple* self, Box* rhs) {
return rtn;
}
Box* tupleMul(BoxedTuple* self, Box* rhs) {
Py_ssize_t n;
if (PyIndex_Check(rhs)) {
n = PyNumber_AsSsize_t(rhs, PyExc_OverflowError);
if (n == -1 && PyErr_Occurred())
throwCAPIException();
} else {
raiseExcHelper(TypeError, "can't multiply sequence by non-int of type '%s'", getTypeName(rhs));
}
Box* tupleMulInt(BoxedTuple* self, int n) {
int s = self->size();
if (n < 0)
......@@ -199,6 +190,19 @@ Box* tupleMul(BoxedTuple* self, Box* rhs) {
}
}
Box* tupleMul(BoxedTuple* self, Box* rhs) {
Py_ssize_t n;
if (PyIndex_Check(rhs)) {
n = PyNumber_AsSsize_t(rhs, PyExc_OverflowError);
if (n == -1 && PyErr_Occurred())
throwCAPIException();
return tupleMulInt(self, n);
} else {
return NotImplemented;
}
}
Box* tupleLen(BoxedTuple* t) {
assert(PyTuple_Check(t));
return boxInt(t->size());
......@@ -718,8 +722,8 @@ void setupTuple() {
// Return type is UNKNOWN as it could be NotImplemented.
tuple_cls->giveAttr("__add__", new BoxedFunction(FunctionMetadata::create((void*)tupleAdd, UNKNOWN, 2)));
tuple_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)tupleMul, BOXED_TUPLE, 2)));
tuple_cls->giveAttr("__rmul__", new BoxedFunction(FunctionMetadata::create((void*)tupleMul, BOXED_TUPLE, 2)));
tuple_cls->giveAttr("__mul__", new BoxedFunction(FunctionMetadata::create((void*)tupleMul, UNKNOWN, 2)));
tuple_cls->giveAttr("__rmul__", new BoxedFunction(FunctionMetadata::create((void*)tupleMul, UNKNOWN, 2)));
tuple_cls->giveAttr("__getnewargs__", new BoxedFunction(FunctionMetadata::create((void*)tuple_getnewargs, UNKNOWN,
1, ParamNames::empty(), CAPI)));
......
......@@ -219,3 +219,19 @@ try:
RaisingCmp() in [1, 2, 3]
except ZeroDivisionError as e:
print e
class D(object):
def __rmul__(self, other):
return other * 2
d = D()
try:
print([1, 2] * 3.5)
except TypeError as e:
print(type(e))
try:
print([1, 2] * d)
except TypeError as e:
print(type(e))
......@@ -239,3 +239,24 @@ class C(object):
def __repr__(self):
return repr(self.t)
print repr(C())
try:
(1, 2) + "a"
except TypeError as e:
print(type(e))
class D(object):
def __rmul__(self, other):
return other * 2
d = D()
try:
print((1, 2) * 3.5)
except TypeError as e:
print(type(e))
try:
print((1, 2) * d)
except TypeError as e:
print(e.message)
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