From 6417cf14b19ba9692e283a2ed8cb6b00043d7f5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Tue, 26 Aug 2014 10:47:22 +0200 Subject: [PATCH] python3Packages.BTrees: fix build on i686-linux --- .../btrees_interger_overflow.patch | 146 ++++++++++++++++++ pkgs/top-level/python-packages.nix | 2 + 2 files changed, 148 insertions(+) create mode 100644 pkgs/development/python-modules/btrees_interger_overflow.patch diff --git a/pkgs/development/python-modules/btrees_interger_overflow.patch b/pkgs/development/python-modules/btrees_interger_overflow.patch new file mode 100644 index 000000000000..a05c7bd6b3cb --- /dev/null +++ b/pkgs/development/python-modules/btrees_interger_overflow.patch @@ -0,0 +1,146 @@ +From be19c1f32e4d430092c029f17984f0087a2b2087 Mon Sep 17 00:00:00 2001 +From: Jim Fulton +Date: Mon, 19 May 2014 19:52:43 -0400 +Subject: [PATCH 1/2] Fixed: integer overflow on 32-bit machines wasn't + detected correctly under Python 3. + +--- + BTrees/intkeymacros.h | 7 ++++--- + BTrees/intvaluemacros.h | 3 ++- + BTrees/tests/testBTrees.py | 11 +++++++++-- + BTrees/tests/test_IIBTree.py | 2 ++ + CHANGES.rst | 2 ++ + 5 files changed, 19 insertions(+), 6 deletions(-) + +diff --git a/BTrees/intkeymacros.h b/BTrees/intkeymacros.h +index d439aa0..f9244b5 100644 +--- a/BTrees/intkeymacros.h ++++ b/BTrees/intkeymacros.h +@@ -19,9 +19,10 @@ + #define KEY_CHECK INT_CHECK + #define COPY_KEY_TO_OBJECT(O, K) O=INT_FROM_LONG(K) + #define COPY_KEY_FROM_ARG(TARGET, ARG, STATUS) \ +- if (INT_CHECK(ARG)) { \ +- long vcopy = INT_AS_LONG(ARG); \ +- if ((int)vcopy != vcopy) { \ ++ if (INT_CHECK(ARG)) { \ ++ long vcopy = INT_AS_LONG(ARG); \ ++ if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \ ++ else if ((int)vcopy != vcopy) { \ + PyErr_SetString(PyExc_TypeError, "integer out of range"); \ + (STATUS)=0; (TARGET)=0; \ + } \ +diff --git a/BTrees/intvaluemacros.h b/BTrees/intvaluemacros.h +index b77a5c9..3072eea 100644 +--- a/BTrees/intvaluemacros.h ++++ b/BTrees/intvaluemacros.h +@@ -23,7 +23,8 @@ + #define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \ + if (INT_CHECK(ARG)) { \ + long vcopy = INT_AS_LONG(ARG); \ +- if ((int)vcopy != vcopy) { \ ++ if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \ ++ else if ((int)vcopy != vcopy) { \ + PyErr_SetString(PyExc_TypeError, "integer out of range"); \ + (STATUS)=0; (TARGET)=0; \ + } \ +diff --git a/BTrees/tests/testBTrees.py b/BTrees/tests/testBTrees.py +index 50f5b43..31d641d 100644 +--- a/BTrees/tests/testBTrees.py ++++ b/BTrees/tests/testBTrees.py +@@ -11,8 +11,11 @@ + # FOR A PARTICULAR PURPOSE + # + ############################################################################## ++import sys + import unittest + ++python3 = sys.version_info >= (3, ) ++ + from BTrees.tests.common import permutations + + +@@ -451,8 +454,12 @@ def test32(self): + # the characteristics change to match the 64 bit version, please + # feel free to change. + big = BTrees.family32.maxint + 1 +- self.assertRaises(TypeError, s.insert, big) +- self.assertRaises(TypeError, s.insert, BTrees.family32.minint - 1) ++ if python3: ++ expected_exception = OverflowError ++ else: ++ expected_exception = TypeError ++ self.assertRaises(expected_exception, s.insert, ++ BTrees.family32.minint - 1) + self.check_pickling(BTrees.family32) + + def test64(self): +diff --git a/BTrees/tests/test_IIBTree.py b/BTrees/tests/test_IIBTree.py +index 72e95b2..fe776b8 100644 +--- a/BTrees/tests/test_IIBTree.py ++++ b/BTrees/tests/test_IIBTree.py +@@ -113,6 +113,8 @@ def trial(i): + i = int(i) + try: + b[i] = 0 ++ except OverflowError: ++ self.assertRaises(OverflowError, b.__setitem__, 0, i) + except TypeError: + self.assertRaises(TypeError, b.__setitem__, 0, i) + else: +diff --git a/CHANGES.rst b/CHANGES.rst +index 4696be3..e3869ff 100644 +--- a/CHANGES.rst ++++ b/CHANGES.rst +@@ -1,6 +1,8 @@ + ``BTrees`` Changelog + ==================== + ++- Fixed: integer overflow on 32-bit machines wasn't detected correctly ++ under Python 3. + + 4.0.9 (unreleased) + ------------------ +-- +2.0.4 + + +From 11a51d2a12bb9904e96349ff86e78e24a0ebe51a Mon Sep 17 00:00:00 2001 +From: Jim Fulton +Date: Wed, 21 May 2014 07:33:06 -0400 +Subject: [PATCH 2/2] added back test mistakedly removed. + +We have to check both TypeError and OverflowError. On Python3 32-bit, +we'll get an OverflowError, otherwise, we get type error. +--- + BTrees/tests/testBTrees.py | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + +diff --git a/BTrees/tests/testBTrees.py b/BTrees/tests/testBTrees.py +index 31d641d..d9be43a 100644 +--- a/BTrees/tests/testBTrees.py ++++ b/BTrees/tests/testBTrees.py +@@ -453,13 +453,13 @@ def test32(self): + # this next bit illustrates an, um, "interesting feature". If + # the characteristics change to match the 64 bit version, please + # feel free to change. +- big = BTrees.family32.maxint + 1 +- if python3: +- expected_exception = OverflowError +- else: +- expected_exception = TypeError +- self.assertRaises(expected_exception, s.insert, +- BTrees.family32.minint - 1) ++ try: s.insert(BTrees.family32.maxint + 1) ++ except (TypeError, OverflowError): pass ++ else: self.assert_(False) ++ ++ try: s.insert(BTrees.family32.minint - 1) ++ except (TypeError, OverflowError): pass ++ else: self.assert_(False) + self.check_pickling(BTrees.family32) + + def test64(self): +-- +2.0.4 + diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 47bea95ef019..e41a9cf210f7 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -9039,6 +9039,8 @@ rec { BTrees = pythonPackages.buildPythonPackage rec { name = "BTrees-4.0.8"; + + patches = [ ./../development/python-modules/btrees_interger_overflow.patch ]; propagatedBuildInputs = [ persistent zope_interface transaction ];