[pypy-commit] pypy reverse-debugger: Failing test about setting up a watchpoint: it doesn't force the object

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r86164:66ba9208c0e9
Date: 2016-08-12 10:28 +0200
http://bitbucket.org/pypy/pypy/changeset/66ba9208c0e9/

Log:Failing test about setting up a watchpoint: it doesn't force the
object to be attached

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
@@ -77,11 +77,28 @@
 dbstate.metavar = stuff
 lambda_allocating = lambda: command_allocating
 
+def command_compilewatch(cmd, expression):
+revdb.send_watch("marshalled_code", ok_flag=1)
+lambda_compilewatch = lambda: command_compilewatch
+
+def command_checkwatch(cmd, marshalled_code):
+assert marshalled_code == "marshalled_code"
+# check that $0 exists
+if dbstate.metavar is not None:
+revdb.send_watch("ok, stuff exists\n", ok_flag=1)
+else:
+revdb.send_watch("stuff does not exist!\n", ok_flag=0)
+lambda_checkwatch = lambda: command_checkwatch
+
 def main(argv):
 revdb.register_debug_command(100, lambda_blip)
 revdb.register_debug_command(CMD_PRINT, lambda_print)
 revdb.register_debug_command(CMD_ATTACHID, lambda_attachid)
 revdb.register_debug_command("ALLOCATING", lambda_allocating)
+revdb.register_debug_command(revdb.CMD_COMPILEWATCH,
+ lambda_compilewatch)
+revdb.register_debug_command(revdb.CMD_CHECKWATCH,
+ lambda_checkwatch)
 for i, op in enumerate(argv[1:]):
 dbstate.stuff = Stuff()
 dbstate.stuff.x = i + 1000
@@ -150,16 +167,35 @@
 assert buf.getvalue() == "$0 = stuff\n"
 return group
 
-def test_print_metavar(self):
-group = self.test_print_cmd()
+def _print_metavar(self, group):
 with stdout_capture() as buf:
 group.print_cmd('$0', nids=[0])
 assert buf.getvalue() == "$0 = stuff\n"
 
+def test_print_metavar(self):
+group = self.test_print_cmd()
+self._print_metavar(group)
+
 def test_jump_and_print_metavar(self):
 group = self.test_print_cmd()
 assert group.is_tainted()
 group.jump_in_time(2)
-with stdout_capture() as buf:
-group.print_cmd('$0', nids=[0])
-assert buf.getvalue() == "$0 = stuff\n"
+self._print_metavar(group)
+
+def _check_watchpoint_expr(self, group, must_exist):
+ok_flag, compiled_code = group.compile_watchpoint_expr("$0")
+assert ok_flag == 1
+assert compiled_code == "marshalled_code"
+nids = [0]
+ok_flag, text = group.check_watchpoint_expr(compiled_code, nids)
+print text
+assert ok_flag == must_exist
+
+def test_check_watchpoint_expr(self):
+group = self.test_print_cmd()
+self._check_watchpoint_expr(group, must_exist=1)
+
+def test_jump_and_check_watchpoint_expr(self):
+group = self.test_print_cmd()
+group.jump_in_time(2)
+self._check_watchpoint_expr(group, must_exist=1)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reverse-debugger: Fix

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r86165:ff0f492637a5
Date: 2016-08-12 10:36 +0200
http://bitbucket.org/pypy/pypy/changeset/ff0f492637a5/

Log:Fix

diff --git a/rpython/translator/revdb/process.py 
b/rpython/translator/revdb/process.py
--- a/rpython/translator/revdb/process.py
+++ b/rpython/translator/revdb/process.py
@@ -447,6 +447,7 @@
 
 def check_watchpoint_expr(self, compiled_code, nids=None):
 if nids:
+self.ensure_nids_to_uids(nids)
 uids = self.nids_to_uids(nids)
 self.attach_printed_objects(uids, watch_env=True)
 self.active.send(Message(CMD_CHECKWATCH, extra=compiled_code))
@@ -542,6 +543,16 @@
 uids.append(uid)
 return uids
 
+def ensure_nids_to_uids(self, nids):
+# Take the objects listed in nids which are alive at the
+# current time, and return a list of uids of them.  This
+# might require some replaying.
+uids = []
+if nids:
+uids = self.nids_to_uids(nids, skip_futures=True)
+self.ensure_printed_objects(uids)
+return uids
+
 def attach_printed_objects(self, uids, watch_env):
 for uid in uids:
 nid = self.all_printed_objects[uid]
@@ -559,11 +570,7 @@
 def print_cmd(self, expression, nids=[]):
 """Print an expression.
 """
-uids = []
-if nids:
-uids = self.nids_to_uids(nids, skip_futures=True)
-self.ensure_printed_objects(uids)
-#
+uids = self.ensure_nids_to_uids(nids)
 self.active.tainted = True
 self.attach_printed_objects(uids, watch_env=False)
 self.active.send(Message(CMD_PRINT, extra=expression))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reverse-debugger: Some tests for prints, including printing $0

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r86163:d7c4d2ccc68a
Date: 2016-08-12 10:20 +0200
http://bitbucket.org/pypy/pypy/changeset/d7c4d2ccc68a/

Log:Some tests for prints, including printing $0

