Skip to content

Commit

Permalink
The value macros for ints also need to convert OverflowError into Typ…
Browse files Browse the repository at this point in the history
…eError.

This only showed up on Windows (because it follows the LLP64 data model). See https://ci.appveyor.com/project/mgedmin/btrees/builds/31998447/job/m3xs7q1d8b4u5u3b
  • Loading branch information
jamadden committed Apr 7, 2020
1 parent d7d826a commit 5f9ce95
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
16 changes: 14 additions & 2 deletions BTrees/intvaluemacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@
#define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \
if (INT_CHECK(ARG)) { \
long vcopy = INT_AS_LONG(ARG); \
if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \
if (PyErr_Occurred()) { \
if (PyErr_ExceptionMatches(PyExc_OverflowError)) { \
PyErr_Clear(); \
PyErr_SetString(PyExc_TypeError, "integer out of range"); \
} \
(STATUS)=0; (TARGET)=0; \
} \
else if ((int)vcopy != vcopy) { \
PyErr_SetString(PyExc_TypeError, "integer out of range"); \
(STATUS)=0; (TARGET)=0; \
Expand Down Expand Up @@ -62,7 +68,13 @@
#define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \
if (INT_CHECK(ARG)) { \
long vcopy = INT_AS_LONG(ARG); \
if (PyErr_Occurred()) { (STATUS)=0; (TARGET)=0; } \
if (PyErr_Occurred()) { \
if (PyErr_ExceptionMatches(PyExc_OverflowError)) { \
PyErr_Clear(); \
PyErr_SetString(PyExc_TypeError, "integer out of range"); \
} \
(STATUS)=0; (TARGET)=0; \
} \
else if (vcopy < 0) { \
PyErr_SetString(PyExc_TypeError, "can't convert negative value to unsigned int"); \
(STATUS)=0; (TARGET)=0; \
Expand Down
16 changes: 8 additions & 8 deletions BTrees/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class NonSub(object):
self.assertFalse(issubclass(NonSub, type(t)))
self.assertFalse(isinstance(NonSub(), type(t)))

class MappingBase(Base):
class MappingBase(Base): # pylint:disable=too-many-public-methods
# Tests common to mappings (buckets, btrees)
SUPPORTS_NEGATIVE_VALUES = True

Expand Down Expand Up @@ -722,7 +722,7 @@ def testEmptyRangeSearches(self):
self.assertEqual(list(keys), [])
self.assertEqual(list(t.iterkeys(max=50, min=200)), [])

def testSlicing(self):
def testSlicing(self): # pylint:disable=too-many-locals
# Test that slicing of .keys()/.values()/.items() works exactly the
# same way as slicing a Python list with the same contents.
# This tests fixes to several bugs in this area, starting with
Expand Down Expand Up @@ -832,7 +832,7 @@ def testIterators(self):
self.assertEqual(list(t.iteritems()), list(t.items()))

@uses_negative_keys_and_values
def testRangedIterators(self):
def testRangedIterators(self): # pylint:disable=too-many-locals
t = self._makeOne()

for keys in [], [-2], [1, 4], list(range(-170, 2000, 13)):
Expand Down Expand Up @@ -1074,7 +1074,6 @@ def testKeyAndValueOverflow(self):
self.skipTest("Needs bounded key and value")

import struct
from .._compat import PY2

good = set()
b = self._makeOne()
Expand Down Expand Up @@ -1995,7 +1994,7 @@ class ModuleTest(object):
key_type = None
value_type = None
def _getModule(self):
pass
raise NotImplementedError

def testNames(self):
names = ['Bucket', 'BTree', 'Set', 'TreeSet']
Expand Down Expand Up @@ -2223,8 +2222,8 @@ def setUp(self):
super(SetResult, self).setUp()
_skip_if_pure_py_and_py_test(self)

self.Akeys = [1, 3, 5, 6]
self.Bkeys = [ 2, 3, 4, 6, 7]
self.Akeys = [1, 3, 5, 6] # pylint:disable=bad-whitespace
self.Bkeys = [ 2, 3, 4, 6, 7] # pylint:disable=bad-whitespace
self.As = [makeset(self.Akeys) for makeset in self.builders()]
self.Bs = [makeset(self.Bkeys) for makeset in self.builders()]
self.emptys = [makeset() for makeset in self.builders()]
Expand Down Expand Up @@ -2336,7 +2335,7 @@ def testDifference(self):
else:
self.assertEqual(list(C), want)

def testLargerInputs(self):
def testLargerInputs(self): # pylint:disable=too-many-locals
from BTrees.IIBTree import IISet # pylint:disable=no-name-in-module
from random import randint
MAXSIZE = 200
Expand Down Expand Up @@ -2592,6 +2591,7 @@ class ConflictTestBase(SignedMixin, object):
# Tests common to all types: sets, buckets, and BTrees

storage = None
db = None

def setUp(self):
super(ConflictTestBase, self).setUp()
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
expected. See `issue 140
<https://github.com/zopefoundation/BTrees/issues/140>`_.

.. note::
The unspecified true return values of ``has_key``
have changed.


4.7.1 (2020-03-22)
==================
Expand Down

0 comments on commit 5f9ce95

Please sign in to comment.