Commit 916a2dcf authored by Marius Wachtler's avatar Marius Wachtler

Merge commit '2a3b70eb' into refcounting

parents 73ab425f 2a3b70eb
...@@ -491,7 +491,7 @@ extern "C" Box* intAdd(BoxedInt* lhs, Box* rhs) { ...@@ -491,7 +491,7 @@ extern "C" Box* intAdd(BoxedInt* lhs, Box* rhs) {
if (PyInt_Check(rhs)) { if (PyInt_Check(rhs)) {
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return add_i64_i64(lhs->n, rhs_int->n); return add_i64_i64(lhs->n, rhs_int->n);
} else if (PyFloat_Check(rhs)) { } else if (PyFloat_CheckExact(rhs)) {
BoxedFloat* rhs_float = static_cast<BoxedFloat*>(rhs); BoxedFloat* rhs_float = static_cast<BoxedFloat*>(rhs);
return boxFloat(lhs->n + rhs_float->d); return boxFloat(lhs->n + rhs_float->d);
} else { } else {
...@@ -620,7 +620,7 @@ extern "C" Box* intDiv(BoxedInt* lhs, Box* rhs) { ...@@ -620,7 +620,7 @@ extern "C" Box* intDiv(BoxedInt* lhs, Box* rhs) {
if (PyInt_Check(rhs)) { if (PyInt_Check(rhs)) {
return intDivInt(lhs, static_cast<BoxedInt*>(rhs)); return intDivInt(lhs, static_cast<BoxedInt*>(rhs));
} else if (PyFloat_Check(rhs)) { } else if (PyFloat_CheckExact(rhs)) {
return intDivFloat(lhs, static_cast<BoxedFloat*>(rhs)); return intDivFloat(lhs, static_cast<BoxedFloat*>(rhs));
} else { } else {
return incref(NotImplemented); return incref(NotImplemented);
...@@ -662,7 +662,7 @@ extern "C" Box* intFloordiv(BoxedInt* lhs, Box* rhs) { ...@@ -662,7 +662,7 @@ extern "C" Box* intFloordiv(BoxedInt* lhs, Box* rhs) {
if (PyInt_Check(rhs)) { if (PyInt_Check(rhs)) {
return intFloordivInt(lhs, static_cast<BoxedInt*>(rhs)); return intFloordivInt(lhs, static_cast<BoxedInt*>(rhs));
} else if (PyFloat_Check(rhs)) { } else if (PyFloat_CheckExact(rhs)) {
return intFloordivFloat(lhs, static_cast<BoxedFloat*>(rhs)); return intFloordivFloat(lhs, static_cast<BoxedFloat*>(rhs));
} else { } else {
return incref(NotImplemented); return incref(NotImplemented);
...@@ -708,7 +708,7 @@ extern "C" Box* intTruediv(BoxedInt* lhs, Box* rhs) { ...@@ -708,7 +708,7 @@ extern "C" Box* intTruediv(BoxedInt* lhs, Box* rhs) {
if (PyInt_Check(rhs)) { if (PyInt_Check(rhs)) {
return intTruedivInt(lhs, static_cast<BoxedInt*>(rhs)); return intTruedivInt(lhs, static_cast<BoxedInt*>(rhs));
} else if (PyFloat_Check(rhs)) { } else if (PyFloat_CheckExact(rhs)) {
return intTruedivFloat(lhs, static_cast<BoxedFloat*>(rhs)); return intTruedivFloat(lhs, static_cast<BoxedFloat*>(rhs));
} else { } else {
return incref(NotImplemented); return incref(NotImplemented);
...@@ -855,7 +855,7 @@ extern "C" Box* intMul(BoxedInt* lhs, Box* rhs) { ...@@ -855,7 +855,7 @@ extern "C" Box* intMul(BoxedInt* lhs, Box* rhs) {
if (PyInt_Check(rhs)) { if (PyInt_Check(rhs)) {
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return intMulInt(lhs, rhs_int); return intMulInt(lhs, rhs_int);
} else if (PyFloat_Check(rhs)) { } else if (PyFloat_CheckExact(rhs)) {
BoxedFloat* rhs_float = static_cast<BoxedFloat*>(rhs); BoxedFloat* rhs_float = static_cast<BoxedFloat*>(rhs);
return intMulFloat(lhs, rhs_float); return intMulFloat(lhs, rhs_float);
} else { } else {
...@@ -907,7 +907,7 @@ extern "C" Box* intPow(BoxedInt* lhs, Box* rhs, Box* mod) { ...@@ -907,7 +907,7 @@ extern "C" Box* intPow(BoxedInt* lhs, Box* rhs, Box* mod) {
if (PyLong_Check(rhs)) if (PyLong_Check(rhs))
return intPowLong(lhs, static_cast<BoxedLong*>(rhs), mod); return intPowLong(lhs, static_cast<BoxedLong*>(rhs), mod);
else if (PyFloat_Check(rhs)) else if (PyFloat_CheckExact(rhs))
return intPowFloat(lhs, static_cast<BoxedFloat*>(rhs), mod); return intPowFloat(lhs, static_cast<BoxedFloat*>(rhs), mod);
else if (!PyInt_Check(rhs)) else if (!PyInt_Check(rhs))
return incref(NotImplemented); return incref(NotImplemented);
...@@ -1002,7 +1002,7 @@ extern "C" Box* intSub(BoxedInt* lhs, Box* rhs) { ...@@ -1002,7 +1002,7 @@ extern "C" Box* intSub(BoxedInt* lhs, Box* rhs) {
if (PyInt_Check(rhs)) { if (PyInt_Check(rhs)) {
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs); BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return intSubInt(lhs, rhs_int); return intSubInt(lhs, rhs_int);
} else if (PyFloat_Check(rhs)) { } else if (PyFloat_CheckExact(rhs)) {
BoxedFloat* rhs_float = static_cast<BoxedFloat*>(rhs); BoxedFloat* rhs_float = static_cast<BoxedFloat*>(rhs);
return intSubFloat(lhs, rhs_float); return intSubFloat(lhs, rhs_float);
} else { } else {
......
...@@ -141,3 +141,35 @@ for x in data: ...@@ -141,3 +141,35 @@ for x in data:
arg2=y))) arg2=y)))
except Exception as e: except Exception as e:
print(e.message) print(e.message)
class Foo1(float):
def __rdiv__(self, other):
print("float custom operation called")
return self / other
class Foo2(long):
def __rdiv__(self, other):
print("long custom operation called")
return self / other
class Foo3(int):
def __rdiv__(self, other):
print("int custom operation called")
return self / other
a = Foo1(1.5)
b = Foo2(1L)
c = Foo3(1)
print(1.5 / a)
print(1.5 / b)
print(1.5 / c)
print(1 / a)
print(1 / b)
print(1 / c)
print(1L / a)
print(1L / b)
print(1L / c)
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