diff --git a/pypy/interpreter/reverse_debugging.py 
b/pypy/interpreter/reverse_debugging.py
--- a/pypy/interpreter/reverse_debugging.py
+++ b/pypy/interpreter/reverse_debugging.py
@@ -41,7 +41,6 @@
 """
 assert space.config.translation.reverse_debugger
 dbstate.space = space
-dbstate.w_future = space.w_Ellipsis# a random prebuilt object
 
 make_sure_not_resized(dbstate.watch_progs)
 make_sure_not_resized(dbstate.metavars)
@@ -228,6 +227,9 @@
 revdb.stop_point(place)
 
 
+def future_object(space):
+return space.w_Ellipsis# a random prebuilt object
+
 def load_metavar(index):
 assert index >= 0
 space = dbstate.space
@@ -236,7 +238,7 @@
 if w_var is None:
 raise oefmt(space.w_NameError, "no constant object '$%d'",
 index)
-if w_var is dbstate.w_future:
+if w_var is future_object(space):
 raise oefmt(space.w_RuntimeError,
 "'$%d' refers to an object created later in time",
 index)
@@ -543,7 +545,7 @@
 except KeyError:
 # uid not found, probably a future object
 dbstate.watch_futures[uid] = index_metavar
-w_obj = dbstate.w_future
+w_obj = future_object(space)
 set_metavar(index_metavar, w_obj)
 lambda_attachid = lambda: command_attachid
 
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
@@ -1536,6 +1536,7 @@
 save_state();
 if (rpy_revdb_commands.rp_alloc) {
 protect_potential_io();
+/* invoke the "ALLOCATING" callback from RPython */
 rpy_revdb_commands.rp_alloc(uid, new_object);
 unprotect_potential_io();
 }
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,12 +1,23 @@
-import py
+import py, sys
+from cStringIO import StringIO
 from rpython.rlib import revdb
-from rpython.rlib.debug import debug_print
+from rpython.rlib.debug import debug_print, ll_assert
+from rpython.rtyper.annlowlevel import cast_gcref_to_instance
 from rpython.translator.revdb.message import *
 from rpython.translator.revdb.process import ReplayProcessGroup, Breakpoint
 
 from hypothesis import given, strategies
 
 
+class stdout_capture(object):
+def __enter__(self):
+self.old_stdout = sys.stdout
+sys.stdout = self.buffer = StringIO()
+return self.buffer
+def __exit__(self, *args):
+sys.stdout = self.old_stdout
+
+
 class TestReplayProcessGroup:
 
 def setup_class(cls):
@@ -17,6 +28,10 @@
 
 class DBState:
 break_loop = -2
+stuff = None
+metavar = None
+printed_stuff = None
+watch_future = -1
 dbstate = DBState()
 
 def blip(cmd, extra):
@@ -27,8 +42,46 @@
 revdb.send_answer(42, cmd.c_cmd, -43, -44, extra)
 lambda_blip = lambda: blip
 
+def command_print(cmd, extra):
+if extra == 'print-me':
+stuff = dbstate.stuff
+elif extra == '$0':
+stuff = dbstate.metavar
+else:
+assert False
+uid = revdb.get_unique_id(stuff)
+ll_assert(uid > 0, "uid == 0")
+revdb.send_nextnid(uid)   # outputs '$NUM = '
+revdb.send_output('stuff\n')
+dbstate.printed_stuff = stuff
+lambda_print = lambda: command_print
+
+def command_attachid(cmd, extra):
+index_metavar = cmd.c_arg1
+uid = cmd.c_arg2
+ll_assert(index_metavar == 0, "index_metavar != 0")  # in this test
+dbstate.metavar = dbstate.printed_stuff
+if dbstate.metavar is None:
+# uid not found, probably a future object
+dbstate.watch_future = uid
+lambda_attachid = lambda: command_attachid
+
+def command_allocating(uid, gcref):
+stuff = cast_gcref_to_instance(Stuff, gcref)
+# 'stuff' is just allocated; 'stuff.x' is not yet initialized
+dbstate.printed_stuff = stuff
+if dbstate.watch_future != -1:
+ll_assert(dbstate.watch_future == uid,
+  "watch_future out of sync")
+dbstate.watch_future = -1
+dbstate.metavar = stuff
+lambda_allocating = lambda: command_allocating
+
 def main(argv):
 revdb.register_debug_command(100, lambda_blip)
+revdb.register_debug_command(CMD_PRINT, lambda_print)
+   

[pypy-commit] pypy reverse-debugger: Update printed text

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r86166:4a605deff6e0
Date: 2016-08-12 11:02 +0200
http://bitbucket.org/pypy/pypy/changeset/4a605deff6e0/

Log:Update printed text

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
@@ -978,12 +978,18 @@
 fprintf(stderr,
 "\n"
 "In the replaying process, the addresses are different than\n"
-"in the recording process.  We don't support this case for\n"
-"now, sorry.  On Linux, check if Address Space Layout\n"
-"Randomization (ASLR) is enabled, and disable it with:\n"
+"in the recording process.  Make sure that the executable\n"
+"\n"
+"%s\n"
+"\n"
+"is the same one as the one that was used during recording.\n"
+"If it is, then you may be hitting an issue with Address\n"
+"Space Layout Randomization.  On Linux, ASLR should be\n"
+"automatically disabled, but just in case, the following\n"
+"command disables it manually:\n"
 "\n"
 "echo 0 | sudo tee /proc/sys/kernel/randomize_va_space\n"
-"\n");
+"\n", argv[0]);
 exit(1);
 }
 *argc_p = h.argc;
@@ -1129,7 +1135,7 @@
 fprintf(stderr, "%s:%d: Attempted to do I/O or access raw memory\n",
 file, line);
 if (flag_io_disabled != FID_POTENTIAL_IO) {
-fprintf(stderr, "but we are not in a jmpbuf_protected section\n");
+fprintf(stderr, "but we are not in a protected section\n");
 exit(1);
 }
 write_answer(ANSWER_ATTEMPT_IO, 0, 0, 0);
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reverse-debugger: When entering debugger commands, make floating-point results

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r86167:c46e5f55f170
Date: 2016-08-12 11:34 +0200
http://bitbucket.org/pypy/pypy/changeset/c46e5f55f170/

Log:When entering debugger commands, make floating-point results
approximately work

diff --git a/rpython/rlib/rdtoa.py b/rpython/rlib/rdtoa.py
--- a/rpython/rlib/rdtoa.py
+++ b/rpython/rlib/rdtoa.py
@@ -3,7 +3,7 @@
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.translator import cdir
 from rpython.rtyper.lltypesystem import lltype, rffi
-from rpython.rlib import jit
+from rpython.rlib import jit, revdb
 from rpython.rlib.rstring import StringBuilder
 import py, sys
 
@@ -54,6 +54,8 @@
 def strtod(input):
 if len(input) > _INT_LIMIT:
 raise MemoryError
+if revdb.flag_io_disabled():
+return revdb.emulate_strtod(input)
 end_ptr = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
 try:
 ll_input = rffi.str2charp(input)
@@ -236,6 +238,8 @@
  special_strings=lower_special_strings, upper=False):
 if precision > _INT_LIMIT:
 raise MemoryError
+if revdb.flag_io_disabled():
+return revdb.emulate_dtoa(value)
 decpt_ptr = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
 try:
 sign_ptr = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
diff --git a/rpython/rlib/revdb.py b/rpython/rlib/revdb.py
--- a/rpython/rlib/revdb.py
+++ b/rpython/rlib/revdb.py
@@ -7,7 +7,7 @@
 from rpython.rtyper.extregistry import ExtRegistryEntry
 from rpython.rtyper.annlowlevel import llhelper, hlstr
 from rpython.rtyper.annlowlevel import cast_gcref_to_instance
-from rpython.rtyper.lltypesystem import rffi
+from rpython.rtyper.lltypesystem import lltype, rffi
 
 
 CMD_PRINT   = 1
@@ -81,6 +81,14 @@
 """
 return llop.revdb_get_value(lltype.Signed, 'p')
 
+def flag_io_disabled():
+"""Returns True if we're in the debugger typing commands."""
+if we_are_translated():
+if fetch_translated_config().translation.reverse_debugger:
+flag = llop.revdb_get_value(lltype.Signed, 'i')
+return flag != ord('R')  # FID_REGULAR_MODE
+return False
+
 ## @specialize.arg(1)
 ## def go_forward(time_delta, callback):
 ## """For RPython debug commands: tells that after this function finishes,
@@ -203,3 +211,22 @@
 
 def specialize_call(self, hop):
 hop.exception_cannot_occur()
+
+
+# 
+
+# Emulation for strtod() and dtoa() when running debugger commands
+# (we can't easily just call C code there).  The emulation can return
+# a crude result.  Hack hack hack.
+
+_INVALID_STRTOD = -3.46739514239368e+113
+
+def emulate_strtod(input):
+d = llop.revdb_strtod(lltype.Float, input)
+if d == _INVALID_STRTOD:
+raise ValueError
+return d
+
+def emulate_dtoa(value):
+s = llop.revdb_dtoa(lltype.Ptr(rstr.STR), value)
+return hlstr(s)
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
@@ -584,6 +584,8 @@
 'revdb_weakref_deref':  LLOp(),
 'revdb_call_destructor': LLOp(),
 'revdb_set_thread_breakpoint': LLOp(),
+'revdb_strtod': LLOp(sideeffects=False),
+'revdb_dtoa':   LLOp(sideeffects=False),
 }
 # * Run test_lloperation after changes. *
 
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
@@ -1523,6 +1523,8 @@
 saved_state.unique_id_seen);
 case 'p':   /* current_place() */
 return current_place;
+case 'i':   /* flag_io_disabled() */
+return flag_io_disabled;
 default:
 return -1;
 }
@@ -1734,6 +1736,39 @@
 break_thread_num = (uint64_t)tnum;
 }
 
