[pypy-commit] pypy memoryview-attributes: merge default

2016-08-24 Thread plan_rich
Author: Richard Plangger 
Branch: memoryview-attributes
Changeset: r86455:4ec423c97a35
Date: 2016-08-24 09:10 +0200
http://bitbucket.org/pypy/pypy/changeset/4ec423c97a35/

Log:merge default

diff --git a/lib_pypy/cffi/recompiler.py b/lib_pypy/cffi/recompiler.py
--- a/lib_pypy/cffi/recompiler.py
+++ b/lib_pypy/cffi/recompiler.py
@@ -515,7 +515,7 @@
 tovar, errcode)
 return
 #
-elif isinstance(tp, (model.StructOrUnion, model.EnumType)):
+elif isinstance(tp, model.StructOrUnionOrEnum):
 # a struct (not a struct pointer) as a function argument
 self._prnt('  if (_cffi_to_c((char *)&%s, _cffi_type(%d), %s) < 0)'
   % (tovar, self._gettypenum(tp), fromvar))
@@ -572,7 +572,7 @@
 elif isinstance(tp, model.ArrayType):
 return '_cffi_from_c_pointer((char *)%s, _cffi_type(%d))' % (
 var, self._gettypenum(model.PointerType(tp.item)))
-elif isinstance(tp, model.StructType):
+elif isinstance(tp, model.StructOrUnion):
 if tp.fldnames is None:
 raise TypeError("'%s' is used as %s, but is opaque" % (
 tp._get_c_name(), context))
diff --git a/lib_pypy/cffi/vengine_cpy.py b/lib_pypy/cffi/vengine_cpy.py
--- a/lib_pypy/cffi/vengine_cpy.py
+++ b/lib_pypy/cffi/vengine_cpy.py
@@ -308,7 +308,7 @@
 elif isinstance(tp, model.ArrayType):
 return '_cffi_from_c_pointer((char *)%s, _cffi_type(%d))' % (
 var, self._gettypenum(model.PointerType(tp.item)))
-elif isinstance(tp, model.StructType):
+elif isinstance(tp, model.StructOrUnion):
 if tp.fldnames is None:
 raise TypeError("'%s' is used as %s, but is opaque" % (
 tp._get_c_name(), context))
diff --git a/pypy/doc/whatsnew-head.rst b/pypy/doc/whatsnew-head.rst
--- a/pypy/doc/whatsnew-head.rst
+++ b/pypy/doc/whatsnew-head.rst
@@ -144,3 +144,9 @@
 ``type.__dict__`` now returns a ``dict_proxy`` object, like on CPython.
 Previously it returned what looked like a regular dict object (but it
 was already read-only).
+
+
+.. branch: const-fold-we-are-jitted
+
+Reduce the size of the generated C code by constant-folding ``we_are_jitted``
+in non-jitcode.
diff --git a/pypy/module/posix/interp_posix.py 
b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -590,6 +590,8 @@
 "decode", w_fs_encoding)
 except OperationError as e:
 # fall back to the original byte string
+if e.async(space):
+raise
 result_w[i] = w_bytes
 return space.newlist(result_w)
 else:
diff --git a/pypy/module/pypyjit/test_pypy_c/test_ffi.py 
b/pypy/module/pypyjit/test_pypy_c/test_ffi.py
--- a/pypy/module/pypyjit/test_pypy_c/test_ffi.py
+++ b/pypy/module/pypyjit/test_pypy_c/test_ffi.py
@@ -423,7 +423,7 @@
 guard_false(i114, descr=...)
 --TICK--
 i123 = arraylen_gc(p67, descr=)
-i119 = call_i(ConstClass(_ll_1_raw_malloc_varsize__Signed), 6, 
descr=)
+i119 = call_i(ConstClass(_ll_1_raw_malloc_varsize_zero__Signed), 6, 
descr=)
 check_memory_error(i119)
 raw_store(i119, 0, i160, descr=)
 raw_store(i119, 2, i160, descr=)
diff --git a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py 
b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
--- a/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
+++ b/pypy/module/test_lib_pypy/cffi_tests/cffi1/test_recompiler.py
@@ -1963,3 +1963,21 @@
ffi, "test_function_returns_opaque", "?")
 assert str(e.value) == ("function foo: 'struct a' is used as result type,"
 " but is opaque")
+
+def test_function_returns_union():
+ffi = FFI()
+ffi.cdef("union u1 { int a, b; }; union u1 f1(int);")
+lib = verify(ffi, "test_function_returns_union", """
+union u1 { int a, b; };
+static union u1 f1(int x) { union u1 u; u.b = x; return u; }
+""")
+assert lib.f1(51).a == 51
+
+def test_function_returns_partial_struct():
+ffi = FFI()
+ffi.cdef("struct a { int a; ...; }; struct a f1(int);")
+lib = verify(ffi, "test_function_returns_partial_struct", """
+struct a { int b, a, c; };
+static struct a f1(int x) { struct a s = {0}; s.a = x; return s; }
+""")
+assert lib.f1(52).a == 52
diff --git a/pypy/objspace/std/bytesobject.py b/pypy/objspace/std/bytesobject.py
--- a/pypy/objspace/std/bytesobject.py
+++ b/pypy/objspace/std/bytesobject.py
@@ -466,8 +466,6 @@
 def descr_getbuffer(self, space, w_flags):
 #from pypy.objspace.std.bufferobject import W_Buffer
 #return 

