[pypy-commit] pypy py3k: Fix syntax error in test

2015-02-16 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3k
Changeset: r75914:e8654d723f68
Date: 2015-02-16 09:54 +0100
http://bitbucket.org/pypy/pypy/changeset/e8654d723f68/

Log:Fix syntax error in test

diff --git a/pypy/module/_sre/test/test_app_sre.py 
b/pypy/module/_sre/test/test_app_sre.py
--- a/pypy/module/_sre/test/test_app_sre.py
+++ b/pypy/module/_sre/test/test_app_sre.py
@@ -206,8 +206,8 @@
 import sys
 if sys.version_info < (2, 7, 9):
 skip()
-assert re.match("(foo)", "foo").group(1L) == "foo"
-exc = raises(IndexError, re.match("", "").group, sys.maxint + 1)
+assert re.match("(foo)", "foo").group(1) == "foo"
+exc = raises(IndexError, re.match("", "").group, sys.maxsize + 1)
 assert str(exc.value) == "no such group"
 
 def test_expand(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: Adapt compiler test to py3k: coding cookie is only used if source is bytes.

2015-02-16 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3k
Changeset: r75915:cb55f5432429
Date: 2015-02-16 10:16 +0100
http://bitbucket.org/pypy/pypy/changeset/cb55f5432429/

Log:Adapt compiler test to py3k: coding cookie is only used if source is
bytes.

diff --git a/pypy/interpreter/test/test_compiler.py 
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -1187,20 +1187,15 @@
 def test_encoding(self):
 code = b'# -*- coding: badencoding -*-\npass\n'
 raises(SyntaxError, compile, code, 'tmp', 'exec')
-code = u"# -*- coding: utf-8 -*-\npass\n"
-raises(SyntaxError, compile, code, 'tmp', 'exec')
 code = 'u"\xc2\xa4"\n'
 assert eval(code) == u'\xc2\xa4'
 code = u'u"\xc2\xa4"\n'
 assert eval(code) == u'\xc2\xa4'
-code = '# -*- coding: latin1 -*-\nu"\xc2\xa4"\n'
+code = b'# -*- coding: latin1 -*-\nu"\xc2\xa4"\n'
 assert eval(code) == u'\xc2\xa4'
-code = '# -*- coding: utf-8 -*-\nu"\xc2\xa4"\n'
+code = b'# -*- coding: utf-8 -*-\nu"\xc2\xa4"\n'
 assert eval(code) == u'\xa4'
-code = '# -*- coding: iso8859-15 -*-\nu"\xc2\xa4"\n'
+code = b'# -*- coding: iso8859-15 -*-\nu"\xc2\xa4"\n'
 assert eval(code) == u'\xc2\u20ac'
-import sys
-if sys.version_info < (2, 7, 9):
-skip()
-code = 'u"""\\\n# -*- coding: utf-8 -*-\n\xc2\xa4"""\n'
-assert eval(code) == u'# -*- coding: utf-8 -*-\n\xc2\xa4'
+code = b'u"""\\\n# -*- coding: ascii -*-\n\xc2\xa4"""\n'
+assert eval(code) == u'# -*- coding: ascii -*-\n\xa4'
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: SSL passwords can be unicode.

2015-02-16 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3k
Changeset: r75913:2cf9d354d605
Date: 2015-02-16 09:52 +0100
http://bitbucket.org/pypy/pypy/changeset/2cf9d354d605/

Log:SSL passwords can be unicode.

diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -1094,13 +1094,16 @@
 if pw_info.w_callable:
 try:
 w_result = space.call_function(pw_info.w_callable)
-try:
-password = pw_info.space.bufferstr_w(w_result)
-except OperationError as e:
-if not e.match(space, space.w_TypeError):
-raise
-raise oefmt(space.w_TypeError, 
-"password callback must return a string")
+if space.isinstance_w(w_result, space.w_unicode):
+password = space.str_w(w_result)
+else:
+try:
+password = pw_info.space.bufferstr_w(w_result)
+except OperationError as e:
+if not e.match(space, space.w_TypeError):
+raise
+raise oefmt(space.w_TypeError, 
+"password callback must return a string")
 except OperationError as e:
 pw_info.operationerror = e
 return rffi.cast(rffi.INT, -1)
@@ -1362,13 +1365,16 @@
 if space.is_true(space.callable(w_password)):
 pw_info.w_callable = w_password
 else:
-try:
-pw_info.password = space.bufferstr_w(w_password)
-except OperationError as e:
-if not e.match(space, space.w_TypeError):
-raise
-raise oefmt(space.w_TypeError, 
-"password should be a string or callable")
+if space.isinstance_w(w_password, space.w_unicode):
+pw_info.password = space.str_w(w_password)
+else:
+try:
+pw_info.password = space.bufferstr_w(w_password)
+except OperationError as e:
+if not e.match(space, space.w_TypeError):
+raise
+raise oefmt(space.w_TypeError, 
+"password should be a string or callable")
 
 libssl_SSL_CTX_set_default_passwd_cb(
 self.ctx, _password_callback)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3k: Fix refcount issue in cpython3 test: this object's reference was

2015-02-16 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3k
Changeset: r75916:745619bed083
Date: 2015-02-16 10:40 +0100
http://bitbucket.org/pypy/pypy/changeset/745619bed083/

Log:Fix refcount issue in cpython3 test: this object's reference was
already "stolen" by a PyTuple_SET_ITEM above.

diff --git a/lib_pypy/_testcapimodule.c b/lib_pypy/_testcapimodule.c
--- a/lib_pypy/_testcapimodule.c
+++ b/lib_pypy/_testcapimodule.c
@@ -808,7 +808,7 @@
 return raiseTestError("test_L_code",
 "L code returned wrong value for long 42");
 
-Py_DECREF(num);
+/* Py_DECREF(num);  <== CPython bug */
 num = PyLong_FromLong(42);
 if (num == NULL)
 return NULL;
@@ -990,7 +990,7 @@
 return raiseTestError("test_k_code",
 "k code returned wrong value for long 0xFFF...FFF");
 
-Py_DECREF(num);
+/* Py_DECREF(num);  <== CPython bug */
 num = PyLong_FromString("-42", NULL, 16);
 if (num == NULL)
 return NULL;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy vmprof: merge

2015-02-16 Thread fijal
Author: Maciej Fijalkowski 
Branch: vmprof
Changeset: r75918:c48ac690c37b
Date: 2015-02-16 13:45 +0200
http://bitbucket.org/pypy/pypy/changeset/c48ac690c37b/

Log:merge

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
@@ -5,7 +5,7 @@
 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
-from rpython.rlib.rbisect import bisect, bisect_tuple
+from rpython.rlib.rbisect import bisect_left, bisect_left_tuple
 
 _memmngr = None # global reference so we can use @entrypoint :/
 
@@ -55,19 +55,16 @@
 self.total_mallocs -= r_uint(stop - start)
 self._add_free_block(start, stop)
 # fix up jit_addr_map
-jit_adr_start = bisect(self.jit_addr_map, start)
-jit_adr_stop = bisect(self.jit_addr_map, stop)
-self.jit_addr_map = (self.jit_addr_map[:jit_adr_start] +
- self.jit_addr_map[jit_adr_stop:])
-self.jit_frame_depth_map = (self.jit_frame_depth_map[:jit_adr_start] +
-self.jit_frame_depth_map[jit_adr_stop:])
+jit_adr_start = bisect_left(self.jit_addr_map, start)
+jit_adr_stop = bisect_left(self.jit_addr_map, stop)
+del self.jit_addr_map[jit_adr_start:jit_adr_stop]
+del self.jit_frame_depth_map[jit_adr_start:jit_adr_stop]
 # fix up codemap
 # (there should only be zero or one codemap entry in that range,
 # but still we use a range to distinguish between zero and one)
-codemap_adr_start = bisect_tuple(self.jit_codemap, start)
-codemap_adr_stop = bisect_tuple(self.jit_codemap, stop)
-self.jit_codemap = (self.jit_codemap[:codemap_adr_start] +
-self.jit_codemap[codemap_adr_stop:])
+codemap_adr_start = bisect_left_tuple(self.jit_codemap, start)
+codemap_adr_stop = bisect_left_tuple(self.jit_codemap, stop)
+del self.jit_codemap[codemap_adr_start:codemap_adr_stop]
 
 def open_malloc(self, minsize):
 """Allocate at least minsize bytes.  Returns (start, stop)."""
@@ -183,7 +180,7 @@
 self.jit_addr_map += [0] * len(frame_positions)
 self.jit_frame_depth_map += [0] * len(frame_positions)
 else:
-start = bisect(self.jit_addr_map, rawstart)
+start = bisect_left(self.jit_addr_map, rawstart)
 self.jit_addr_map = (self.jit_addr_map[:start] +
  [0] * len(frame_positions) +
  self.jit_addr_map[start:])
@@ -196,12 +193,8 @@
 
 def register_codemap(self, codemap):
 start = codemap[0]
-pos = bisect_tuple(self.jit_codemap, start)
-if pos == len(self.jit_codemap): # common case
-self.jit_codemap.append(codemap)
-else:
-self.jit_codemap = (self.jit_codemap[:pos] + [codemap] +
-self.jit_codemap[pos:])
+pos = bisect_left_tuple(self.jit_codemap, start)
+self.jit_codemap.insert(pos, codemap)
 
 def _delete(self):
 "NOT_RPYTHON"
diff --git a/rpython/jit/backend/llsupport/codemap.py 
b/rpython/jit/backend/llsupport/codemap.py
--- a/rpython/jit/backend/llsupport/codemap.py
+++ b/rpython/jit/backend/llsupport/codemap.py
@@ -12,7 +12,7 @@
 from rpython.rlib import rgc
 from rpython.rlib.entrypoint import jit_entrypoint
 from rpython.jit.backend.llsupport import asmmemmgr
-from rpython.rlib.rbisect import bisect, bisect_tuple
+from rpython.rlib.rbisect import bisect_right, bisect_right_tuple
 from rpython.rtyper.lltypesystem import lltype, rffi
 
 @jit_entrypoint([lltype.Signed], lltype.Signed,
@@ -21,7 +21,7 @@
 def stack_depth_at_loc(loc):
 _memmngr = asmmemmgr._memmngr
 
-pos = bisect(_memmngr.jit_addr_map, loc + 1)
+pos = bisect_right(_memmngr.jit_addr_map, loc)
 if pos == 0 or pos == len(_memmngr.jit_addr_map):
 return -1
 return _memmngr.jit_frame_depth_map[pos - 1]
@@ -43,9 +43,7 @@
 def find_codemap_at_addr(addr):
 _memmngr = asmmemmgr._memmngr
 
-res = bisect_tuple(_memmngr.jit_codemap, addr) - 1
-if res == len(_memmngr.jit_codemap):
-return -1
+res = bisect_right_tuple(_memmngr.jit_codemap, addr) - 1
 return res
 
 @jit_entrypoint([lltype.Signed, lltype.Signed,
diff --git a/rpython/rlib/rbisect.py b/rpython/rlib/rbisect.py
--- a/rpython/rlib/rbisect.py
+++ b/rpython/rlib/rbisect.py
@@ -1,21 +1,39 @@
 
-def bisect(a, x):
+def bisect_left(a, x):
 """Return the index in the sorted list 'a' of 'x'.  If 'x' is not in 'a',
 return the index where it can be inserted."""
 lo = 0
 hi = len(a)
 while lo < hi:
 mid = (lo+hi)//2
-if x <= a[mid]: hi = mid
+if a[mid] < x: lo = mid+1

[pypy-commit] pypy vmprof: Somewhat controversial strategy - store info about code objects in a tempfile().

2015-02-16 Thread fijal
Author: Maciej Fijalkowski 
Branch: vmprof
Changeset: r75917:ef83e90448b8
Date: 2015-02-16 13:41 +0200
http://bitbucket.org/pypy/pypy/changeset/ef83e90448b8/

Log:Somewhat controversial strategy - store info about code objects in a
tempfile(). Let's see how it goes

diff --git a/pypy/config/pypyoption.py b/pypy/config/pypyoption.py
--- a/pypy/config/pypyoption.py
+++ b/pypy/config/pypyoption.py
@@ -38,8 +38,8 @@
 "_csv", "cppyy", "_pypyjson"
 ])
 
-if sys.platform.startswith('linux') and sys.maxint > 2147483647:
-working_modules.add('_vmprof')
+#if sys.platform.startswith('linux') and sys.maxint > 2147483647:
+#working_modules.add('_vmprof')
 
 translation_modules = default_modules.copy()
 translation_modules.update([
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1,15 +1,14 @@
-import sys
+import sys, os
 
 from rpython.rlib.cache import Cache
 from rpython.tool.uid import HUGEVAL_BYTES
-from rpython.rlib import jit, types
+from rpython.rlib import jit, types, rfile
 from rpython.rlib.debug import make_sure_not_resized
 from rpython.rlib.objectmodel import (we_are_translated, newlist_hint,
  compute_unique_id, specialize)
 from rpython.rlib.signature import signature
 from rpython.rlib.rarithmetic import r_uint, SHRT_MIN, SHRT_MAX, \
 INT_MIN, INT_MAX, UINT_MAX, USHRT_MAX
-from rpython.rlib.rweaklist import RWeakListMixin
 
 from pypy.interpreter.executioncontext import (ExecutionContext, ActionFlag,
 UserDelAction)
@@ -367,10 +366,6 @@
 
 # 
 
-class CodeObjWeakList(RWeakListMixin):
-def __init__(self):
-self.initialize()
-
 class ObjSpace(object):
 """Base class for the interpreter-level implementations of object spaces.
 http://pypy.readthedocs.org/en/latest/objspace.html""";
@@ -394,7 +389,6 @@
 self.check_signal_action = None   # changed by the signal module
 self.user_del_action = UserDelAction(self)
 self._code_of_sys_exc_info = None
-self.all_code_objs = CodeObjWeakList()
 
 # can be overridden to a subclass
 self.initialize()
@@ -672,16 +666,31 @@
 assert ec is not None
 return ec
 
+def _open_code_info_file(self):
+ec = self.getexecutioncontext()
+try:
+ec.code_info_file = os.tmpfile()
+except:
+ec.code_info_file_present = False # we failed to open it
+
 def register_code_object(self, pycode):
-callback = self.getexecutioncontext().register_code_callback
-if callback is not None:
-callback(self, pycode)
-self.all_code_objs.add_handle(pycode)
-
-def set_code_callback(self, callback):
 ec = self.getexecutioncontext()
-ec.register_code_callback = callback
-
+if ec.code_info_file is None:
+self._open_code_info_file()
+if not ec.code_info_file_present:
+return
+try:
+rfile.write_int(ec.code_info_file, pycode._unique_id)
+s = pycode._get_full_name()
+rfile.write_int(ec.code_info_file, len(s))
+ec.code_info_file.write(s)
+except OSError:
+ec.code_info_file_present = False
+try:
+ec.code_info_file.close()
+except:
+pass # can fail, ignore
+
 def _freeze_(self):
 return True
 
diff --git a/pypy/interpreter/executioncontext.py 
b/pypy/interpreter/executioncontext.py
--- a/pypy/interpreter/executioncontext.py
+++ b/pypy/interpreter/executioncontext.py
@@ -33,7 +33,9 @@
 self.profilefunc = None
 self.w_profilefuncarg = None
 self.thread_disappeared = False   # might be set to True after 
os.fork()
-self.register_code_callback = None
+self.code_info_file = None
+self.code_info_file_present = True
+
 if sys.maxint == 2147483647:
 self._code_unique_id = 0 # XXX this is wrong, it won't work on 
32bit
 else:
diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -70,6 +70,7 @@
 'debug_stop': 'interp_debug.debug_stop',
 'debug_print_once'  : 'interp_debug.debug_print_once',
 'debug_flush'   : 'interp_debug.debug_flush',
+'all_code_info' : 'interp_magic.all_code_info',
 'builtinify': 'interp_magic.builtinify',
 'lookup_special': 'interp_magic.lookup_special',
 'do_what_I_mean': 'interp_magic.do_what_I_mean',
diff --git a/pypy/module/__pypy__/interp_magic.py 
b/pypy/module/__pypy__/interp_magic.py
--- a/pypy/module/__pypy__/interp_magic.py
+++ b/pypy/module/__pypy__/interp_magic.py
@@ -130,3 +1

[pypy-commit] pypy dtrace-support: start writing dtrace support for basic events

2015-02-16 Thread fijal
Author: Maciej Fijalkowski 
Branch: dtrace-support
Changeset: r75919:1c6e04d35be2
Date: 2015-02-16 16:09 +0200
http://bitbucket.org/pypy/pypy/changeset/1c6e04d35be2/

Log:start writing dtrace support for basic events

diff --git a/rpython/config/translationoption.py 
b/rpython/config/translationoption.py
--- a/rpython/config/translationoption.py
+++ b/rpython/config/translationoption.py
@@ -189,6 +189,9 @@
 BoolOption("lldebug0",
"If true, makes an lldebug0 build", default=False,
cmdline="--lldebug0"),
+BoolOption("dtrace",
+   "If true, enable emitting dtrace debug probes", default=False,
+   cmdline='--enable-dtrace'),
 
 OptionDescription("backendopt", "Backend Optimization Options", [
 # control inlining
diff --git a/rpython/translator/c/database.py b/rpython/translator/c/database.py
--- a/rpython/translator/c/database.py
+++ b/rpython/translator/c/database.py
@@ -16,6 +16,7 @@
 from rpython.translator.c.extfunc import do_the_getting
 from rpython.translator.c import gc
 from rpython.tool.identity_dict import identity_dict
+from rpython.flowspace.model import Constant
 
 
 class NoCorrespondingNode(Exception):
@@ -47,6 +48,7 @@
 self.containerstats = {}
 self.externalfuncs = {}
 self.helper2ptr = {}
+self.debug_nodes = set()
 
 # late_initializations is for when the value you want to
 # assign to a constant object is something C doesn't think is
@@ -232,6 +234,13 @@
 else:
 raise Exception("don't know about %r" % (obj,))
 
+def seen_debug_start(self, op):
+arg = op.args[0]
+if not isinstance(arg, Constant):
+return
+name = ''.join(arg.value.chars)
+self.debug_nodes.add(name)
+
 def complete(self, show_progress=True):
 assert not self.completed
 if self.translator and self.translator.rtyper:
diff --git a/rpython/translator/c/funcgen.py b/rpython/translator/c/funcgen.py
--- a/rpython/translator/c/funcgen.py
+++ b/rpython/translator/c/funcgen.py
@@ -792,6 +792,7 @@
 return x
 
 def OP_DEBUG_START(self, op):
+self.db.seen_debug_start(op)
 return self._op_debug('PYPY_DEBUG_START', op.args[0])
 
 def OP_DEBUG_STOP(self, op):
diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py
--- a/rpython/translator/c/genc.py
+++ b/rpython/translator/c/genc.py
@@ -246,8 +246,22 @@
 self.extrafiles = self.eventually_copy(extra)
 self.gen_makefile(targetdir, exe_name=exe_name,
   headers_to_precompile=headers_to_precompile)
+if self.config.translation.dtrace:
+self._generate_dtrace_probe_file(db.debug_nodes)
 return cfile
 
+def _generate_dtrace_probe_file(self, debug_nodes):
+name = self.targetdir.join('pypy.p')
+f = name.open('w')
+f.write('provider pypy_probes {\n')
+for debug_node in debug_nodes:
+debug_node = debug_node.replace('-', '_')
+f.write('  probe %s__start(void);' % debug_node)
+f.write('  probe %s__done(void);' % debug_node)
+f.write('};')
+f.close()
+# XXX run dtrace
+
 def eventually_copy(self, cfiles):
 extrafiles = []
 for fn in cfiles:
diff --git a/rpython/translator/c/test/test_dtrace.py 
b/rpython/translator/c/test/test_dtrace.py
new file mode 100644
--- /dev/null
+++ b/rpython/translator/c/test/test_dtrace.py
@@ -0,0 +1,19 @@
+
+from rpython.translator.c.test.test_standalone import StandaloneTests
+from rpython.rlib.debug import debug_start, debug_stop
+from rpython.config.translationoption import get_combined_translation_config
+
+class TestDTrace(StandaloneTests):
+config = get_combined_translation_config(translating=True)
+config.translation.dtrace = True
+
+def test_dtrace_probes(self):
+def f(argv):
+debug_start("x")
+for i in range(1000):
+pass
+debug_stop("x")
+return 0
+
+_, cbuilder = self.compile(f)
+cbuilder.cmdexec('')
diff --git a/rpython/translator/c/test/test_standalone.py 
b/rpython/translator/c/test/test_standalone.py
--- a/rpython/translator/c/test/test_standalone.py
+++ b/rpython/translator/c/test/test_standalone.py
@@ -1390,7 +1390,6 @@
 and result.count('a') == 1
 and result.count('d') == 6)
 
-
 class TestShared(StandaloneTests):
 
 def test_entrypoint(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc default: Backed out changeset: 7540c1f155d0

2015-02-16 Thread Raemi
Author: Remi Meier 
Branch: 
Changeset: r1625:689a9663d13f
Date: 2015-02-16 15:55 +0100
http://bitbucket.org/pypy/stmgc/changeset/689a9663d13f/

Log:Backed out changeset: 7540c1f155d0

diff --git a/c8/stm/gcpage.c b/c8/stm/gcpage.c
--- a/c8/stm/gcpage.c
+++ b/c8/stm/gcpage.c
@@ -566,13 +566,10 @@
 struct stm_commit_log_entry_s *cl, *next;
 
 #ifndef NDEBUG
-/* check that all segments are at the same revision (or not running
-   a transaction at all): */
+/* check that all segments are at the same revision: */
 cl = get_priv_segment(0)->last_commit_log_entry;
 for (long i = 1; i < NB_SEGMENTS; i++) {
-if (get_priv_segment(i)->transaction_state != TS_NONE) {
-assert(get_priv_segment(i)->last_commit_log_entry == cl);
-}
+assert(get_priv_segment(i)->last_commit_log_entry == cl);
 }
 #endif
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc default: Backed out changeset: 60f7ccae893c

2015-02-16 Thread Raemi
Author: Remi Meier 
Branch: 
Changeset: r1624:edb90028410a
Date: 2015-02-16 15:53 +0100
http://bitbucket.org/pypy/stmgc/changeset/edb90028410a/

Log:Backed out changeset: 60f7ccae893c

diff --git a/c8/stm/gcpage.c b/c8/stm/gcpage.c
--- a/c8/stm/gcpage.c
+++ b/c8/stm/gcpage.c
@@ -96,9 +96,12 @@
 
 object_t *_stm_allocate_old(ssize_t size_rounded_up)
 {
-/* this is for tests, and for stm_setup_prebuilt() */
+/* only for tests xxx but stm_setup_prebuilt() uses this now too */
 stm_char *p = allocate_outside_nursery_large(size_rounded_up);
 object_t *o = (object_t *)p;
+
+// sharing seg0 needs to be current:
+assert(STM_SEGMENT->segment_num == 0);
 memset(REAL_ADDRESS(STM_SEGMENT->segment_base, o), 0, size_rounded_up);
 o->stm_flags = GCFLAG_WRITE_BARRIER;
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc default: fix for on-major-gc validation not doing anything when a transaction thought it was still uncommitted and inevitable

2015-02-16 Thread Raemi
Author: Remi Meier 
Branch: 
Changeset: r1627:30791bd74ef2
Date: 2015-02-16 16:34 +0100
http://bitbucket.org/pypy/stmgc/changeset/30791bd74ef2/

Log:fix for on-major-gc validation not doing anything when a transaction
thought it was still uncommitted and inevitable

diff --git a/c8/stm/core.c b/c8/stm/core.c
--- a/c8/stm/core.c
+++ b/c8/stm/core.c
@@ -179,7 +179,7 @@
 /* increment_total_allocated(4096); */
 
 if (copy_from_segnum == -1) {
-/* this page is only accessible in the sharing segment so far (new
+/* this page is only accessible in the sharing segment seg0 so far (new
allocation). We can thus simply mark it accessible here. */
 pagecopy(get_virtual_page(my_segnum, pagenum),
  get_virtual_page(0, pagenum));
@@ -288,7 +288,8 @@
 {
 /* returns true if we reached a valid state, or false if
we need to abort now */
-dprintf(("_stm_validate()\n"));
+dprintf(("_stm_validate() at cl=%p, rev=%lu\n", 
STM_PSEGMENT->last_commit_log_entry,
+ STM_PSEGMENT->last_commit_log_entry->rev_num));
 /* go from last known entry in commit log to the
most current one and apply all changes done
by other transactions. Abort if we have read one of
@@ -388,6 +389,7 @@
  !needs_abort);  /* if we abort, we still want to copy 
everything */
 }
 
+dprintf(("_stm_validate() to cl=%p, rev=%lu\n", cl, 
cl->rev_num));
 /* last fully validated entry */
 STM_PSEGMENT->last_commit_log_entry = cl;
 if (cl == last_cl)
@@ -531,6 +533,9 @@
 _validate_and_attach(new);
 }
 
+STM_PSEGMENT->transaction_state = TS_NONE;
+STM_PSEGMENT->safe_point = SP_NO_TRANSACTION;
+
 acquire_modification_lock(STM_SEGMENT->segment_num);
 list_clear(STM_PSEGMENT->modified_old_objects);
 STM_PSEGMENT->last_commit_log_entry = new;
@@ -843,6 +848,7 @@
 
 push_new_objects_to_other_segments();
 /* push before validate. otherwise they are reachable too early */
+bool was_inev = STM_PSEGMENT->transaction_state == TS_INEVITABLE;
 _validate_and_add_to_commit_log();
 
 invoke_and_clear_user_callbacks(0);   /* for commit */
@@ -854,7 +860,7 @@
 
 stm_rewind_jmp_forget(STM_SEGMENT->running_thread);
 
-if (globally_unique_transaction && STM_PSEGMENT->transaction_state == 
TS_INEVITABLE) {
+if (globally_unique_transaction && was_inev) {
 committed_globally_unique_transaction();
 }
 
diff --git a/c8/stm/gcpage.c b/c8/stm/gcpage.c
--- a/c8/stm/gcpage.c
+++ b/c8/stm/gcpage.c
@@ -100,7 +100,9 @@
 stm_char *p = allocate_outside_nursery_large(size_rounded_up);
 object_t *o = (object_t *)p;
 
-// sharing seg0 needs to be current:
+/* Sharing seg0 needs to be current, because in core.c 
handle_segfault_in_page,
+   we depend on simply copying the page from seg0 if it was never accessed 
by
+   anyone so far (we only run in seg1 <= seg < NB_SEGMENT). */
 assert(STM_SEGMENT->segment_num == 0);
 memset(REAL_ADDRESS(STM_SEGMENT->segment_base, o), 0, size_rounded_up);
 o->stm_flags = GCFLAG_WRITE_BARRIER;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] stmgc default: fix demo_random.c

2015-02-16 Thread Raemi
Author: Remi Meier 
Branch: 
Changeset: r1626:1df0ed9de072
Date: 2015-02-16 16:34 +0100
http://bitbucket.org/pypy/stmgc/changeset/1df0ed9de072/

Log:fix demo_random.c

diff --git a/c8/demo/demo_random.c b/c8/demo/demo_random.c
--- a/c8/demo/demo_random.c
+++ b/c8/demo/demo_random.c
@@ -9,12 +9,12 @@
 
 #include "stmgc.h"
 
-#define NUMTHREADS 3
+#define NUMTHREADS 4
 #define STEPS_PER_THREAD 500
 #define THREAD_STARTS 1000 // how many restarts of threads
 #define PREBUILT_ROOTS 3
 #define MAXROOTS 1000
-#define FORKS 3
+#define FORKS 0
 
 // SUPPORT
 struct node_s;
@@ -438,7 +438,7 @@
 .next = NULL
 };
 
-stm_start_inevitable_transaction(&stm_thread_local);
+//stm_start_inevitable_transaction(&stm_thread_local);
 for (i = 0; i < PREBUILT_ROOTS; i++) {
 void* new_templ = malloc(sizeof(struct node_s));
 memcpy(new_templ, &prebuilt_template, sizeof(struct node_s));
@@ -451,7 +451,7 @@
 ((nodeptr_t)prebuilt_roots[i])->my_hash = hash;
 }
 }
-stm_commit_transaction();
+//stm_commit_transaction();
 }
 
 int main(void)
@@ -470,10 +470,11 @@
 
 
 stm_setup();
+setup_globals();
+
 stm_register_thread_local(&stm_thread_local);
 stm_rewind_jmp_enterframe(&stm_thread_local, &rjbuf);
 
-setup_globals();
 
 int thread_starts = NUMTHREADS * THREAD_STARTS;
 for (i = 0; i < NUMTHREADS; i++) {
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


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

2015-02-16 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.3
Changeset: r75920:2f8ea7e067df
Date: 2015-02-16 15:41 +0100
http://bitbucket.org/pypy/pypy/changeset/2f8ea7e067df/

Log:hg merge py3k

Lots of conflicts...

diff too long, truncating to 2000 out of 50524 lines

diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -7,7 +7,10 @@
 
 bin/pypy-c
 include/*.h
+include/numpy/
 lib_pypy/ctypes_config_cache/_[^_]*_*.py
+libpypy-c.*
+pypy-c
 pypy/_cache
 pypy/doc/*.html
 pypy/doc/config/*.html
@@ -18,4 +21,5 @@
 pypy/translator/c/src/dtoa.o
 pypy/translator/goal/pypy-c
 pypy/translator/goal/target*-c
-release/
\ No newline at end of file
+release/
+rpython/_cache/
diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -7,10 +7,7 @@
 9b623bc48b5950cf07184462a0e48f2c4df0d720 pypy-2.1-beta1-arm
 ab0dd631c22015ed88e583d9fdd4c43eebf0be21 pypy-2.1-beta1-arm
 20e51c4389ed4469b66bb9d6289ce0ecfc82c4b9 release-2.3.0
-20e51c4389ed4469b66bb9d6289ce0ecfc82c4b9 release-2.3.0
- release-2.3.0
 394146e9bb673514c61f0150ab2013ccf78e8de7 release-2.3
 32f35069a16d819b58c1b6efb17c44e3e53397b2 release-2.2=3.1
 32f35069a16d819b58c1b6efb17c44e3e53397b2 release-2.3.1
-32f35069a16d819b58c1b6efb17c44e3e53397b2 release-2.2=3.1
- release-2.2=3.1
+10f1b29a2bd21f837090286174a9ca030b8680b2 release-2.5.0
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -42,19 +42,19 @@
   Amaury Forgeot d'Arc
   Samuele Pedroni
   Alex Gaynor
+  Brian Kearns
+  Matti Picus
+  Philip Jenvey
   Michael Hudson
   David Schneider
-  Matti Picus
-  Brian Kearns
-  Philip Jenvey
   Holger Krekel
   Christian Tismer
   Hakan Ardo
   Benjamin Peterson
   Manuel Jacob
+  Ronan Lamy
   Anders Chrigstrom
   Eric van Riet Paap
-  Ronan Lamy
   Wim Lavrijsen
   Richard Emslie
   Alexander Schremmer
@@ -68,9 +68,9 @@
   Camillo Bruni
   Laura Creighton
   Toon Verwaest
+  Romain Guillebert
   Leonardo Santagada
   Seo Sanghyeon
-  Romain Guillebert
   Justin Peel
   Ronny Pfannschmidt
   David Edelsohn
@@ -91,15 +91,16 @@
   Michal Bendowski
   Jan de Mooij
   stian
+  Tyler Wade
   Michael Foord
   Stephan Diehl
-  Tyler Wade
   Stefan Schwarzer
   Valentino Volonghi
   Tomek Meka
   Patrick Maupin
   Bob Ippolito
   Bruno Gola
+  David Malcolm
   Jean-Paul Calderone
   Timo Paulssen
   Squeaky
@@ -108,18 +109,19 @@
   Marius Gedminas
   Martin Matusiak
   Konstantin Lopuhin
+  Wenzhu Man
   John Witulski
-  Wenzhu Man
+  Laurence Tratt
+  Ivan Sichmann Freitas
   Greg Price
   Dario Bertini
   Mark Pearse
   Simon Cross
-  Ivan Sichmann Freitas
   Andreas Stührk
+  Stefano Rivera
   Jean-Philippe St. Pierre
   Guido van Rossum
   Pavel Vinogradov
-  Stefano Rivera
   Paweł Piotr Przeradowski
   Paul deGrandis
   Ilya Osadchiy
@@ -129,7 +131,6 @@
   tav
   Taavi Burns
   Georg Brandl
-  Laurence Tratt
   Bert Freudenberg
   Stian Andreassen
   Wanja Saatkamp
@@ -141,13 +142,12 @@
   Jeremy Thurgood
   Rami Chowdhury
   Tobias Pape
-  David Malcolm
   Eugene Oden
   Henry Mason
   Vasily Kuznetsov
   Preston Timmons
+  David Ripton
   Jeff Terrace
-  David Ripton
   Dusty Phillips
   Lukas Renggli
   Guenter Jantzen
@@ -166,13 +166,16 @@
   Gintautas Miliauskas
   Michael Twomey
   Lucian Branescu Mihaila
+  Yichao Yu
   Gabriel Lavoie
   Olivier Dormond
   Jared Grubb
   Karl Bartel
+  Wouter van Heyst
   Brian Dorsey
   Victor Stinner
   Andrews Medina
+  anatoly techtonik
   Stuart Williams
   Jasper Schulz
   Christian Hudon
@@ -182,12 +185,11 @@
   Michael Cheng
   Justas Sadzevicius
   Gasper Zejn
-  anatoly techtonik
   Neil Shepperd
+  Stanislaw Halik
   Mikael Schönenberg
   Elmo M?ntynen
   Jonathan David Riehl
-  Stanislaw Halik
   Anders Qvist
   Corbin Simpson
   Chirag Jadwani
@@ -196,10 +198,13 @@
   Vincent Legoll
   Alan McIntyre
   Alexander Sedov
+  Attila Gobi
   Christopher Pope
   Christian Tismer 
   Marc Abramowitz
   Dan Stromberg
+  Arjun Naik
+  Valentina Mukhamedzhanova
   Stefano Parmesan
   Alexis Daboville
   Jens-Uwe Mager
@@ -213,8 +218,6 @@
   Sylvain Thenault
   Nathan Taylor
   Vladimir Kryachko
-  Arjun Naik
-  Attila Gobi
   Jacek Generowicz
   Alejandro J. Cura
   Jacob Oscarson
@@ -222,22 +225,23 @@
   Ryan Gonzalez
   Ian Foote
   Kristjan Valur Jonsson
+  David Lievens
   Neil Blakey-Milner
   Lutz Paelike
   Lucio Torre
   Lars Wassermann
-  Valentina Mukhamedzhanova
   Henrik Vendelbo
   Dan Buch
   Miguel de Val Borro
   Artur Lisiecki
   Sergey Kishchenko
-  Yichao Yu
   Ignas Mikalajunas
   Christoph Gerum
   Martin Blais
   Lene Wagner
   Tomo Cocoa
+  Toni Mattis
+  Lucas Stadler
   roberto@goyle
   Yury V. Zaytsev
   Anna Katrina Dominguez
@@ -265,23 +269,30 @@
   Stephan Busemann
   Rafał Gałczyński
   Christian Muirhead
+  Berker Peksag
   James Lan
   shoma hosaka
-  Daniel Neuh?user
-  Matthew Miller
+  Daniel Neuhäuser
+  Ben Mather
+  halgari
+  Boglarka Vezer
+  Chris Pressey
   Buck Golemon
   Konra

[pypy-commit] pypy py3.3: Fixes

2015-02-16 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.3
Changeset: r75921:36e9b041cbb7
Date: 2015-02-16 18:46 +0100
http://bitbucket.org/pypy/pypy/changeset/36e9b041cbb7/

Log:Fixes

diff --git a/pypy/module/_ssl/test/test_ssl.py 
b/pypy/module/_ssl/test/test_ssl.py
--- a/pypy/module/_ssl/test/test_ssl.py
+++ b/pypy/module/_ssl/test/test_ssl.py
@@ -411,6 +411,7 @@
 cls.w_keycert = cls.space.wrap(str(tmpfile))
 
 def test_str(self):
+import _ssl
 # The str() of a SSLError doesn't include the errno
 e = _ssl.SSLError(1, "foo")
 assert str(e) == "foo"
diff --git a/pypy/module/signal/interp_signal.py 
b/pypy/module/signal/interp_signal.py
--- a/pypy/module/signal/interp_signal.py
+++ b/pypy/module/signal/interp_signal.py
@@ -335,7 +335,7 @@
 "Send a signal to a thread."
 ret = c_pthread_kill(tid, signum)
 if widen(ret) < 0:
-raise exception_from_errno(space, space.w_OSError)
+raise exception_from_saved_errno(space, space.w_OSError)
 # the signal may have been send to the current thread
 space.getexecutioncontext().checksignals()
 
@@ -379,7 +379,7 @@
 with lltype.scoped_alloc(rffi.INTP.TO, 1) as signum_ptr:
 ret = c_sigwait(sigset, signum_ptr)
 if ret != 0:
-raise exception_from_errno(space, space.w_OSError)
+raise exception_from_saved_errno(space, space.w_OSError)
 signum = signum_ptr[0]
 return space.wrap(signum)
 
@@ -387,7 +387,7 @@
 with lltype.scoped_alloc(c_sigset_t.TO) as mask:
 ret = c_sigpending(mask)
 if ret != 0:
-raise exception_from_errno(space, space.w_OSError)
+raise exception_from_saved_errno(space, space.w_OSError)
 return _sigset_to_signals(space, mask)
 
 @unwrap_spec(how=int)
@@ -396,7 +396,7 @@
 with lltype.scoped_alloc(c_sigset_t.TO) as previous:
 ret = c_pthread_sigmask(how, sigset, previous)
 if ret != 0:
-raise exception_from_errno(space, space.w_OSError)
+raise exception_from_saved_errno(space, space.w_OSError)
 # if signals was unblocked, signal handlers have been called
 space.getexecutioncontext().checksignals()
 return _sigset_to_signals(space, previous)
diff --git a/rpython/rlib/rsignal.py b/rpython/rlib/rsignal.py
--- a/rpython/rlib/rsignal.py
+++ b/rpython/rlib/rsignal.py
@@ -102,7 +102,8 @@
save_err=rffi.RFFI_SAVE_ERRNO)
 c_getitimer = external('getitimer', [rffi.INT, itimervalP], rffi.INT)
 
-c_pthread_kill = external('pthread_kill', [lltype.Signed, rffi.INT], rffi.INT)
+c_pthread_kill = external('pthread_kill', [lltype.Signed, rffi.INT], rffi.INT,
+  save_err=rffi.RFFI_SAVE_ERRNO)
 
 if sys.platform != 'win32':
 c_sigset_t = rffi.COpaquePtr('sigset_t', compilation_info=eci)
@@ -110,7 +111,10 @@
 c_sigaddset = external('sigaddset', [c_sigset_t, rffi.INT], rffi.INT)
 c_sigismember = external('sigismember', [c_sigset_t, rffi.INT], rffi.INT)
 c_sigwait = external('sigwait', [c_sigset_t, rffi.INTP], rffi.INT,
- releasegil=True)
-c_sigpending = external('sigpending', [c_sigset_t], rffi.INT)
+ releasegil=True,
+ save_err=rffi.RFFI_SAVE_ERRNO)
+c_sigpending = external('sigpending', [c_sigset_t], rffi.INT,
+save_err=rffi.RFFI_SAVE_ERRNO)
 c_pthread_sigmask = external('pthread_sigmask',
- [rffi.INT, c_sigset_t, c_sigset_t], rffi.INT)
+ [rffi.INT, c_sigset_t, c_sigset_t], rffi.INT,
+ save_err=rffi.RFFI_SAVE_ERRNO)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy framestate: add 2 tests for with blocks

2015-02-16 Thread rlamy
Author: Ronan Lamy 
Branch: framestate
Changeset: r75924:42000e974b69
Date: 2015-02-15 04:19 +
http://bitbucket.org/pypy/pypy/changeset/42000e974b69/

Log:add 2 tests for with blocks

diff --git a/rpython/flowspace/test/test_objspace.py 
b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -960,6 +960,20 @@
 'simple_call': 4, # __enter__, g and 2 possible calls to __exit__
 }
 
+def test_return_in_with(self):
+def f(x):
+with x:
+return 1
+self.codetest(f)
+
+def test_break_in_with(self):
+def f(n, x):
+for i in range(n):
+with x:
+break
+return 1
+self.codetest(f)
+
 def monkey_patch_code(self, code, stacksize, flags, codestring, names, 
varnames):
 c = code
 return types.CodeType(c.co_argcount, c.co_nlocals, stacksize, flags,
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy framestate: handle interaction of return with finally: in analyze_signals()

2015-02-16 Thread rlamy
Author: Ronan Lamy 
Branch: framestate
Changeset: r75922:e6c7a78a35e5
Date: 2015-02-14 23:11 +
http://bitbucket.org/pypy/pypy/changeset/e6c7a78a35e5/

Log:handle interaction of return with finally: in analyze_signals()

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -618,8 +618,7 @@
 block.operations.append(POP_BLOCK(offset=self.offset))
 elif isinstance(context, FinallyBlock):
 block.operations.append(POP_BLOCK(offset=self.offset))
-reader.splice_finally_handler(block, context)
-block = context.handler_end
+block = reader.splice_finally_handler(block, context)
 else:  # LoopBlock
 reader.blockstack.append(context)
 block.set_exits([self.target])
@@ -645,9 +644,20 @@
 class RETURN(NullaryOpcode):
 num = name = 'RETURN'
 arg = NO_ARG
+def do_signals(self, reader):
+block = reader.curr_block
+assert block.operations[-1] is self
+del block.operations[-1]
+from rpython.flowspace.flowcontext import FinallyBlock
+while reader.blockstack:
+context = reader.blockstack.pop()
+block.operations.append(POP_BLOCK(offset=self.offset))
+if isinstance(context, FinallyBlock):
+block = reader.splice_finally_handler(block, context)
+block.operations.append(self)
+
 def eval(self, ctx):
-from rpython.flowspace.flowcontext import Return
-raise Return()
+ctx.do_return()
 
 @bc_reader.register_opcode
 class END_FINALLY(NullaryOpcode):
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -1012,9 +1012,6 @@
 
 class Return(FlowSignal):
 """Signals a 'return' statement.  """
-def nomoreblocks(self, ctx):
-ctx.do_return()
-
 @property
 def args(self):
 return []
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy framestate: deal with unreachable END_FINALLY

2015-02-16 Thread rlamy
Author: Ronan Lamy 
Branch: framestate
Changeset: r75927:feaa2a862f65
Date: 2015-02-16 19:21 +
http://bitbucket.org/pypy/pypy/changeset/feaa2a862f65/

Log:deal with unreachable END_FINALLY

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -235,7 +235,10 @@
 
 def splice_finally_handler(self, block, context):
 cell = []
+copied = {}
 def copy_block(handler):
+if handler in copied:
+return copied[handler]
 b = handler.copy()
 if handler is context.handler_end:
 instr = b.operations.pop()
@@ -244,13 +247,17 @@
 else:
 b.set_exits([copy_block(child) for child in handler._exits])
 self.blocks.append(b)
+copied[handler] = b
 return b
 block.set_exits([copy_block(context.handler)])
-copy_of_handler_end, = cell
-return copy_of_handler_end
+if cell:
+copy_of_handler_end, = cell
+return copy_of_handler_end
+else:  # END_FINALLY is unreachable
+return None
 
 def check_graph(self):
-for b in self.blocks:
+for b in self.graph.iterblocks():
 if not b._exits:
 instr = b.operations[-1]
 assert instr.name in (
@@ -670,7 +677,9 @@
 block = reader.splice_finally_handler(block, context.block)
 assert len(block.operations) == 1
 block.operations = [PUSH_NONE()] + block.operations + 
[POP_TOP()]
-block.operations.append(self)
+if block is not None:
+block.operations.append(self)
+block.set_exits([])
 
 def eval(self, ctx):
 ctx.do_return()
diff --git a/rpython/flowspace/test/test_bytecode.py 
b/rpython/flowspace/test/test_bytecode.py
--- a/rpython/flowspace/test/test_bytecode.py
+++ b/rpython/flowspace/test/test_bytecode.py
@@ -12,7 +12,7 @@
 else:
 return 0
 bc_graph = make_graph(f)
-assert [lst[0].offset for lst in bc_graph.dump()] == [0, 6, 10, 14]
+assert [lst[0].offset for lst in bc_graph.dump()] == [0, 6, 10]
 assert bc_graph.dump()[0][0] == bc_reader.new_instr('LOAD_FAST', 0)
 
 def test_blockstack():
diff --git a/rpython/flowspace/test/test_objspace.py 
b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -263,6 +263,19 @@
 def test_finallys(self):
 x = self.codetest(self.finallys)
 
+def test_branching_in_finally(self):
+def f(x, y):
+try:
+return x
+finally:
+if x:
+x = 0
+if y > 0:
+y -= 1
+return y
+self.codetest(f)
+
+
 #__
 def const_pow():
 return 2 ** 5
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy framestate: delete unused FlowSignals

2015-02-16 Thread rlamy
Author: Ronan Lamy 
Branch: framestate
Changeset: r75923:dae9c828b3d3
Date: 2015-02-15 02:40 +
http://bitbucket.org/pypy/pypy/changeset/dae9c828b3d3/

Log:delete unused FlowSignals

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -138,7 +138,6 @@
 except KeyError:
 return GenericOpcode(self.opnames[opnum], opnum, arg, offset)
 
-
 def _iter_instr(self, code):
 self.offset = 0
 i = 0
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -1010,17 +1010,6 @@
 return type(other) is type(self) and other.args == self.args
 
 
-class Return(FlowSignal):
-"""Signals a 'return' statement.  """
-@property
-def args(self):
-return []
-
-@staticmethod
-def rebuild():
-return Return()
-
-
 class Raise(FlowSignal):
 """Signals an application-level exception
 (i.e. an OperationException)."""
@@ -1061,35 +1050,6 @@
 raise StopFlowing
 
 
-class Break(FlowSignal):
-"""Signals a 'break' statement."""
-
-@property
-def args(self):
-return []
-
-@staticmethod
-def rebuild():
-return Break.singleton
-
-Break.singleton = Break()
-
-class Continue(FlowSignal):
-"""Signals a 'continue' statement.
-Argument is the bytecode position of the beginning of the loop."""
-
-def __init__(self, jump_to):
-self.jump_to = jump_to
-
-@property
-def args(self):
-return [const(self.jump_to)]
-
-@staticmethod
-def rebuild(w_jump_to):
-return Continue(w_jump_to.value)
-
-
 class FrameBlock(object):
 """Abstract base class for frame blocks from the blockstack,
 used by the SETUP_XXX and POP_BLOCK opcodes."""
@@ -1117,7 +1077,7 @@
 
 class LoopBlock(FrameBlock):
 """A loop block.  Stores the end-of-loop pointer in case of 'break'."""
-handles = (Break, Continue)
+handles = type(None)
 
 class ExceptBlock(FrameBlock):
 """An try:except: block.  Stores the position of the exception handler."""
diff --git a/rpython/flowspace/test/test_flowcontext.py 
b/rpython/flowspace/test/test_flowcontext.py
--- a/rpython/flowspace/test/test_flowcontext.py
+++ b/rpython/flowspace/test/test_flowcontext.py
@@ -2,14 +2,11 @@
 import pytest
 from rpython.flowspace.model import Variable, FSException
 from rpython.flowspace.flowcontext import (
-Return, Raise, RaiseImplicit, Continue, Break)
+Raise, RaiseImplicit)
 
 @pytest.mark.parametrize('signal', [
-Return(),
 Raise(FSException(Variable(), Variable())),
 RaiseImplicit(FSException(Variable(), Variable())),
-Break(),
-Continue(42),
 ])
 def test_signals(signal):
 assert signal.rebuild(*signal.args) == signal
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy framestate: Use SETUP_ instructions rather than FrameBlocks in do_signals()

2015-02-16 Thread rlamy
Author: Ronan Lamy 
Branch: framestate
Changeset: r75925:53b3547f5829
Date: 2015-02-15 17:55 +
http://bitbucket.org/pypy/pypy/changeset/53b3547f5829/

Log:Use SETUP_ instructions rather than FrameBlocks in do_signals()

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -584,17 +584,15 @@
 block = reader.curr_block
 assert block.operations[-1] is self
 del block.operations[-1]
-from rpython.flowspace.flowcontext import ExceptBlock, FinallyBlock
 while reader.blockstack:
 context = reader.blockstack.pop()
 block.operations.append(POP_BLOCK(offset=self.offset))
-if isinstance(context, ExceptBlock):
+if isinstance(context, SETUP_EXCEPT):
 pass
-elif isinstance(context, FinallyBlock):
-reader.splice_finally_handler(block, context)
-block = context.handler_end
+elif isinstance(context, (SETUP_WITH, SETUP_FINALLY)):
+block = reader.splice_finally_handler(block, context.block)
 else:  # LoopBlock
-block.set_exits([context.handler])
+block.set_exits([context.target])
 return
 raise BytecodeCorruption(
 "A break statement should not escape from the function")
@@ -610,15 +608,14 @@
 block = reader.curr_block
 assert block.operations[-1] is self
 del block.operations[-1]
-from rpython.flowspace.flowcontext import ExceptBlock, FinallyBlock
 while reader.blockstack:
 context = reader.blockstack.pop()
-if isinstance(context, ExceptBlock):
+if isinstance(context, SETUP_EXCEPT):
 block.operations.append(POP_BLOCK(offset=self.offset))
-elif isinstance(context, FinallyBlock):
+elif isinstance(context, (SETUP_FINALLY, SETUP_WITH)):
 block.operations.append(POP_BLOCK(offset=self.offset))
-block = reader.splice_finally_handler(block, context)
-else:  # LoopBlock
+block = reader.splice_finally_handler(block, context.block)
+else:  # SETUP_LOOP
 reader.blockstack.append(context)
 block.set_exits([self.target])
 return
@@ -647,12 +644,11 @@
 block = reader.curr_block
 assert block.operations[-1] is self
 del block.operations[-1]
-from rpython.flowspace.flowcontext import FinallyBlock
 while reader.blockstack:
 context = reader.blockstack.pop()
 block.operations.append(POP_BLOCK(offset=self.offset))
-if isinstance(context, FinallyBlock):
-block = reader.splice_finally_handler(block, context)
+if isinstance(context, SETUP_FINALLY):
+block = reader.splice_finally_handler(block, context.block)
 block.operations.append(self)
 
 def eval(self, ctx):
@@ -706,7 +702,7 @@
 
 def context_effect(self, reader):
 self.target.set_blockstack(reader.blockstack)
-reader.blockstack.append(self.block)
+reader.blockstack.append(self)
 
 def eval(self, ctx):
 self.block.stackdepth = ctx.stackdepth
diff --git a/rpython/flowspace/test/test_objspace.py 
b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -964,7 +964,9 @@
 def f(x):
 with x:
 return 1
-self.codetest(f)
+graph = self.codetest(f)
+simplify_graph(graph)
+assert self.all_operations(graph) == {'getattr': 2, 'simple_call': 2}
 
 def test_break_in_with(self):
 def f(n, x):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy framestate: put a dummy unroller on the stack for WITH_CLEANUP

2015-02-16 Thread rlamy
Author: Ronan Lamy 
Branch: framestate
Changeset: r75926:3838b73fb409
Date: 2015-02-16 16:57 +
http://bitbucket.org/pypy/pypy/changeset/3838b73fb409/

Log:put a dummy unroller on the stack for WITH_CLEANUP

diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -12,6 +12,8 @@
 CO_VARARGS = 0x0004
 CO_VARKEYWORDS = 0x0008
 
+w_None = const(None)
+
 def cpython_code_signature(code):
 "([list-of-arg-names], vararg-name-or-None, kwarg-name-or-None)."
 argcount = code.co_argcount
@@ -589,8 +591,12 @@
 block.operations.append(POP_BLOCK(offset=self.offset))
 if isinstance(context, SETUP_EXCEPT):
 pass
-elif isinstance(context, (SETUP_WITH, SETUP_FINALLY)):
+elif isinstance(context, SETUP_FINALLY):
 block = reader.splice_finally_handler(block, context.block)
+elif isinstance(context, SETUP_WITH):
+block = reader.splice_finally_handler(block, context.block)
+assert len(block.operations) == 1
+block.operations = [PUSH_NONE()] + block.operations + 
[POP_TOP()]
 else:  # LoopBlock
 block.set_exits([context.target])
 return
@@ -612,9 +618,14 @@
 context = reader.blockstack.pop()
 if isinstance(context, SETUP_EXCEPT):
 block.operations.append(POP_BLOCK(offset=self.offset))
-elif isinstance(context, (SETUP_FINALLY, SETUP_WITH)):
+elif isinstance(context, SETUP_FINALLY):
 block.operations.append(POP_BLOCK(offset=self.offset))
 block = reader.splice_finally_handler(block, context.block)
+elif isinstance(context, SETUP_WITH):
+block.operations.append(POP_BLOCK(offset=self.offset))
+block = reader.splice_finally_handler(block, context.block)
+assert len(block.operations) == 1
+block.operations = [PUSH_NONE()] + block.operations + 
[POP_TOP()]
 else:  # SETUP_LOOP
 reader.blockstack.append(context)
 block.set_exits([self.target])
@@ -637,6 +648,12 @@
 w_value = ctx.popvalue()
 ctx.w_return_value = w_value
 
+class PUSH_NONE(NullaryOpcode):
+num = name = 'PUSH_NONE'
+arg = NO_ARG
+def eval(self, ctx):
+ctx.pushvalue(w_None)
+
 class RETURN(NullaryOpcode):
 num = name = 'RETURN'
 arg = NO_ARG
@@ -649,6 +666,10 @@
 block.operations.append(POP_BLOCK(offset=self.offset))
 if isinstance(context, SETUP_FINALLY):
 block = reader.splice_finally_handler(block, context.block)
+elif isinstance(context, SETUP_WITH):
+block = reader.splice_finally_handler(block, context.block)
+assert len(block.operations) == 1
+block.operations = [PUSH_NONE()] + block.operations + 
[POP_TOP()]
 block.operations.append(self)
 
 def eval(self, ctx):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Fix typo in cffi

2015-02-16 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.3
Changeset: r75928:3c7542345bfa
Date: 2015-02-16 21:47 +0100
http://bitbucket.org/pypy/pypy/changeset/3c7542345bfa/

Log:Fix typo in cffi

diff --git a/lib_pypy/cffi/verifier.py b/lib_pypy/cffi/verifier.py
--- a/lib_pypy/cffi/verifier.py
+++ b/lib_pypy/cffi/verifier.py
@@ -4,7 +4,7 @@
 
 if sys.version_info >= (3, 3):
 import importlib.machinery
-def extension_suffixes():
+def _extension_suffixes():
 return importlib.machinery.EXTENSION_SUFFIXES[:]
 else:
 import imp
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: test, fix load_dh_params get_saved_errno for win32

2015-02-16 Thread mattip
Author: mattip 
Branch: 
Changeset: r75929:1bf192278b3f
Date: 2015-02-17 00:11 +0200
http://bitbucket.org/pypy/pypy/changeset/1bf192278b3f/

Log:test, fix load_dh_params get_saved_errno for win32

diff --git a/pypy/module/_ssl/test/test_ssl.py 
b/pypy/module/_ssl/test/test_ssl.py
--- a/pypy/module/_ssl/test/test_ssl.py
+++ b/pypy/module/_ssl/test/test_ssl.py
@@ -361,12 +361,14 @@
 assert ctx.cert_store_stats() == {'x509_ca': 0, 'crl': 0, 'x509': 1}
 
 def test_load_dh_params(self):
-import _ssl
+import _ssl, errno
 ctx = _ssl._SSLContext(_ssl.PROTOCOL_TLSv1)
 ctx.load_dh_params(self.dh512)
 raises(TypeError, ctx.load_dh_params)
 raises(TypeError, ctx.load_dh_params, None)
 raises(_ssl.SSLError, ctx.load_dh_params, self.keycert)
+exc = raises(IOError, ctx.load_dh_params, "inexistent.pem")
+assert exc.value.errno == errno.ENOENT
 
 def test_set_ecdh_curve(self):
 import _ssl
diff --git a/rpython/rlib/ropenssl.py b/rpython/rlib/ropenssl.py
--- a/rpython/rlib/ropenssl.py
+++ b/rpython/rlib/ropenssl.py
@@ -5,7 +5,7 @@
 from rpython.translator.platform import platform
 from rpython.translator.tool.cbuild import ExternalCompilationInfo
 from rpython.rlib.unroll import unrolling_iterable
-from rpython.rlib._rsocket_rffi import MAX_FD_SIZE, SAVE_ERR
+from rpython.rlib._rsocket_rffi import SAVE_ERR
 
 
 if sys.platform == 'win32' and platform.name != 'mingw32':
@@ -467,7 +467,7 @@
 ssl_external('BIO_new', [BIO_METHOD], BIO)
 ssl_external('BIO_set_nbio', [BIO, rffi.INT], rffi.INT, macro=True)
 ssl_external('BIO_new_file', [rffi.CCHARP, rffi.CCHARP], BIO,
- save_err=SAVE_ERR)
+ save_err=rffi.RFFI_FULL_ERRNO_ZERO)
 ssl_external('BIO_new_mem_buf', [rffi.VOIDP, rffi.INT], BIO)
 ssl_external('BIO_free', [BIO], rffi.INT)
 ssl_external('BIO_reset', [BIO], rffi.INT, macro=True)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: import * masked unused import from 1bf192278b3f, fix

2015-02-16 Thread mattip
Author: mattip 
Branch: 
Changeset: r75930:3ffd8f58f1b5
Date: 2015-02-17 08:01 +0200
http://bitbucket.org/pypy/pypy/changeset/3ffd8f58f1b5/

Log:import * masked unused import from 1bf192278b3f, fix

diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -1,6 +1,8 @@
 from rpython.rlib import rpoll, rsocket, rthread, rweakref
 from rpython.rlib.rarithmetic import intmask, widen, r_uint
 from rpython.rlib.ropenssl import *
+from pypy.module._socket import interp_socket
+from rpython.rlib._rsocket_rffi import MAX_FD_SIZE
 from rpython.rlib.rposix import get_saved_errno
 from rpython.rlib.rweakref import RWeakValueDictionary
 from rpython.rlib.objectmodel import specialize, compute_unique_id
@@ -12,7 +14,6 @@
 from pypy.interpreter.typedef import TypeDef, GetSetProperty
 from pypy.module._ssl.ssl_data import (
 LIBRARY_CODES_TO_NAMES, ERROR_CODES_TO_NAMES)
-from pypy.module._socket import interp_socket
 
 
 # user defined constants
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit