From d1b05672d94d95fd2dfe2fc048017ead66f3eace Mon Sep 17 00:00:00 2001 From: Sverker Nilsson <sn@sncs.se> Date: Tue, 8 Jun 2010 17:17:00 +0000 Subject: [PATCH 2/2] Preliminary changes to cope with Python version 2.7; seems to work but is slower (10 times so in test ClassificationCase) git-svn-id: https://guppy-pe.svn.sourceforge.net/svnroot/guppy-pe/trunk/guppy@87 a2a17790-8729-0410-921b-93eeb8b3d4a2 modification for python 2.7 git-svn-id: https://guppy-pe.svn.sourceforge.net/svnroot/guppy-pe/trunk/guppy@88 a2a17790-8729-0410-921b-93eeb8b3d4a2 --- guppy/heapy/test/test_Part.py | 14 +++++++++++--- guppy/sets/test.py | 2 +- src/sets/bitset.c | 21 +++++++++++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/guppy/heapy/test/test_Part.py b/guppy/heapy/test/test_Part.py index 278a3fb..d8c2784 100644 --- a/guppy/heapy/test/test_Part.py +++ b/guppy/heapy/test/test_Part.py @@ -88,16 +88,24 @@ Set of 100 <float> objects. Total size = 1600 bytes. class MixedCase(support.TestCase): def test_1(self): + import sys x = self.iso(1, 2, 1.0, 2.0, '1', '2') if self.allocation_behaves_as_originally: - self.aseq(str(x), """\ + if sys.version < '2.7': + self.aseq(str(x), """\ Partition of a set of 6 objects. Total size = 112 bytes. Index Count % Size % Cumulative % Kind (class / dict of class) 0 2 33 56 50 56 50 str 1 2 33 32 29 88 79 float 2 2 33 24 21 112 100 int""") - - + else: + self.aseq(str(x), """\ +Partition of a set of 6 objects. Total size = 104 bytes. + Index Count % Size % Cumulative % Kind (class / dict of class) + 0 2 33 48 46 48 46 str + 1 2 33 32 31 80 77 float + 2 2 33 24 23 104 100 int""") + for row in x.partition.get_rows(): self.assert_(row.set <= row.kind) diff --git a/guppy/sets/test.py b/guppy/sets/test.py index c6ae676..1afcbdf 100644 --- a/guppy/sets/test.py +++ b/guppy/sets/test.py @@ -892,7 +892,7 @@ MutBitSet([]) except OverflowError: pass else: - raise 'expected ValueError' + raise 'expected OverflowError' tsv(bitset([maxint]), 1) tsv(bitset([minint]), -1) diff --git a/src/sets/bitset.c b/src/sets/bitset.c index 2a9d6c0..9ef46ab 100644 --- a/src/sets/bitset.c +++ b/src/sets/bitset.c @@ -2017,7 +2017,11 @@ mutbitset_iop_PyLongObject(NyMutBitSetObject *ms, int op, PyObject *v) int cpl = 0; PyObject *w = 0; - x = _PyLong_AsScaledDouble(v, &e); +#if PY_VERSION_HEX >= 0x02070000 + x = _PyLong_Frexp(v, &e); +#else + x = _PyLong_AsScaledDouble(v, &e); +#endif if (x == -1 && PyErr_Occurred()) return -1; if (x < 0) { @@ -2026,15 +2030,24 @@ mutbitset_iop_PyLongObject(NyMutBitSetObject *ms, int op, PyObject *v) w = PyNumber_Invert(v); if (!w) return -1; v = w; +#if PY_VERSION_HEX >= 0x02070000 + x = _PyLong_Frexp(v, &e); +#else x = _PyLong_AsScaledDouble(v, &e); +#endif if (x == -1 && PyErr_Occurred()) return -1; assert(x >= 0); } - if (x != 0) - num_bits = 1.0 * e * SHIFT + log(x)/log(2) + 1; + if (x != 0) { + num_bits = e; +#if PY_VERSION_HEX < 0x02070000 + num_bits *= SHIFT; +#endif + num_bits += log(x)/log(2) + 1; + } else - num_bits = 0; + num_bits = 0; num_poses = (long)(num_bits / NyBits_N + 1); /* fprintf(stderr, "x %f e %d num_bits %f num_poses %ld\n", x, e, num_bits, num_poses); */ -- 1.7.4