+#define INVALID_STRTOD  (-3.46739514239368e+113)
+
+RPY_EXTERN
+double rpy_reverse_db_strtod(RPyString *s)
+{
+/* approximate hacks only */
+double result;
+char *endptr = NULL;
+char buffer[8192];
+size_t size = RPyString_Size(s);
+
+if (size >= sizeof(buffer))
+return INVALID_STRTOD;
+memcpy(buffer, _RPyString_AsString(s), size);
+buffer[size] = '\0';
+result = strtod(buffer, &endptr);
+if (endptr == NULL || *endptr != '\0')
+return INVALID_STRTOD;
+return result;
+}
+
+RPY_EXTERN RPyString *rpy_reverse_db_dtoa(double d)
+{
+char buffer[128];
+RPyString *result;
+int size;
+size = snprintf(buffer, sizeof(buffer), "%g", d);
+if (size < 0) size = 0;   /* XXX? */
+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/rpyth

[pypy-commit] pypy reverse-debugger: translation fix

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r86168:bec055ffd7c0
Date: 2016-08-12 11:53 +0200
http://bitbucket.org/pypy/pypy/changeset/bec055ffd7c0/

Log:translation fix

diff --git a/rpython/rlib/revdb.py b/rpython/rlib/revdb.py
--- a/rpython/rlib/revdb.py
+++ b/rpython/rlib/revdb.py
@@ -229,4 +229,6 @@
 
 def emulate_dtoa(value):
 s = llop.revdb_dtoa(lltype.Ptr(rstr.STR), value)
-return hlstr(s)
+s = hlstr(s)
+assert s is not None
+return s
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy refactor_rmmap: Refactor rmmap.py JIT support into its own file.

2016-08-12 Thread vext01
Author: Edd Barrett 
Branch: refactor_rmmap
Changeset: r86169:a80e988edfd0
Date: 2016-08-12 11:26 +0100
http://bitbucket.org/pypy/pypy/changeset/a80e988edfd0/

Log:Refactor rmmap.py JIT support into its own file.

And test with a W^X patch to the build system.

diff --git a/rpython/jit/backend/llsupport/asmmemmgr.py 
b/rpython/jit/backend/llsupport/asmmemmgr.py
--- a/rpython/jit/backend/llsupport/asmmemmgr.py
+++ b/rpython/jit/backend/llsupport/asmmemmgr.py
@@ -1,7 +1,7 @@
 import sys
 from rpython.rlib.rarithmetic import intmask, r_uint, LONG_BIT
 from rpython.rlib.objectmodel import we_are_translated
-from rpython.rlib import rmmap
+from rpython.jit.backend.llsupport import rmmap
 from rpython.rlib.debug import debug_start, debug_print, debug_stop
 from rpython.rlib.debug import have_debug_prints
 from rpython.rtyper.lltypesystem import lltype, rffi
diff --git a/rpython/jit/backend/llsupport/rmmap.py 
b/rpython/jit/backend/llsupport/rmmap.py
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/llsupport/rmmap.py
@@ -0,0 +1,145 @@
+"""mmap for the JIT
+
+Derived from rlib.rmmap
+"""
+
+# borrow a few bits from our rlib cousin, but we must not share functions
+from rpython.rlib.rmmap import _POSIX, _MS_WINDOWS, _CYGWIN, constants, CConfig
+if _POSIX:
+from rpython.rlib.rmmap import (
+MAP_PRIVATE, MAP_ANONYMOUS, PROT_EXEC, PROT_READ, PROT_WRITE, PTR)
+if _MS_WINDOWS:
+from rpython.rlib.rwin32 import LPDWORD, DWORD, BOOL
+from rpython.rlib.rmmap import (
+MEM_COMMIT, MEM_RESERVE, PAGE_EXECUTE_READWRITE, MEM_RELEASE)
+
+from rpython.rtyper.lltypesystem import rffi, lltype
+from rpython.rlib import rposix
+from rpython.rtyper.tool import rffi_platform
+
+
+locals().update(constants)
+
+
+def safe_external(name, args, result, save_err_on_unsafe=0, save_err_on_safe=0,
+  **kwargs):
+return rffi.llexternal(name, args, result,
+   compilation_info=CConfig._compilation_info_,
+   sandboxsafe=True, releasegil=False,
+   save_err=save_err_on_safe, **kwargs)
+
+
+def safe_winexternal(name, args, result, **kwargs):
+return rffi.llexternal(name, args, result,
+   compilation_info=CConfig._compilation_info_,
+   calling_conv='win', sandboxsafe=True,
+   releasegil=False, **kwargs)
+
+
+if _POSIX:
+c_mmap_safe = safe_external(
+'mmap', [PTR, size_t, rffi.INT, rffi.INT, rffi.INT, off_t], PTR,
+macro=True, save_err_on_unsafe=rffi.RFFI_SAVE_ERRNO)
+
+c_munmap_safe = safe_external('munmap', [PTR, size_t], rffi.INT)
+
+
+if _CYGWIN:
+c_free_safe = safe_external('free', [PTR], lltype.Void, macro=True)
+c_malloc_safe = safe_external('malloc', [size_t], PTR, macro=True)
+
+if _MS_WINDOWS:
+VirtualAlloc_safe = safe_winexternal(
+'VirtualAlloc', [rffi.VOIDP, rffi.SIZE_T, DWORD, DWORD], rffi.VOIDP)
+
+_VirtualProtect_safe = safe_winexternal(
+'VirtualProtect', [rffi.VOIDP, rffi.SIZE_T, DWORD, LPDWORD], BOOL)
+
+def VirtualProtect(addr, size, mode, oldmode_ptr):
+return _VirtualProtect_safe(
+addr, rffi.cast(rffi.SIZE_T, size), rffi.cast(DWORD, mode),
+oldmode_ptr)
+VirtualProtect._annspecialcase_ = 'specialize:ll'
+
+VirtualFree_safe = safe_winexternal(
+'VirtualFree', [rffi.VOIDP, rffi.SIZE_T, DWORD], BOOL)
+
+
+if _POSIX:
+def alloc_hinted(hintp, map_size):
+flags = MAP_PRIVATE | MAP_ANONYMOUS
+prot = PROT_EXEC | PROT_READ | PROT_WRITE
+return c_mmap_safe(hintp, map_size, prot, flags, -1, 0)
+
+# XXX is this really necessary?
+class Hint:
+pos = -0x4fff   # for reproducible results
+hint = Hint()
+
+def alloc(map_size):
+"""Allocate memory.  This is intended to be used by the JIT,
+so the memory has the executable bit set and gets allocated
+internally in case of a sandboxed process.
+"""
+from errno import ENOMEM
+from rpython.rlib import debug
+
+if _CYGWIN:
+# XXX: JIT memory should be using mmap MAP_PRIVATE with
+#  PROT_EXEC but Cygwin's fork() fails.  mprotect()
+#  cannot be used, but seems to be unnecessary there.
+res = c_malloc_safe(map_size)
+if res == rffi.cast(PTR, 0):
+raise MemoryError
+return res
+res = alloc_hinted(rffi.cast(PTR, hint.pos), map_size)
+if res == rffi.cast(PTR, -1):
+# some systems (some versions of OS/X?) complain if they
+# are passed a non-zero address.  Try again.
+res = alloc_hinted(rffi.cast(PTR, 0), map_size)
+if res == rffi.cast(PTR, -1):
+# ENOMEM simply raises MemoryError, but other errors are fatal
+if rposix.get_saved_errno() != ENOMEM:
+debug.fataler

[pypy-commit] pypy reverse-debugger: Emulate modf. Fix emulation of dtoa(2.0) to output the ".0" too.

2016-08-12 Thread arigo
Author: Armin Rigo 
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
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy refactor_rmmap: Close branch.

2016-08-12 Thread vext01
Author: Edd Barrett 
Branch: refactor_rmmap
Changeset: r86171:9f7d18f5d82f
Date: 2016-08-12 15:12 +0100
http://bitbucket.org/pypy/pypy/changeset/9f7d18f5d82f/

Log:Close branch.

___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.5: hg merge py3k

2016-08-12 Thread mjacob
Author: Manuel Jacob 
Branch: py3.5
Changeset: r86172:d1ba25403058
Date: 2016-08-12 17:48 +0200
http://bitbucket.org/pypy/pypy/changeset/d1ba25403058/

Log:hg merge py3k

diff too long, truncating to 2000 out of 4110 lines

diff --git a/include/PyPy.h b/include/PyPy.h
--- a/include/PyPy.h
+++ b/include/PyPy.h
@@ -2,7 +2,11 @@
 #define _PYPY_H_
 
 /* This header is meant to be included in programs that use PyPy as an
-   embedded library. */
+   embedded library.
+
+   NOTE: this is deprecated.  Instead, use cffi's embedding support:
+   http://cffi.readthedocs.org/en/latest/embedding.html
+*/
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/lib_pypy/cffi.egg-info/PKG-INFO b/lib_pypy/cffi.egg-info/PKG-INFO
--- a/lib_pypy/cffi.egg-info/PKG-INFO
+++ b/lib_pypy/cffi.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: cffi
-Version: 1.7.0
+Version: 1.8.0
 Summary: Foreign Function Interface for Python calling C code.
 Home-page: http://cffi.readthedocs.org
 Author: Armin Rigo, Maciej Fijalkowski
diff --git a/lib_pypy/cffi/__init__.py b/lib_pypy/cffi/__init__.py
--- a/lib_pypy/cffi/__init__.py
+++ b/lib_pypy/cffi/__init__.py
@@ -4,8 +4,8 @@
 from .api import FFI, CDefError, FFIError
 from .ffiplatform import VerificationError, VerificationMissing
 
-__version__ = "1.7.0"
-__version_info__ = (1, 7, 0)
+__version__ = "1.8.0"
+__version_info__ = (1, 8, 0)
 
 # The verifier module file names are based on the CRC32 of a string that
 # contains the following version number.  It may be older than __version__
diff --git a/lib_pypy/cffi/_cffi_include.h b/lib_pypy/cffi/_cffi_include.h
--- a/lib_pypy/cffi/_cffi_include.h
+++ b/lib_pypy/cffi/_cffi_include.h
@@ -42,7 +42,9 @@
 #  include 
 # endif
 # if _MSC_VER < 1800   /* MSVC < 2013 */
-   typedef unsigned char _Bool;
+#  ifndef __cplusplus
+typedef unsigned char _Bool;
+#  endif
 # endif
 #else
 # include 
@@ -59,7 +61,7 @@
 
 #ifdef __cplusplus
 # ifndef _Bool
-#  define _Bool bool   /* semi-hackish: C++ has no _Bool; bool is builtin */
+   typedef bool _Bool;   /* semi-hackish: C++ has no _Bool; bool is builtin */
 # endif
 #endif
 
@@ -196,20 +198,6 @@
 return NULL;
 }
 
-_CFFI_UNUSED_FN
-static PyObject **_cffi_unpack_args(PyObject *args_tuple, Py_ssize_t expected,
-const char *fnname)
-{
-if (PyTuple_GET_SIZE(args_tuple) != expected) {
-PyErr_Format(PyExc_TypeError,
- "%.150s() takes exactly %zd arguments (%zd given)",
- fnname, expected, PyTuple_GET_SIZE(args_tuple));
-return NULL;
-}
-return &PyTuple_GET_ITEM(args_tuple, 0);   /* pointer to the first item,
-  the others follow */
-}
-
 /**  end CPython-specific section  **/
 #else
 _CFFI_UNUSED_FN
diff --git a/lib_pypy/cffi/_embedding.h b/lib_pypy/cffi/_embedding.h
--- a/lib_pypy/cffi/_embedding.h
+++ b/lib_pypy/cffi/_embedding.h
@@ -233,7 +233,7 @@
 f = PySys_GetObject((char *)"stderr");
 if (f != NULL && f != Py_None) {
 PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-   "\ncompiled with cffi version: 1.7.0"
+   "\ncompiled with cffi version: 1.8.0"
"\n_cffi_backend module: ", f);
 modules = PyImport_GetModuleDict();
 mod = PyDict_GetItemString(modules, "_cffi_backend");
diff --git a/lib_pypy/cffi/model.py b/lib_pypy/cffi/model.py
--- a/lib_pypy/cffi/model.py
+++ b/lib_pypy/cffi/model.py
@@ -519,12 +519,10 @@
 smallest_value = min(self.enumvalues)
 largest_value = max(self.enumvalues)
 else:
-import warnings
-warnings.warn("%r has no values explicitly defined; next version "
-  "will refuse to guess which integer type it is "
-  "meant to be (unsigned/signed, int/long)"
-  % self._get_c_name())
-smallest_value = largest_value = 0
+raise api.CDefError("%r has no values explicitly defined: "
+"refusing to guess which integer type it is "
+"meant to be (unsigned/signed, int/long)"
+% self._get_c_name())
 if smallest_value < 0:   # needs a signed type
 sign = 1
 candidate1 = PrimitiveType("int")
diff --git a/lib_pypy/cffi/recompiler.py b/lib_pypy/cffi/recompiler.py
--- a/lib_pypy/cffi/recompiler.py
+++ b/lib_pypy/cffi/recompiler.py
@@ -275,6 +275,8 @@
 def write_c_source_to_f(self, f, preamble):
 self._f = f
 prnt = self._prnt
+if self.ffi._embedding is None:
+prnt('#define Py_LIMITED_API')
 #
 # first the '#include' (actually done by inlining the file's content)
 lines = self._rel_readlines('_cffi_include.h')
@@ -683,13 +685,11 @@
 rng = range(len(tp.args

[pypy-commit] pypy py3.5: Fix BUILD_SET_UNPACK by changing iterator to iter instead of itervalues as w_item should never be a dict anyway

2016-08-12 Thread raffael_t
Author: Raffael Tfirst 
Branch: py3.5
Changeset: r86173:f658ed1189a5
Date: 2016-08-12 17:57 +0200
http://bitbucket.org/pypy/pypy/changeset/f658ed1189a5/

Log:Fix BUILD_SET_UNPACK by changing iterator to iter instead of
itervalues as w_item should never be a dict anyway

diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -1375,10 +1375,11 @@
 for i in range(itemcount, 0, -1):
 w_item = self.peekvalue(i-1)
 # cannot use w_sum.update, w_item might not be a set
-iterator = w_item.itervalues()
+iterator = space.iter(w_item)
 while True:
-w_value = iterator.next_value()
-if w_value is None:
+try:
+w_value = space.next(iterator)
+except OperationError:
 break
 w_sum.add(w_value)
 while itemcount != 0:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: Remove code added by py2-specific branch 'resource_warning'

2016-08-12 Thread rlamy
Author: Ronan Lamy 
Branch: py3k
Changeset: r86174:b00718188b59
Date: 2016-08-12 17:35 +0100
http://bitbucket.org/pypy/pypy/changeset/b00718188b59/

Log:Remove code added by py2-specific branch 'resource_warning'

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1801,40 +1801,6 @@
 _warnings.warn(msg, warningcls, stacklevel=stacklevel)
 """)
 
-def resource_warning(self, w_msg, w_tb):
-self.appexec([w_msg, w_tb],
- """(msg, tb):
-import sys
-print >> sys.stderr, msg
-if tb:
-print >> sys.stderr, "Created at (most recent call last):"
-print >> sys.stderr, tb
-""")
-
-def format_traceback(self):
-# we need to disable track_resources before calling the traceback
-# module. Else, it tries to open more files to format the traceback,
-# the file constructor will call space.format_traceback etc., in an
-# inifite recursion
-flag = self.sys.track_resources
-self.sys.track_resources = False
-try:
-return self.appexec([],
- """():
-import sys, traceback
-# the "1" is because we don't want to show THIS code
-# object in the traceback
-try:
-f = sys._getframe(1)
-except ValueError:
-# this happens if you call format_traceback at the very 
beginning
-# of startup, when there is no bottom code object
-return ''
-return "".join(traceback.format_stack(f))
-""")
-finally:
-self.sys.track_resources = flag
-
 
 class AppExecCache(SpaceCache):
 def build(cache, source):
diff --git a/pypy/interpreter/test/test_app_main.py 
b/pypy/interpreter/test/test_app_main.py
--- a/pypy/interpreter/test/test_app_main.py
+++ b/pypy/interpreter/test/test_app_main.py
@@ -209,14 +209,6 @@
 self.check(['-c', 'pass'], {'PYTHONNOUSERSITE': '1'}, sys_argv=['-c'],
run_command='pass', **expected)
 
-def test_track_resources(self, monkeypatch):
-myflag = [False]
-def pypy_set_track_resources(flag):
-myflag[0] = flag
-monkeypatch.setattr(sys, 'pypy_set_track_resources', 
pypy_set_track_resources, raising=False)
-self.check(['-X', 'track-resources'], {}, sys_argv=[''], 
run_stdin=True)
-assert myflag[0] == True
-
 class TestInteraction:
 """
 These tests require pexpect (UNIX-only).
diff --git a/pypy/interpreter/test/test_objspace.py 
b/pypy/interpreter/test/test_objspace.py
--- a/pypy/interpreter/test/test_objspace.py
+++ b/pypy/interpreter/test/test_objspace.py
@@ -134,7 +134,7 @@
 assert self.space.lookup(w_instance, "gobbledygook") is None
 w_instance = self.space.appexec([], """():
 class Lookup(object):
-"bla" 
+"bla"
 return Lookup()""")
 assert self.space.str_w(self.space.lookup(w_instance, "__doc__")) == 
"bla"
 
@@ -148,7 +148,7 @@
 assert is_callable(w_func)
 w_lambda_func = self.space.appexec([], "(): return lambda: True")
 assert is_callable(w_lambda_func)
-
+
 w_instance = self.space.appexec([], """():
 class Call(object):
 def __call__(self): pass
@@ -308,7 +308,7 @@
 
 def test_call_obj_args(self):
 from pypy.interpreter.argument import Arguments
-
+
 space = self.space
 
 w_f = space.appexec([], """():
@@ -333,7 +333,7 @@
 assert w_x is w_9
 assert w_y is w_1
 
-w_res = space.call_obj_args(w_a, w_9, Arguments(space, []))
+w_res = space.call_obj_args(w_a, w_9, Arguments(space, []))
 assert w_res is w_9
 
 def test_compare_by_iteration(self):
@@ -383,7 +383,7 @@
 assert not space.isabstractmethod_w(space.getattr(w_B, 
space.wrap('g')))
 assert not space.isabstractmethod_w(space.getattr(w_B, 
space.wrap('h')))
 
-class TestModuleMinimal: 
+class TestModuleMinimal:
 def test_sys_exists(self):
 assert self.space.sys
 
@@ -458,28 +458,3 @@
 space.finish()
 # assert that we reach this point without getting interrupted
 # by the OperationError(NameError)
-
-def test_format_traceback(self):
-from pypy.tool.pytest.objspace import maketestobjspace
-from pypy.interpreter.gateway import interp2app
-#
-def format_traceback(space):
-return space.format_traceback()
-#
-space = maketestobjspace()
-w_format_traceback = space.wrap(interp2app(format_traceback))
-w_tb = space.appexec([w_format_traceback], """(format_traceback):
-def foo():
- 

[pypy-commit] pypy reverse-debugger: Next emulation (we'll see how far it makes sense to continue)

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r86175:9dbb62851b3f
Date: 2016-08-12 18:52 +0200
http://bitbucket.org/pypy/pypy/changeset/9dbb62851b3f/

Log:Next emulation (we'll see how far it makes sense to continue)

diff --git a/rpython/rlib/revdb.py b/rpython/rlib/revdb.py
--- a/rpython/rlib/revdb.py
+++ b/rpython/rlib/revdb.py
@@ -236,3 +236,7 @@
 def emulate_modf(x):
 return (llop.revdb_modf(lltype.Float, x, 0),
 llop.revdb_modf(lltype.Float, x, 1))
+
+def emulate_frexp(x):
+return (llop.revdb_frexp(lltype.Float, x, 0),
+int(llop.revdb_frexp(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
@@ -587,6 +587,7 @@
 'revdb_strtod': LLOp(sideeffects=False),
 'revdb_dtoa':   LLOp(sideeffects=False),
 'revdb_modf':   LLOp(sideeffects=False),
+'revdb_frexp':  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
@@ -185,6 +185,8 @@
 mantissa = x
 exponent = 0
 else:
+if revdb.flag_io_disabled():
+return revdb.emulate_frexp(x)
 exp_p = lltype.malloc(rffi.INTP.TO, 1, flavor='raw')
 try:
 mantissa = math_frexp(x, exp_p)
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
@@ -243,6 +243,13 @@
 r = (index == 0) ? _r0 : _r1;   \
 } while (0)
 
+#define OP_REVDB_FREXP(x, index, r) \
+do {\
+double _r0; int _r1;\
+_r0 = frexp(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
@@ -52,6 +52,9 @@
 valx, valy = math.modf(val)
 revdb.send_output(rdtoa.dtoa(valx) + '\n')
 revdb.send_output(rdtoa.dtoa(valy) + '\n')
+xx, yy = math.frexp(val)
+revdb.send_output(rdtoa.dtoa(xx) + '\n')
+revdb.send_output('%d\n' % yy)
 return
 else:
 assert False
@@ -210,4 +213,4 @@
 group = ReplayProcessGroup(str(self.exename), self.rdbname)
 with stdout_capture() as buf:
 group.print_cmd('2.35')
-assert buf.getvalue() == "0.35\n2.0\n"
+assert buf.getvalue() == "0.35\n2.0\n0.5875\n2\n"
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: Fix translation

2016-08-12 Thread rlamy
Author: Ronan Lamy 
Branch: py3k
Changeset: r86176:b1def8b63787
Date: 2016-08-12 17:58 +0100
http://bitbucket.org/pypy/pypy/changeset/b1def8b63787/

Log:Fix translation

diff --git a/pypy/module/_cffi_backend/ctypeptr.py 
b/pypy/module/_cffi_backend/ctypeptr.py
--- a/pypy/module/_cffi_backend/ctypeptr.py
+++ b/pypy/module/_cffi_backend/ctypeptr.py
@@ -267,7 +267,7 @@
 space = self.space
 if self.accept_str and space.isinstance_w(w_init, space.w_str):
 # special case to optimize strings passed to a "char *" argument
-value = w_init.str_w(space)
+value = space.bytes_w(w_init)
 keepalives[i] = value
 buf, buf_flag = rffi.get_nonmovingbuffer_final_null(value)
 rffi.cast(rffi.CCHARPP, cdata)[0] = buf
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: Fix bad change in b053ff5c2d6d

2016-08-12 Thread rlamy
Author: Ronan Lamy 
Branch: py3k
Changeset: r86177:3a81057901f3
Date: 2016-08-12 18:48 +0100
http://bitbucket.org/pypy/pypy/changeset/3a81057901f3/

Log:Fix bad change in b053ff5c2d6d

diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -1288,8 +1288,9 @@
 cycle.append(candidate)
 cycle.reverse()
 names = [cls.getname(space) for cls in cycle]
-raise oefmt(space.w_TypeError,
-"cycle among base classes: %s", ' < '.join(names))
+# Can't use oefmt() here, since names is a list of unicodes
+raise OperationError(space.w_TypeError, space.newunicode(
+u"cycle among base classes: " + u' < '.join(names)))
 
 
 class TypeCache(SpaceCache):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Test and probable fix (thanks sbauman)

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r86178:cd39a869a312
Date: 2016-08-12 20:59 +0200
http://bitbucket.org/pypy/pypy/changeset/cd39a869a312/

Log:Test and probable fix (thanks sbauman)

diff --git a/rpython/rlib/rweakref.py b/rpython/rlib/rweakref.py
--- a/rpython/rlib/rweakref.py
+++ b/rpython/rlib/rweakref.py
@@ -142,7 +142,7 @@
 
 def compute_result_annotation(self, s_keyclass, s_valueclass):
 assert s_keyclass.is_constant()
-s_key = self.bookkeeper.immutablevalue(s_keyclass.const())
+s_key = self.bookkeeper.valueoftype(s_keyclass.const)
 return SomeWeakValueDict(
 s_key,
 _getclassdef(s_valueclass))
@@ -158,7 +158,7 @@
 bk = self.bookkeeper
 x = self.instance
 return SomeWeakValueDict(
-bk.immutablevalue(x._keyclass()),
+bk.valueoftype(x._keyclass),
 bk.getuniqueclassdef(x._valueclass))
 
 def _getclassdef(s_instance):
diff --git a/rpython/rlib/test/test_rweakvaldict.py 
b/rpython/rlib/test/test_rweakvaldict.py
--- a/rpython/rlib/test/test_rweakvaldict.py
+++ b/rpython/rlib/test/test_rweakvaldict.py
@@ -180,3 +180,36 @@
 RWeakValueDictionary(str, X).get("foobar")
 RWeakValueDictionary(int, Y).get(42)
 interpret(g, [])
+
+def test_key_instance():
+class K(object):
+pass
+keys = [K(), K(), K()]
+
+def g(d):
+assert d.get(keys[3]) is None
+x1 = X(); x2 = X(); x3 = X()
+d.set(keys[0], x1)
+d.set(keys[1], x2)
+d.set(keys[2], x3)
+assert d.get(keys[0]) is x1
+assert d.get(keys[1]) is x2
+assert d.get(keys[2]) is x3
+assert d.get(keys[3]) is None
+return x1, x3# x2 dies
+def f():
+keys.append(K())
+d = RWeakValueDictionary(K, X)
+x1, x3 = g(d)
+rgc.collect(); rgc.collect()
+assert d.get(keys[0]) is x1
+assert d.get(keys[1]) is None
+assert d.get(keys[2]) is x3
+assert d.get(keys[3]) is None
+d.set(keys[0], None)
+assert d.get(keys[0]) is None
+assert d.get(keys[1]) is None
+assert d.get(keys[2]) is x3
+assert d.get(keys[3]) is None
+f()
+interpret(f, [])
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reverse-debugger: Install a minimal __import__ hook to use interactively. At least this

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r86179:423804b65c4c
Date: 2016-08-12 21:27 +0200
http://bitbucket.org/pypy/pypy/changeset/423804b65c4c/

Log:Install a minimal __import__ hook to use interactively. At least
this version doesn't try to look for a file in the current
directory, e.g. if we do "import math" instead a package, which just
fails with "Attempted to do I/O".

diff --git a/pypy/interpreter/reverse_debugging.py 
b/pypy/interpreter/reverse_debugging.py
--- a/pypy/interpreter/reverse_debugging.py
+++ b/pypy/interpreter/reverse_debugging.py
@@ -321,18 +321,52 @@
 revdb.send_output(s)
 revdb.send_output("\n")
 
+@gateway.unwrap_spec(name='str0', level=int)
+def revdb_importhook(space, name, w_globals=None,
+ w_locals=None, w_fromlist=None, level=-1):
+# Incredibly simplified version of __import__, which only returns
+# already-imported modules and doesn't call any custom import
+# hooks.  Recognizes only absolute imports.  With a 'fromlist'
+# argument that is a non-empty list, returns the module 'name3' if
+# the 'name' argument is 'name1.name2.name3'.  With an empty or
+# None 'fromlist' argument, returns the module 'name1' instead.
+return space.appexec([space.wrap(name), w_fromlist or space.w_None,
+  space.wrap(level), space.wrap(space.sys)],
+"""(name, fromlist, level, sys):
+if level > 0:
+raise ImportError("only absolute imports are "
+   "supported in the debugger")
+basename = name.split('.')[0]
+try:
+basemod = sys.modules[basename]
+mod = sys.modules[name]
+except KeyError:
+raise ImportError("'%s' not found or not imported yet "
+"(the debugger can't import new modules, "
+"and only supports absolute imports)" % (name,))
+if fromlist:
+return mod
+return basemod
+""")
+
 @specialize.memo()
 def get_revdb_displayhook(space):
 return space.wrap(gateway.interp2app(revdb_displayhook))
 
+@specialize.memo()
+def get_revdb_importhook(space):
+return space.wrap(gateway.interp2app(revdb_importhook))
+
 
 def prepare_print_environment(space):
 assert not dbstate.standard_code
 w_revdb_output = space.wrap(W_RevDBOutput(space))
 w_displayhook = get_revdb_displayhook(space)
+w_import = get_revdb_importhook(space)
 space.sys.setdictvalue(space, 'stdout', w_revdb_output)
 space.sys.setdictvalue(space, 'stderr', w_revdb_output)
 space.sys.setdictvalue(space, 'displayhook', w_displayhook)
+space.builtin.setdictvalue(space, '__import__', w_import)
 
 def command_print(cmd, expression):
 frame = fetch_cur_frame()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy reverse-debugger: Trying to support pressing Ctrl-C to interrupt the current operation

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r86180:2311c3b8a675
Date: 2016-08-12 22:44 +0200
http://bitbucket.org/pypy/pypy/changeset/2311c3b8a675/

Log:Trying to support pressing Ctrl-C to interrupt the current operation

diff --git a/rpython/translator/revdb/interact.py 
b/rpython/translator/revdb/interact.py
--- a/rpython/translator/revdb/interact.py
+++ b/rpython/translator/revdb/interact.py
@@ -35,59 +35,79 @@
 self.print_extra_pending_info = None
 
 def interact(self):
-last_command = 'help'
-previous_time = None
-previous_thread = 0
+self.last_command = 'help'
+self.previous_time = None
+self.previous_thread = 0
 while True:
+prompt = self.print_lines_before_prompt()
+try:
+while True:
+cmdline = self.display_prompt(prompt)
+self.run_command(cmdline)
+prompt = self.print_lines_before_prompt()
+except KeyboardInterrupt:
+self.pgroup.recreate_subprocess(self.previous_time or 1)
+self.last_command = ''
+self.previous_thread = '?'
+self.previous_time = '?'
+
+def print_lines_before_prompt(self):
+last_time = self.pgroup.get_current_time()
+if last_time != self.previous_time:
+print
+if self.pgroup.get_current_thread() != self.previous_thread:
+self.previous_thread = self.pgroup.get_current_thread()
+if self.previous_thread == 0:
+print (' in main thread #0 '
+   '')
+else:
+print (' in non-main thread '
+   '#%d ' % 
(self.previous_thread,))
+self.pgroup.update_watch_values()
 last_time = self.pgroup.get_current_time()
-if last_time != previous_time:
-print
-if self.pgroup.get_current_thread() != previous_thread:
-previous_thread = self.pgroup.get_current_thread()
-if previous_thread == 0:
-print (' in main thread #0 '
-   '')
-else:
-print (' in non-main thread '
-   '#%d ' % (previous_thread,))
-self.pgroup.update_watch_values()
-last_time = self.pgroup.get_current_time()
-if self.print_extra_pending_info:
-print self.print_extra_pending_info
-self.print_extra_pending_info = None
-if last_time != previous_time:
-self.pgroup.show_backtrace(complete=0)
-previous_time = last_time
+if self.print_extra_pending_info:
+print self.print_extra_pending_info
+self.print_extra_pending_info = None
+if last_time != self.previous_time:
+self.pgroup.show_backtrace(complete=0)
+self.previous_time = last_time
+prompt = '(%d)$ ' % last_time
+return prompt
 
-prompt = '(%d)$ ' % last_time
+def display_prompt(self, prompt):
+try:
+cmdline = raw_input(prompt).strip()
+except EOFError:
+print
+cmdline = 'quit'
+if not cmdline:
+cmdline = self.last_command
+return cmdline
+
+def run_command(self, cmdline):
+match = r_cmdline.match(cmdline)
+if not match:
+return
+self.last_command = cmdline
+command, argument = match.groups()
+try:
+runner = getattr(self, 'command_' + command)
+except AttributeError:
+print >> sys.stderr, "no command '%s', try 'help'" % (command,)
+else:
 try:
-cmdline = raw_input(prompt).strip()
-except EOFError:
-print
-cmdline = 'quit'
-if not cmdline:
-cmdline = last_command
-match = r_cmdline.match(cmdline)
-if not match:
-continue
-last_command = cmdline
-command, argument = match.groups()
-try:
-runner = getattr(self, 'command_' + command)
-except AttributeError:
-print >> sys.stderr, "no command '%s', try 'help'" % (command,)
-else:
-try:
-runner(argument)
-except Exception as e:
-traceback.print_exc()
-print >> sys.stderr
-print >> sys.stderr, 'Something went wrong.  You are now',
-print >> sys.stderr, 'in a pdb; press Ctrl-D to continue.'
- 

[pypy-commit] pypy reverse-debugger: Print something here

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: reverse-debugger
Changeset: r86181:c431addcce4e
Date: 2016-08-12 22:53 +0200
http://bitbucket.org/pypy/pypy/changeset/c431addcce4e/

Log:Print something here

diff --git a/rpython/translator/revdb/interact.py 
b/rpython/translator/revdb/interact.py
--- a/rpython/translator/revdb/interact.py
+++ b/rpython/translator/revdb/interact.py
@@ -46,7 +46,11 @@
 self.run_command(cmdline)
 prompt = self.print_lines_before_prompt()
 except KeyboardInterrupt:
-self.pgroup.recreate_subprocess(self.previous_time or 1)
+rtime = self.previous_time or 1
+print
+print 'KeyboardInterrupt: restoring state at time %d...' % (
+rtime,)
+self.pgroup.recreate_subprocess(rtime)
 self.last_command = ''
 self.previous_thread = '?'
 self.previous_time = '?'
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: For now, we can't specify both ``-O1`` and ``--platform=arm``: the first

2016-08-12 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r86182:31c39adab9d0
Date: 2016-08-13 08:24 +0200
http://bitbucket.org/pypy/pypy/changeset/31c39adab9d0/

Log:For now, we can't specify both ``-O1`` and ``--platform=arm``: the
first option picks ``--gc=boehm`` and the second option picks
``--gcrootfinder=shadowstack``, which are incompatible.

diff --git a/rpython/doc/arm.rst b/rpython/doc/arm.rst
--- a/rpython/doc/arm.rst
+++ b/rpython/doc/arm.rst
@@ -148,7 +148,7 @@
 
 ::
 
-  pypy ~/path_to_pypy_checkout/rpython/bin/rpython -O1 --platform=arm target.py
+  pypy ~/path_to_pypy_checkout/rpython/bin/rpython -O2 --platform=arm target.py
 
 If everything worked correctly this should yield an ARM binary. Running this 
binary in the ARM chroot or on an ARM device should produce the output ``"Hello 
World"``.
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit