[Python-checkins] r64525 - in python/branches/tlee-ast-optimize: Doc/library/fractions.rst Include/object.h Lib/difflib.py Lib/multiprocessing/connection.py Lib/multiprocessing/dummy/__init__.py Lib/multiprocessing/managers.py Lib/multiprocessing/process.py Lib/test/test_builtin.py Lib/test/test_sys.py Misc/NEWS Objects/floatobject.c Objects/intobject.c Objects/longobject.c Objects/typeobject.c Python/bltinmodule.c

thomas.lee python-checkins at python.org
Wed Jun 25 15:47:29 CEST 2008


Author: thomas.lee
Date: Wed Jun 25 15:47:24 2008
New Revision: 64525

Log:
Merged revisions 64503-64524 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r64508 | mark.dickinson | 2008-06-25 01:35:14 +1000 (Wed, 25 Jun 2008) | 2 lines
  
  Remove references to Py3k in __floor__, __ceil__ and __round__ documentation.
........
  r64511 | raymond.hettinger | 2008-06-25 01:58:53 +1000 (Wed, 25 Jun 2008) | 1 line
  
  Issue 3189:  Py3k DeprecationWarning in difflib
........
  r64516 | raymond.hettinger | 2008-06-25 08:46:07 +1000 (Wed, 25 Jun 2008) | 1 line
  
  Revert 64424, 64438, and 64439.
........
  r64517 | benjamin.peterson | 2008-06-25 13:09:05 +1000 (Wed, 25 Jun 2008) | 1 line
  
  remove bytes alias in multiprocessing
........
  r64518 | robert.schuppenies | 2008-06-25 19:20:03 +1000 (Wed, 25 Jun 2008) | 2 lines
  
  Issue 3147: Fixed SizeofTest failure for LLP64 systems.
........
  r64519 | benjamin.peterson | 2008-06-25 22:39:05 +1000 (Wed, 25 Jun 2008) | 1 line
  
  use byte literals in multiprocessing
........
  r64520 | benjamin.peterson | 2008-06-25 22:44:29 +1000 (Wed, 25 Jun 2008) | 1 line
  
  get rid of 2.6/3.0 switch statements in multiprocessing
........


Modified:
   python/branches/tlee-ast-optimize/   (props changed)
   python/branches/tlee-ast-optimize/Doc/library/fractions.rst
   python/branches/tlee-ast-optimize/Include/object.h
   python/branches/tlee-ast-optimize/Lib/difflib.py
   python/branches/tlee-ast-optimize/Lib/multiprocessing/connection.py
   python/branches/tlee-ast-optimize/Lib/multiprocessing/dummy/__init__.py
   python/branches/tlee-ast-optimize/Lib/multiprocessing/managers.py
   python/branches/tlee-ast-optimize/Lib/multiprocessing/process.py
   python/branches/tlee-ast-optimize/Lib/test/test_builtin.py
   python/branches/tlee-ast-optimize/Lib/test/test_sys.py
   python/branches/tlee-ast-optimize/Misc/NEWS
   python/branches/tlee-ast-optimize/Objects/floatobject.c
   python/branches/tlee-ast-optimize/Objects/intobject.c
   python/branches/tlee-ast-optimize/Objects/longobject.c
   python/branches/tlee-ast-optimize/Objects/typeobject.c
   python/branches/tlee-ast-optimize/Python/bltinmodule.c

Modified: python/branches/tlee-ast-optimize/Doc/library/fractions.rst
==============================================================================
--- python/branches/tlee-ast-optimize/Doc/library/fractions.rst	(original)
+++ python/branches/tlee-ast-optimize/Doc/library/fractions.rst	Wed Jun 25 15:47:24 2008
@@ -65,14 +65,12 @@
 
    .. method:: __floor__()
 
-      Returns the greatest :class:`int` ``<= self``. Will be accessible through
-      :func:`math.floor` in Py3k.
+      Returns the greatest :class:`int` ``<= self``.
 
 
    .. method:: __ceil__()
 