[pypy-commit] pypy memoryview-attributes: merge default into branch

2016-08-21 Thread mattip
Author: Matti Picus 
Branch: memoryview-attributes
Changeset: r86373:6cb76ef9492b
Date: 2016-08-21 21:08 +1000
http://bitbucket.org/pypy/pypy/changeset/6cb76ef9492b/

Log:merge default into branch

diff --git a/lib_pypy/resource.py b/lib_pypy/resource.py
--- a/lib_pypy/resource.py
+++ b/lib_pypy/resource.py
@@ -86,7 +86,11 @@
 if len(limits) != 2:
 raise ValueError("expected a tuple of 2 integers")
 
-if lib.my_setrlimit(resource, limits[0], limits[1]) == -1:
+# accept and round down floats, like CPython does
+limit0 = int(limits[0])
+limit1 = int(limits[1])
+
+if lib.my_setrlimit(resource, limit0, limit1) == -1:
 if ffi.errno == EINVAL:
 raise ValueError("current limit exceeds maximum limit")
 elif ffi.errno == EPERM:
diff --git a/pypy/doc/faq.rst b/pypy/doc/faq.rst
--- a/pypy/doc/faq.rst
+++ b/pypy/doc/faq.rst
@@ -356,6 +356,11 @@
 that a C-level traceback is usually of no help at all in PyPy.
 Debugging PyPy can be annoying.
 
+`This is a clear and useful bug report.`__  (Admittedly, sometimes
+the problem is really hard to reproduce, but please try to.)
+
+.. __: 
https://bitbucket.org/pypy/pypy/issues/2363/segfault-in-gc-pinned-object-in
+
 In more details:
 
 * First, please give the exact PyPy version, and the OS.
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
@@ -387,7 +387,8 @@
 def _stacksize(self, blocks):
 """Compute co_stacksize."""
 for block in blocks:
-block.initial_depth = 0
+block.initial_depth = -99
+blocks[0].initial_depth = 0
 # Assumes that it is sufficient to walk the blocks in 'post-order'.
 # This means we ignore all back-edges, but apart from that, we only
 # look into a block when all the previous blocks have been done.
@@ -406,8 +407,11 @@
 
 def _do_stack_depth_walk(self, block):
 depth = block.initial_depth
+if depth == -99: # this block is never reached, skip
+ return 0
 for instr in block.instructions:
 depth += _opcode_stack_effect(instr.opcode, instr.arg)
+assert depth >= 0
 if depth >= self._max_depth:
 self._max_depth = depth
 jump_op = instr.opcode
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1707,6 +1707,23 @@
 "Python int too large for C unsigned short")
 return value
 
+def c_uid_t_w(self, w_obj):
+# xxx assumes that uid_t and gid_t are a C unsigned int.
+# Equivalent to space.c_uint_w(), with the exception that
+# it also accepts -1 and converts that to UINT_MAX, which
+# is (uid_t)-1.  And values smaller than -1 raise
+# OverflowError, not ValueError.
+try:
+return self.c_uint_w(w_obj)
+except OperationError as e:
+if e.match(self, self.w_ValueError):
+# ValueError: cannot convert negative integer to unsigned
+if self.int_w(w_obj) == -1:
+return UINT_MAX
+raise oefmt(self.w_OverflowError,
+"user/group id smaller than minimum (-1)")
+raise
+
 def truncatedint_w(self, w_obj, allow_conversion=True):
 # Like space.gateway_int_w(), but return the integer truncated
 # instead of raising OverflowError.  For obscure cases only.
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -167,6 +167,9 @@
 def visit_c_ushort(self, el, app_sig):
 self.checked_space_method(el, app_sig)
 
+def visit_c_uid_t(self, el, app_sig):
+self.checked_space_method(el, app_sig)
+
 def visit_truncatedint_w(self, el, app_sig):
 self.checked_space_method(el, app_sig)
 
@@ -294,6 +297,9 @@
 def visit_c_ushort(self, typ):
 self.run_args.append("space.c_ushort_w(%s)" % (self.scopenext(),))
 
+def visit_c_uid_t(self, typ):
+self.run_args.append("space.c_uid_t_w(%s)" % (self.scopenext(),))
+
 def visit_truncatedint_w(self, typ):
 self.run_args.append("space.truncatedint_w(%s)" % (self.scopenext(),))
 
@@ -440,6 +446,9 @@
 def visit_c_ushort(self, typ):
 self.unwrap.append("space.c_ushort_w(%s)" % (self.nextarg(),))
 
+def visit_c_uid_t(self, typ):
+self.unwrap.append("space.c_uid_t_w(%s)" % (self.nextarg(),))
+
 def visit_truncatedint_w(self, typ):
 self.unwrap.append("space.truncatedint_w(%s)" % (self.nextarg(),))
 
@@ -587,7 +596,10 @@
 
 # First extract the signature from the (CPython-level) code object
 from pypy.interpreter import