From 57c3abba8b09fdb3f9fc2ddccaf5efce3edace31 Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Fri, 7 Jan 2011 17:39:18 -0200 Subject: Fix bug#530 - "Importing division from future breaks QPoint division" Reviewer: Marcelo Lira Lauro Moura --- generator/cppgenerator.cpp | 2 +- tests/libsample/point.cpp | 6 ++++++ tests/libsample/point.h | 1 + tests/samplebinding/newdivision_test.py | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/samplebinding/newdivision_test.py diff --git a/generator/cppgenerator.cpp b/generator/cppgenerator.cpp index 18e9d0b22..26809edc0 100644 --- a/generator/cppgenerator.cpp +++ b/generator/cppgenerator.cpp @@ -2659,7 +2659,7 @@ void CppGenerator::writeTypeAsNumberDefinition(QTextStream& s, const AbstractMet s << INDENT << "/*nb_inplace_xor*/ (binaryfunc)" << nb["__ixor__"] << ',' << endl; s << INDENT << "/*nb_inplace_or*/ (binaryfunc)" << nb["__ior__"] << ',' << endl; s << INDENT << "/*nb_floor_divide*/ 0," << endl; - s << INDENT << "/*nb_true_divide*/ 0," << endl; + s << INDENT << "/*nb_true_divide*/ (binaryfunc)" << nb["__div__"] << ',' << endl; s << INDENT << "/*nb_inplace_floor_divide*/ 0," << endl; s << INDENT << "/*nb_inplace_true_divide*/ 0," << endl; s << INDENT << "/*nb_index*/ 0" << endl; diff --git a/tests/libsample/point.cpp b/tests/libsample/point.cpp index b8d310cfe..484e7c11c 100644 --- a/tests/libsample/point.cpp +++ b/tests/libsample/point.cpp @@ -118,6 +118,12 @@ operator!(const Point& pt) return (pt.m_x == 0.0 && pt.m_y == 0.0); } +Point +Point::operator/(int operand) +{ + return Point(m_x/operand, m_y/operand); +} + Complex transmutePointIntoComplex(const Point& point) { diff --git a/tests/libsample/point.h b/tests/libsample/point.h index 5c1e19a25..cc7a1bc5a 100644 --- a/tests/libsample/point.h +++ b/tests/libsample/point.h @@ -54,6 +54,7 @@ public: Point operator+(const Point& other); Point operator-(const Point& other); + Point operator/(int operand); friend LIBSAMPLE_API Point operator*(const Point& pt, double mult); friend LIBSAMPLE_API Point operator*(const Point& pt, int mult); diff --git a/tests/samplebinding/newdivision_test.py b/tests/samplebinding/newdivision_test.py new file mode 100644 index 000000000..fbaeeab1b --- /dev/null +++ b/tests/samplebinding/newdivision_test.py @@ -0,0 +1,14 @@ +from __future__ import division +from sample import * +import unittest + +class TestNewDivision(unittest.TestCase): + + def testIt(self): + p = Point(4, 4) + p2 = p/2 + self.assertEqual(p2, Point(2, 2)) + +if __name__ == "__main__": + unittest.main() + -- cgit v1.2.3