[pypy-commit] pypy default: merge

2014-12-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r75010:c3be2cabf20d
Date: 2014-12-18 10:15 +0200
http://bitbucket.org/pypy/pypy/changeset/c3be2cabf20d/

Log:merge

diff --git a/rpython/jit/metainterp/optimizeopt/rewrite.py 
b/rpython/jit/metainterp/optimizeopt/rewrite.py
--- a/rpython/jit/metainterp/optimizeopt/rewrite.py
+++ b/rpython/jit/metainterp/optimizeopt/rewrite.py
@@ -483,11 +483,14 @@
 self.emit_operation(op)
 
 def _optimize_CALL_ARRAYCOPY(self, op):
+length = self.get_constant_box(op.getarg(5))
+if length and length.getint() == 0:
+return True # 0-length arraycopy
+
 source_value = self.getvalue(op.getarg(1))
 dest_value = self.getvalue(op.getarg(2))
 source_start_box = self.get_constant_box(op.getarg(3))
 dest_start_box = self.get_constant_box(op.getarg(4))
-length = self.get_constant_box(op.getarg(5))
 extrainfo = op.getdescr().get_extra_info()
 if (source_start_box and dest_start_box
 and length and (dest_value.is_virtual() or length.getint() <= 8) 
and
@@ -498,6 +501,8 @@
 dest_start = dest_start_box.getint()
 # XXX fish fish fish
 arraydescr = extrainfo.write_descrs_arrays[0]
+if arraydescr.is_array_of_structs():
+return False   # not supported right now
 for index in range(length.getint()):
 if source_value.is_virtual():
 assert isinstance(source_value, VArrayValue)
@@ -527,8 +532,6 @@
  descr=arraydescr)
 self.emit_operation(newop)
 return True
-if length and length.getint() == 0:
-return True # 0-length arraycopy
 return False
 
 def optimize_CALL_PURE(self, op):
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py 
b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_optimizebasic.py
@@ -999,6 +999,40 @@
 """
 self.optimize_loop(ops, expected)
 
+def test_virtual_array_of_struct_arraycopy(self):
+ops = """
+[f0, f1]
+p0 = new_array_clear(3, descr=complexarraydescr)
+setinteriorfield_gc(p0, 0, f0, descr=compleximagdescr)
+setinteriorfield_gc(p0, 0, f1, descr=complexrealdescr)
+call(0, p0, p0, 0, 2, 1, descr=complexarraycopydescr)
+f2 = getinteriorfield_gc(p0, 2, descr=complexrealdescr)
+f3 = getinteriorfield_gc(p0, 2, descr=compleximagdescr)
+escape(f2)
+escape(f3)
+finish(1)
+"""
+expected = """
+[f0, f1]
+escape(f1)
+escape(f0)
+finish(1)
+"""
+self.optimize_loop(ops, ops)
+py.test.skip("XXX missing optimization: 
ll_arraycopy(array-of-structs)")
+
+def test_nonvirtual_array_of_struct_arraycopy(self):
+ops = """
+[p0]
+call(0, p0, p0, 0, 2, 1, descr=complexarraycopydescr)
+f2 = getinteriorfield_gc(p0, 2, descr=compleximagdescr)
+f3 = getinteriorfield_gc(p0, 2, descr=complexrealdescr)
+escape(f2)
+escape(f3)
+finish(1)
+"""
+self.optimize_loop(ops, ops)
+
 def test_nonvirtual_1(self):
 ops = """
 [i]
diff --git a/rpython/jit/metainterp/optimizeopt/test/test_util.py 
b/rpython/jit/metainterp/optimizeopt/test/test_util.py
--- a/rpython/jit/metainterp/optimizeopt/test/test_util.py
+++ b/rpython/jit/metainterp/optimizeopt/test/test_util.py
@@ -223,6 +223,10 @@
 complexarraydescr = cpu.arraydescrof(complexarray)
 complexrealdescr = cpu.interiorfielddescrof(complexarray, "real")
 compleximagdescr = cpu.interiorfielddescrof(complexarray, "imag")
+complexarraycopydescr = cpu.calldescrof(FUNC, FUNC.ARGS, FUNC.RESULT,
+EffectInfo([], [complexarraydescr], [], [], [complexarraydescr], 
[],
+   EffectInfo.EF_CANNOT_RAISE,
+   oopspecindex=EffectInfo.OS_ARRAYCOPY))
 
 rawarraydescr = cpu.arraydescrof(lltype.Array(lltype.Signed,
   hints={'nolength': True}))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: this broke stuff, revert

2014-12-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r75009:1568f745143e
Date: 2014-12-18 10:13 +0200
http://bitbucket.org/pypy/pypy/changeset/1568f745143e/

Log:this broke stuff, revert

diff --git a/rpython/jit/metainterp/optimizeopt/unroll.py 
b/rpython/jit/metainterp/optimizeopt/unroll.py
--- a/rpython/jit/metainterp/optimizeopt/unroll.py
+++ b/rpython/jit/metainterp/optimizeopt/unroll.py
@@ -97,6 +97,7 @@
 jumpop = None
 
 self.import_state(start_label, starting_state)
+
 self.optimizer.propagate_all_forward(clear=False)
 
 if not jumpop:
diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py 
b/rpython/jit/metainterp/optimizeopt/virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py
@@ -638,7 +638,6 @@
 for i in range(op.numargs()):
 op.setarg(i, self.renamed(op.getarg(i)))
 if box in self.short_boxes:
-return
 if op is None:
 oldop = self.short_boxes[box].clone()
 oldres = oldop.result
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: someone has to explain to me why this is not reasonable

2014-12-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r75011:57d177436b84
Date: 2014-12-18 10:45 +0200
http://bitbucket.org/pypy/pypy/changeset/57d177436b84/

Log:someone has to explain to me why this is not reasonable

diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py 
b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -107,7 +107,9 @@
 assert other.level == LEVEL_CONSTANT
 assert other.box.same_constant(self.box)
 return
-assert self.level <= LEVEL_NONNULL
+if self.level == LEVEL_KNOWNCLASS:
+return
+#assert self.level <= LEVEL_NONNULL
 if other.level == LEVEL_CONSTANT:
 self.make_constant(other.get_key_box())
 optimizer.turned_constant(self)
diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py 
b/rpython/jit/metainterp/optimizeopt/virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py
@@ -638,6 +638,7 @@
 for i in range(op.numargs()):
 op.setarg(i, self.renamed(op.getarg(i)))
 if box in self.short_boxes:
+return
 if op is None:
 oldop = self.short_boxes[box].clone()
 oldres = oldop.result
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Copy better error message from CPython 2.7 for list.index().

2014-12-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r75012:c1e5d1cca6aa
Date: 2014-12-18 09:48 +
http://bitbucket.org/pypy/pypy/changeset/c1e5d1cca6aa/

Log:Copy better error message from CPython 2.7 for list.index(). As
there is no reason not to, also use it for list.remove().

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -618,8 +618,8 @@
 try:
 i = self.find(w_value, 0, sys.maxint)
 except ValueError:
-raise OperationError(space.w_ValueError,
- space.wrap("list.remove(x): x not in list"))
+raise oefmt(space.w_ValueError,
+"list.remove(): %R is not in list", w_value)
 if i < self.length():  # otherwise list was mutated
 self.pop(i)
 
@@ -633,8 +633,7 @@
 try:
 i = self.find(w_value, i, stop)
 except ValueError:
-raise OperationError(space.w_ValueError,
- space.wrap("list.index(x): x not in list"))
+raise oefmt(space.w_ValueError, "%R is not in list", w_value)
 return space.wrap(i)
 
 @unwrap_spec(reverse=bool)
diff --git a/pypy/objspace/std/test/test_listobject.py 
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -976,7 +976,10 @@
 
 c = [0.0, 2.2, 4.4]
 assert c.index(0) == 0.0
-raises(ValueError, c.index, 3)
+e = raises(ValueError, c.index, 3)
+import sys
+if sys.version_info[:2] == (2, 7): # CPython 2.7, PyPy
+assert str(e.value) == '3 is not in list'
 
 def test_index_cpython_bug(self):
 if self.on_cpython:
@@ -1228,7 +1231,9 @@
 assert l == [0.0, 1.1, 3.3, 4.4]
 l = [0.0, 3.3, 5.5]
 raises(ValueError, c.remove, 2)
-raises(ValueError, c.remove, 2.2)
+e = raises(ValueError, c.remove, 2.2)
+if not self.on_cpython:
+assert str(e.value) == 'list.remove(): 2.2 is not in list'
 
 def test_reverse(self):
 c = list('hello world')
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Backed out changeset 57d177436b84

2014-12-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r75013:01fc6eb5e20c
Date: 2014-12-18 14:47 +0200
http://bitbucket.org/pypy/pypy/changeset/01fc6eb5e20c/

Log:Backed out changeset 57d177436b84

diff --git a/rpython/jit/metainterp/optimizeopt/optimizer.py 
b/rpython/jit/metainterp/optimizeopt/optimizer.py
--- a/rpython/jit/metainterp/optimizeopt/optimizer.py
+++ b/rpython/jit/metainterp/optimizeopt/optimizer.py
@@ -107,9 +107,7 @@
 assert other.level == LEVEL_CONSTANT
 assert other.box.same_constant(self.box)
 return
-if self.level == LEVEL_KNOWNCLASS:
-return
-#assert self.level <= LEVEL_NONNULL
+assert self.level <= LEVEL_NONNULL
 if other.level == LEVEL_CONSTANT:
 self.make_constant(other.get_key_box())
 optimizer.turned_constant(self)
diff --git a/rpython/jit/metainterp/optimizeopt/virtualstate.py 
b/rpython/jit/metainterp/optimizeopt/virtualstate.py
--- a/rpython/jit/metainterp/optimizeopt/virtualstate.py
+++ b/rpython/jit/metainterp/optimizeopt/virtualstate.py
@@ -638,7 +638,6 @@
 for i in range(op.numargs()):
 op.setarg(i, self.renamed(op.getarg(i)))
 if box in self.short_boxes:
-return
 if op is None:
 oldop = self.short_boxes[box].clone()
 oldres = oldop.result
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: merge

2014-12-18 Thread fijal
Author: Maciej Fijalkowski 
Branch: 
Changeset: r75014:d19489819ae6
Date: 2014-12-18 14:49 +0200
http://bitbucket.org/pypy/pypy/changeset/d19489819ae6/

Log:merge

diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -618,8 +618,8 @@
 try:
 i = self.find(w_value, 0, sys.maxint)
 except ValueError:
-raise OperationError(space.w_ValueError,
- space.wrap("list.remove(x): x not in list"))
+raise oefmt(space.w_ValueError,
+"list.remove(): %R is not in list", w_value)
 if i < self.length():  # otherwise list was mutated
 self.pop(i)
 
@@ -633,8 +633,7 @@
 try:
 i = self.find(w_value, i, stop)
 except ValueError:
-raise OperationError(space.w_ValueError,
- space.wrap("list.index(x): x not in list"))
+raise oefmt(space.w_ValueError, "%R is not in list", w_value)
 return space.wrap(i)
 
 @unwrap_spec(reverse=bool)
diff --git a/pypy/objspace/std/test/test_listobject.py 
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -976,7 +976,10 @@
 
 c = [0.0, 2.2, 4.4]
 assert c.index(0) == 0.0
-raises(ValueError, c.index, 3)
+e = raises(ValueError, c.index, 3)
+import sys
+if sys.version_info[:2] == (2, 7): # CPython 2.7, PyPy
+assert str(e.value) == '3 is not in list'
 
 def test_index_cpython_bug(self):
 if self.on_cpython:
@@ -1228,7 +1231,9 @@
 assert l == [0.0, 1.1, 3.3, 4.4]
 l = [0.0, 3.3, 5.5]
 raises(ValueError, c.remove, 2)
-raises(ValueError, c.remove, 2.2)
+e = raises(ValueError, c.remove, 2.2)
+if not self.on_cpython:
+assert str(e.value) == 'list.remove(): 2.2 is not in list'
 
 def test_reverse(self):
 c = list('hello world')
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: (idea by antocuni) Complain clearly when trying to import 'readline' on

2014-12-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r75015:e8b468bcd294
Date: 2014-12-18 16:37 +
http://bitbucket.org/pypy/pypy/changeset/e8b468bcd294/

Log:(idea by antocuni) Complain clearly when trying to import 'readline'
on Windows.

diff --git a/lib_pypy/readline.py b/lib_pypy/readline.py
--- a/lib_pypy/readline.py
+++ b/lib_pypy/readline.py
@@ -6,4 +6,11 @@
 are only stubs at the moment.
 """
 
-from pyrepl.readline import *
+try:
+from pyrepl.readline import *
+except ImportError:
+import sys
+if sys.platform == 'win32':
+raise ImportError("the 'readline' module is not available on Windows"
+  " (on either PyPy or CPython)")
+raise
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy libgccjit-backend: Clarify _impl_guard; start adding boilerplate for bridges

2014-12-18 Thread dmalcolm
Author: David Malcolm 
Branch: libgccjit-backend
Changeset: r75017:a1db64631c41
Date: 2014-12-17 13:20 -0500
http://bitbucket.org/pypy/pypy/changeset/a1db64631c41/

Log:Clarify _impl_guard; start adding boilerplate for bridges

diff --git a/rpython/jit/backend/libgccjit/assembler.py 
b/rpython/jit/backend/libgccjit/assembler.py
--- a/rpython/jit/backend/libgccjit/assembler.py
+++ b/rpython/jit/backend/libgccjit/assembler.py
@@ -259,6 +259,15 @@
 
 # FIXME: this leaks the gcc_jit_result
 
+def assemble_bridge(self, logger, faildescr, inputargs, operations,
+original_loop_token, log):
+print('assemble_bridge(%r)' % locals())
+if not we_are_translated():
+# Arguments should be unique
+assert len(set(inputargs)) == len(inputargs)
+
+raise foo
+
 def expr_to_rvalue(self, expr):
 """
 print('expr_to_rvalue')
@@ -391,9 +400,14 @@
 b_true, b_false)
 
 if istrue:
-self.b_current = b_false
+b_guard_failure = b_false
+b_guard_success = b_true
 else:
-self.b_current = b_true
+b_guard_failure = b_true
+b_guard_success = b_false
+
+# Write out guard failure impl:
+self.b_current = b_guard_failure
 self._impl_write_output_args(resop._fail_args)
 self._impl_write_jf_descr(resop)
 self.b_current.end_with_return(self.param_frame.as_rvalue ())
@@ -402,10 +416,8 @@
 rd_locs.append(idx * self.sizeof_signed)
 resop.getdescr().rd_locs = rd_locs
 
-if istrue:
-self.b_current = b_true
-else:
-self.b_current = b_false
+# Further operations go into the guard success block:
+self.b_current = b_guard_success
 
 def emit_guard_true(self, resop):
 self._impl_guard(resop, r_int(1))
diff --git a/rpython/jit/backend/libgccjit/runner.py 
b/rpython/jit/backend/libgccjit/runner.py
--- a/rpython/jit/backend/libgccjit/runner.py
+++ b/rpython/jit/backend/libgccjit/runner.py
@@ -17,20 +17,13 @@
 
 def compile_loop(self, inputargs, operations, looptoken,
  log=True, name='', logger=None):
-"""
-import sys
-sys.stderr.write('compile_loop:\n')
-for i, arg in enumerate(inputargs):
-sys.stderr.write('  arg[%i] = %r\n' % (i, arg))
-sys.stderr.write('type(arg[%i]) = %r\n' % (i, type(arg)))
-for i, op in enumerate(operations):
-sys.stderr.write('  op[%i] = %r\n' % (i, op))
-sys.stderr.write('type(op[%i]) = %r\n' % (i, type(op)))
-sys.stderr.write('  looptoken: %r\n' % (looptoken, ))
-sys.stderr.write('  log: %r\n' % (log, ))
-sys.stderr.write('  name: %r\n' % (name, ))
-sys.stderr.write('  logger: %r\n' % (logger, ))
-sys.stderr.write('compile_loop: %r\n' % locals ())
-"""
 return self.assembler.assemble_loop(inputargs, operations, looptoken, 
log,
 name, logger)
+
+def compile_bridge(self, faildescr, inputargs, operations,
+   original_loop_token, log=True, logger=None):
+clt = original_loop_token.compiled_loop_token
+clt.compiling_a_bridge()
+return self.assembler.assemble_bridge(logger, faildescr, inputargs,
+  operations,
+  original_loop_token, log=log)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy libgccjit-backend: Document the changes to libgccjit that I need to merge

2014-12-18 Thread dmalcolm
Author: David Malcolm 
Branch: libgccjit-backend
Changeset: r75020:5d890f2ddecd
Date: 2014-12-18 12:17 -0500
http://bitbucket.org/pypy/pypy/changeset/5d890f2ddecd/

Log:Document the changes to libgccjit that I need to merge

diff --git a/rpython/jit/backend/libgccjit/notes.rst 
b/rpython/jit/backend/libgccjit/notes.rst
new file mode 100644
--- /dev/null
+++ b/rpython/jit/backend/libgccjit/notes.rst
@@ -0,0 +1,16 @@
+This is an experiment, and merely a work-in-progress.
+
+In particular, this needs some changes to libgccjit that are currently
+only in my local repo:
+
+   * new API entrypoints:
+
+ * :c:func:`gcc_jit_result_get_global`
+
+ * :c:func:`gcc_jit_context_new_rvalue_from_long`
+
+   * a new value :c:macro:`GCC_JIT_UNARY_OP_ABS` within
+ :c:type:`enum gcc_jit_unary_op`.
+
+   * an extra param to :c:func:`gcc_jit_context_new_global`
+ (enum gcc_jit_global_kind).
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy libgccjit-backend: Begin implementing code patching

2014-12-18 Thread dmalcolm
Author: David Malcolm 
Branch: libgccjit-backend
Changeset: r75019:ee6c48dc603d
Date: 2014-12-18 12:10 -0500
http://bitbucket.org/pypy/pypy/changeset/ee6c48dc603d/

Log:Begin implementing code patching

When generating guard failure handling, replace direct call to
default handler with a jump through a function pointer, so that (in
theory) we can write to this function pointer to use a different
handler.

This requires a couple of extra changes to libgccjit that are
currently only in my local repo:

 * a new API entrypoint "gcc_jit_result_get_global"
   * an extra param to gcc_jit_context_new_global (enum
gcc_jit_global_kind)

diff --git a/rpython/jit/backend/libgccjit/assembler.py 
b/rpython/jit/backend/libgccjit/assembler.py
--- a/rpython/jit/backend/libgccjit/assembler.py
+++ b/rpython/jit/backend/libgccjit/assembler.py
@@ -20,6 +20,93 @@
 self.param_addr = assembler.ctxt.new_param(assembler.t_void_ptr,
"addr")
 self.paramlist.append(self.param_addr)
+self.paramtypes = [assembler.t_jit_frame_ptr,
+   assembler.t_void_ptr]
+
+class Patchpoint:
+"""
+We need to be able to patch out the generated code that runs when a
+guard fails; this class handles that.
+
+We handle guard failure with a tail-call through a function pointer,
+equivalent to this C code:
+
+  struct JITFRAME * (*guard_failure_fn_ptr_0) (struct JITFRAME *, void *);
+
+  extern struct JITFRAME *
+  anonloop_0 (struct JITFRAME * jitframe, void * addr)
+  {
+...various operations...
+
+if (!guard)
+ goto on_guard_failure;
+
+...various operations...
+
+   on_guard_failure:
+  return guard_failure_fn_ptr_0 (frame, );
+  }
+
+This can hopefully be optimized to a jump through a ptr, since it's
+a tail call:
+
+  0x7fffeb7086d0 <+16>:  jle0x7fffeb7086c8 
+  0x7fffeb7086d2 <+18>:  mov%rax,0x48(%rdi)
+  0x7fffeb7086d6 <+22>:  mov0x2008fb(%rip),%rax# 
0x7fffeb908fd8
+  0x7fffeb7086dd <+29>:  mov(%rax),%rax
+  0x7fffeb7086e0 <+32>:  jmpq   *%rax
+"""
+def __init__(self, assembler):
+self.failure_params = Params(assembler)
+self.serial = assembler.num_guard_failure_fns
+assembler.num_guard_failure_fns += 1
+self.t_fn_ptr_type = (
+assembler.ctxt.new_function_ptr_type (assembler.t_jit_frame_ptr,
+  
self.failure_params.paramtypes,
+  r_int(0)))
+# Create the function ptr
+# Globals are zero-initialized, so we'll need to
+# write in the ptr to the initial handler before the loop is called,
+# or we'll have a jump-through-NULL segfault.
+self.fn_ptr_name = "guard_failure_fn_ptr_%i" % self.serial
+self.failure_fn_ptr = (
+assembler.ctxt.new_global(assembler.lib.GCC_JIT_GLOBAL_EXPORTED,
+  self.t_fn_ptr_type,
+  self.fn_ptr_name))
+self.handler_name = "on_guard_failure_%i" % self.serial
+self.failure_fn = (
+
assembler.ctxt.new_function(assembler.lib.GCC_JIT_FUNCTION_EXPORTED,
+assembler.t_jit_frame_ptr,
+self.handler_name,
+self.failure_params.paramlist,
+r_int(0)))
+
+def write_initial_handler(self, result):
+# Get the address of the machine code for the handler;
+# this is a:
+#   struct JITFRAME * (*guard_failure_fn) (struct JITFRAME *, void *)
+handler = result.get_code(self.handler_name)
+
+# Get the address of the function ptr to be written to;
+# this is a:
+#   struct JITFRAME * (**guard_failure_fn) (struct JITFRAME *, void *)
+# i.e. one extra level of indirection.
+fn_ptr_ptr = result.get_global(self.fn_ptr_name)
+
+# We want to write the equivalent of:
+#(*fn_ptr_ptr) = handler;
+#
+# "fn_ptr_ptr" and "handler" are both currently (void *).
+# so we need to cast them to a form where we can express
+# the above.
+
+# We can't directly express the function ptr ptr in lltype,
+# so instead pretend we have a (const char **) and a (const char *):
+fn_ptr_ptr = rffi.cast(rffi.CCHARPP, fn_ptr_ptr)
+handler = rffi.cast(rffi.CCHARP, handler)
+
+# ...and write through the ptr:
+fn_ptr_ptr[0] = handler
 
 class AssemblerLibgccjit(BaseAssembler):
 _regalloc = None
@@ -48,6 +135,7 @@
 self.num_guard_failure_fns = 0
 
 self.sizeof_signed = rffi.sizeof(lltype.Signed)
+self.pat

[pypy-commit] pypy libgccjit-backend: Split out guard failure into a tail call to another function

2014-12-18 Thread dmalcolm
Author: David Malcolm 
Branch: libgccjit-backend
Changeset: r75018:eb3ba1b9910e
Date: 2014-12-17 15:43 -0500
http://bitbucket.org/pypy/pypy/changeset/eb3ba1b9910e/

Log:Split out guard failure into a tail call to another function

Eventually this could be a jump through a function pointer.

Right now it's simply a call to a internal function. The call gets
inlined away, back into the code we had before.

diff --git a/rpython/jit/backend/libgccjit/assembler.py 
b/rpython/jit/backend/libgccjit/assembler.py
--- a/rpython/jit/backend/libgccjit/assembler.py
+++ b/rpython/jit/backend/libgccjit/assembler.py
@@ -10,6 +10,17 @@
 from rpython.rtyper.lltypesystem.rffi import *
 from rpython.rtyper.lltypesystem import lltype, rffi, rstr, llmemory
 
+class Params:
+def __init__(self, assembler):
+self.paramlist = []
+self.param_frame = assembler.ctxt.new_param(assembler.t_jit_frame_ptr,
+"jitframe")
+self.paramlist.append(self.param_frame)
+
+self.param_addr = assembler.ctxt.new_param(assembler.t_void_ptr,
+   "addr")
+self.paramlist.append(self.param_addr)
+
 class AssemblerLibgccjit(BaseAssembler):
 _regalloc = None
 #_output_loop_log = None
@@ -34,6 +45,7 @@
 #self.teardown()
 
 self.num_anon_loops = 0
+self.num_guard_failure_fns = 0
 
 self.sizeof_signed = rffi.sizeof(lltype.Signed)
 
@@ -98,6 +110,7 @@
 self.t_float = self.ctxt.get_type(self.lib.GCC_JIT_TYPE_DOUBLE) # 
FIXME  
 self.t_bool = self.ctxt.get_type(self.lib.GCC_JIT_TYPE_BOOL)
 self.t_void_ptr = self.ctxt.get_type(self.lib.GCC_JIT_TYPE_VOID_PTR)
+self.t_void = self.ctxt.get_type(self.lib.GCC_JIT_TYPE_VOID)
 
 self.u_signed = self.ctxt.new_field(self.t_Signed, "u_signed")
 self.u_float = self.ctxt.new_field(self.t_float, "u_float")
@@ -134,7 +147,7 @@
 
 struct_jit_frame = self.ctxt.new_opaque_struct ("JITFRAME")
 
-t_jit_frame_ptr = struct_jit_frame.as_type().get_pointer()
+self.t_jit_frame_ptr = struct_jit_frame.as_type().get_pointer()
 
 fields = []
 # FIXME: Does the GCStruct implicitly add any fields?
@@ -149,7 +162,7 @@
 make_field('jf_extra_stack_depth', self.t_Signed)
 make_field('jf_savedata', self.t_void_ptr)
 make_field('jf_guard_exc', self.t_void_ptr)
-make_field('jf_forward', t_jit_frame_ptr)
+make_field('jf_forward', self.t_jit_frame_ptr)
 # FIXME: for some reason there's an implicit word here;
 # create it
 make_field('jf_frame', self.t_Signed)
@@ -176,22 +189,16 @@
 # Make function:
 #print('  inputargs: %r' % (inputargs, ))
 #jitframe.JITFRAMEINFOPTR
-params = []
-
-self.param_frame = self.ctxt.new_param(t_jit_frame_ptr, "jitframe")
-params.append(self.param_frame)
-
-self.param_addr = self.ctxt.new_param(self.t_void_ptr, "addr")
-params.append(self.param_addr)
+self.loop_params = Params(self)
 
 if not loopname:
 loopname = 'anonloop_%i' % self.num_anon_loops
 self.num_anon_loops += 1
 print("  loopname: %r" % loopname)
 self.fn = self.ctxt.new_function(self.lib.GCC_JIT_FUNCTION_EXPORTED,
- t_jit_frame_ptr,
+ self.t_jit_frame_ptr,
  loopname,
- params,
+ self.loop_params.paramlist,
  r_int(0))
 
 self.b_current = self.fn.new_block("initial")
@@ -300,7 +307,7 @@
 return self.lvalue_for_box[box]
 
 def get_arg_as_lvalue(self, idx):
-return self.param_frame.as_rvalue ().dereference_field (
+return self.loop_params.param_frame.as_rvalue ().dereference_field (
 self.field_for_arg_idx[idx])
 
 def expr_to_lvalue(self, expr):
@@ -371,9 +378,9 @@
 
self.b_current.end_with_jump(self.block_for_label_descr[jumpop.getdescr()])
 
 def emit_finish(self, resop):
-self._impl_write_output_args(resop._args)
-self._impl_write_jf_descr(resop)
-self.b_current.end_with_return(self.param_frame.as_rvalue ())
+self._impl_write_output_args(self.loop_params, resop._args)
+self._impl_write_jf_descr(self.loop_params, resop)
+self.b_current.end_with_return(self.loop_params.param_frame.as_rvalue 
())
 
 def emit_label(self, resop):
 print(resop)
@@ -408,15 +415,34 @@
 
 # Write out guard failure impl:
 self.b_current = b_guard_failure
-self._impl_write_output_args(resop._fail_args)
-self._impl_write_jf_descr(resop)
-self.b_current.end_with_return(self.param

[pypy-commit] pypy libgccjit-backend: Implement uint_floordiv and uint_rshift; reduce debug spew

2014-12-18 Thread dmalcolm
Author: David Malcolm 
Branch: libgccjit-backend
Changeset: r75016:3e8180a52286
Date: 2014-12-17 12:47 -0500
http://bitbucket.org/pypy/pypy/changeset/3e8180a52286/

Log:Implement uint_floordiv and uint_rshift; reduce debug spew

diff --git a/rpython/jit/backend/libgccjit/assembler.py 
b/rpython/jit/backend/libgccjit/assembler.py
--- a/rpython/jit/backend/libgccjit/assembler.py
+++ b/rpython/jit/backend/libgccjit/assembler.py
@@ -44,19 +44,22 @@
 if 0:
 
self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DUMP_INITIAL_TREE,
   r_int(1))
-if 1:
+if 0:
 
self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DUMP_INITIAL_GIMPLE,
   r_int(1))
-self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DEBUGINFO,
-  r_int(1))
+if 1:
+self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DEBUGINFO,
+  r_int(1))
 if 1:
 
