Author: Armin Rigo <[email protected]>
Branch: reverse-debugger
Changeset: r86170:44f0653642eb
Date: 2016-08-12 15:00 +0200
http://bitbucket.org/pypy/pypy/changeset/44f0653642eb/
Log: Emulate modf. Fix emulation of dtoa(2.0) to output the ".0" too.
diff --git a/rpython/rlib/revdb.py b/rpython/rlib/revdb.py
--- a/rpython/rlib/revdb.py
+++ b/rpython/rlib/revdb.py
@@ -232,3 +232,7 @@
s = hlstr(s)
assert s is not None
return s
+
+def emulate_modf(x):
+ return (llop.revdb_modf(lltype.Float, x, 0),
+ llop.revdb_modf(lltype.Float, x, 1))
diff --git a/rpython/rtyper/lltypesystem/lloperation.py
b/rpython/rtyper/lltypesystem/lloperation.py
--- a/rpython/rtyper/lltypesystem/lloperation.py
+++ b/rpython/rtyper/lltypesystem/lloperation.py
@@ -586,6 +586,7 @@
'revdb_set_thread_breakpoint': LLOp(),
'revdb_strtod': LLOp(sideeffects=False),
'revdb_dtoa': LLOp(sideeffects=False),
+ 'revdb_modf': LLOp(sideeffects=False),
}
# ***** Run test_lloperation after changes. *****
diff --git a/rpython/rtyper/lltypesystem/module/ll_math.py
b/rpython/rtyper/lltypesystem/module/ll_math.py
--- a/rpython/rtyper/lltypesystem/module/ll_math.py
+++ b/rpython/rtyper/lltypesystem/module/ll_math.py
@@ -4,7 +4,7 @@
import sys
from rpython.translator import cdir
-from rpython.rlib import jit, rposix
+from rpython.rlib import jit, rposix, revdb
from rpython.rlib.rfloat import INFINITY, NAN, isfinite, isinf, isnan
from rpython.rlib.rposix import UNDERSCORE_ON_WIN32
from rpython.rtyper.lltypesystem import lltype, rffi
@@ -221,6 +221,8 @@
def ll_math_modf(x):
# some platforms don't do the right thing for NaNs and
# infinities, so we take care of special cases directly.
+ if revdb.flag_io_disabled():
+ return revdb.emulate_modf(x)
if not isfinite(x):
if isnan(x):
return (x, x)
diff --git a/rpython/translator/revdb/src-revdb/revdb.c
b/rpython/translator/revdb/src-revdb/revdb.c
--- a/rpython/translator/revdb/src-revdb/revdb.c
+++ b/rpython/translator/revdb/src-revdb/revdb.c
@@ -1759,11 +1759,18 @@
RPY_EXTERN RPyString *rpy_reverse_db_dtoa(double d)
{
- char buffer[128];
+ char buffer[128], *p;
RPyString *result;
int size;
- size = snprintf(buffer, sizeof(buffer), "%g", d);
- if (size < 0) size = 0; /* XXX? */
+ size = snprintf(buffer, sizeof(buffer) - 3, "%g", d);
+ if (size < 0)
+ size = 0;
+ for (p = buffer; '0' <= *p && *p <= '9'; p++) {
+ }
+ if (*p == 0) { /* a pure integer */
+ buffer[size++] = '.';
+ buffer[size++] = '0';
+ }
result = make_rpy_string(size);
memcpy(_RPyString_AsString(result), buffer, size);
return result;
diff --git a/rpython/translator/revdb/src-revdb/revdb_include.h
b/rpython/translator/revdb/src-revdb/revdb_include.h
--- a/rpython/translator/revdb/src-revdb/revdb_include.h
+++ b/rpython/translator/revdb/src-revdb/revdb_include.h
@@ -236,6 +236,13 @@
#define OP_REVDB_DTOA(d, r) \
r = rpy_reverse_db_dtoa(d)
+#define OP_REVDB_MODF(x, index, r) \
+ do { \
+ double _r0, _r1; \
+ _r0 = modf(x, &_r1); \
+ r = (index == 0) ? _r0 : _r1; \
+ } while (0)
+
RPY_EXTERN void rpy_reverse_db_flush(void); /* must be called with the lock */
RPY_EXTERN void rpy_reverse_db_fetch(const char *file, int line);
diff --git a/rpython/translator/revdb/test/test_process.py
b/rpython/translator/revdb/test/test_process.py
--- a/rpython/translator/revdb/test/test_process.py
+++ b/rpython/translator/revdb/test/test_process.py
@@ -1,4 +1,4 @@
-import py, sys
+import py, sys, math
from cStringIO import StringIO
from rpython.rlib import revdb, rdtoa
from rpython.rlib.debug import debug_print, ll_assert
@@ -49,7 +49,9 @@
stuff = dbstate.metavar
elif extra == '2.35':
val = rdtoa.strtod('2.35')
- revdb.send_output(rdtoa.dtoa(val))
+ valx, valy = math.modf(val)
+ revdb.send_output(rdtoa.dtoa(valx) + '\n')
+ revdb.send_output(rdtoa.dtoa(valy) + '\n')
return
else:
assert False
@@ -208,4 +210,4 @@
group = ReplayProcessGroup(str(self.exename), self.rdbname)
with stdout_capture() as buf:
group.print_cmd('2.35')
- assert buf.getvalue() == "2.35"
+ assert buf.getvalue() == "0.35\n2.0\n"
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit