pock: Probe for the fixnum width by enquiring the largest fixnum value.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 22 Oct 2019 11:16:37 +0000 (12:16 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Mon, 25 Nov 2019 17:43:08 +0000 (17:43 +0000)
Python 3 doesn't distinguish fixnums from bignums at the type level, so
this would run forever.  Instead, get (a guess at) the largest fixnum
value, and use that.

pock

diff --git a/pock b/pock
index 377b811..7112530 100644 (file)
--- a/pock
+++ b/pock
@@ -218,8 +218,10 @@ class Sieve (object):
 
   ## Figure out the number of bits in a (nonnegative) primitive `int'.  We'll
   ## use a list of these as our sieve.
+  try: _MAX = SYS.maxint
+  except AttributeError: _MAX = SYS.maxsize
   _NBIT = 15
-  while type(1 << (_NBIT + 1)) == int: _NBIT += 1
+  while 1 << (_NBIT + 1) < _MAX: _NBIT += 1
 
   def __init__(me, limit):
     """