self.ctxt.set_int_option(self.lib.GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL,
  r_int(2))
-
self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES,
-  r_int(1))
-self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING,
-  r_int(1))
-if 1:
+if 0:
+
self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_KEEP_INTERMEDIATES,
+  r_int(1))
+if 0:
+
self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DUMP_EVERYTHING,
+  r_int(1))
+if 0:
 
self.ctxt.set_bool_option(self.lib.GCC_JIT_BOOL_OPTION_DUMP_GENERATED_CODE,
   r_int(1))
 
@@ -75,7 +78,7 @@
   loopname, logger):
 print('assemble_loop')
 clt = CompiledLoopToken(self.cpu, looptoken.number)
-print(clt)
+#print(clt)
 looptoken.compiled_loop_token = clt
 clt._debug_nbargs = len(inputargs)
 
@@ -90,6 +93,8 @@
 self.make_context()
 self.t_Signed = self.ctxt.get_int_type(r_int(self.sizeof_signed),
r_int(1))
+self.t_UINT = self.ctxt.get_int_type(r_int(self.sizeof_signed),
+ r_int(0))
 self.t_float = self.ctxt.get_type(self.lib.GCC_JIT_TYPE_DOUBLE) # 
FIXME  
 self.t_bool = self.ctxt.get_type(self.lib.GCC_JIT_TYPE_BOOL)
 self.t_void_ptr = self.ctxt.get_type(self.lib.GCC_JIT_TYPE_VOID_PTR)
@@ -101,9 +106,9 @@
 self.u_float])
 self.lvalue_for_box = {}
 
-print(jitframe.JITFRAME)
-print(dir(jitframe.JITFRAME))
-print('jitframe.JITFRAME._flds: %r' % jitframe.JITFRAME._flds)
+#print(jitframe.JITFRAME)
+#print(dir(jitframe.JITFRAME))
+#print('jitframe.JITFRAME._flds: %r' % jitframe.JITFRAME._flds)
 
 # For now, build a "struct JITFRAME".
 # This will have the fields of jitframe,
@@ -169,7 +174,7 @@
 struct_jit_frame.set_fields (fields)
 
 # Make function:
-print('  inputargs: %r' % (inputargs, ))
+#print('  inputargs: %r' % (inputargs, ))
 #jitframe.JITFRAMEINFOPTR
 params = []
 
@@ -179,10 +184,10 @@
 self.param_addr = self.ctxt.new_param(self.t_void_ptr, "addr")
 params.append(self.param_addr)
 
-print("loopname: %r" % loopname)
 if not loopname:
 loopname = 'anonloop_%i' % self.num_anon_loops
 self.num_anon_loops += 1
+print("  loopname: %r" % loopname)
 self.fn = self.ctxt.new_function(self.lib.GCC_JIT_FUNCTION_EXPORTED,
  t_jit_frame_ptr,
  loopname,
@@ -196,10 +201,10 @@
 # Add an initial comment summarizing the loop
 text = '\n\tinputargs: %s\n\n' % inputargs
 for op in operations:
-print(op)
-print(type(op))
-print(dir(op))
-print(repr(op.getopname()))
+#print(op)
+#print(type(op))
+#print(dir(op))
+#print(repr(op.getopname()))
 text += '\t%s\n' % op
 self.b_current.add_comment(str(text))
 
@@ -223,10 +228,10 @@
 src_rvalue)
 
 for op in operations:
-print(op)
-print(type(op))
-print(dir(op))
-print(repr(op.getopname()))
+#print(op)
+#print(type(op))
+#print(dir(op))
+#print(repr(op.getopname()))
 # Add a comment describing this ResOperation
 self.b_curren

[pypy-commit] pypy py3.3: Add type.__qualname__

2014-12-18 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.3
Changeset: r75023:9db6340d5ce9
Date: 2014-12-18 22:35 +0100
http://bitbucket.org/pypy/pypy/changeset/9db6340d5ce9/

Log:Add type.__qualname__

diff --git a/pypy/interpreter/astcompiler/assemble.py 
b/pypy/interpreter/astcompiler/assemble.py
--- a/pypy/interpreter/astcompiler/assemble.py
+++ b/pypy/interpreter/astcompiler/assemble.py
@@ -157,7 +157,6 @@
 def __init__(self, space, name, first_lineno, scope, compile_info):
 self.space = space
 self.name = name
-self.qualname = name
 self.first_lineno = first_lineno
 self.compile_info = compile_info
 self.first_block = self.new_block()
diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -177,7 +177,8 @@
 across the AST tree generating bytecode as needed.
 """
 
-def __init__(self, space, name, tree, lineno, symbols, compile_info):
+def __init__(self, space, name, tree, lineno, symbols, compile_info,
+ qualname):
 self.scope = symbols.find_scope(tree)
 assemble.PythonCodeMaker.__init__(self, space, name, lineno,
   self.scope, compile_info)
@@ -185,6 +186,7 @@
 self.frame_blocks = []
 self.interactive = False
 self.temporary_name_counter = 1
+self.qualname = qualname
 self._compile(tree)
 
 def _compile(self, tree):
@@ -203,10 +205,13 @@
 
 def sub_scope(self, kind, name, node, lineno):
 """Convenience function for compiling a sub scope."""
+if self.qualname:
+qualname = '%s.%s' % (self.qualname, name)
+else:
+qualname = name
 generator = kind(self.space, name, node, lineno, self.symbols,
- self.compile_info)
-generator.qualname = '%s.%s' % (self.qualname, name)
-return generator.assemble(), generator.qualname
+ self.compile_info, qualname)
+return generator.assemble(), qualname
 
 def push_frame_block(self, kind, block):
 self.frame_blocks.append((kind, block))
@@ -285,9 +290,7 @@
 
 def _make_function(self, code, num_defaults=0, qualname=None):
 """Emit the opcodes to turn a code object into a function."""
-code_index = self.add_const(code)
 w_qualname = self.space.wrap(qualname or code.co_name)
-qualname_index = self.add_const(w_qualname)
 if code.co_freevars:
 # Load cell and free vars to pass on.
 for free in code.co_freevars:
@@ -298,12 +301,12 @@
 index = self.free_vars[free]
 self.emit_op_arg(ops.LOAD_CLOSURE, index)
 self.emit_op_arg(ops.BUILD_TUPLE, len(code.co_freevars))
-self.emit_op_arg(ops.LOAD_CONST, code_index)
-self.emit_op_arg(ops.LOAD_CONST, qualname_index)
+self.load_const(code)
+self.load_const(w_qualname)
 self.emit_op_arg(ops.MAKE_CLOSURE, num_defaults)
 else:
-self.emit_op_arg(ops.LOAD_CONST, code_index)
-self.emit_op_arg(ops.LOAD_CONST, qualname_index)
+self.load_const(code)
+self.load_const(w_qualname)
 self.emit_op_arg(ops.MAKE_FUNCTION, num_defaults)
 
 def _visit_kwonlydefaults(self, args):
@@ -1242,7 +1245,7 @@
 
 def __init__(self, space, tree, symbols, compile_info):
 PythonCodeGenerator.__init__(self, space, "", tree, -1,
- symbols, compile_info)
+ symbols, compile_info, qualname=None)
 
 def _compile(self, tree):
 tree.walkabout(self)
@@ -1361,6 +1364,10 @@
 self.name_op("__name__", ast.Load)
 # ... and store it as __module__
 self.name_op("__module__", ast.Store)
+# store the qualname
+w_qualname = self.space.wrap(self.qualname)
+self.load_const(w_qualname)
+self.name_op("__qualname__", ast.Store)
 # compile the body proper
 self._handle_body(cls.body)
 # return the (empty) __class__ cell
diff --git a/pypy/interpreter/test/test_class.py 
b/pypy/interpreter/test/test_class.py
--- a/pypy/interpreter/test/test_class.py
+++ b/pypy/interpreter/test/test_class.py
@@ -109,3 +109,10 @@
 c = C()
 assert c.one == "two"
 raises(AttributeError, getattr, c, "two")
+
+def test_qualname(self):
+class C:
+class D:
+pass
+assert C.__qualname__ == 'test_qualname.C'
+assert C.D.__qualname__ == 'test_qualname.C.D'
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Add "" in the qualname when the object comes from an executed function block.

2014-12-18 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.3
Changeset: r75024:daf8e9141435
Date: 2014-12-18 22:35 +0100
http://bitbucket.org/pypy/pypy/changeset/daf8e9141435/

Log:Add "" in the qualname when the object comes from an
executed function block.

diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -186,7 +186,10 @@
 self.frame_blocks = []
 self.interactive = False
 self.temporary_name_counter = 1
-self.qualname = qualname
+if isinstance(self.scope, symtable.FunctionScope):
+self.qualname = qualname + '.'
+else:
+self.qualname = qualname
 self._compile(tree)
 
 def _compile(self, tree):
diff --git a/pypy/interpreter/test/test_class.py 
b/pypy/interpreter/test/test_class.py
--- a/pypy/interpreter/test/test_class.py
+++ b/pypy/interpreter/test/test_class.py
@@ -114,5 +114,5 @@
 class C:
 class D:
 pass
-assert C.__qualname__ == 'test_qualname.C'
-assert C.D.__qualname__ == 'test_qualname.C.D'
+assert C.__qualname__ == 'test_qualname..C'
+assert C.D.__qualname__ == 'test_qualname..C.D'
diff --git a/pypy/interpreter/test/test_function.py 
b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -22,8 +22,12 @@
 assert f.__module__ == 'mymodulename'
 
 def test_qualname(self):
-def f(): pass
-assert f.__qualname__ == 'test_qualname.f'
+def f():
+def g():
+pass
+return g
+assert f.__qualname__ == 'test_qualname..f'
+assert f().__qualname__ == 'test_qualname..f..g'
 f.__qualname__ = 'qualname'
 assert f.__qualname__ == 'qualname'
 raises(TypeError, "f.__qualname__ = b'name'")
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Add rfloat.log2(), which tries to be exact for powers of two.

2014-12-18 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.3
Changeset: r75026:d3c7a156cc70
Date: 2014-12-18 22:35 +0100
http://bitbucket.org/pypy/pypy/changeset/d3c7a156cc70/

Log:Add rfloat.log2(), which tries to be exact for powers of two. Use it
in math.log2.

diff --git a/pypy/module/math/interp_math.py b/pypy/module/math/interp_math.py
--- a/pypy/module/math/interp_math.py
+++ b/pypy/module/math/interp_math.py
@@ -202,6 +202,8 @@
 x = _get_double(space, w_x)
 if base == 10.0:
 result = math.log10(x)
+elif base == 2.0:
+result = rfloat.log2(x)
 else:
 result = math.log(x)
 if base != 0.0:
diff --git a/rpython/rlib/rfloat.py b/rpython/rlib/rfloat.py
--- a/rpython/rlib/rfloat.py
+++ b/rpython/rlib/rfloat.py
@@ -281,6 +281,35 @@
 return (u - 1.) * x / math.log(u)
 return math.exp(x) - 1.
 
+def log2(x):
+# Uses an algorithm that should:
+#   (a) produce exact results for powers of 2, and
+#   (b) be monotonic, assuming that the system log is monotonic.
+if not isfinite(x):
+if isnan(x):
+return x  # log2(nan) = nan
+elif x > 0.0:
+return x  # log2(+inf) = +inf
+else:
+# log2(-inf) = nan, invalid-operation
+raise ValueError("math domain error")
+
+if x > 0.0:
+if 0:  # HAVE_LOG2
+return math.log2(x)
+m, e = math.frexp(x)
+# We want log2(m * 2**e) == log(m) / log(2) + e.  Care is needed when
+# x is just greater than 1.0: in that case e is 1, log(m) is negative,
+# and we get significant cancellation error from the addition of
+# log(m) / log(2) to e.  The slight rewrite of the expression below
+# avoids this problem.
+if x >= 1.0:
+return math.log(2.0 * m) / math.log(2.0) + (e - 1)
+else:
+return math.log(m) / math.log(2.0) + e
+else:
+raise ValueError("math domain error")
+
 def round_away(x):
 # round() from libm, which is not available on all platforms!
 absx = abs(x)
diff --git a/rpython/rlib/test/test_rfloat.py b/rpython/rlib/test/test_rfloat.py
--- a/rpython/rlib/test/test_rfloat.py
+++ b/rpython/rlib/test/test_rfloat.py
@@ -265,3 +265,12 @@
 if s.strip(): # empty s raises OperationError directly
 py.test.raises(ParseStringError, string_to_float, s)
 py.test.raises(ParseStringError, string_to_float, "")
+
+def test_log2():
+from rpython.rlib import rfloat
+assert rfloat.log2(1.0) == 0.0
+assert rfloat.log2(2.0) == 1.0
+assert rfloat.log2(2.0**1023) == 1023.0
+assert 1.584 < rfloat.log2(3.0) < 1.585
+py.test.raises(ValueError, rfloat.log2, 0)
+py.test.raises(ValueError, rfloat.log2, -1)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: unicode_internal codec accept both bytes and unicode for both functions

2014-12-18 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.3
Changeset: r75025:0b478e4a57e3
Date: 2014-12-18 22:35 +0100
http://bitbucket.org/pypy/pypy/changeset/0b478e4a57e3/

Log:unicode_internal codec accept both bytes and unicode for both
functions

diff --git a/pypy/module/_codecs/interp_codecs.py 
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -512,7 +512,7 @@
 wrap_decoder.func_name = rname
 globals()[name] = wrap_decoder
 
-for encoders in [
+for encoder in [
  "ascii_encode",
  "latin_1_encode",
  "utf_7_encode",
@@ -524,11 +524,10 @@
  "utf_32_le_encode",
  "unicode_escape_encode",
  "raw_unicode_escape_encode",
- "unicode_internal_encode",
 ]:
-make_encoder_wrapper(encoders)
+make_encoder_wrapper(encoder)
 
-for decoders in [
+for decoder in [
  "ascii_decode",
  "latin_1_decode",
  "utf_7_decode",
@@ -539,7 +538,7 @@
  "utf_32_be_decode",
  "utf_32_le_decode",
  ]:
-make_decoder_wrapper(decoders)
+make_decoder_wrapper(decoder)
 
 if hasattr(runicode, 'str_decode_mbcs'):
 # mbcs functions are not regular, because we have to pass
@@ -810,6 +809,8 @@
 
 @unwrap_spec(errors='str_or_None')
 def unicode_internal_decode(space, w_string, errors="strict"):
+space.warn(space.wrap("unicode_internal codec has been deprecated"),
+   space.w_DeprecationWarning)
 if errors is None:
 errors = 'strict'
 # special case for this codec: unicodes are returned as is
@@ -828,6 +829,23 @@
 final, state.decode_error_handler)
 return space.newtuple([space.wrap(result), space.wrap(consumed)])
 
+@unwrap_spec(errors='str_or_None')
+def unicode_internal_encode(space, w_uni, errors="strict"):
+space.warn(space.wrap("unicode_internal codec has been deprecated"),
+   space.w_DeprecationWarning)
+if errors is None:
+errors = 'strict'
+if space.isinstance_w(w_uni, space.w_unicode):
+uni = space.unicode_w(w_uni)
+state = space.fromcache(CodecState)
+result = runicode.unicode_encode_unicode_internal(
+uni, len(uni), errors, state.encode_error_handler)
+return space.newtuple([space.wrapbytes(result), space.wrap(len(uni))])
+else:
+# special case for this codec: bytes are returned as is
+string = space.readbuf_w(w_uni).as_str()
+return space.newtuple([space.wrapbytes(string), 
space.wrap(len(string))])
+
 # 
 # support for the "string escape" translation
 # This is a bytes-to bytes transformation
diff --git a/pypy/module/_codecs/test/test_codecs.py 
b/pypy/module/_codecs/test/test_codecs.py
--- a/pypy/module/_codecs/test/test_codecs.py
+++ b/pypy/module/_codecs/test/test_codecs.py
@@ -295,6 +295,12 @@
 assert _codecs.unicode_internal_decode(array.array('b', bytes))[0] == 
u"a"
 assert _codecs.unicode_internal_decode(memoryview(bytes))[0] == u"a"
 
+# This codec accepts bytes and unicode on both sides
+_codecs.unicode_internal_decode(u'\0\0\0\0')
+_codecs.unicode_internal_decode(b'\0\0\0\0')
+_codecs.unicode_internal_encode(u'\0\0\0\0')
+_codecs.unicode_internal_encode(b'\0\0\0\0')
+
 def test_raw_unicode_escape(self):
 import _codecs
 assert str(b"\u0663", "raw-unicode-escape") == "\u0663"
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy py3.3: Really implement __qualname__ for nested blocks.

2014-12-18 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.3
Changeset: r75022:9ebba4eb7768
Date: 2014-12-18 22:36 +0100
http://bitbucket.org/pypy/pypy/changeset/9ebba4eb7768/

Log:Really implement __qualname__ for nested blocks.

diff --git a/lib-python/3/importlib/_bootstrap.py 
b/lib-python/3/importlib/_bootstrap.py
--- a/lib-python/3/importlib/_bootstrap.py
+++ b/lib-python/3/importlib/_bootstrap.py
@@ -405,8 +405,10 @@
 due to the addition of new opcodes).
 
 """
-_RAW_MAGIC_NUMBER = 3230 | ord('\r') << 16 | ord('\n') << 24
-_MAGIC_BYTES = bytes(_RAW_MAGIC_NUMBER >> n & 0xff for n in range(0, 25, 8))
+
+# PyPy change
+import _imp
+_MAGIC_BYTES = _imp.get_magic()
 
 _PYCACHE = '__pycache__'
 
diff --git a/pypy/interpreter/astcompiler/assemble.py 
b/pypy/interpreter/astcompiler/assemble.py
--- a/pypy/interpreter/astcompiler/assemble.py
+++ b/pypy/interpreter/astcompiler/assemble.py
@@ -157,6 +157,7 @@
 def __init__(self, space, name, first_lineno, scope, compile_info):
 self.space = space
 self.name = name
+self.qualname = name
 self.first_lineno = first_lineno
 self.compile_info = compile_info
 self.first_block = self.new_block()
diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -205,7 +205,8 @@
 """Convenience function for compiling a sub scope."""
 generator = kind(self.space, name, node, lineno, self.symbols,
  self.compile_info)
-return generator.assemble()
+generator.qualname = '%s.%s' % (self.qualname, name)
+return generator.assemble(), generator.qualname
 
 def push_frame_block(self, kind, block):
 self.frame_blocks.append((kind, block))
@@ -282,9 +283,11 @@
 self.add_none_to_final_return = False
 mod.body.walkabout(self)
 
-def _make_function(self, code, num_defaults=0):
+def _make_function(self, code, num_defaults=0, qualname=None):
 """Emit the opcodes to turn a code object into a function."""
 code_index = self.add_const(code)
+w_qualname = self.space.wrap(qualname or code.co_name)
+qualname_index = self.add_const(w_qualname)
 if code.co_freevars:
 # Load cell and free vars to pass on.
 for free in code.co_freevars:
@@ -296,9 +299,11 @@
 self.emit_op_arg(ops.LOAD_CLOSURE, index)
 self.emit_op_arg(ops.BUILD_TUPLE, len(code.co_freevars))
 self.emit_op_arg(ops.LOAD_CONST, code_index)
+self.emit_op_arg(ops.LOAD_CONST, qualname_index)
 self.emit_op_arg(ops.MAKE_CLOSURE, num_defaults)
 else:
 self.emit_op_arg(ops.LOAD_CONST, code_index)
+self.emit_op_arg(ops.LOAD_CONST, qualname_index)
 self.emit_op_arg(ops.MAKE_FUNCTION, num_defaults)
 
 def _visit_kwonlydefaults(self, args):
@@ -359,9 +364,9 @@
 oparg = num_defaults
 oparg |= kw_default_count << 8
 oparg |= num_annotations << 16
-code = self.sub_scope(FunctionCodeGenerator, func.name, func,
-  func.lineno)
-self._make_function(code, oparg)
+code, qualname = self.sub_scope(FunctionCodeGenerator, func.name, func,
+func.lineno)
+self._make_function(code, oparg, qualname=qualname)
 # Apply decorators.
 if func.decorator_list:
 for i in range(len(func.decorator_list)):
@@ -377,20 +382,22 @@
 kw_default_count = self._visit_kwonlydefaults(args)
 self.visit_sequence(args.defaults)
 default_count = len(args.defaults) if args.defaults is not None else 0
-code = self.sub_scope(LambdaCodeGenerator, "", lam, lam.lineno)
+code, qualname = self.sub_scope(
+LambdaCodeGenerator, "", lam, lam.lineno)
 oparg = default_count
 oparg |= kw_default_count << 8
-self._make_function(code, oparg)
+self._make_function(code, oparg, qualname=qualname)
 
 def visit_ClassDef(self, cls):
 self.update_position(cls.lineno, True)
 self.visit_sequence(cls.decorator_list)
 # 1. compile the class body into a code object
-code = self.sub_scope(ClassCodeGenerator, cls.name, cls, cls.lineno)
+code, qualname = self.sub_scope(
+ClassCodeGenerator, cls.name, cls, cls.lineno)
 # 2. load the 'build_class' function
 self.emit_op(ops.LOAD_BUILD_CLASS)
 # 3. load a function (or closure) made from the code object
-self._make_function(code, 0)
+self._make_function(code, qualname=qualname)
 # 4. load class name
 self.load_const(self.space.wrap(cls.name.decode('utf-8')))
 # 5. generate the rest of the code for the call
@@ -1140,9 +1147,9 @@
 self.use_next_block(anchor)
 
 def _compile_

[pypy-commit] pypy py3.3: Add Function.__qualname__, basic form.

2014-12-18 Thread amauryfa
Author: Amaury Forgeot d'Arc 
Branch: py3.3
Changeset: r75021:a81d1ddf3dfe
Date: 2014-12-18 22:36 +0100
http://bitbucket.org/pypy/pypy/changeset/a81d1ddf3dfe/

Log:Add Function.__qualname__, basic form.

diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -39,6 +39,7 @@
  closure=None, w_ann=None, forcename=None):
 self.space = space
 self.name = forcename or code.co_name
+self.qualname = self.name.decode('utf-8')  # So far
 self.w_doc = None   # lazily read from code.getdocstring()
 self.code = code   # Code instance
 self.w_func_globals = w_globals  # the globals dictionary
@@ -400,7 +401,20 @@
 except OperationError, e:
 if e.match(space, space.w_TypeError):
 raise OperationError(space.w_TypeError,
- space.wrap("func_name must be set "
+ space.wrap("__name__ must be set "
+"to a string object"))
+raise
+
+def fget_func_qualname(self, space):
+return space.wrap(self.qualname)
+
+def fset_func_qualname(self, space, w_name):
+try:
+self.qualname = space.unicode_w(w_name)
+except OperationError, e:
+if e.match(space, space.w_TypeError):
+raise OperationError(space.w_TypeError,
+ space.wrap("__qualname__ must be set "
 "to a string object"))
 raise
 
diff --git a/pypy/interpreter/test/test_function.py 
b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -21,6 +21,13 @@
 assert f.__name__ == 'f'
 assert f.__module__ == 'mymodulename'
 
+def test_qualname(self):
+def f(): pass
+assert f.__qualname__ == 'f'
+f.__qualname__ = 'qualname'
+assert f.__qualname__ == 'qualname'
+raises(TypeError, "f.__qualname__ = b'name'")
+
 def test_annotations(self):
 def f(): pass
 ann = f.__annotations__
diff --git a/pypy/interpreter/typedef.py b/pypy/interpreter/typedef.py
--- a/pypy/interpreter/typedef.py
+++ b/pypy/interpreter/typedef.py
@@ -814,6 +814,8 @@
   Function.fset_func_code)
 getset_func_name = GetSetProperty(Function.fget_func_name,
   Function.fset_func_name)
+getset_func_qualname = GetSetProperty(Function.fget_func_qualname,
+  Function.fset_func_qualname)
 getset_func_annotations = GetSetProperty(Function.fget_func_annotations,
 Function.fset_func_annotations,
 Function.fdel_func_annotations)
@@ -831,6 +833,7 @@
 __code__ = getset_func_code,
 __doc__ = getset_func_doc,
 __name__ = getset_func_name,
+__qualname__ = getset_func_qualname,
 __dict__ = getset_func_dict,
 __defaults__ = getset_func_defaults,
 __kwdefaults__ = getset_func_kwdefaults,
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] creflect default: more tests

2014-12-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r202:80584114b8eb
Date: 2014-12-18 17:38 +
http://bitbucket.org/cffi/creflect/changeset/80584114b8eb/

Log:more tests

diff --git a/zeffir/test/test_funcptr.py b/zeffir/test/test_funcptr.py
--- a/zeffir/test/test_funcptr.py
+++ b/zeffir/test/test_funcptr.py
@@ -15,6 +15,8 @@
 def test_get_fnptr():
 ffi, lib = support.compile_and_open('funcptr')
 fn = lib.get_fnptr(42)
+assert fn == lib.get_fnptr(42)
+assert fn != lib.get_fnptr(1)
 assert fn(100) == 142
 assert ffi.typeof(fn) == ffi.typeof("int(*)(int)")
 #
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] creflect default: Stop trying to be clever and reject overloaded functions. Change

2014-12-18 Thread arigo
Author: Armin Rigo 
Branch: 
Changeset: r201:83606604d6cd
Date: 2014-12-18 17:34 +
http://bitbucket.org/cffi/creflect/changeset/83606604d6cd/

Log:Stop trying to be clever and reject overloaded functions. Change
the tests to use one possible workaround instead.

diff --git a/creflect/codegen.py b/creflect/codegen.py
--- a/creflect/codegen.py
+++ b/creflect/codegen.py
@@ -65,7 +65,6 @@
 outerblock = CodeBlock(parent=None)
 outerblock.writeline('#include "creflect.h"')
 outerblock.crx_func_name = crx_func_name
-outerblock.func_names_seen = set()
 
 funcblock = CodeBlock(outerblock)
 
diff --git a/creflect/model.py b/creflect/model.py
--- a/creflect/model.py
+++ b/creflect/model.py
@@ -348,7 +348,7 @@
 def shadow_global_var(self, top_level_block, fnname):
 if self.ellipsis:
 return fnname
-shadowname = _unique_name(top_level_block, '%s__d%s_%s', fnname)
+shadowname = _unique_name(top_level_block, '%s__d_%s', fnname)
 wrline = top_level_block.writeline
 args = [arg.get_c_name('a%d' % i) for i, arg in enumerate(self.args)]
 decl = '%s(%s)' % (shadowname, ', '.join(args) or 'void')
@@ -365,7 +365,7 @@
 # a special-case for global function declarations
 assert not self.ellipsis
 toplevel = block.crx_top_level
-crx_func_name = _unique_name(toplevel, '%s__c%s_%s', fnname)
+crx_func_name = _unique_name(toplevel, '%s__c_%s', fnname)
 wrline = toplevel.writeline
 wrline('static void %s(void *args[], void *result) {' % (
 crx_func_name,))
@@ -379,13 +379,7 @@
 
 
 def _unique_name(toplevel, pattern, fnname):
-result = pattern % (toplevel.crx_func_name, '', fnname)
-n = 0
-while result in toplevel.func_names_seen:
-n += 1
-result = pattern % (toplevel.crx_func_name, n, fnname)
-toplevel.func_names_seen.add(result)
-return result
+return pattern % (toplevel.crx_func_name, fnname)
 
 
 class PointerType(BaseType):
diff --git a/creflect/test/codegen/func-006.c b/creflect/test/codegen/func-006.c
--- a/creflect/test/codegen/func-006.c
+++ b/creflect/test/codegen/func-006.c
@@ -1,30 +1,32 @@
-/* Multiple declarations of a function with the same name:
-   a way to work around "..." in signatures */
+/* A manual way to work around "..." in signatures */
 
-int f(int);
-int f(int, long);
+int f_1(int);
+int f_2(int, long);
 
 # 
 # drop
 
+#define f_1  f
+#define f_2  f
+
 int f(int a, ...) { return 42 * a; }
 
 # 
 
-static void testfunc_006__c_f(void *args[], void *result) {
-*(int *)result = f(*(int *)args[0]);
+static void testfunc_006__c_f_1(void *args[], void *result) {
+*(int *)result = f_1(*(int *)args[0]);
 }
 
-static int testfunc_006__d_f(int a0) {
-return f(a0);
+static int testfunc_006__d_f_1(int a0) {
+return f_1(a0);
 }
 
-static void testfunc_006__c1_f(void *args[], void *result) {
-*(int *)result = f(*(int *)args[0], *(long *)args[1]);
+static void testfunc_006__c_f_2(void *args[], void *result) {
+*(int *)result = f_2(*(int *)args[0], *(long *)args[1]);
 }
 
-static int testfunc_006__d1_f(int a0, long a1) {
-return f(a0, a1);
+static int testfunc_006__d_f_2(int a0, long a1) {
+return f_2(a0, a1);
 }
 
 void testfunc_006(_crx_builder_t *cb)
@@ -36,8 +38,8 @@
 t1 = cb->get_signed_type(cb, sizeof(int), "int");
 a1[0].type = t1;
 a1[0].qualifiers = 0;
-cb->define_func(cb, "f", t1, a1, 1, &testfunc_006__c_f, 
&testfunc_006__d_f);
-#expect FUNC f: int -> int
+cb->define_func(cb, "f_1", t1, a1, 1, &testfunc_006__c_f_1, 
&testfunc_006__d_f_1);
+#expect FUNC f_1: int -> int
 }
 {
 t2 = cb->get_signed_type(cb, sizeof(long), "long");
@@ -45,7 +47,7 @@
 a2[0].qualifiers = 0;
 a2[1].type = t2;
 a2[1].qualifiers = 0;
-cb->define_func(cb, "f", t1, a2, 2, &testfunc_006__c1_f, 
&testfunc_006__d1_f);
-#expect FUNC f: int -> long -> int
+cb->define_func(cb, "f_2", t1, a2, 2, &testfunc_006__c_f_2, 
&testfunc_006__d_f_2);
+#expect FUNC f_2: int -> long -> int
 }
 }
diff --git a/zeffir/builder.c b/zeffir/builder.c
--- a/zeffir/builder.c
+++ b/zeffir/builder.c
@@ -828,10 +828,10 @@
 
 PyObject *l_dict = ((zeffir_builder_t *)cb)->l_dict;
 PyObject *l_libname_obj = ((zeffir_builder_t *)cb)->lib->l_libname_obj;
-PyObject *x = PyDict_GetItemString(l_dict, name);
+PyObject *x;
 
 assert(trampl != NULL);
-x = make_builtin_func(l_libname_obj, name, ret, args, nargs, trampl, x);
+x = make_builtin_func(l_libname_obj, name, ret, args, nargs, trampl);
 if (x == NULL)
 return;
 
diff --git a/zeffir/cfunc.c b/zeffir/cfunc.c
--- a/zeffir/cfunc.c
+++ b/zeffir/cfunc.c
@@ -1,5 +1,5 @@
 
-typedef struct ZefFuncSupportObject_s {
+typedef struct {
 PyObject_H

[pypy-commit] pypy stdlib-2.7.9: skip some added tests when run against older cpython

2014-12-18 Thread bdkearns
Author: Brian Kearns 
Branch: stdlib-2.7.9
Changeset: r75028:b85da8ff6c09
Date: 2014-12-18 18:29 -0500
http://bitbucket.org/pypy/pypy/changeset/b85da8ff6c09/

Log:skip some added tests when run against older cpython

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
@@ -5,6 +5,7 @@
 from pypy.interpreter.error import OperationError
 from pypy.interpreter.argument import Arguments
 
+
 class BaseTestCompiler:
 def setup_method(self, method):
 self.compiler = self.space.createcompiler()
@@ -709,13 +710,13 @@
 else:
 py.test.fail("Did not raise")
 
+
 class TestECCompiler(BaseTestCompiler):
 def setup_method(self, method):
 self.compiler = self.space.getexecutioncontext().compiler
 
 
 class AppTestCompiler:
-
 def test_bom_with_future(self):
 s = '\xef\xbb\xbffrom __future__ import division\nx = 1/2'
 ns = {}
@@ -766,8 +767,8 @@
 ##def test_try_except_finally(self):
 ##py.test.skip("unsupported")
 
+
 class AppTestOptimizer:
-
 def setup_class(cls):
 cls.w_runappdirect = cls.space.wrap(cls.runappdirect)
 
@@ -920,14 +921,14 @@
 sys.stdout = save_stdout
 output = s.getvalue()
 assert "STOP_CODE" not in output
-
+
 def test_optimize_list_comp(self):
 source = """def _f(a):
 return [x for x in a if None]
 """
 exec source
 code = _f.func_code
-
+
 import StringIO, sys, dis
 s = StringIO.StringIO()
 out = sys.stdout
@@ -959,7 +960,7 @@
 """
 exec source
 code = _f.func_code
-
+
 import StringIO, sys, dis
 s = StringIO.StringIO()
 out = sys.stdout
@@ -1039,5 +1040,8 @@
 assert eval(code) == u'\xa4'
 code = '# -*- 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'
diff --git a/pypy/interpreter/test/test_exec.py 
b/pypy/interpreter/test/test_exec.py
--- a/pypy/interpreter/test/test_exec.py
+++ b/pypy/interpreter/test/test_exec.py
@@ -246,6 +246,9 @@
 assert ord(x[0]) == 0x0439
 
 def test_nested_qualified_exec(self):
+import sys
+if sys.version_info < (2, 7, 9):
+skip()
 code = ["""
 def g():
 def f():
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
@@ -194,6 +194,8 @@
 def test_group_takes_long(self):
 import re
 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 str(exc.value) == "no such group"
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-2.7.9: update version to 2.7.9

2014-12-18 Thread bdkearns
Author: Brian Kearns 
Branch: stdlib-2.7.9
Changeset: r75027:2d54007751f0
Date: 2014-12-18 18:23 -0500
http://bitbucket.org/pypy/pypy/changeset/2d54007751f0/

Log:update version to 2.7.9

diff --git a/pypy/module/cpyext/include/patchlevel.h 
b/pypy/module/cpyext/include/patchlevel.h
--- a/pypy/module/cpyext/include/patchlevel.h
+++ b/pypy/module/cpyext/include/patchlevel.h
@@ -21,12 +21,12 @@
 /* Version parsed out into numeric values */
 #define PY_MAJOR_VERSION   2
 #define PY_MINOR_VERSION   7
-#define PY_MICRO_VERSION   8
+#define PY_MICRO_VERSION   9
 #define PY_RELEASE_LEVEL   PY_RELEASE_LEVEL_FINAL
 #define PY_RELEASE_SERIAL  0
 
 /* Version as a string */
-#define PY_VERSION "2.7.8"
+#define PY_VERSION "2.7.9"
 
 /* PyPy version as a string */
 #define PYPY_VERSION "2.5.0-alpha0"
diff --git a/pypy/module/sys/version.py b/pypy/module/sys/version.py
--- a/pypy/module/sys/version.py
+++ b/pypy/module/sys/version.py
@@ -6,7 +6,7 @@
 from pypy.interpreter import gateway
 
 #XXX # the release serial 42 is not in range(16)
-CPYTHON_VERSION= (2, 7, 8, "final", 42)
+CPYTHON_VERSION= (2, 7, 9, "final", 42)
 #XXX # sync CPYTHON_VERSION with patchlevel.h, package.py
 CPYTHON_API_VERSION= 1013   #XXX # sync with include/modsupport.h
 
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-2.7.9: update _ctypes_test.c from cpython

2014-12-18 Thread bdkearns
Author: Brian Kearns 
Branch: stdlib-2.7.9
Changeset: r75029:3f0415c7d6b1
Date: 2014-12-18 18:39 -0500
http://bitbucket.org/pypy/pypy/changeset/3f0415c7d6b1/

Log:update _ctypes_test.c from cpython

diff --git a/lib_pypy/_ctypes_test.c b/lib_pypy/_ctypes_test.c
--- a/lib_pypy/_ctypes_test.c
+++ b/lib_pypy/_ctypes_test.c
@@ -541,6 +541,49 @@
 return 1;
 }
 
+EXPORT(long left = 10);
+EXPORT(long top = 20);
+EXPORT(long right = 30);
+EXPORT(long bottom = 40);
+
+EXPORT(RECT) ReturnRect(int i, RECT ar, RECT* br, POINT cp, RECT dr,
+RECT *er, POINT fp, RECT gr)
+{
+/*Check input */
+if (ar.left + br->left + dr.left + er->left + gr.left != left * 5)
+{
+ar.left = 100;
+return ar;
+}
+if (ar.right + br->right + dr.right + er->right + gr.right != right * 5)
+{
+ar.right = 100;
+return ar;
+}
+if (cp.x != fp.x)
+{
+ar.left = -100;
+}
+if (cp.y != fp.y)
+{
+ar.left = -200;
+}
+switch(i)
+{
+case 0:
+return ar;
+break;
+case 1:
+return dr;
+break;
+case 2:
+return gr;
+break;
+
+}
+return ar;
+}
+
 typedef struct {
 short x;
 short y;
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-2.7.9: skip a test_unicode when no ctypes.pythonapi exists

2014-12-18 Thread bdkearns
Author: Brian Kearns 
Branch: stdlib-2.7.9
Changeset: r75030:773018d6ae59
Date: 2014-12-18 18:50 -0500
http://bitbucket.org/pypy/pypy/changeset/773018d6ae59/

Log:skip a test_unicode when no ctypes.pythonapi exists

diff --git a/lib-python/2.7/test/test_unicode.py 
b/lib-python/2.7/test/test_unicode.py
--- a/lib-python/2.7/test/test_unicode.py
+++ b/lib-python/2.7/test/test_unicode.py
@@ -1664,6 +1664,10 @@
 # Test PyUnicode_FromFormat()
 def test_from_format(self):
 test_support.import_module('ctypes')
+try:
+from ctypes import pythonapi
+except ImportError:
+self.skipTest( "no pythonapi in ctypes")
 from ctypes import (
 pythonapi, py_object, sizeof,
 c_int, c_long, c_longlong, c_ssize_t,
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-2.7.9: add a failing binascii.a2b_uu case

2014-12-18 Thread bdkearns
Author: Brian Kearns 
Branch: stdlib-2.7.9
Changeset: r75031:c297e68f8ff0
Date: 2014-12-18 19:19 -0500
http://bitbucket.org/pypy/pypy/changeset/c297e68f8ff0/

Log:add a failing binascii.a2b_uu case

diff --git a/pypy/module/binascii/test/test_binascii.py 
b/pypy/module/binascii/test/test_binascii.py
--- a/pypy/module/binascii/test/test_binascii.py
+++ b/pypy/module/binascii/test/test_binascii.py
@@ -11,6 +11,7 @@
 assert self.binascii.a2b_uu("") == "\x00" * 0x20
 #
 for input, expected in [
+("!,_", "3"),
 (" ", ""),
 ("!", "\x00"),
 ("!6", "X"),
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-2.7.9: fix test_readline version check

2014-12-18 Thread bdkearns
Author: Brian Kearns 
Branch: stdlib-2.7.9
Changeset: r75032:96a806f14899
Date: 2014-12-18 23:06 -0500
http://bitbucket.org/pypy/pypy/changeset/96a806f14899/

Log:fix test_readline version check

diff --git a/lib-python/2.7/test/test_readline.py 
b/lib-python/2.7/test/test_readline.py
--- a/lib-python/2.7/test/test_readline.py
+++ b/lib-python/2.7/test/test_readline.py
@@ -44,7 +44,8 @@
 
 class TestReadline(unittest.TestCase):
 
-@unittest.skipIf(readline._READLINE_VERSION < 0x0600
+@unittest.skipIf(hasattr(readline, '_READLINE_VERSION')
+ and readline._READLINE_VERSION < 0x0600
  and "libedit" not in readline.__doc__,
  "not supported in this library version")
 def test_init(self):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-2.7.9: fix test_xdrlib by correcting struct.pack exception types

2014-12-18 Thread bdkearns
Author: Brian Kearns 
Branch: stdlib-2.7.9
Changeset: r75033:8ed6988ac4dd
Date: 2014-12-18 23:27 -0500
http://bitbucket.org/pypy/pypy/changeset/8ed6988ac4dd/

Log:fix test_xdrlib by correcting struct.pack exception types

diff --git a/pypy/module/struct/formatiterator.py 
b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -84,7 +84,12 @@
 else:
 msg = "integer argument expected, got non-integer"
 space.warn(space.wrap(msg), space.w_DeprecationWarning)
-return space.int(w_obj)   # wrapped float -> wrapped int or long
+try:
+return space.int(w_obj)   # wrapped float -> wrapped int or long
+except OperationError as e:
+if e.match(space, space.w_TypeError):
+raise StructError("cannot convert argument to integer")
+raise
 
 def accept_bool_arg(self):
 w_obj = self.accept_obj_arg()
@@ -100,7 +105,12 @@
 
 def accept_float_arg(self):
 w_obj = self.accept_obj_arg()
-return self.space.float_w(w_obj)
+try:
+return self.space.float_w(w_obj)
+except OperationError as e:
+if e.match(self.space, self.space.w_TypeError):
+raise StructError("required argument is not a float")
+raise
 
 
 class UnpackFormatIterator(FormatIterator):
diff --git a/pypy/module/struct/test/test_struct.py 
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -328,6 +328,12 @@
 raises(error, unpack, "0p", "")   # segfaults on CPython 2.5.2!
 raises(error, pack, "b", 150)   # argument out of range
 # XXX the accepted ranges still differs between PyPy and CPython
+exc = raises(error, pack, ">d", 'abc')
+assert str(exc.value) == "required argument is not a float"
+exc = raises(error, pack, ">l", 'abc')
+assert str(exc.value) == "cannot convert argument to integer"
+exc = raises(error, pack, ">H", 'abc')
+assert str(exc.value) == "cannot convert argument to integer"
 
 def test_overflow_error(self):
 """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-2.7.9: further fix struct.pack conversions

2014-12-18 Thread bdkearns
Author: Brian Kearns 
Branch: stdlib-2.7.9
Changeset: r75035:09d67d2e9a36
Date: 2014-12-19 02:17 -0500
http://bitbucket.org/pypy/pypy/changeset/09d67d2e9a36/

Log:further fix struct.pack conversions

diff --git a/pypy/module/struct/formatiterator.py 
b/pypy/module/struct/formatiterator.py
--- a/pypy/module/struct/formatiterator.py
+++ b/pypy/module/struct/formatiterator.py
@@ -65,32 +65,25 @@
 w_index = w_obj
 else:
 w_index = None
-w_index_method = space.lookup(w_obj, "__index__")
-if w_index_method is not None:
+if space.lookup(w_obj, '__index__'):
 try:
 w_index = space.index(w_obj)
 except OperationError, e:
 if not e.match(space, space.w_TypeError):
 raise
 pass
+if w_index is None and space.lookup(w_obj, '__int__'):
+if space.isinstance_w(w_obj, space.w_float):
+msg = "integer argument expected, got float"
+else:
+msg = "integer argument expected, got non-integer" \
+  " (implicit conversion using __int__ is deprecated)"
+space.warn(space.wrap(msg), space.w_DeprecationWarning)
+w_index = space.int(w_obj)   # wrapped float -> wrapped int or 
long
 if w_index is None:
-w_index = self._maybe_float(w_obj)
+raise StructError("cannot convert argument to integer")
 return getattr(space, meth)(w_index)
 
-def _maybe_float(self, w_obj):
-space = self.space
-if space.isinstance_w(w_obj, space.w_float):
-msg = "struct: integer argument expected, got float"
-else:
-msg = "integer argument expected, got non-integer"
-space.warn(space.wrap(msg), space.w_DeprecationWarning)
-try:
-return space.int(w_obj)   # wrapped float -> wrapped int or long
-except OperationError as e:
-if e.match(space, space.w_TypeError):
-raise StructError("cannot convert argument to integer")
-raise
-
 def accept_bool_arg(self):
 w_obj = self.accept_obj_arg()
 return self.space.is_true(w_obj)
diff --git a/pypy/module/struct/test/test_struct.py 
b/pypy/module/struct/test/test_struct.py
--- a/pypy/module/struct/test/test_struct.py
+++ b/pypy/module/struct/test/test_struct.py
@@ -63,12 +63,22 @@
 def test_deprecation_warning(self):
 import warnings
 for code in 'b', 'B', 'h', 'H', 'i', 'I', 'l', 'L', 'q', 'Q':
-with warnings.catch_warnings(record=True) as w:
-warnings.simplefilter("always")
-raises(TypeError, self.struct.pack, code, 3j)
-assert len(w) == 1
-assert str(w[0].message) == "integer argument expected, got 
non-integer"
-assert w[0].category is DeprecationWarning
+for val in [3., 3j]:
+with warnings.catch_warnings(record=True) as w:
+warnings.simplefilter("always")
+if type(val) is float:
+self.struct.pack(code, val)
+else:
+raises(TypeError, self.struct.pack, code, val)
+assert len(w) == 1
+if type(val) is float:
+assert str(w[0].message) == (
+"integer argument expected, got float")
+else:
+assert str(w[0].message) == (
+"integer argument expected, got non-integer"
+" (implicit conversion using __int__ is deprecated)")
+assert w[0].category is DeprecationWarning
 
 def test_pack_standard_little(self):
 """
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy stdlib-2.7.9: provide complex.__int__ method

2014-12-18 Thread bdkearns
Author: Brian Kearns 
Branch: stdlib-2.7.9
Changeset: r75034:04003981e306
Date: 2014-12-19 02:15 -0500
http://bitbucket.org/pypy/pypy/changeset/04003981e306/

Log:provide complex.__int__ method

diff --git a/pypy/objspace/std/complexobject.py 
b/pypy/objspace/std/complexobject.py
--- a/pypy/objspace/std/complexobject.py
+++ b/pypy/objspace/std/complexobject.py
@@ -274,8 +274,7 @@
 return space.newlong_from_rbigint(val)
 
 def int(self, space):
-raise oefmt(space.w_TypeError,
-"can't convert complex to int; use int(abs(z))")
+raise oefmt(space.w_TypeError, "can't convert complex to int")
 
 def _to_complex(self, space, w_obj):
 if isinstance(w_obj, W_ComplexObject):
@@ -381,8 +380,7 @@
 return space.newbool((self.realval != 0.0) or (self.imagval != 0.0))
 
 def descr_float(self, space):
-raise oefmt(space.w_TypeError,
-"can't convert complex to float; use abs(z)")
+raise oefmt(space.w_TypeError, "can't convert complex to float")
 
 def descr_neg(self, space):
 return W_ComplexObject(-self.realval, -self.imagval)
@@ -603,6 +601,7 @@
 __coerce__ = interp2app(W_ComplexObject.descr_coerce),
 __format__ = interp2app(W_ComplexObject.descr_format),
 __nonzero__ = interp2app(W_ComplexObject.descr_nonzero),
+__int__ = interp2app(W_ComplexObject.int),
 __float__ = interp2app(W_ComplexObject.descr_float),
 __neg__ = interp2app(W_ComplexObject.descr_neg),
 __pos__ = interp2app(W_ComplexObject.descr_pos),
diff --git a/pypy/objspace/std/test/test_complexobject.py 
b/pypy/objspace/std/test/test_complexobject.py
--- a/pypy/objspace/std/test/test_complexobject.py
+++ b/pypy/objspace/std/test/test_complexobject.py
@@ -161,6 +161,12 @@
 def test_coerce(self):
 raises(OverflowError, complex.__coerce__, 1+1j, 1L<<1)
 
+def test_convert(self):
+exc = raises(TypeError, complex.__int__, 3j)
+assert str(exc.value) == "can't convert complex to int"
+exc = raises(TypeError, complex.__float__, 3j)
+assert str(exc.value) == "can't convert complex to float"
+
 def test_richcompare(self):
 assert complex.__lt__(1+1j, None) is NotImplemented
 assert complex.__eq__(1+1j, 2+2j) is False
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit