[pypy-svn] r15922 - in pypy/dist/pypy: lib module/__builtin__ objspace/std/test rpython translator

pedronis at codespeak.net pedronis at codespeak.net
Wed Aug 10 17:17:48 CEST 2005


Author: pedronis
Date: Wed Aug 10 17:17:41 2005
New Revision: 15922

Modified:
   pypy/dist/pypy/lib/_formatting.py
   pypy/dist/pypy/module/__builtin__/special.py
   pypy/dist/pypy/objspace/std/test/test_stringformat.py
   pypy/dist/pypy/rpython/rarithmetic.py
   pypy/dist/pypy/translator/geninterplevel.py
Log:
fix for test_str/userstring/format failures with tests

bump geninterp number because _formatting is an indirect import



Modified: pypy/dist/pypy/lib/_formatting.py
==============================================================================
--- pypy/dist/pypy/lib/_formatting.py	(original)
+++ pypy/dist/pypy/lib/_formatting.py	Wed Aug 10 17:17:41 2005
@@ -242,9 +242,8 @@
         return self.numeric_postprocess(r, sign)
 
     def _formatd(self, kind, v):
-        fmt = '%' + (self.flags.f_alt and '#' or '') + '.' + str(self.prec) + kind
         import __builtin__
-        return __builtin__._formatd(fmt, v)
+        return __builtin__._formatd(self.flags.f_alt, self.prec, kind, v)
 
 class FloatFFormatter(FloatFormatter):
     def _format(self, v):

Modified: pypy/dist/pypy/module/__builtin__/special.py
==============================================================================
--- pypy/dist/pypy/module/__builtin__/special.py	(original)
+++ pypy/dist/pypy/module/__builtin__/special.py	Wed Aug 10 17:17:41 2005
@@ -1,4 +1,5 @@
 from pypy.interpreter import gateway
+from pypy.interpreter.error import OperationError
 from pypy.rpython import rarithmetic
 
 def _isfake(space, w_obj): 
@@ -6,6 +7,18 @@
     #return space.wrap(bool(getattr(w_obj.typedef, 'fakedcpytype', None)))
 
 
-def _formatd(space, fmt, x):
+def _formatd(space, alt, prec, kind, x):
+    formatd_max_length = rarithmetic.formatd_max_length
+    if ((kind == 'g' and formatd_max_length <= 10+prec) or
+        (kind == 'f' and formatd_max_length <= 53+prec)):
+        raise OperationError(space.w_OverflowError,
+                             space.wrap("formatted float is too long (precision too large?)"))    
+    if alt:
+        alt = '#'
+    else:
+        alt = ''
+
+    fmt = "%%%s.%d%s" % (alt, prec, kind)
+    
     return space.wrap(rarithmetic.formatd(fmt, x))
-_formatd.unwrap_spec = [gateway.ObjSpace, str, float]
+_formatd.unwrap_spec = [gateway.ObjSpace, int, int, str, float]

Modified: pypy/dist/pypy/objspace/std/test/test_stringformat.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_stringformat.py	(original)
+++ pypy/dist/pypy/objspace/std/test/test_stringformat.py	Wed Aug 10 17:17:41 2005
@@ -156,3 +156,9 @@
         assert "%*.*s"%( 5, 3, 'abc') ==    '  abc'
         assert "%*.*s"%( 5, 3, 'abcde') ==  '  abc'
         assert "%*.*s"%(-5, 3, 'abcde') ==  'abc  '
+
+    def test_too_long(self):
+        def f(fmt, x):
+            return fmt % x
+        raises(OverflowError, f, "%.70f", 2.0)
+        raises(OverflowError, f, "%.110g", 2.0)

Modified: pypy/dist/pypy/rpython/rarithmetic.py
==============================================================================
--- pypy/dist/pypy/rpython/rarithmetic.py	(original)
+++ pypy/dist/pypy/rpython/rarithmetic.py	Wed Aug 10 17:17:41 2005
@@ -379,5 +379,7 @@
 
 # float -> string
 
+formatd_max_length = 120
+
 def formatd(fmt, x):
     return fmt % (x,)

Modified: pypy/dist/pypy/translator/geninterplevel.py
==============================================================================
--- pypy/dist/pypy/translator/geninterplevel.py	(original)
+++ pypy/dist/pypy/translator/geninterplevel.py	Wed Aug 10 17:17:41 2005
@@ -77,7 +77,7 @@
 import pypy # __path__
 import py.path
 
-GI_VERSION = '1.1.10'  # bump this for substantial changes
+GI_VERSION = '1.1.11'  # bump this for substantial changes
 # ____________________________________________________________
 
 try:



More information about the Pypy-commit mailing list