-      Returns the least :class:`int` ``>= self``. Will be accessible through
-      :func:`math.ceil` in Py3k.
+      Returns the least :class:`int` ``>= self``.
 
 
    .. method:: __round__()
@@ -81,8 +79,7 @@
       The first version returns the nearest :class:`int` to ``self``, rounding
       half to even. The second version rounds ``self`` to the nearest multiple
       of ``Fraction(1, 10**ndigits)`` (logically, if ``ndigits`` is negative),
-      again rounding half toward even. Will be accessible through :func:`round`
-      in Py3k.
+      again rounding half toward even.
 
 
 .. seealso::

Modified: python/branches/tlee-ast-optimize/Include/object.h
==============================================================================
--- python/branches/tlee-ast-optimize/Include/object.h	(original)
+++ python/branches/tlee-ast-optimize/Include/object.h	Wed Jun 25 15:47:24 2008
@@ -267,9 +267,6 @@
 
 	/* Added in release 2.5 */
 	unaryfunc nb_index;
-
-	/* Added in release 2.6 */
-	unaryfunc nb_bin;
 } PyNumberMethods;
 
 typedef struct {

Modified: python/branches/tlee-ast-optimize/Lib/difflib.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/difflib.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/difflib.py	Wed Jun 25 15:47:24 2008
@@ -202,7 +202,7 @@
         #      DON'T USE!  Only __chain_b uses this.  Use isbjunk.
         # isbjunk
         #      for x in b, isbjunk(x) == isjunk(x) but much faster;
-        #      it's really the has_key method of a hidden dict.
+        #      it's really the __contains__ method of a hidden dict.
         #      DOES NOT WORK for x in a!
         # isbpopular
         #      for x in b, isbpopular(x) is true iff b is reasonably long
@@ -344,8 +344,8 @@
         # lot of junk in the sequence, the number of *unique* junk
         # elements is probably small.  So the memory burden of keeping
         # this dict alive is likely trivial compared to the size of b2j.
-        self.isbjunk = junkdict.has_key
-        self.isbpopular = populardict.has_key
+        self.isbjunk = junkdict.__contains__
+        self.isbpopular = populardict.__contains__
 
     def find_longest_match(self, alo, ahi, blo, bhi):
         """Find longest matching block in a[alo:ahi] and b[blo:bhi].
@@ -677,7 +677,7 @@
         # avail[x] is the number of times x appears in 'b' less the
         # number of times we've seen it in 'a' so far ... kinda
         avail = {}
-        availhas, matches = avail.has_key, 0
+        availhas, matches = avail.__contains__, 0
         for elt in self.a:
             if availhas(elt):
                 numb = avail[elt]

Modified: python/branches/tlee-ast-optimize/Lib/multiprocessing/connection.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/multiprocessing/connection.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/multiprocessing/connection.py	Wed Jun 25 15:47:24 2008
@@ -352,14 +352,9 @@
 
 MESSAGE_LENGTH = 20
 
-CHALLENGE = '#CHALLENGE#'
-WELCOME = '#WELCOME#'
-FAILURE = '#FAILURE#'
-
-if sys.version_info >= (3, 0):         # XXX can use bytes literals in 2.6/3.0
-    CHALLENGE = CHALLENGE.encode('ascii')
-    WELCOME = WELCOME.encode('ascii')
-    FAILURE = FAILURE.encode('ascii')
+CHALLENGE = b'#CHALLENGE#'
+WELCOME = b'#WELCOME#'
+FAILURE = b'#FAILURE#'
 
 def deliver_challenge(connection, authkey):
     import hmac

Modified: python/branches/tlee-ast-optimize/Lib/multiprocessing/dummy/__init__.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/multiprocessing/dummy/__init__.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/multiprocessing/dummy/__init__.py	Wed Jun 25 15:47:24 2008
@@ -53,30 +53,18 @@
         else:
             return None
 
-    # XXX
-    if sys.version_info < (3, 0):
-        is_alive = threading.Thread.is_alive.im_func
-        get_name = threading.Thread.get_name.im_func
-        set_name = threading.Thread.set_name.im_func
-        is_daemon = threading.Thread.is_daemon.im_func
-        set_daemon = threading.Thread.set_daemon.im_func
-    else:
-        is_alive = threading.Thread.is_alive
-        get_name = threading.Thread.get_name
-        set_name = threading.Thread.set_name
-        is_daemon = threading.Thread.is_daemon
-        set_daemon = threading.Thread.set_daemon
+    is_alive = threading.Thread.is_alive.im_func
+    get_name = threading.Thread.get_name.im_func
+    set_name = threading.Thread.set_name.im_func
+    is_daemon = threading.Thread.is_daemon.im_func
+    set_daemon = threading.Thread.set_daemon.im_func
 
 #
 #
 #
 
 class Condition(threading._Condition):
-    # XXX
-    if sys.version_info < (3, 0):
-        notify_all = threading._Condition.notify_all.im_func
-    else:
-        notify_all = threading._Condition.notify_all
+    notify_all = threading._Condition.notify_all.im_func
 
 #
 #

Modified: python/branches/tlee-ast-optimize/Lib/multiprocessing/managers.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/multiprocessing/managers.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/multiprocessing/managers.py	Wed Jun 25 15:47:24 2008
@@ -33,15 +33,6 @@
     from pickle import PicklingError
 
 #
-#
-#
-
-try:
-    bytes
-except NameError:
-    bytes = str                  # XXX not needed in Py2.6 and Py3.0
-
-#
 # Register some things for pickling
 #
 
@@ -50,11 +41,6 @@
 copy_reg.pickle(array.array, reduce_array)
 
 view_types = [type(getattr({}, name)()) for name in ('items','keys','values')]
-if view_types[0] is not list:       # XXX only needed in Py3.0
-    def rebuild_as_list(obj):
-        return list, (list(obj),)
-    for view_type in view_types:
-        copy_reg.pickle(view_type, rebuild_as_list)
 
 #
 # Type for identifying shared objects

Modified: python/branches/tlee-ast-optimize/Lib/multiprocessing/process.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/multiprocessing/process.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/multiprocessing/process.py	Wed Jun 25 15:47:24 2008
@@ -26,11 +26,6 @@
 except OSError:
     ORIGINAL_DIR = None
 
-try:
-    bytes
-except NameError:
-    bytes = str                  # XXX not needed in Py2.6 and Py3.0
-
 #
 # Public functions
 #

Modified: python/branches/tlee-ast-optimize/Lib/test/test_builtin.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_builtin.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_builtin.py	Wed Jun 25 15:47:24 2008
@@ -631,15 +631,6 @@
         self.assertEqual(hex(-16), '-0x10')
         self.assertEqual(hex(-16L), '-0x10L')
         self.assertRaises(TypeError, hex, {})
-        self.assertEqual(hex(3.125), '0x19 * 2.0 ** -3')
-        self.assertEqual(hex(0.0), '0x0 * 2.0 ** 0')
-        for sv in float('nan'), float('inf'), float('-inf'):
-            self.assertEqual(hex(sv), repr(sv))
-        for i in range(100):
-            x = random.expovariate(.05)
-            self.assertEqual(eval(hex(x)), x, (x, hex(x), eval(hex(x))))
-            self.assertEqual(eval(hex(-x)), -x)
-            self.assertEqual(hex(-x), ('-' + hex(x)))
 
     def test_id(self):
         id(None)
@@ -923,15 +914,6 @@
         self.assertEqual(oct(-100), '-0144')
         self.assertEqual(oct(-100L), '-0144L')
         self.assertRaises(TypeError, oct, ())
-        self.assertEqual(oct(3.125), '031 * 2.0 ** -3')
-        self.assertEqual(oct(0.0), '0 * 2.0 ** 0')
-        for sv in float('nan'), float('inf'), float('-inf'):
-            self.assertEqual(oct(sv), repr(sv))
-        for i in range(100):
-            x = random.expovariate(.05)
-            self.assertEqual(eval(oct(x)), x)
-            self.assertEqual(eval(oct(-x)), -x)
-            self.assertEqual(oct(-x), ('-' + oct(x)))
 
     def write_testfile(self):
         # NB the first 4 lines are also used to test input and raw_input, below
@@ -1484,15 +1466,6 @@
         self.assertEqual(bin(2**65-1), '0b' + '1' * 65)
         self.assertEqual(bin(-(2**65)), '-0b1' + '0' * 65)
         self.assertEqual(bin(-(2**65-1)), '-0b' + '1' * 65)
-        self.assertEqual(bin(3.125), '0b11001 * 2.0 ** -3')
-        self.assertEqual(bin(0.0), '0b0 * 2.0 ** 0')
-        for sv in float('nan'), float('inf'), float('-inf'):
-            self.assertEqual(bin(sv), repr(sv))
-        for i in range(100):
-            x = random.expovariate(.05)
-            self.assertEqual(eval(bin(x)), x)
-            self.assertEqual(eval(bin(-x)), -x)
-            self.assertEqual(bin(-x), ('-' + bin(x)))
 
 class TestSorted(unittest.TestCase):
 

Modified: python/branches/tlee-ast-optimize/Lib/test/test_sys.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_sys.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_sys.py	Wed Jun 25 15:47:24 2008
@@ -1,6 +1,7 @@
 # -*- coding: iso-8859-1 -*-
 import unittest, test.test_support
 import sys, cStringIO, os
+import struct
 
 class SysModuleTest(unittest.TestCase):
 
@@ -408,13 +409,16 @@
 class SizeofTest(unittest.TestCase):
 
     def setUp(self):
-        import struct
+        self.c = len(struct.pack('c', ' '))
+        self.H = len(struct.pack('H', 0))
         self.i = len(struct.pack('i', 0))
         self.l = len(struct.pack('l', 0))
-        self.p = len(struct.pack('P', 0))
-        self.headersize = self.l + self.p
+        self.P = len(struct.pack('P', 0))
+        # due to missing size_t information from struct, it is assumed that
+        # sizeof(Py_ssize_t) = sizeof(void*)
+        self.header = 'lP'
         if hasattr(sys, "gettotalrefcount"):
-            self.headersize += 2 * self.p
+            self.header += '2P'
         self.file = open(test.test_support.TESTFN, 'wb')
 
     def tearDown(self):
@@ -430,64 +434,53 @@
         else:
             self.assertEqual(result, size, msg + str(size))
 
-    def align(self, value):
-        mod = value % self.p
-        if mod != 0:
-            return value - mod + self.p
-        else:
-            return value
-
-    def test_align(self):
-        self.assertEqual(self.align(0) % self.p, 0)
-        self.assertEqual(self.align(1) % self.p, 0)
-        self.assertEqual(self.align(3) % self.p, 0)
-        self.assertEqual(self.align(4) % self.p, 0)
-        self.assertEqual(self.align(7) % self.p, 0)
-        self.assertEqual(self.align(8) % self.p, 0)
-        self.assertEqual(self.align(9) % self.p, 0)
+    def calcsize(self, fmt):
+        """Wrapper around struct.calcsize which enforces the alignment of the
+        end of a structure to the alignment requirement of pointer.
+
+        Note: This wrapper should only be used if a pointer member is included
+        and no member with a size larger than a pointer exists.
+        """
+        return struct.calcsize(fmt + '0P')
 
     def test_standardtypes(self):
-        i = self.i
-        l = self.l
-        p = self.p
-        h = self.headersize
+        h = self.header
+        size = self.calcsize
         # bool
-        self.check_sizeof(True, h + l)
+        self.check_sizeof(True, size(h + 'l'))
         # buffer
-        self.check_sizeof(buffer(''), h + 2*p + 2*l + self.align(i) +l)
+        self.check_sizeof(buffer(''), size(h + '2P2Pil'))
         # cell
         def get_cell():
             x = 42
             def inner():
                 return x
             return inner
-        self.check_sizeof(get_cell().func_closure[0], h + p)
+        self.check_sizeof(get_cell().func_closure[0], size(h + 'P'))
         # old-style class
         class class_oldstyle():
             def method():
                 pass
-        self.check_sizeof(class_oldstyle, h + 6*p)
+        self.check_sizeof(class_oldstyle, size(h + '6P'))
         # instance
-        self.check_sizeof(class_oldstyle(), h + 3*p)
+        self.check_sizeof(class_oldstyle(), size(h + '3P'))
         # method
-        self.check_sizeof(class_oldstyle().method, h + 4*p)
+        self.check_sizeof(class_oldstyle().method, size(h + '4P'))
         # code
-        self.check_sizeof(get_cell().func_code, h + self.align(4*i) + 8*p +\
-                            self.align(i) + 2*p)
+        self.check_sizeof(get_cell().func_code, size(h + '4i8Pi2P'))
         # complex
-        self.check_sizeof(complex(0,1), h + 2*8)
+        self.check_sizeof(complex(0,1), size(h + '2d'))
         # enumerate
-        self.check_sizeof(enumerate([]), h + l + 3*p)
+        self.check_sizeof(enumerate([]), size(h + 'l3P'))
         # reverse
-        self.check_sizeof(reversed(''), h + l + p )
+        self.check_sizeof(reversed(''), size(h + 'PP'))
         # file
-        self.check_sizeof(self.file, h + 4*p + self.align(2*i) + 4*p +\
-                            self.align(3*i) + 3*p + self.align(i))
+        self.check_sizeof(self.file, size(h + '4P2i4P3i3Pi'))
         # float
-        self.check_sizeof(float(0), h + 8)
+        self.check_sizeof(float(0), size(h + 'd'))
         # function
         def func(): pass
-        self.check_sizeof(func, h + 9 * l)
+        self.check_sizeof(func, size(h + '9l'))
         class c():
             @staticmethod
             def foo():
@@ -496,54 +489,50 @@
             def bar(cls):
                 pass
             # staticmethod
-            self.check_sizeof(foo, h + l)
+            self.check_sizeof(foo, size(h + 'l'))
             # classmethod
-            self.check_sizeof(bar, h + l)
+            self.check_sizeof(bar, size(h + 'l'))
         # generator
         def get_gen(): yield 1
-        self.check_sizeof(get_gen(), h + p + self.align(i) + 2*p)
+        self.check_sizeof(get_gen(), size(h + 'Pi2P'))
         # integer
-        self.check_sizeof(1, h + l)
+        self.check_sizeof(1, size(h + 'l'))
         # builtin_function_or_method
-        self.check_sizeof(abs, h + 3*p)
+        self.check_sizeof(abs, size(h + '3P'))
         # module
-        self.check_sizeof(unittest, h + p)
+        self.check_sizeof(unittest, size(h + 'P'))
         # xrange
-        self.check_sizeof(xrange(1), h + 3*p)
+        self.check_sizeof(xrange(1), size(h + '3P'))
         # slice
-        self.check_sizeof(slice(0), h + 3*p)
+        self.check_sizeof(slice(0), size(h + '3P'))
 
-        h += l
+        h += 'l'
         # new-style class
         class class_newstyle(object):
             def method():
                 pass
         # type (PyTypeObject + PyNumberMethods +  PyMappingMethods +
-        #       PySequenceMethods +  PyBufferProcs)
-        len_typeobject = p + 2*l + 15*p + l + 4*p + l + 9*p +\
-                         l + 11*p + self.align(4)
-        self.check_sizeof(class_newstyle,
-                          h + len_typeobject + 42*p + 10*p + 3*p + 6*p)
+        #       PySequenceMethods + PyBufferProcs)
+        self.check_sizeof(class_newstyle, size('P2P15Pl4PP9PP11PI') +\
+                                          size(h + '41P 10P 3P 6P'))
 
     def test_specialtypes(self):
-        i = self.i
-        l = self.l
-        p = self.p
-        h = self.headersize
+        h = self.header
+        size = self.calcsize
         # dict
-        self.check_sizeof({}, h + 3*l + 3*p + 8*(l + 2*p))
+        self.check_sizeof({}, size(h + '3P3P') + 8*size('P2P'))
         longdict = {1:1, 2:2, 3:3, 4:4, 5:5, 6:6, 7:7, 8:8}
-        self.check_sizeof(longdict, h + 3*l + 3*p + 8*(l + 2*p) + 16*(l + 2*p))
+        self.check_sizeof(longdict, size(h + '3P3P') + (8+16)*size('P2P'))
         # list
-        self.check_sizeof([], h + l + p + l)
-        self.check_sizeof([1, 2, 3], h + l + p + l + 3*l)
+        self.check_sizeof([], size(h + 'lPP'))
+        self.check_sizeof([1, 2, 3], size(h + 'lPP') + 3*self.P)
         # unicode
         usize = len(u'\0'.encode('unicode-internal'))
         samples = [u'', u'1'*100]
         # we need to test for both sizes, because we don't know if the string
         # has been cached
         for s in samples:
-            basicsize =  h + l + p + l + p + usize * (len(s) + 1)
+            basicsize =  size(h + 'PPlP') + usize * (len(s) + 1)
             self.check_sizeof(s, basicsize,\
                                   size2=basicsize + sys.getsizeof(str(s)))
         # XXX trigger caching encoded version as Python string
@@ -555,20 +544,20 @@
         finally:
             self.check_sizeof(s, basicsize + sys.getsizeof(str(s)))
 
-        h += l
+        h += 'l'
         # long
-        self.check_sizeof(0L, h + self.align(2))
-        self.check_sizeof(1L, h + self.align(2))
-        self.check_sizeof(-1L, h + self.align(2))
-        self.check_sizeof(32768L, h + self.align(2) + 2)
-        self.check_sizeof(32768L*32768L-1, h + self.align(2) + 2)
-        self.check_sizeof(32768L*32768L, h + self.align(2) + 4)
+        self.check_sizeof(0L, size(h + 'H'))
+        self.check_sizeof(1L, size(h + 'H'))
+        self.check_sizeof(-1L, size(h + 'H'))
+        self.check_sizeof(32768L, size(h + 'H') + self.H)
+        self.check_sizeof(32768L*32768L-1, size(h + 'H') + self.H)
+        self.check_sizeof(32768L*32768L, size(h + 'H') + 2*self.H)
         # string
-        self.check_sizeof('', h + l + self.align(i + 1))
-        self.check_sizeof('abc', h + l + self.align(i + 1) + 3)
+        self.check_sizeof('', size(h + 'lic'))
+        self.check_sizeof('abc', size(h + 'lic') + 3*self.c)
         # tuple
-        self.check_sizeof((), h)
-        self.check_sizeof((1,2,3), h + 3*p)
+        self.check_sizeof((), size(h))
+        self.check_sizeof((1,2,3), size(h) + 3*self.P)
 
 
 def test_main():

Modified: python/branches/tlee-ast-optimize/Misc/NEWS
==============================================================================
--- python/branches/tlee-ast-optimize/Misc/NEWS	(original)
+++ python/branches/tlee-ast-optimize/Misc/NEWS	Wed Jun 25 15:47:24 2008
@@ -17,12 +17,6 @@
   slice(None, 10, -1).indices(10) returns (9, 9, -1) instead of (9,
   10, -1).
 
-- Issue 3008: hex(), oct(), and bin() can now create exact reprs 
-  for floats.
-
-- Make bin() implementation parallel oct() and hex().
-
-
 What's New in Python 2.6 beta 1?
 ================================
 

Modified: python/branches/tlee-ast-optimize/Objects/floatobject.c
==============================================================================
--- python/branches/tlee-ast-optimize/Objects/floatobject.c	(original)
+++ python/branches/tlee-ast-optimize/Objects/floatobject.c	Wed Jun 25 15:47:24 2008
@@ -405,11 +405,11 @@
    obj is not of float, int or long type, Py_NotImplemented is incref'ed,
    stored in obj, and returned from the function invoking this macro.
 */
-#define CONVERT_TO_DOUBLE(obj, dbl)					\
-	if (PyFloat_Check(obj))						\
-		dbl = PyFloat_AS_DOUBLE(obj);				\
-	else if (convert_to_double((PyObject **)&(obj), &(dbl)) < 0)	\
-		return (PyObject *)(obj);
+#define CONVERT_TO_DOUBLE(obj, dbl)			\
+	if (PyFloat_Check(obj))				\
+		dbl = PyFloat_AS_DOUBLE(obj);		\
+	else if (convert_to_double(&(obj), &(dbl)) < 0)	\
+		return obj;
 
 static int
 convert_to_double(PyObject **v, double *dbl)
@@ -1204,62 +1204,6 @@
 ">>> (-.25).as_integer_ratio()\n"
 "(-1, 4)");
 
-static PyObject *
-_float_to_base(PyFloatObject *v, unaryfunc int_to_base)
-{
-	PyObject *mant, *conv, *result;
-	double x, fr;
-	int i, exp, n;
-	char *conv_str;
-
-	CONVERT_TO_DOUBLE(v, x);
-	if (!Py_IS_FINITE(x))
-		return PyObject_Repr((PyObject *)v);
-	fr = frexp(x, &exp);
-	for (i=0; i<300 && fr != floor(fr) ; i++) {
-		fr *= 2.0;
-		exp--;
-	}
-	mant = PyLong_FromDouble(floor(fr));
-	if (mant == NULL)
-		return NULL;
-	conv = int_to_base(mant);
-	Py_DECREF(mant);
-	if (conv== NULL)
-		return NULL;
-	n = PyString_GET_SIZE(conv);
-	conv_str = PyString_AS_STRING(conv);
-	/* Remove the trailing 'L' if present */
-	if (n && conv_str[n-1] == 'L') {
-		PyObject *newconv = PySequence_GetSlice(conv, 0, -1);
-		Py_DECREF(conv);
-		if (newconv == NULL)
-			return NULL;
-		conv = newconv;
-		conv_str = PyString_AS_STRING(conv);
-	}
-	result = PyString_FromFormat("%s * 2.0 ** %d", conv_str, exp);
-	Py_DECREF(conv);
-	return result;
-}
-
-static PyObject *
-float_hex(PyFloatObject *v)
-{
-	return _float_to_base(v, PyLong_Type.tp_as_number->nb_hex);
-}
-
-static PyObject *
-float_oct(PyFloatObject *v)
-{
-	return _float_to_base(v, PyLong_Type.tp_as_number->nb_oct);
-}
-
-static PyObject *
-float_bin(PyFloatObject *v)
-{
-	return _float_to_base(v, PyLong_Type.tp_as_number->nb_bin);
-}
 
 static PyObject *
 float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
@@ -1546,8 +1490,8 @@
 	float_trunc, 	/*nb_int*/
 	float_trunc, 	/*nb_long*/
 	float_float,	/*nb_float*/
-	(unaryfunc)float_oct,		/* nb_oct */
-	(unaryfunc)float_hex,		/* nb_hex */
+	0,		/* nb_oct */
+	0,		/* nb_hex */
 	0,		/* nb_inplace_add */
 	0,		/* nb_inplace_subtract */
 	0,		/* nb_inplace_multiply */
@@ -1563,8 +1507,6 @@
 	float_div,	/* nb_true_divide */
 	0,		/* nb_inplace_floor_divide */
 	0,		/* nb_inplace_true_divide */
-	0,		/* nb_index */
-	(unaryfunc)float_bin,		/* nb_bin */
 };
 
 PyTypeObject PyFloat_Type = {

Modified: python/branches/tlee-ast-optimize/Objects/intobject.c
==============================================================================
--- python/branches/tlee-ast-optimize/Objects/intobject.c	(original)
+++ python/branches/tlee-ast-optimize/Objects/intobject.c	Wed Jun 25 15:47:24 2008
@@ -934,12 +934,6 @@
 }
 
 static PyObject *
-int_bin(PyObject *v)
-{
-        return PyNumber_ToBase(v, 2);
-}
-
-static PyObject *
 int_oct(PyIntObject *v)
 {
 	return _PyInt_Format(v, 8, 0);
@@ -1237,7 +1231,6 @@
 	0,			/* nb_inplace_floor_divide */
 	0,			/* nb_inplace_true_divide */
 	(unaryfunc)int_int,	/* nb_index */
-	(unaryfunc)int_bin, 	/* nb_bin */
 };
 
 PyTypeObject PyInt_Type = {

Modified: python/branches/tlee-ast-optimize/Objects/longobject.c
==============================================================================
--- python/branches/tlee-ast-optimize/Objects/longobject.c	(original)
+++ python/branches/tlee-ast-optimize/Objects/longobject.c	Wed Jun 25 15:47:24 2008
@@ -3301,12 +3301,6 @@
 }
 
 static PyObject *
-long_bin(PyObject *v)
-{
-        return PyNumber_ToBase(v, 2);
-}
-
-static PyObject *
 long_oct(PyObject *v)
 {
 	return _PyLong_Format(v, 8, 1, 0);
@@ -3546,7 +3540,6 @@
 	0,				/* nb_inplace_floor_divide */
 	0,				/* nb_inplace_true_divide */
 	long_long,			/* nb_index */
-	long_bin,			/* nb_bin */
 };
 
 PyTypeObject PyLong_Type = {

Modified: python/branches/tlee-ast-optimize/Objects/typeobject.c
==============================================================================
--- python/branches/tlee-ast-optimize/Objects/typeobject.c	(original)
+++ python/branches/tlee-ast-optimize/Objects/typeobject.c	Wed Jun 25 15:47:24 2008
@@ -3743,7 +3743,6 @@
 		if (base->tp_flags & Py_TPFLAGS_HAVE_INDEX) {
 			COPYNUM(nb_index);
 		}
-		COPYNUM(nb_hex);
 	}
 
 	if (type->tp_as_sequence != NULL && base->tp_as_sequence != NULL) {
@@ -5136,7 +5135,6 @@
 SLOT0(slot_nb_int, "__int__")
 SLOT0(slot_nb_long, "__long__")
 SLOT0(slot_nb_float, "__float__")
-SLOT0(slot_nb_bin, "__bin__")
 SLOT0(slot_nb_oct, "__oct__")
 SLOT0(slot_nb_hex, "__hex__")
 SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *, "O")
@@ -5804,8 +5802,6 @@
 	       "long(x)"),
 	UNSLOT("__float__", nb_float, slot_nb_float, wrap_unaryfunc,
 	       "float(x)"),
-	UNSLOT("__bin__", nb_bin, slot_nb_bin, wrap_unaryfunc,
-	       "bin(x)"),
 	UNSLOT("__oct__", nb_oct, slot_nb_oct, wrap_unaryfunc,
 	       "oct(x)"),
 	UNSLOT("__hex__", nb_hex, slot_nb_hex, wrap_unaryfunc,

Modified: python/branches/tlee-ast-optimize/Python/bltinmodule.c
==============================================================================
--- python/branches/tlee-ast-optimize/Python/bltinmodule.c	(original)
+++ python/branches/tlee-ast-optimize/Python/bltinmodule.c	Wed Jun 25 15:47:24 2008
@@ -213,24 +213,7 @@
 static PyObject *
 builtin_bin(PyObject *self, PyObject *v)
 {
-	PyNumberMethods *nb;
-	PyObject *res;
-
-	if ((nb = v->ob_type->tp_as_number) == NULL ||
-	    nb->nb_hex == NULL) {
-		PyErr_SetString(PyExc_TypeError,
-			   "bin() argument can't be converted to hex");
-		return NULL;
-	}
-	res = (*nb->nb_bin)(v);
-	if (res && !PyString_Check(res)) {
-		PyErr_Format(PyExc_TypeError,
-			     "__bin__ returned non-string (type %.200s)",
-			     res->ob_type->tp_name);
-		Py_DECREF(res);
-		return NULL;
-	}
-	return res;
+        return PyNumber_ToBase(v, 2);
 }
 
 PyDoc_STRVAR(bin_doc,


More information about the Python-checkins mailing list