[pypy-commit] pypy vmprof: Test and fix

arigo noreply at buildbot.pypy.org
Sat Apr 4 12:21:53 CEST 2015


Author: Armin Rigo <arigo at tunes.org>
Branch: vmprof
Changeset: r76711:e492b2d111b0
Date: 2015-04-04 12:22 +0200
http://bitbucket.org/pypy/pypy/changeset/e492b2d111b0/

Log:	Test and fix

diff --git a/pypy/module/_vmprof/interp_vmprof.py b/pypy/module/_vmprof/interp_vmprof.py
--- a/pypy/module/_vmprof/interp_vmprof.py
+++ b/pypy/module/_vmprof/interp_vmprof.py
@@ -4,6 +4,7 @@
 from rpython.rtyper.annlowlevel import cast_instance_to_gcref, cast_base_ptr_to_instance
 from rpython.rlib.objectmodel import we_are_translated
 from rpython.rlib import jit, rposix, rgc
+from rpython.rlib.rarithmetic import ovfcheck_float_to_int
 from rpython.rtyper.tool import rffi_platform as platform
 from rpython.rlib.rstring import StringBuilder
 from pypy.interpreter.baseobjspace import W_Root
@@ -222,12 +223,12 @@
     assert isinstance(mod_vmprof, Module)
     #
     try:
-        period_usec = int(period * 1000000.0 + 0.5)
+        period_usec = ovfcheck_float_to_int(period * 1000000.0 + 0.5)
         if period_usec <= 0:
             raise ValueError
     except (ValueError, OverflowError):
-        raise OperationError(self.w_ValueError,
-                             self.wrap("'period' too large or non positive"))
+        raise OperationError(space.w_ValueError,
+                             space.wrap("'period' too large or non positive"))
     #
     mod_vmprof.vmprof.enable(space, fileno, period_usec)
 
diff --git a/pypy/module/_vmprof/test/test__vmprof.py b/pypy/module/_vmprof/test/test__vmprof.py
--- a/pypy/module/_vmprof/test/test__vmprof.py
+++ b/pypy/module/_vmprof/test/test__vmprof.py
@@ -58,3 +58,11 @@
         assert "py:foo:" in s
         assert "py:foo2:" in s
         assert no_of_codes2 >= no_of_codes + 2 # some extra codes from tests
+
+    def test_enable_ovf(self):
+        import _vmprof
+        raises(ValueError, _vmprof.enable, 999, 0)
+        raises(ValueError, _vmprof.enable, 999, -2.5)
+        raises(ValueError, _vmprof.enable, 999, 1e300)
+        raises(ValueError, _vmprof.enable, 999, 1e300 * 1e300)
+        raises(ValueError, _vmprof.enable, 999, (1e300*1e300) / (1e300*1e300))


More information about the pypy-commit mailing list