[pypy-commit] pypy py3tests: hg merge py3.6

rlamy pypy.commits at gmail.com
Wed Jul 24 13:13:41 EDT 2019


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3tests
Changeset: r97023:5ec00f642d67
Date: 2019-07-24 18:12 +0100
http://bitbucket.org/pypy/pypy/changeset/5ec00f642d67/

Log:	hg merge py3.6

diff too long, truncating to 2000 out of 32952 lines

diff --git a/.hgtags b/.hgtags
--- a/.hgtags
+++ b/.hgtags
@@ -10,10 +10,6 @@
 32f35069a16d819b58c1b6efb17c44e3e53397b2 release-2.3.1
 10f1b29a2bd21f837090286174a9ca030b8680b2 release-2.5.0
 9c4588d731b7fe0b08669bd732c2b676cb0a8233 release-2.5.1
-fcdb941565156385cbac04cfb891f8f4c7a92ef6 release-2.6.0
-fcdb941565156385cbac04cfb891f8f4c7a92ef6 release-2.6.0
-e03971291f3a0729ecd3ee7fae7ddb0bb82d476c release-2.6.0
-e03971291f3a0729ecd3ee7fae7ddb0bb82d476c release-2.6.0
 295ee98b69288471b0fcf2e0ede82ce5209eb90b release-2.6.0
 f3ad1e1e1d6215e20d34bb65ab85ff9188c9f559 release-2.6.1
 850edf14b2c75573720f59e95767335fb1affe55 release-4.0.0
@@ -24,17 +20,10 @@
 b0a649e90b6642251fb4a765fe5b27a97b1319a9 release-5.1.1
 80ef432a32d9baa4b3c5a54c215e8ebe499f6374 release-5.1.2
 40497617ae91caa1a394d8be6f9cd2de31cb0628 release-pypy3.3-v5.2
-40497617ae91caa1a394d8be6f9cd2de31cb0628 release-pypy3.3-v5.2
 c09c19272c990a0611b17569a0085ad1ab00c8ff release-pypy2.7-v5.3
 7e8df3df96417c16c2d55b41352ec82c9c69c978 release-pypy2.7-v5.3.1
-68bb3510d8212ae9efb687e12e58c09d29e74f87 release-pypy2.7-v5.4.0
-68bb3510d8212ae9efb687e12e58c09d29e74f87 release-pypy2.7-v5.4.0
 77392ad263504df011ccfcabf6a62e21d04086d0 release-pypy2.7-v5.4.0
-050d84dd78997f021acf0e133934275d63547cc0 release-pypy2.7-v5.4.1
-050d84dd78997f021acf0e133934275d63547cc0 release-pypy2.7-v5.4.1
 0e2d9a73f5a1818d0245d75daccdbe21b2d5c3ef release-pypy2.7-v5.4.1
-4909c06daf41ce88f87dc01c57959cadad4df4a8 RevDB-pypy2.7-v5.4.1
-4909c06daf41ce88f87dc01c57959cadad4df4a8 RevDB-pypy2.7-v5.4.1
 d7724c0a5700b895a47de44074cdf5fd659a988f RevDB-pypy2.7-v5.4.1
 aff251e543859ce4508159dd9f1a82a2f553de00 release-pypy2.7-v5.6.0
 e90317857d27917bf840caf675832292ee070510 RevDB-pypy2.7-v5.6.1
@@ -45,25 +34,20 @@
 2875f328eae2216a87f3d6f335092832eb031f56 release-pypy3.5-v5.7.1
 c925e73810367cd960a32592dd7f728f436c125c release-pypy2.7-v5.8.0
 a37ecfe5f142bc971a86d17305cc5d1d70abec64 release-pypy3.5-v5.8.0
-03d614975835870da65ff0481e1edad68ebbcb8d release-pypy2.7-v5.9.0
 d72f9800a42b46a8056951b1da2426d2c2d8d502 release-pypy3.5-v5.9.0
-03d614975835870da65ff0481e1edad68ebbcb8d release-pypy2.7-v5.9.0
 84a2f3e6a7f88f2fe698e473998755b3bd1a12e2 release-pypy2.7-v5.9.0
 0e7ea4fe15e82d5124e805e2e4a37cae1a402d4b release-pypy2.7-v5.10.0
-a91df6163fb76df245091f741dbf6a23ddc72374 release-pypy3.5-v5.10.0
-a91df6163fb76df245091f741dbf6a23ddc72374 release-pypy3.5-v5.10.0
-0000000000000000000000000000000000000000 release-pypy3.5-v5.10.0
-0000000000000000000000000000000000000000 release-pypy3.5-v5.10.0
 09f9160b643e3f02ccb8c843b2fbb4e5cbf54082 release-pypy3.5-v5.10.0
 3f6eaa010fce78cc7973bdc1dfdb95970f08fed2 release-pypy3.5-v5.10.1
 ab0b9caf307db6592905a80b8faffd69b39005b8 release-pypy2.7-v6.0.0
 fdd60ed87e941677e8ea11acf9f1819466521bf2 release-pypy3.5-v6.0.0
 9112c8071614108b1042bfef0713915107004d62 release-pypy2.7-v7.0.0
 1f86f25937b6ae6c8b25236c35228fac587678bf release-pypy3.5-v7.0.0
-dab365a465140aa79a5f3ba4db784c4af4d5c195 release-pypy3.6-v7.0.0
-9112c8071614108b1042bfef0713915107004d62 release-pypy2.7-v7.0.0
 c8805ee6d7846ca2722b106eeaa2f128c699aba3 release-pypy2.7-v7.0.0
-1f86f25937b6ae6c8b25236c35228fac587678bf release-pypy3.5-v7.0.0
 928a4f70d3de7d17449456946154c5da6e600162 release-pypy3.5-v7.0.0
-dab365a465140aa79a5f3ba4db784c4af4d5c195 release-pypy3.6-v7.0.0
 fb40f7a5524c77b80e6c468e087d621610137261 release-pypy3.6-v7.0.0
+990cef41fe11e5d46b019a46aa956ff46ea1a234 release-pypy2.7-v7.1.0
+de061d87e39c7df4e436974096d7982c676a859d release-pypy3.6-v7.1.0
+784b254d669919c872a505b807db8462b6140973 release-pypy3.6-v7.1.1
+8cdda8b8cdb8ff29d9e620cccd6c5edd2f2a23ec release-pypy2.7-v7.1.1
+
diff --git a/LICENSE b/LICENSE
--- a/LICENSE
+++ b/LICENSE
@@ -110,6 +110,7 @@
   Devin Jeanpierre
   Bob Ippolito
   Bruno Gola
+  Andrew Lawrence
   David Malcolm
   Squeaky
   Edd Barrett
@@ -125,7 +126,6 @@
   John Witulski
   Stefan Beyer
   Jeremy Thurgood
-  Andrew Lawrence
   Greg Price
   Ivan Sichmann Freitas
   Dario Bertini
@@ -254,6 +254,7 @@
   Omer Katz
   Jacek Generowicz
   Tomasz Dziopa
+  Lin Cheng
   Sylvain Thenault
   Jakub Stasiak
   Andrew Dalke
@@ -403,6 +404,7 @@
   Niclas Olofsson
   Chris Pressey
   Tobias Diaz
+  Paul Graydon
   Nikolaos-Digenis Karagiannis
   Kurt Griffiths
   Ben Mather
diff --git a/extra_tests/cffi_tests/cffi0/backend_tests.py b/extra_tests/cffi_tests/cffi0/backend_tests.py
--- a/extra_tests/cffi_tests/cffi0/backend_tests.py
+++ b/extra_tests/cffi_tests/cffi0/backend_tests.py
@@ -1,5 +1,6 @@
 # Generated by pypy/tool/import_cffi.py
 import py
+import pytest
 import platform
 import sys, ctypes
 from cffi import FFI, CDefError, FFIError, VerificationMissing
@@ -113,10 +114,14 @@
         p[9] = 43
         assert p[0] == 42
         assert p[9] == 43
-        py.test.raises(IndexError, "p[10]")
-        py.test.raises(IndexError, "p[10] = 44")
-        py.test.raises(IndexError, "p[-1]")
-        py.test.raises(IndexError, "p[-1] = 44")
+        with pytest.raises(IndexError):
+            p[10]
+        with pytest.raises(IndexError):
+            p[10] = 44
+        with pytest.raises(IndexError):
+            p[-1]
+        with pytest.raises(IndexError):
+            p[-1] = 44
 
     def test_new_array_args(self):
         ffi = FFI(backend=self.Backend())
@@ -141,18 +146,21 @@
         ffi = FFI(backend=self.Backend())
         p = ffi.new("int[]", 10)     # a single integer is the length
         assert p[9] == 0
-        py.test.raises(IndexError, "p[10]")
+        with pytest.raises(IndexError):
+            p[10]
         #
         py.test.raises(TypeError, ffi.new, "int[]")
         #
         p = ffi.new("int[]", [-6, -7])    # a list is all the items, like C
         assert p[0] == -6
         assert p[1] == -7
-        py.test.raises(IndexError, "p[2]")
+        with pytest.raises(IndexError):
+            p[2]
         assert repr(p) == "<cdata 'int[]' owning %d bytes>" % (2*SIZE_OF_INT)
         #
         p = ffi.new("int[]", 0)
-        py.test.raises(IndexError, "p[0]")
+        with pytest.raises(IndexError):
+            p[0]
         py.test.raises(ValueError, ffi.new, "int[]", -1)
         assert repr(p) == "<cdata 'int[]' owning 0 bytes>"
 
@@ -260,7 +268,8 @@
         p[2][3] = 33
         assert p[0][0] == 10
         assert p[2][3] == 33
-        py.test.raises(IndexError, "p[1][-1]")
+        with pytest.raises(IndexError):
+            p[1][-1]
 
     def test_constructor_array_of_array(self):
         ffi = FFI(backend=self.Backend())
@@ -387,7 +396,8 @@
         n = ffi.new("int*", 99)
         p = ffi.new("int*[]", [n])
         assert p[0][0] == 99
-        py.test.raises(TypeError, "p[0] = None")
+        with pytest.raises(TypeError):
+            p[0] = None
         p[0] = ffi.NULL
         assert p[0] == ffi.NULL
 
@@ -423,13 +433,15 @@
         assert s.a == s.b == s.c == 0
         s.b = -23
         assert s.b == -23
-        py.test.raises(OverflowError, "s.b = 32768")
+        with pytest.raises(OverflowError):
+            s.b = 32768
         #
         s = ffi.new("struct foo*", [-2, -3])
         assert s.a == -2
         assert s.b == -3
         assert s.c == 0
-        py.test.raises((AttributeError, TypeError), "del s.a")
+        with pytest.raises((AttributeError, TypeError)):
+            del s.a
         assert repr(s) == "<cdata 'struct foo *' owning %d bytes>" % (
             SIZE_OF_INT + 2 * SIZE_OF_SHORT)
         #
@@ -451,8 +463,10 @@
         assert s[0].a == s[0].b == s[0].c == 0
         s[0].b = -23
         assert s[0].b == s.b == -23
-        py.test.raises(OverflowError, "s[0].b = -32769")
-        py.test.raises(IndexError, "s[1]")
+        with pytest.raises(OverflowError):
+            s[0].b = -32769
+        with pytest.raises(IndexError):
+            s[1]
 
     def test_struct_opaque(self):
         ffi = FFI(backend=self.Backend())
@@ -512,11 +526,13 @@
         u.b = -23
         assert u.b == -23
         assert u.a != 0
-        py.test.raises(OverflowError, "u.b = 32768")
+        with pytest.raises(OverflowError):
+            u.b = 32768
         #
         u = ffi.new("union foo*", [-2])
         assert u.a == -2
-        py.test.raises((AttributeError, TypeError), "del u.a")
+        with pytest.raises((AttributeError, TypeError)):
+            del u.a
         assert repr(u) == "<cdata 'union foo *' owning %d bytes>" % SIZE_OF_INT
 
     def test_union_opaque(self):
@@ -592,7 +608,8 @@
         p[3] = b'\x00'
         assert ffi.string(p) == b"hel"
         assert ffi.string(p, 2) == b"he"
-        py.test.raises(IndexError, "p[7] = b'X'")
+        with pytest.raises(IndexError):
+            p[7] = b'X'
         #
         a = ffi.new("char[]", b"hello\x00world")
         assert len(a) == 12
@@ -616,7 +633,8 @@
         p[3] = u+'\x00'
         assert ffi.string(p) == u+"hel"
         assert ffi.string(p, 123) == u+"hel"
-        py.test.raises(IndexError, "p[7] = u+'X'")
+        with pytest.raises(IndexError):
+            p[7] = u+'X'
         #
         a = ffi.new("wchar_t[]", u+"hello\x00world")
         assert len(a) == 12
@@ -634,7 +652,8 @@
         s = ffi.new("struct foo*", [t])
         assert type(s.name) not in (bytes, str, unicode)
         assert ffi.string(s.name) == b"testing"
-        py.test.raises(TypeError, "s.name = None")
+        with pytest.raises(TypeError):
+            s.name = None
         s.name = ffi.NULL
         assert s.name == ffi.NULL
 
@@ -658,18 +677,21 @@
         a = ffi.new("int[]", [10, 11, 12])
         p = ffi.new("void **", a)
         vp = p[0]
-        py.test.raises(TypeError, "vp[0]")
+        with pytest.raises(TypeError):
+            vp[0]
         py.test.raises(TypeError, ffi.new, "short **", a)
         #
         ffi.cdef("struct foo { void *p; int *q; short *r; };")
         s = ffi.new("struct foo *")
         s.p = a    # works
         s.q = a    # works
-        py.test.raises(TypeError, "s.r = a")    # fails
+        with pytest.raises(TypeError):
+            s.r = a    # fails
         b = ffi.cast("int *", a)
         s.p = b    # works
         s.q = b    # works
-        py.test.raises(TypeError, "s.r = b")    # fails
+        with pytest.raises(TypeError):
+            s.r = b    # fails
 
     def test_functionptr_simple(self):
         ffi = FFI(backend=self.Backend())
@@ -688,7 +710,8 @@
         q = ffi.new("int(**)(int)", p)
         assert repr(q) == "<cdata 'int(* *)(int)' owning %d bytes>" % (
             SIZE_OF_PTR)
-        py.test.raises(TypeError, "q(43)")
+        with pytest.raises(TypeError):
+            q(43)
         res = q[0](43)
         assert res == 44
         q = ffi.cast("int(*)(int)", p)
@@ -913,10 +936,14 @@
         assert s.e == 4294967295
         assert s[0].e == 4294967295
         s.e = s.e
-        py.test.raises(TypeError, "s.e = 'B'")
-        py.test.raises(TypeError, "s.e = '2'")
-        py.test.raises(TypeError, "s.e = '#2'")
-        py.test.raises(TypeError, "s.e = '#7'")
+        with pytest.raises(TypeError):
+            s.e = 'B'
+        with pytest.raises(TypeError):
+            s.e = '2'
+        with pytest.raises(TypeError):
+            s.e = '#2'
+        with pytest.raises(TypeError):
+            s.e = '#7'
 
     def test_enum_non_contiguous(self):
         ffi = FFI(backend=self.Backend())
@@ -951,11 +978,14 @@
         ffi = FFI(backend=self.Backend())
         ffi.cdef("struct foo { int a, b; };")
         s = ffi.new("struct foo[1]")
-        py.test.raises(AttributeError, 's.b')
-        py.test.raises(AttributeError, 's.b = 412')
+        with pytest.raises(AttributeError):
+            s.b
+        with pytest.raises(AttributeError):
+            s.b = 412
         s[0].b = 412
         assert s[0].b == 412
-        py.test.raises(IndexError, 's[1]')
+        with pytest.raises(IndexError):
+            s[1]
 
     def test_pointer_to_array(self):
         ffi = FFI(backend=self.Backend())
@@ -1012,17 +1042,23 @@
         assert ffi.sizeof("struct foo") == 8
         s = ffi.new("struct foo *")
         s.a = 511
-        py.test.raises(OverflowError, "s.a = 512")
-        py.test.raises(OverflowError, "s[0].a = 512")
+        with pytest.raises(OverflowError):
+            s.a = 512
+        with pytest.raises(OverflowError):
+            s[0].a = 512
         assert s.a == 511
         s.a = -512
-        py.test.raises(OverflowError, "s.a = -513")
-        py.test.raises(OverflowError, "s[0].a = -513")
+        with pytest.raises(OverflowError):
+            s.a = -513
+        with pytest.raises(OverflowError):
+            s[0].a = -513
         assert s.a == -512
         s.c = 3
         assert s.c == 3
-        py.test.raises(OverflowError, "s.c = 4")
-        py.test.raises(OverflowError, "s[0].c = 4")
+        with pytest.raises(OverflowError):
+            s.c = 4
+        with pytest.raises(OverflowError):
+            s[0].c = 4
         s.c = -4
         assert s.c == -4
 
@@ -1280,7 +1316,8 @@
         p = ffi.new("struct foo_s *", 10)     # a single integer is the length
         assert p.len == 0
         assert p.data[9] == 0
-        py.test.raises(IndexError, "p.data[10]")
+        with pytest.raises(IndexError):
+            p.data[10]
 
     def test_ffi_typeof_getcname(self):
         ffi = FFI(backend=self.Backend())
diff --git a/extra_tests/cffi_tests/cffi0/test_ffi_backend.py b/extra_tests/cffi_tests/cffi0/test_ffi_backend.py
--- a/extra_tests/cffi_tests/cffi0/test_ffi_backend.py
+++ b/extra_tests/cffi_tests/cffi0/test_ffi_backend.py
@@ -130,6 +130,36 @@
         alloc5 = ffi.new_allocator(myalloc5)
         py.test.raises(MemoryError, alloc5, "int[5]")
 
+    def test_new_struct_containing_struct_containing_array_varsize(self):
+        ffi = FFI(backend=self.Backend())
+        ffi.cdef("""
+            struct foo_s { int len[100]; short data[]; };
+            struct bar_s { int abc[100]; struct foo_s tail; };
+        """)
+        # loop to try to detect heap overwrites, if the size allocated
+        # is too small
+        for i in range(1, 501, 100):
+            p = ffi.new("struct bar_s *", [[10], [[20], [3,4,5,6,7,8,9] * i]])
+            assert p.abc[0] == 10
+            assert p.tail.len[0] == 20
+            assert p.tail.data[0] == 3
+            assert p.tail.data[6] == 9
+            assert p.tail.data[7 * i - 1] == 9
+
+    def test_bogus_struct_containing_struct_containing_array_varsize(self):
+        ffi = FFI(backend=self.Backend())
+        ffi.cdef("""
+            struct foo_s { signed char len; signed char data[]; };
+            struct bar_s { struct foo_s foo; int bcd; };
+        """)
+        p = ffi.new("struct bar_s *", [[123, [45, 56, 67, 78]], 9999999])
+        assert p.foo.len == 123
+        assert p.foo.data[0] == 45
+        assert p.foo.data[1] == 56
+        assert p.foo.data[2] == 67
+        assert p.bcd == 9999999
+        assert p.foo.data[3] != 78   # has been overwritten with 9999999
+
 
 class TestBitfield:
     def check(self, source, expected_ofs_y, expected_align, expected_size):
@@ -269,12 +299,15 @@
 
     def test_error_cases(self):
         ffi = FFI()
-        py.test.raises(TypeError,
-            'ffi.cdef("struct s1 { float x:1; };"); ffi.new("struct s1 *")')
-        py.test.raises(TypeError,
-            'ffi.cdef("struct s2 { char x:0; };"); ffi.new("struct s2 *")')
-        py.test.raises(TypeError,
-            'ffi.cdef("struct s3 { char x:9; };"); ffi.new("struct s3 *")')
+        ffi.cdef("struct s1 { float x:1; };")
+        with pytest.raises(TypeError):
+            ffi.new("struct s1 *")
+        ffi.cdef("struct s2 { char x:0; };")
+        with pytest.raises(TypeError):
+            ffi.new("struct s2 *")
+        ffi.cdef("struct s3 { char x:9; };")
+        with pytest.raises(TypeError):
+            ffi.new("struct s3 *")
 
     def test_struct_with_typedef(self):
         ffi = FFI()
diff --git a/extra_tests/cffi_tests/cffi0/test_function.py b/extra_tests/cffi_tests/cffi0/test_function.py
--- a/extra_tests/cffi_tests/cffi0/test_function.py
+++ b/extra_tests/cffi_tests/cffi0/test_function.py
@@ -1,5 +1,6 @@
 # Generated by pypy/tool/import_cffi.py
 import py
+import pytest
 from cffi import FFI, CDefError
 import math, os, sys
 import ctypes.util
@@ -91,7 +92,8 @@
         """)
         m = ffi.dlopen(lib_m)
         assert m.FOOBAR == 42
-        py.test.raises(NotImplementedError, "m.baz")
+        with pytest.raises(NotImplementedError):
+            m.baz
 
     def test_tlsalloc(self):
         if sys.platform != 'win32':
diff --git a/extra_tests/cffi_tests/cffi0/test_parsing.py b/extra_tests/cffi_tests/cffi0/test_parsing.py
--- a/extra_tests/cffi_tests/cffi0/test_parsing.py
+++ b/extra_tests/cffi_tests/cffi0/test_parsing.py
@@ -410,7 +410,17 @@
 def test_enum():
     ffi = FFI()
     ffi.cdef("""
-        enum Enum { POS = +1, TWO = 2, NIL = 0, NEG = -1, OP = (POS+TWO)-1};
+        enum Enum {
+            POS = +1,
+            TWO = 2,
+            NIL = 0,
+            NEG = -1,
+            ADDSUB = (POS+TWO)-1,
+            DIVMULINT = (3 * 3) / 2,
+            SHIFT = (1 << 3) >> 1,
+            BINOPS = (0x7 & 0x1) | 0x8,
+            XOR = 0xf ^ 0xa
+        };
         """)
     needs_dlopen_none()
     C = ffi.dlopen(None)
@@ -418,7 +428,11 @@
     assert C.TWO == 2
     assert C.NIL == 0
     assert C.NEG == -1
-    assert C.OP == 2
+    assert C.ADDSUB == 2
+    assert C.DIVMULINT == 4
+    assert C.SHIFT == 4
+    assert C.BINOPS == 0b1001
+    assert C.XOR == 0b0101
 
 def test_stdcall():
     ffi = FFI()
@@ -467,3 +481,40 @@
     e = py.test.raises(CDefError, ffi.cdef, 'void foo(void) {}')
     assert str(e.value) == ('<cdef source string>:1: unexpected <FuncDef>: '
                             'this construct is valid C but not valid in cdef()')
+
+def test_unsigned_int_suffix_for_constant():
+    ffi = FFI()
+    ffi.cdef("""enum e {
+                    bin_0=0b10,
+                    bin_1=0b10u,
+                    bin_2=0b10U,
+                    bin_3=0b10l,
+                    bin_4=0b10L,
+                    bin_5=0b10ll,
+                    bin_6=0b10LL,
+                    oct_0=010,
+                    oct_1=010u,
+                    oct_2=010U,
+                    oct_3=010l,
+                    oct_4=010L,
+                    oct_5=010ll,
+                    oct_6=010LL,
+                    dec_0=10,
+                    dec_1=10u,
+                    dec_2=10U,
+                    dec_3=10l,
+                    dec_4=10L,
+                    dec_5=10ll,
+                    dec_6=10LL,
+                    hex_0=0x10,
+                    hex_1=0x10u,
+                    hex_2=0x10U,
+                    hex_3=0x10l,
+                    hex_4=0x10L,
+                    hex_5=0x10ll,
+                    hex_6=0x10LL,};""")
+    needs_dlopen_none()
+    C = ffi.dlopen(None)
+    for base, expected_result in (('bin', 2), ('oct', 8), ('dec', 10), ('hex', 16)):
+        for index in range(7):
+            assert getattr(C, '{base}_{index}'.format(base=base, index=index)) == expected_result
diff --git a/extra_tests/cffi_tests/cffi0/test_verify.py b/extra_tests/cffi_tests/cffi0/test_verify.py
--- a/extra_tests/cffi_tests/cffi0/test_verify.py
+++ b/extra_tests/cffi_tests/cffi0/test_verify.py
@@ -1,5 +1,6 @@
 # Generated by pypy/tool/import_cffi.py
 import py, re
+import pytest
 import sys, os, math, weakref
 from cffi import FFI, VerificationError, VerificationMissing, model, FFIError
 from extra_tests.cffi_tests.support import *
@@ -21,7 +22,8 @@
         extra_compile_args.append('-Qunused-arguments')
     else:
         # assume a standard gcc
-        extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion']
+        extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion',
+                              '-Wno-unused-parameter']
 
     class FFI(FFI):
         def verify(self, *args, **kwds):
@@ -590,7 +592,8 @@
     assert ffi.sizeof('struct foo_s') == 19 * ffi.sizeof('int')
     s = ffi.new("struct foo_s *")
     assert ffi.sizeof(s.a) == 17 * ffi.sizeof('int')
-    py.test.raises(IndexError, 's.a[17]')
+    with pytest.raises(IndexError):
+        s.a[17]
 
 def test_struct_array_c99_1():
     if sys.platform == 'win32':
@@ -648,7 +651,8 @@
     ffi.verify("struct foo_s { int a:2, b:3; };")
     s = ffi.new("struct foo_s *")
     s.b = 3
-    py.test.raises(OverflowError, "s.b = 4")
+    with pytest.raises(OverflowError):
+        s.b = 4
     assert s.b == 3
 
 def test_struct_with_bitfield_enum():
@@ -1464,8 +1468,10 @@
     p = ffi.new("struct foo_s *")
     p.x = 1
     assert p.x is True
-    py.test.raises(OverflowError, "p.x = -1")
-    py.test.raises(TypeError, "p.x = 0.0")
+    with pytest.raises(OverflowError):
+        p.x = -1
+    with pytest.raises(TypeError):
+        p.x = 0.0
     assert lib.foop(1) is False
     assert lib.foop(True) is False
     assert lib.foop(0) is True
@@ -1533,7 +1539,8 @@
                 }
             """ % (type, type))
             p = ffi.new("struct foo_s *")
-            py.test.raises(TypeError, "p.x = 0.0")
+            with pytest.raises(TypeError):
+                p.x = 0.0
             assert lib.foo(42) == 0
             assert lib.foo(0) == 1
             py.test.raises(TypeError, lib.foo, 0.0)
@@ -2099,6 +2106,11 @@
             raise errors[0][1]
 
 def test_errno_working_even_with_pypys_jit():
+    # NOTE: on some platforms, to work correctly, this test needs to be
+    # compiled with -pthread.  Otherwise, the accesses to errno done from f()
+    # are compiled by assuming this small library won't be used from multiple
+    # threads, which is wrong.  If you see failures _and_ if you pass your
+    # own CFLAGS environment variable, please make sure "-pthread" is in it.
     ffi = FFI()
     ffi.cdef("int f(int);")
     lib = ffi.verify("""
@@ -2523,3 +2535,29 @@
         x.p = p
         x.cyclic = x
         del p, x
+
+def test_arithmetic_in_cdef():
+    for a in [0, 11, 15]:
+        ffi = FFI()
+        ffi.cdef("""
+            enum FOO {
+                DIVNN = ((-?) / (-3)),
+                DIVNP = ((-?) / (+3)),
+                DIVPN = ((+?) / (-3)),
+                MODNN = ((-?) % (-3)),
+                MODNP = ((-?) % (+3)),
+                MODPN = ((+?) % (-3)),
+                };
+        """.replace('?', str(a)))
+        lib = ffi.verify("""
+            enum FOO {
+                DIVNN = ((-?) / (-3)),
+                DIVNP = ((-?) / (+3)),
+                DIVPN = ((+?) / (-3)),
+                MODNN = ((-?) % (-3)),
+                MODNP = ((-?) % (+3)),
+                MODPN = ((+?) % (-3)),
+                };
+        """.replace('?', str(a)))
+        # the verify() crashes if the values in the enum are different from
+        # the values we computed ourselves from the cdef()
diff --git a/extra_tests/cffi_tests/cffi0/test_zintegration.py b/extra_tests/cffi_tests/cffi0/test_zintegration.py
--- a/extra_tests/cffi_tests/cffi0/test_zintegration.py
+++ b/extra_tests/cffi_tests/cffi0/test_zintegration.py
@@ -2,11 +2,13 @@
 import py, os, sys, shutil
 import subprocess
 from extra_tests.cffi_tests.udir import udir
+import pytest
 
 if sys.platform == 'win32':
-    py.test.skip('snippets do not run on win32')
+    pytestmark = pytest.mark.skip('snippets do not run on win32')
 if sys.version_info < (2, 7):
-    py.test.skip('fails e.g. on a Debian/Ubuntu which patches virtualenv'
+    pytestmark = pytest.mark.skip(
+                 'fails e.g. on a Debian/Ubuntu which patches virtualenv'
                  ' in a non-2.6-friendly way')
 
 def create_venv(name):
diff --git a/extra_tests/cffi_tests/cffi1/test_ffi_obj.py b/extra_tests/cffi_tests/cffi1/test_ffi_obj.py
--- a/extra_tests/cffi_tests/cffi1/test_ffi_obj.py
+++ b/extra_tests/cffi_tests/cffi1/test_ffi_obj.py
@@ -1,5 +1,6 @@
 # Generated by pypy/tool/import_cffi.py
 import py, sys
+import pytest
 import _cffi_backend as _cffi1_backend
 
 
@@ -86,9 +87,12 @@
 
 def test_ffi_no_attr():
     ffi = _cffi1_backend.FFI()
-    py.test.raises(AttributeError, "ffi.no_such_name")
-    py.test.raises(AttributeError, "ffi.no_such_name = 42")
-    py.test.raises(AttributeError, "del ffi.no_such_name")
+    with pytest.raises(AttributeError):
+        ffi.no_such_name
+    with pytest.raises(AttributeError):
+        ffi.no_such_name = 42
+    with pytest.raises(AttributeError):
+        del ffi.no_such_name
 
 def test_ffi_string():
     ffi = _cffi1_backend.FFI()
diff --git a/extra_tests/cffi_tests/cffi1/test_new_ffi_1.py b/extra_tests/cffi_tests/cffi1/test_new_ffi_1.py
--- a/extra_tests/cffi_tests/cffi1/test_new_ffi_1.py
+++ b/extra_tests/cffi_tests/cffi1/test_new_ffi_1.py
@@ -1,5 +1,6 @@
 # Generated by pypy/tool/import_cffi.py
 import py
+import pytest
 import platform, imp
 import sys, os, ctypes
 import cffi
@@ -187,10 +188,14 @@
         p[9] = 43
         assert p[0] == 42
         assert p[9] == 43
-        py.test.raises(IndexError, "p[10]")
-        py.test.raises(IndexError, "p[10] = 44")
-        py.test.raises(IndexError, "p[-1]")
-        py.test.raises(IndexError, "p[-1] = 44")
+        with pytest.raises(IndexError):
+            p[10]
+        with pytest.raises(IndexError):
+            p[10] = 44
+        with pytest.raises(IndexError):
+            p[-1]
+        with pytest.raises(IndexError):
+            p[-1] = 44
 
     def test_new_array_args(self):
         # this tries to be closer to C: where we say "int x[5] = {10, 20, ..}"
@@ -213,18 +218,21 @@
     def test_new_array_varsize(self):
         p = ffi.new("int[]", 10)     # a single integer is the length
         assert p[9] == 0
-        py.test.raises(IndexError, "p[10]")
+        with pytest.raises(IndexError):
+            p[10]
         #
         py.test.raises(TypeError, ffi.new, "int[]")
         #
         p = ffi.new("int[]", [-6, -7])    # a list is all the items, like C
         assert p[0] == -6
         assert p[1] == -7
-        py.test.raises(IndexError, "p[2]")
+        with pytest.raises(IndexError):
+            p[2]
         assert repr(p) == "<cdata 'int[]' owning %d bytes>" % (2*SIZE_OF_INT)
         #
         p = ffi.new("int[]", 0)
-        py.test.raises(IndexError, "p[0]")
+        with pytest.raises(IndexError):
+            p[0]
         py.test.raises(ValueError, ffi.new, "int[]", -1)
         assert repr(p) == "<cdata 'int[]' owning 0 bytes>"
 
@@ -325,7 +333,8 @@
         p[2][3] = 33
         assert p[0][0] == 10
         assert p[2][3] == 33
-        py.test.raises(IndexError, "p[1][-1]")
+        with pytest.raises(IndexError):
+            p[1][-1]
 
     def test_constructor_array_of_array(self):
         p = ffi.new("int[3][2]", [[10, 11], [12, 13], [14, 15]])
@@ -446,7 +455,8 @@
         n = ffi.new("int*", 99)
         p = ffi.new("int*[]", [n])
         assert p[0][0] == 99
-        py.test.raises(TypeError, "p[0] = None")
+        with pytest.raises(TypeError):
+            p[0] = None
         p[0] = ffi.NULL
         assert p[0] == ffi.NULL
 
@@ -479,13 +489,15 @@
         assert s.a == s.b == s.c == 0
         s.b = -23
         assert s.b == -23
-        py.test.raises(OverflowError, "s.b = 32768")
+        with pytest.raises(OverflowError):
+            s.b = 32768
         #
         s = ffi.new("struct simple*", [-2, -3])
         assert s.a == -2
         assert s.b == -3
         assert s.c == 0
-        py.test.raises((AttributeError, TypeError), "del s.a")
+        with pytest.raises((AttributeError, TypeError)):
+            del s.a
         assert repr(s) == "<cdata 'struct simple *' owning %d bytes>" % (
             SIZE_OF_INT + 2 * SIZE_OF_SHORT)
         #
@@ -503,8 +515,10 @@
         assert s[0].a == s[0].b == s[0].c == 0
         s[0].b = -23
         assert s[0].b == s.b == -23
-        py.test.raises(OverflowError, "s[0].b = -32769")
-        py.test.raises(IndexError, "s[1]")
+        with pytest.raises(OverflowError):
+            s[0].b = -32769
+        with pytest.raises(IndexError):
+            s[1]
 
     def test_struct_opaque(self):
         py.test.raises(ffi.error, ffi.new, "struct baz*")
@@ -556,11 +570,13 @@
         u.b = -23
         assert u.b == -23
         assert u.a != 0
-        py.test.raises(OverflowError, "u.b = 32768")
+        with pytest.raises(OverflowError):
+            u.b = 32768
         #
         u = ffi.new("union simple_u*", [-2])
         assert u.a == -2
-        py.test.raises((AttributeError, TypeError), "del u.a")
+        with pytest.raises((AttributeError, TypeError)):
+            del u.a
         assert repr(u) == "<cdata 'union simple_u *' owning %d bytes>" % (
             SIZE_OF_INT,)
 
@@ -626,7 +642,8 @@
         p[3] = b'\x00'
         assert ffi.string(p) == b"hel"
         assert ffi.string(p, 2) == b"he"
-        py.test.raises(IndexError, "p[7] = b'X'")
+        with pytest.raises(IndexError):
+            p[7] = b'X'
         #
         a = ffi.new("char[]", b"hello\x00world")
         assert len(a) == 12
@@ -649,7 +666,8 @@
         p[3] = u+'\x00'
         assert ffi.string(p) == u+"hel"
         assert ffi.string(p, 123) == u+"hel"
-        py.test.raises(IndexError, "p[7] = u+'X'")
+        with pytest.raises(IndexError):
+            p[7] = u+'X'
         #
         a = ffi.new("wchar_t[]", u+"hello\x00world")
         assert len(a) == 12
@@ -665,7 +683,8 @@
         s = ffi.new("struct string*", [t])
         assert type(s.name) not in (bytes, str, unicode)
         assert ffi.string(s.name) == b"testing"
-        py.test.raises(TypeError, "s.name = None")
+        with pytest.raises(TypeError):
+            s.name = None
         s.name = ffi.NULL
         assert s.name == ffi.NULL
 
@@ -686,17 +705,20 @@
         a = ffi.new("int[]", [10, 11, 12])
         p = ffi.new("void **", a)
         vp = p[0]
-        py.test.raises(TypeError, "vp[0]")
+        with pytest.raises(TypeError):
+            vp[0]
         py.test.raises(TypeError, ffi.new, "short **", a)
         #
         s = ffi.new("struct voidp *")
         s.p = a    # works
         s.q = a    # works
-        py.test.raises(TypeError, "s.r = a")    # fails
+        with pytest.raises(TypeError):
+            s.r = a    # fails
         b = ffi.cast("int *", a)
         s.p = b    # works
         s.q = b    # works
-        py.test.raises(TypeError, "s.r = b")    # fails
+        with pytest.raises(TypeError):
+            s.r = b    # fails
 
     def test_functionptr_simple(self):
         py.test.raises(TypeError, ffi.callback, "int(*)(int)", 0)
@@ -714,7 +736,8 @@
         q = ffi.new("int(**)(int)", p)
         assert repr(q) == "<cdata 'int(* *)(int)' owning %d bytes>" % (
             SIZE_OF_PTR)
-        py.test.raises(TypeError, "q(43)")
+        with pytest.raises(TypeError):
+            q(43)
         res = q[0](43)
         assert res == 44
         q = ffi.cast("int(*)(int)", p)
@@ -923,10 +946,14 @@
         assert s.e in (4294967295, -1)     # two choices
         assert s[0].e in (4294967295, -1)
         s.e = s.e
-        py.test.raises(TypeError, "s.e = 'B3'")
-        py.test.raises(TypeError, "s.e = '2'")
-        py.test.raises(TypeError, "s.e = '#2'")
-        py.test.raises(TypeError, "s.e = '#7'")
+        with pytest.raises(TypeError):
+            s.e = 'B3'
+        with pytest.raises(TypeError):
+            s.e = '2'
+        with pytest.raises(TypeError):
+            s.e = '#2'
+        with pytest.raises(TypeError):
+            s.e = '#7'
 
     def test_enum_non_contiguous(self):
         # enum noncont { A4, B4=42, C4 };
@@ -948,11 +975,14 @@
 
     def test_array_of_struct(self):
         s = ffi.new("struct ab[1]")
-        py.test.raises(AttributeError, 's.b')
-        py.test.raises(AttributeError, 's.b = 412')
+        with pytest.raises(AttributeError):
+            s.b
+        with pytest.raises(AttributeError):
+            s.b = 412
         s[0].b = 412
         assert s[0].b == 412
-        py.test.raises(IndexError, 's[1]')
+        with pytest.raises(IndexError):
+            s[1]
 
     def test_pointer_to_array(self):
         p = ffi.new("int(**)[5]")
@@ -1001,17 +1031,23 @@
         assert ffi.sizeof("struct bitfield") == 8
         s = ffi.new("struct bitfield *")
         s.a = 511
-        py.test.raises(OverflowError, "s.a = 512")
-        py.test.raises(OverflowError, "s[0].a = 512")
+        with pytest.raises(OverflowError):
+            s.a = 512
+        with pytest.raises(OverflowError):
+            s[0].a = 512
         assert s.a == 511
         s.a = -512
-        py.test.raises(OverflowError, "s.a = -513")
-        py.test.raises(OverflowError, "s[0].a = -513")
+        with pytest.raises(OverflowError):
+            s.a = -513
+        with pytest.raises(OverflowError):
+            s[0].a = -513
         assert s.a == -512
         s.c = 3
         assert s.c == 3
-        py.test.raises(OverflowError, "s.c = 4")
-        py.test.raises(OverflowError, "s[0].c = 4")
+        with pytest.raises(OverflowError):
+            s.c = 4
+        with pytest.raises(OverflowError):
+            s[0].c = 4
         s.c = -4
         assert s.c == -4
 
@@ -1236,7 +1272,8 @@
         p = ffi.new("struct foo_s *", 10)     # a single integer is the length
         assert p.len == 0
         assert p.data[9] == 0
-        py.test.raises(IndexError, "p.data[10]")
+        with pytest.raises(IndexError):
+            p.data[10]
 
     def test_ffi_typeof_getcname(self):
         assert ffi.getctype("int") == "int"
@@ -1753,7 +1790,8 @@
         assert MYFOO == 42
         assert myfunc(43) == 44
         assert myvar == -5     # but can't be changed, so not very useful
-        py.test.raises(ImportError, "from _test_import_from_lib.lib import bar")
+        with pytest.raises(ImportError):
+            from _test_import_from_lib.lib import bar
         d = {}
         exec("from _test_import_from_lib.lib import *", d)
         assert (set(key for key in d if not key.startswith('_')) ==
diff --git a/extra_tests/cffi_tests/cffi1/test_recompiler.py b/extra_tests/cffi_tests/cffi1/test_recompiler.py
--- a/extra_tests/cffi_tests/cffi1/test_recompiler.py
+++ b/extra_tests/cffi_tests/cffi1/test_recompiler.py
@@ -1,6 +1,7 @@
 # Generated by pypy/tool/import_cffi.py
 
 import sys, os, py
+import pytest
 from cffi import FFI, VerificationError, FFIError, CDefError
 from cffi import recompiler
 from extra_tests.cffi_tests.udir import udir
@@ -189,20 +190,26 @@
     assert lib.a == -2
     lib.a = -2147483648
     assert lib.a == -2147483648
-    py.test.raises(OverflowError, "lib.a = 2147483648")
-    py.test.raises(OverflowError, "lib.a = -2147483649")
+    with pytest.raises(OverflowError):
+        lib.a = 2147483648
+    with pytest.raises(OverflowError):
+        lib.a = -2147483649
     lib.b = 525      # try with the first access being in setattr, too
     assert lib.b == 525
-    py.test.raises(AttributeError, "del lib.a")
-    py.test.raises(AttributeError, "del lib.c")
-    py.test.raises(AttributeError, "del lib.foobarbaz")
+    with pytest.raises(AttributeError):
+        del lib.a
+    with pytest.raises(AttributeError):
+        del lib.c
+    with pytest.raises(AttributeError):
+        del lib.foobarbaz
 
 def test_macro():
     ffi = FFI()
     ffi.cdef("#define FOOBAR ...")
     lib = verify(ffi, 'test_macro', "#define FOOBAR (-6912)")
     assert lib.FOOBAR == -6912
-    py.test.raises(AttributeError, "lib.FOOBAR = 2")
+    with pytest.raises(AttributeError):
+        lib.FOOBAR = 2
 
 def test_macro_check_value():
     # the value '-0x80000000' in C sources does not have a clear meaning
@@ -248,7 +255,8 @@
     ffi.cdef("static const int FOOBAR;")
     lib = verify(ffi, 'test_constant', "#define FOOBAR (-6912)")
     assert lib.FOOBAR == -6912
-    py.test.raises(AttributeError, "lib.FOOBAR = 2")
+    with pytest.raises(AttributeError):
+        lib.FOOBAR = 2
 
 def test_check_value_of_static_const():
     ffi = FFI()
@@ -264,7 +272,8 @@
     ffi.cdef("static const double FOOBAR;")
     lib = verify(ffi, 'test_constant_nonint', "#define FOOBAR (-6912.5)")
     assert lib.FOOBAR == -6912.5
-    py.test.raises(AttributeError, "lib.FOOBAR = 2")
+    with pytest.raises(AttributeError):
+        lib.FOOBAR = 2
 
 def test_constant_ptr():
     ffi = FFI()
@@ -316,8 +325,10 @@
     p = ffi.new("struct foo_s *", {'a': -32768, 'b': -2147483648})
     assert p.a == -32768
     assert p.b == -2147483648
-    py.test.raises(OverflowError, "p.a -= 1")
-    py.test.raises(OverflowError, "p.b -= 1")
+    with pytest.raises(OverflowError):
+        p.a -= 1
+    with pytest.raises(OverflowError):
+        p.b -= 1
     q = ffi.new("struct bar_s *", {'f': p})
     assert q.f == p
     #
@@ -388,8 +399,10 @@
     assert ffi.sizeof("struct foo_s") == (42 + 11) * 4
     p = ffi.new("struct foo_s *")
     assert p.a[41] == p.b[10] == 0
-    py.test.raises(IndexError, "p.a[42]")
-    py.test.raises(IndexError, "p.b[11]")
+    with pytest.raises(IndexError):
+        p.a[42]
+    with pytest.raises(IndexError):
+        p.b[11]
 
 def test_dotdotdot_global_array():
     ffi = FFI()
@@ -399,8 +412,10 @@
     assert ffi.sizeof(lib.aa) == 41 * 4
     assert ffi.sizeof(lib.bb) == 12 * 4
     assert lib.aa[40] == lib.bb[11] == 0
-    py.test.raises(IndexError, "lib.aa[41]")
-    py.test.raises(IndexError, "lib.bb[12]")
+    with pytest.raises(IndexError):
+        lib.aa[41]
+    with pytest.raises(IndexError):
+        lib.bb[12]
 
 def test_misdeclared_field_1():
     ffi = FFI()
@@ -1021,8 +1036,10 @@
     assert ffi.typeof(s.a) == ffi.typeof("int[5][8]")
     assert ffi.sizeof(s.a) == 40 * ffi.sizeof('int')
     assert s.a[4][7] == 0
-    py.test.raises(IndexError, 's.a[4][8]')
-    py.test.raises(IndexError, 's.a[5][0]')
+    with pytest.raises(IndexError):
+        s.a[4][8]
+    with pytest.raises(IndexError):
+        s.a[5][0]
     assert ffi.typeof(s.a) == ffi.typeof("int[5][8]")
     assert ffi.typeof(s.a[0]) == ffi.typeof("int[8]")
 
@@ -1035,7 +1052,8 @@
     s = ffi.new("struct foo_s *")
     assert ffi.typeof(s.a) == ffi.typeof("int[][7]")
     assert s.a[4][6] == 0
-    py.test.raises(IndexError, 's.a[4][7]')
+    with pytest.raises(IndexError):
+        s.a[4][7]
     assert ffi.typeof(s.a[0]) == ffi.typeof("int[7]")
 
 def test_global_var_array_2():
@@ -1044,8 +1062,10 @@
     lib = verify(ffi, 'test_global_var_array_2', 'int a[10][8];')
     lib.a[9][7] = 123456
     assert lib.a[9][7] == 123456
-    py.test.raises(IndexError, 'lib.a[0][8]')
-    py.test.raises(IndexError, 'lib.a[10][0]')
+    with pytest.raises(IndexError):
+        lib.a[0][8]
+    with pytest.raises(IndexError):
+        lib.a[10][0]
     assert ffi.typeof(lib.a) == ffi.typeof("int[10][8]")
     assert ffi.typeof(lib.a[0]) == ffi.typeof("int[8]")
 
@@ -1055,7 +1075,8 @@
     lib = verify(ffi, 'test_global_var_array_3', 'int a[10][8];')
     lib.a[9][7] = 123456
     assert lib.a[9][7] == 123456
-    py.test.raises(IndexError, 'lib.a[0][8]')
+    with pytest.raises(IndexError):
+        lib.a[0][8]
     assert ffi.typeof(lib.a) == ffi.typeof("int(*)[8]")
     assert ffi.typeof(lib.a[0]) == ffi.typeof("int[8]")
 
@@ -1065,8 +1086,10 @@
     lib = verify(ffi, 'test_global_var_array_4', 'int a[10][8];')
     lib.a[9][7] = 123456
     assert lib.a[9][7] == 123456
-    py.test.raises(IndexError, 'lib.a[0][8]')
-    py.test.raises(IndexError, 'lib.a[10][8]')
+    with pytest.raises(IndexError):
+        lib.a[0][8]
+    with pytest.raises(IndexError):
+        lib.a[10][8]
     assert ffi.typeof(lib.a) == ffi.typeof("int[10][8]")
     assert ffi.typeof(lib.a[0]) == ffi.typeof("int[8]")
 
@@ -1339,7 +1362,8 @@
         #define aaa 42
     """)
     assert lib.aaa == 42
-    py.test.raises(AttributeError, "lib.aaa = 43")
+    with pytest.raises(AttributeError):
+        lib.aaa = 43
 
 def test_win32_calling_convention_0():
     ffi = FFI()
@@ -2315,3 +2339,89 @@
         typedef int foo_t; struct foo_s { void (*x)(foo_t); };
     """)
     py.test.raises(TypeError, ffi.new, "struct foo_s *")
+
+def test_from_buffer_struct():
+    ffi = FFI()
+    ffi.cdef("""struct foo_s { int a, b; };""")
+    lib = verify(ffi, "test_from_buffer_struct_p", """
+        struct foo_s { int a, b; };
+    """)
+    p = ffi.new("struct foo_s *", [-219239, 58974983])
+    q = ffi.from_buffer("struct foo_s[]", ffi.buffer(p))
+    assert ffi.typeof(q) == ffi.typeof("struct foo_s[]")
+    assert len(q) == 1
+    assert q[0].a == p.a
+    assert q[0].b == p.b
+    assert q == p
+    q = ffi.from_buffer("struct foo_s *", ffi.buffer(p))
+    assert ffi.typeof(q) == ffi.typeof("struct foo_s *")
+    assert q.a == p.a
+    assert q.b == p.b
+    assert q[0].a == p.a
+    assert q[0].b == p.b
+    assert q == p
+
+def test_unnamed_bitfield_1():
+    ffi = FFI()
+    ffi.cdef("""struct A { char : 1; };""")
+    lib = verify(ffi, "test_unnamed_bitfield_1", """
+        struct A { char : 1; };
+    """)
+    p = ffi.new("struct A *")
+    assert ffi.sizeof(p[0]) == 1
+    # Note: on gcc, the type name is ignored for anonymous bitfields
+    # and that's why the result is 1.  On MSVC, the result is
+    # sizeof("char") which is also 1.
+
+def test_unnamed_bitfield_2():
+    ffi = FFI()
+    ffi.cdef("""struct A {
+        short c : 1; short : 1; short d : 1; short : 1; };""")
+    lib = verify(ffi, "test_unnamed_bitfield_2", """
+        struct A {
+            short c : 1; short : 1; short d : 1; short : 1;
+        };
+    """)
+    p = ffi.new("struct A *")
+    assert ffi.sizeof(p[0]) == ffi.sizeof("short")
+
+def test_unnamed_bitfield_3():
+    ffi = FFI()
+    ffi.cdef("""struct A { struct { char : 1; char : 1; } b; };""")
+    lib = verify(ffi, "test_unnamed_bitfield_3", """
+        struct A { struct { char : 1; char : 1; } b; };
+    """)
+    p = ffi.new("struct A *")
+    assert ffi.sizeof(p[0]) == 1
+    # Note: on gcc, the type name is ignored for anonymous bitfields
+    # and that's why the result is 1.  On MSVC, the result is
+    # sizeof("char") which is also 1.
+
+def test_unnamed_bitfield_4():
+    ffi = FFI()
+    ffi.cdef("""struct A { struct {
+        unsigned c : 1; unsigned : 1; unsigned d : 1; unsigned : 1; } a;
+        };
+        struct B { struct A a; };""")
+    lib = verify(ffi, "test_unnamed_bitfield_4", """
+        struct A { struct {
+            unsigned c : 1; unsigned : 1; unsigned d : 1; unsigned : 1; } a;
+        };
+        struct B { struct A a; };
+    """)
+    b = ffi.new("struct B *")
+    a = ffi.new("struct A *")
+    assert ffi.sizeof(a[0]) == ffi.sizeof("unsigned")
+    assert ffi.sizeof(b[0]) == ffi.sizeof(a[0])
+
+def test_struct_with_func_with_struct_arg():
+    ffi = FFI()
+    ffi.cdef("""struct BinaryTree {
+            int (* CompareKey)(struct BinaryTree tree);
+        };""")
+    lib = verify(ffi, "test_struct_with_func_with_struct_arg", """
+        struct BinaryTree {
+            int (* CompareKey)(struct BinaryTree tree);
+        };
+    """)
+    py.test.raises(RuntimeError, ffi.new, "struct BinaryTree *")
diff --git a/extra_tests/cffi_tests/cffi1/test_verify1.py b/extra_tests/cffi_tests/cffi1/test_verify1.py
--- a/extra_tests/cffi_tests/cffi1/test_verify1.py
+++ b/extra_tests/cffi_tests/cffi1/test_verify1.py
@@ -1,5 +1,6 @@
 # Generated by pypy/tool/import_cffi.py
 import os, sys, math, py
+import pytest
 from cffi import FFI, FFIError, VerificationError, VerificationMissing, model
 from cffi import CDefError
 from cffi import recompiler
@@ -23,7 +24,8 @@
         extra_compile_args.append('-Qunused-arguments')
     else:
         # assume a standard gcc
-        extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion']
+        extra_compile_args = ['-Werror', '-Wall', '-Wextra', '-Wconversion',
+                              '-Wno-unused-parameter']
 
 class FFI(FFI):
     error = _cffi_backend.FFI.error
@@ -572,7 +574,8 @@
     assert ffi.sizeof('struct foo_s') == 19 * ffi.sizeof('int')
     s = ffi.new("struct foo_s *")
     assert ffi.sizeof(s.a) == 17 * ffi.sizeof('int')
-    py.test.raises(IndexError, 's.a[17]')
+    with pytest.raises(IndexError):
+        s.a[17]
 
 def test_struct_array_c99_1():
     if sys.platform == 'win32':
@@ -630,7 +633,8 @@
     ffi.verify("struct foo_s { int a:2, b:3; };")
     s = ffi.new("struct foo_s *")
     s.b = 3
-    py.test.raises(OverflowError, "s.b = 4")
+    with pytest.raises(OverflowError):
+        s.b = 4
     assert s.b == 3
 
 def test_struct_with_bitfield_enum():
@@ -1434,8 +1438,10 @@
     p = ffi.new("struct foo_s *")
     p.x = 1
     assert p.x is True
-    py.test.raises(OverflowError, "p.x = -1")
-    py.test.raises(TypeError, "p.x = 0.0")
+    with pytest.raises(OverflowError):
+        p.x = -1
+    with pytest.raises(TypeError):
+        p.x = 0.0
     assert lib.foop(1) is False
     assert lib.foop(True) is False
     assert lib.foop(0) is True
@@ -1503,7 +1509,8 @@
                 }
             """ % (type, type))
             p = ffi.new("struct foo_s *")
-            py.test.raises(TypeError, "p.x = 0.0")
+            with pytest.raises(TypeError):
+                p.x = 0.0
             assert lib.foo(42) == 0
             assert lib.foo(0) == 1
             py.test.raises(TypeError, lib.foo, 0.0)
@@ -2194,7 +2201,8 @@
     ffi = FFI()
     ffi.cdef("#define FOO 123")
     lib = ffi.verify("#define FOO 124")     # used to complain
-    e = py.test.raises(ffi.error, "lib.FOO")
+    with pytest.raises(ffi.error) as e:
+        lib.FOO
     assert str(e.value) == ("the C compiler says 'FOO' is equal to 124 (0x7c),"
                             " but the cdef disagrees")
 
diff --git a/extra_tests/cffi_tests/embedding/test_basic.py b/extra_tests/cffi_tests/embedding/test_basic.py
--- a/extra_tests/cffi_tests/embedding/test_basic.py
+++ b/extra_tests/cffi_tests/embedding/test_basic.py
@@ -64,8 +64,8 @@
         output = popen.stdout.read()
         err = popen.wait()
         if err:
-            raise OSError("popen failed with exit code %r: %r" % (
-                err, args))
+            raise OSError(("popen failed with exit code %r: %r\n\n%s" % (
+                err, args, output)).rstrip())
         print(output.rstrip())
         return output
 
@@ -173,7 +173,8 @@
         result = popen.stdout.read()
         err = popen.wait()
         if err:
-            raise OSError("%r failed with exit code %r" % (name, err))
+            raise OSError("%r failed with exit code %r" % (
+                os.path.join(path, executable_name), err))
         return result
 
 
diff --git a/extra_tests/cffi_tests/embedding/test_performance.py b/extra_tests/cffi_tests/embedding/test_performance.py
--- a/extra_tests/cffi_tests/embedding/test_performance.py
+++ b/extra_tests/cffi_tests/embedding/test_performance.py
@@ -3,8 +3,8 @@
 from extra_tests.cffi_tests.embedding.test_basic import EmbeddingTests
 
 if sys.platform == 'win32':
-    import py
-    py.test.skip("written with POSIX functions")
+    import pytest
+    pytestmark = pytest.mark.skip("written with POSIX functions")
 
 
 class TestPerformance(EmbeddingTests):
diff --git a/lib-python/2.7/test/capath/efa5f9c3.0 b/lib-python/2.7/test/capath/efa5f9c3.0
new file mode 100644
--- /dev/null
+++ b/lib-python/2.7/test/capath/efa5f9c3.0
@@ -0,0 +1,34 @@
+-----BEGIN CERTIFICATE-----
+MIIF9zCCA9+gAwIBAgIUH98b4Fw/DyugC9cV7VK7ZODzHsIwDQYJKoZIhvcNAQEL
+BQAwgYoxCzAJBgNVBAYTAlhZMRcwFQYDVQQIDA5DYXN0bGUgQW50aHJheDEYMBYG
+A1UEBwwPQXJndW1lbnQgQ2xpbmljMSMwIQYDVQQKDBpQeXRob24gU29mdHdhcmUg
+Rm91bmRhdGlvbjEjMCEGA1UEAwwac2VsZi1zaWduZWQucHl0aG9udGVzdC5uZXQw
+HhcNMTkwNTA4MDEwMjQzWhcNMjcwNzI0MDEwMjQzWjCBijELMAkGA1UEBhMCWFkx
+FzAVBgNVBAgMDkNhc3RsZSBBbnRocmF4MRgwFgYDVQQHDA9Bcmd1bWVudCBDbGlu
+aWMxIzAhBgNVBAoMGlB5dGhvbiBTb2Z0d2FyZSBGb3VuZGF0aW9uMSMwIQYDVQQD
+DBpzZWxmLXNpZ25lZC5weXRob250ZXN0Lm5ldDCCAiIwDQYJKoZIhvcNAQEBBQAD
+ggIPADCCAgoCggIBAMKdJlyCThkahwoBb7pl5q64Pe9Fn5jrIvzsveHTc97TpjV2
+RLfICnXKrltPk/ohkVl6K5SUZQZwMVzFubkyxE0nZPHYHlpiKWQxbsYVkYv01rix
+IFdLvaxxbGYke2jwQao31s4o61AdlsfK1SdpHQUynBBMssqI3SB4XPmcA7e+wEEx
+jxjVish4ixA1vuIZOx8yibu+CFCf/geEjoBMF3QPdzULzlrCSw8k/45iZCSoNbvK
+DoL4TVV07PHOxpheDh8ZQmepGvU6pVqhb9m4lgmV0OGWHgozd5Ur9CbTVDmxIEz3
+TSoRtNJK7qtyZdGNqwjksQxgZTjM/d/Lm/BJG99AiOmYOjsl9gbQMZgvQmMAtUsI
+aMJnQuZ6R+KEpW/TR5qSKLWZSG45z/op+tzI2m+cE6HwTRVAWbcuJxcAA55MZjqU
+OOOu3BBYMjS5nf2sQ9uoXsVBFH7i0mQqoW1SLzr9opI8KsWwFxQmO2vBxWYaN+lH
+OmwBZBwyODIsmI1YGXmTp09NxRYz3Qe5GCgFzYowpMrcxUC24iduIdMwwhRM7rKg
+7GtIWMSrFfuI1XCLRmSlhDbhNN6fVg2f8Bo9PdH9ihiIyxSrc+FOUasUYCCJvlSZ
+8hFUlLvcmrZlWuazohm0lsXuMK1JflmQr/DA/uXxP9xzFfRy+RU3jDyxJbRHAgMB
+AAGjUzBRMB0GA1UdDgQWBBSQJyxiPMRK01i+0BsV9zUwDiBaHzAfBgNVHSMEGDAW
+gBSQJyxiPMRK01i+0BsV9zUwDiBaHzAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3
+DQEBCwUAA4ICAQCR+7a7N/m+WLkxPPIA/CB4MOr2Uf8ixTv435Nyv6rXOun0+lTP
+ExSZ0uYQ+L0WylItI3cQHULldDueD+s8TGzxf5woaLKf6tqyr0NYhKs+UeNEzDnN
+9PHQIhX0SZw3XyXGUgPNBfRCg2ZDdtMMdOU4XlQN/IN/9hbYTrueyY7eXq9hmtI9
+1srftAMqr9SR1JP7aHI6DVgrEsZVMTDnfT8WmLSGLlY1HmGfdEn1Ip5sbo9uSkiH
+AEPgPfjYIvR5LqTOMn4KsrlZyBbFIDh9Sl99M1kZzgH6zUGVLCDg1y6Cms69fx/e
+W1HoIeVkY4b4TY7Bk7JsqyNhIuqu7ARaxkdaZWhYaA2YyknwANdFfNpfH+elCLIk
+BUt5S3f4i7DaUePTvKukCZiCq4Oyln7RcOn5If73wCeLB/ZM9Ei1HforyLWP1CN8
+XLfpHaoeoPSWIveI0XHUl65LsPN2UbMbul/F23hwl+h8+BLmyAS680Yhn4zEN6Ku
+B7Po90HoFa1Du3bmx4jsN73UkT/dwMTi6K072FbipnC1904oGlWmLwvAHvrtxxmL
+Pl3pvEaZIu8wa/PNF6Y7J7VIewikIJq6Ta6FrWeFfzMWOj2qA1ZZi6fUaDSNYvuV
+J5quYKCc/O+I/yDDf8wyBbZ/gvUXzUHTMYGG+bFrn1p7XDbYYeEJ6R/xEg==
+-----END CERTIFICATE-----
diff --git a/lib-python/3/_osx_support.py b/lib-python/3/_osx_support.py
--- a/lib-python/3/_osx_support.py
+++ b/lib-python/3/_osx_support.py
@@ -107,7 +107,9 @@
             if m is not None:
                 _SYSTEM_VERSION = '.'.join(m.group(1).split('.')[:2])
             # else: fall back to the default behaviour
-
+    if not _SYSTEM_VERSION:
+        # minimum supported MACOSX_DEPLOYMENT_TARGET version
+        return '10.14'
     return _SYSTEM_VERSION
 
 def _remove_original_values(_config_vars):
diff --git a/lib-python/3/ctypes/test/test_loading.py b/lib-python/3/ctypes/test/test_loading.py
--- a/lib-python/3/ctypes/test/test_loading.py
+++ b/lib-python/3/ctypes/test/test_loading.py
@@ -4,7 +4,6 @@
 import unittest
 import test.support
 from ctypes.util import find_library
-from ctypes.test import xfail
 
 libc_name = None
 
@@ -82,7 +81,6 @@
         self.assertRaises(AttributeError, dll.__getitem__, 1234)
 
     @unittest.skipUnless(os.name == "nt", 'Windows-specific test')
-    @xfail
     def test_1703286_A(self):
         from _ctypes import LoadLibrary, FreeLibrary
         # On winXP 64-bit, advapi32 loads at an address that does
@@ -94,7 +92,6 @@
         FreeLibrary(handle)
 
     @unittest.skipUnless(os.name == "nt", 'Windows-specific test')
-    @xfail
     def test_1703286_B(self):
         # Since on winXP 64-bit advapi32 loads like described
         # above, the (arbitrarily selected) CloseEventLog function
diff --git a/lib-python/3/datetime.py b/lib-python/3/datetime.py
--- a/lib-python/3/datetime.py
+++ b/lib-python/3/datetime.py
@@ -6,6 +6,7 @@
 
 import time as _time
 import math as _math
+import sys
 
 # for cpyext, use these as base classes
 from __pypy__._pypydatetime import dateinterop, deltainterop, timeinterop
@@ -1379,7 +1380,8 @@
 
     def __new__(cls, year, month=None, day=None, hour=0, minute=0, second=0,
                 microsecond=0, tzinfo=None, *, fold=0):
-        if isinstance(year, bytes) and len(year) == 10 and 1 <= year[2]&0x7F <= 12:
+        if (isinstance(year, (bytes, str)) and len(year) == 10 and
+            1 <= ord(year[2:3])&0x7F <= 12):
             # Pickle support
             self = dateinterop.__new__(cls)
             self.__setstate(year, month)
@@ -1456,6 +1458,14 @@
             # 23 hours at 1969-09-30 13:00:00 in Kwajalein.
             # Let's probe 24 hours in the past to detect a transition:
             max_fold_seconds = 24 * 3600
+
+            # On Windows localtime_s throws an OSError for negative values,
+            # thus we can't perform fold detection for values of time less
+            # than the max time fold. See comments in _datetimemodule's
+            # version of this method for more details.
+            if t < max_fold_seconds and sys.platform.startswith("win"):
+                return result
+
             y, m, d, hh, mm, ss = converter(t - max_fold_seconds)[:6]
             probe1 = cls(y, m, d, hh, mm, ss, us, tz)
             trans = result - probe1 - timedelta(0, max_fold_seconds)
diff --git a/lib-python/3/pdb.py b/lib-python/3/pdb.py
--- a/lib-python/3/pdb.py
+++ b/lib-python/3/pdb.py
@@ -341,8 +341,14 @@
     def interaction(self, frame, traceback):
         # Restore the previous signal handler at the Pdb prompt.
         if Pdb._previous_sigint_handler:
-            signal.signal(signal.SIGINT, Pdb._previous_sigint_handler)
-            Pdb._previous_sigint_handler = None
+            try:
+                signal.signal(signal.SIGINT, Pdb._previous_sigint_handler)
+                Pdb._previous_sigint_handler = None
+            except ValueError:
+                # ValueError happens when we're in a non-main thread,
+                # if we already invoked pdb in the same program from the
+                # main thread.  (PyPy fix)
+                pass
         if self.setup(frame, traceback):
             # no interaction desired at this time (happens if .pdbrc contains
             # a command like "continue")
diff --git a/lib-python/3/sysconfig.py b/lib-python/3/sysconfig.py
--- a/lib-python/3/sysconfig.py
+++ b/lib-python/3/sysconfig.py
@@ -563,6 +563,7 @@
             _CONFIG_VARS['abiflags'] = ''
         _CONFIG_VARS['implementation'] = _get_implementation()
         _CONFIG_VARS['implementation_lower'] = _get_implementation().lower()
+        _CONFIG_VARS['LIBRARY'] = ''
 
         if os.name == 'nt':
             _init_non_posix(_CONFIG_VARS)
diff --git a/lib-python/3/test/test_timeit.py b/lib-python/3/test/test_timeit.py
--- a/lib-python/3/test/test_timeit.py
+++ b/lib-python/3/test/test_timeit.py
@@ -366,9 +366,9 @@
     def test_main_recommends_perf(self):
         s = self.run_main(seconds_per_increment=2.0, switches=['-n35', '-s', 'print("CustomSetup")'])
         self.assertIn(dedent("""\
-            WARNING: timeit is a very unreliable tool. use perf or something else for real measurements
+            WARNING: timeit is a very unreliable tool. use pyperf or something else for real measurements
         """), s)
-        self.assertIn("-m pip install perf", s)
+        self.assertIn("-m pip install pyperf", s)
 
     def autorange(self, callback=None):
         timer = FakeTimer(seconds_per_increment=0.001)
diff --git a/lib-python/3/timeit.py b/lib-python/3/timeit.py
--- a/lib-python/3/timeit.py
+++ b/lib-python/3/timeit.py
@@ -310,10 +310,10 @@
             return 0
     setup = "\n".join(setup) or "pass"
 
-    print("WARNING: timeit is a very unreliable tool. use perf or something else for real measurements")
+    print("WARNING: timeit is a very unreliable tool. use pyperf or something else for real measurements")
     executable = os.path.basename(sys.executable)
-    print("%s -m pip install perf" % executable)
-    print("%s -m perf timeit %s" % (
+    print("%s -m pip install pyperf" % executable)
+    print("%s -m pyperf timeit %s" % (
         executable,
         " ".join([(arg if arg.startswith("-") else repr(arg))
                         for arg in origargs]), ))
diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -172,7 +172,7 @@
     RegrTest('test_coroutines.py'),
     RegrTest('test_cprofile.py'),
     RegrTest('test_crashers.py'),
-    RegrTest('test_crypt.py', usemodules='crypt'),
+    RegrTest('test_crypt.py'),
     RegrTest('test_csv.py', usemodules='_csv'),
     RegrTest('test_ctypes.py', usemodules="_rawffi thread cpyext"),
     RegrTest('test_curses.py'),
diff --git a/lib_pypy/_blake2/_blake2_build.py b/lib_pypy/_blake2/_blake2_build.py
--- a/lib_pypy/_blake2/_blake2_build.py
+++ b/lib_pypy/_blake2/_blake2_build.py
@@ -4,17 +4,18 @@
 
 from cffi import FFI
 
-IS_ARM = platform.machine().startswith('arm')
 IS_WIN = sys.platform == 'win32'
-if IS_ARM:
-    # XXX Choose neon accelaration
-    define_macros = []
-    extra_compile_args = []
-elif IS_WIN:
+if IS_WIN:
+    BLAKE2_USE_SSE = True
     extra_compile_args = []
     define_macros = [('__SSE2__', '1')]
+elif platform.machine().startswith('x86'):
+    BLAKE2_USE_SSE = True
+    extra_compile_args = ['-msse2']
+    define_macros = []
 else:
-    extra_compile_args = ['-msse2']
+    BLAKE2_USE_SSE = False
+    extra_compile_args = []
     define_macros = []
     
     
@@ -80,13 +81,18 @@
 
 
 _libdir = os.path.abspath(os.path.join(os.path.dirname(__file__), 'impl'))
+if BLAKE2_USE_SSE:
+    sourcesB=[os.path.join(_libdir, 'blake2b.c'), ]
+    sourcesS=[os.path.join(_libdir, 'blake2s.c'), ]
+else:    
+    sourcesB=[os.path.join(_libdir, 'blake2b-ref.c'), ]
+    sourcesS=[os.path.join(_libdir, 'blake2s-ref.c'), ]
 
 blake2b_ffi = FFI()
 blake2b_ffi.cdef(blake_cdef)
 blake2b_ffi.set_source(
     '_blake2b_cffi', blake2b_source,
-    sources=[os.path.join(_libdir, 'blake2b.c'),
-            ],
+    sources=sourcesB,
     include_dirs=[_libdir],
     extra_compile_args=extra_compile_args,
     define_macros=define_macros,
@@ -102,8 +108,7 @@
 blake2s_ffi.cdef(blake_cdef)
 blake2s_ffi.set_source(
     '_blake2s_cffi', _replace_b2s(blake2b_source),
-    sources=[os.path.join(_libdir, 'blake2s.c'),
-            ],
+    sources=sourcesS,
     include_dirs=[_libdir],
     extra_compile_args=extra_compile_args,
     define_macros=define_macros,
diff --git a/lib_pypy/_blake2/impl/blake2b.o b/lib_pypy/_blake2/impl/blake2b.o
deleted file mode 100644
index 0957bfc2e8b188b193b9eee3808641a638e0a2f7..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch

[cut]

diff --git a/lib_pypy/_cffi_ssl/.gitignore b/lib_pypy/_cffi_ssl/.gitignore
deleted file mode 100644
--- a/lib_pypy/_cffi_ssl/.gitignore
+++ /dev/null
@@ -1,95 +0,0 @@
-# Byte-compiled / optimized / DLL files
-__pycache__/
-*.py[cod]
-*$py.class
-
-# C extensions
-*.so
-
-# Distribution / packaging
-.Python
-env/
-build/
-develop-eggs/
-dist/
-downloads/
-eggs/
-.eggs/
-lib/
-lib64/
-parts/
-sdist/
-var/
-*.egg-info/
-.installed.cfg
-*.egg
-
-# PyInstaller
-#  Usually these files are written by a python script from a template
-#  before PyInstaller builds the exe, so as to inject date/other infos into it.
-*.manifest
-*.spec
-
-# Installer logs
-pip-log.txt
-pip-delete-this-directory.txt
-
-# Unit test / coverage reports
-htmlcov/
-.tox/
-.coverage
-.coverage.*
-.cache
-nosetests.xml
-coverage.xml
-*,cover
-.hypothesis/
-
-# Translations
-*.mo
-*.pot
-
-# Django stuff:
-*.log
-local_settings.py
-
-# Flask stuff:
-instance/
-.webassets-cache
-
-# Scrapy stuff:
-.scrapy
-
-# Sphinx documentation
-docs/_build/
-
-# PyBuilder
-target/
-
-# Jupyter Notebook
-.ipynb_checkpoints
-
-# pyenv
-.python-version
-
-# celery beat schedule file
-celerybeat-schedule
-
-# dotenv
-.env
-
-# virtualenv
-.venv/
-venv/
-ENV/
-
-# Spyder project settings
-.spyderproject
-
-# Rope project settings
-.ropeproject
-
-# Vim
-
-*.swp
-*.swo
diff --git a/lib_pypy/_cffi_ssl/__init__.py b/lib_pypy/_cffi_ssl/__init__.py
new file mode 100644
diff --git a/lib_pypy/_cffi_ssl/_cffi_src/openssl/ssl.py b/lib_pypy/_cffi_ssl/_cffi_src/openssl/ssl.py
--- a/lib_pypy/_cffi_ssl/_cffi_src/openssl/ssl.py
+++ b/lib_pypy/_cffi_ssl/_cffi_src/openssl/ssl.py
@@ -40,6 +40,11 @@
  */
 static const long Cryptography_HAS_OP_NO_COMPRESSION;
 
+/* Internally invented symbol to tell us if SSL_OP_ENABLE_MIDDLEBOX_COMPAT is
+ * supported
+ */
+static const long Cryptography_HAS_OP_ENABLE_MIDDLEBOX_COMPAT;
+
 static const long Cryptography_HAS_SSL_OP_MSIE_SSLV2_RSA_PADDING;
 static const long Cryptography_HAS_SSL_SET_SSL_CTX;
 static const long Cryptography_HAS_SSL_OP_NO_TICKET;
@@ -71,7 +76,9 @@
 static const long SSL_OP_MICROSOFT_SESS_ID_BUG;
 static const long SSL_OP_NETSCAPE_CHALLENGE_BUG;
 static const long SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG;
+static const long SSL_OP_NO_SSLv2;
 static const long SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG;
+static const long SSL_OP_ENABLE_MIDDLEBOX_COMPAT;
 static const long SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER;
 static const long SSL_OP_MSIE_SSLV2_RSA_PADDING;
 static const long SSL_OP_SSLEAY_080_CLIENT_DH_BUG;
@@ -559,6 +566,13 @@
 const long SSL_OP_NO_COMPRESSION = 0;
 #endif
 
+#ifdef SSL_OP_ENABLE_MIDDLEBOX_COMPAT
+static const long Cryptography_HAS_OP_ENABLE_MIDDLEBOX_COMPAT = 1;
+#else
+static const long Cryptography_HAS_OP_ENABLE_MIDDLEBOX_COMPAT = 0;
+const long SSL_OP_ENABLE_MIDDLEBOX_COMPAT = 0;
+#endif
+
 #ifdef SSL_OP_NO_TLSv1_1
 static const long Cryptography_HAS_TLSv1_1 = 1;
 #else
diff --git a/lib_pypy/_cffi_ssl/_stdssl/__init__.py b/lib_pypy/_cffi_ssl/_stdssl/__init__.py
--- a/lib_pypy/_cffi_ssl/_stdssl/__init__.py
+++ b/lib_pypy/_cffi_ssl/_stdssl/__init__.py
@@ -1,7 +1,6 @@
 import sys
 import time
 import _thread
-import socket
 import weakref
 from _pypy_openssl import ffi
 from _pypy_openssl import lib
@@ -21,6 +20,7 @@
         pyerr_write_unraisable)
 from _cffi_ssl._stdssl import error
 from select import select
+import socket
 from enum import IntEnum as _IntEnum
 
 if sys.platform == 'win32':
@@ -70,6 +70,7 @@
             globals()[name[4:]] = getattr(lib, name)
 
 OP_ALL = lib.SSL_OP_ALL & ~lib.SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
+OP_NO_SSLv2 = lib.SSL_OP_NO_SSLv2
 
 SSL_CLIENT = 0
 SSL_SERVER = 1
@@ -78,7 +79,8 @@
 
 if lib.Cryptography_HAS_SSL2:
     PROTOCOL_SSLv2  = 0
-PROTOCOL_SSLv3  = 1
+if lib.Cryptography_HAS_SSL3_METHOD:
+    PROTOCOL_SSLv3  = 1
 PROTOCOL_SSLv23 = 2
 PROTOCOL_TLS    = PROTOCOL_SSLv23
 PROTOCOL_TLSv1    = 3
@@ -220,6 +222,7 @@
     def _new__ssl_socket(sslctx, sock, socket_type, server_hostname, inbio, outbio):
         self = _SSLSocket(sslctx)
         ctx = sslctx.ctx
+        self.owner = None
 
         if server_hostname:
             self.server_hostname = server_hostname.decode('idna', 'strict')
@@ -288,7 +291,8 @@
     def owner(self, value):
         if value is None:
             self._owner = None
-        self._owner = weakref.ref(value)
+        else:
+            self._owner = weakref.ref(value)
 
     @property
     def context(self):
@@ -804,7 +808,7 @@
             method = lib.TLSv1_1_method()
         elif lib.Cryptography_HAS_TLSv1_2 and protocol == PROTOCOL_TLSv1_2 :
             method = lib.TLSv1_2_method()
-        elif protocol == PROTOCOL_SSLv3 and lib.Cryptography_HAS_SSL3_METHOD:
+        elif lib.Cryptography_HAS_SSL3_METHOD and protocol == PROTOCOL_SSLv3:
             method = lib.SSLv3_method()
         elif lib.Cryptography_HAS_SSL2 and protocol == PROTOCOL_SSLv2:
             method = lib.SSLv2_method()
@@ -835,7 +839,7 @@
         options = lib.SSL_OP_ALL & ~lib.SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
         if not lib.Cryptography_HAS_SSL2 or protocol != PROTOCOL_SSLv2:
             options |= lib.SSL_OP_NO_SSLv2
-        if protocol != PROTOCOL_SSLv3:
+        if not lib.Cryptography_HAS_SSL3_METHOD or protocol != PROTOCOL_SSLv3:
             options |= lib.SSL_OP_NO_SSLv3
         # Minimal security flags for server and client side context.
         # Client sockets ignore server-side parameters.
@@ -1055,7 +1059,7 @@
             self._add_ca_certs(buf, len(buf), ca_file_type)
 
         # load cafile or capath
-        if cafile or capath:
+        if cafile is not None or capath is not None:
             if cafile is None:
                 cafilebuf = ffi.NULL
             else:
@@ -1564,3 +1568,5 @@
                            "enough data to seed the PRNG");
         return bytecount
 
+socket.RAND_add = RAND_add
+socket.RAND_status = RAND_status
diff --git a/lib_pypy/_cffi_ssl/_stdssl/error.py b/lib_pypy/_cffi_ssl/_stdssl/error.py
--- a/lib_pypy/_cffi_ssl/_stdssl/error.py
+++ b/lib_pypy/_cffi_ssl/_stdssl/error.py
@@ -1,5 +1,6 @@
 import sys
 import os
+import socket
 import traceback
 from _pypy_openssl import ffi
 from _pypy_openssl import lib
@@ -26,6 +27,13 @@
         if self.strerror and isinstance(self.strerror, str):
             return self.strerror
         return str(self.args)
+# these are expected on socket as well
+socket.sslerror = SSLError
+for v in [ 'SSL_ERROR_ZERO_RETURN', 'SSL_ERROR_WANT_READ',
+     'SSL_ERROR_WANT_WRITE', 'SSL_ERROR_WANT_X509_LOOKUP', 'SSL_ERROR_SYSCALL',
+     'SSL_ERROR_SSL', 'SSL_ERROR_WANT_CONNECT', 'SSL_ERROR_EOF',
+     'SSL_ERROR_INVALID_ERROR_CODE' ]:
+    setattr(socket, v, locals()[v]) 
 
 class SSLZeroReturnError(SSLError):
     """ SSL/TLS session closed cleanly. """
diff --git a/lib_pypy/_cffi_ssl/_stdssl/utility.py b/lib_pypy/_cffi_ssl/_stdssl/utility.py
--- a/lib_pypy/_cffi_ssl/_stdssl/utility.py
+++ b/lib_pypy/_cffi_ssl/_stdssl/utility.py
@@ -19,7 +19,7 @@
     elif isinstance(view, memoryview):
         # NOTE pypy limitation StringBuffer does not allow
         # to get a raw address to the string!
-        view = bytes(view)
+        view = view.tobytes()
     # dont call call ffi.from_buffer(bytes(view)), arguments
     # like ints/bools should result in a TypeError
     return ffi.from_buffer(view)
diff --git a/lib_pypy/_cffi_ssl/_stdssl/win32_extra.py b/lib_pypy/_cffi_ssl/_stdssl/win32_extra.py
--- a/lib_pypy/_cffi_ssl/_stdssl/win32_extra.py
+++ b/lib_pypy/_cffi_ssl/_stdssl/win32_extra.py
@@ -1,101 +1,101 @@
 from _pypy_openssl import lib, ffi
-
-
-def enum_certificates(store_name):
-    """Retrieve certificates from Windows' cert store.
-
-store_name may be one of 'CA', 'ROOT' or 'MY'.  The system may provide
-more cert storages, too.  The function returns a list of (bytes,
-encoding_type, trust) tuples.  The encoding_type flag can be interpreted
-with X509_ASN_ENCODING or PKCS_7_ASN_ENCODING. The trust setting is either
-a set of OIDs or the boolean True.
-    """
-    hStore = lib.CertOpenStore(lib.CERT_STORE_PROV_SYSTEM_A, 0, ffi.NULL,
-                               lib.CERT_STORE_READONLY_FLAG | lib.CERT_SYSTEM_STORE_LOCAL_MACHINE,
-                               bytes(store_name, "ascii"))
-    if hStore == ffi.NULL:
-        raise WindowsError(*ffi.getwinerror())
-    
-    result = []
-    pCertCtx = ffi.NULL
-    try:
-        while True:
-            pCertCtx = lib.CertEnumCertificatesInStore(hStore, pCertCtx)
-            if pCertCtx == ffi.NULL:
-                break
-            cert = ffi.buffer(pCertCtx.pbCertEncoded, pCertCtx.cbCertEncoded)[:]
-            enc = certEncodingType(pCertCtx.dwCertEncodingType)
-            keyusage = parseKeyUsage(pCertCtx, lib.CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG)
-            if keyusage is True:
-                keyusage = parseKeyUsage(pCertCtx, lib.CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG)
-            result.append((cert, enc, keyusage))
-    finally:
-        if pCertCtx != ffi.NULL:
-            lib.CertFreeCertificateContext(pCertCtx)
-        if not lib.CertCloseStore(hStore, 0):
-            # This error case might shadow another exception.
-            raise WindowsError(*ffi.getwinerror())
-    return result
-
-
-def enum_crls(store_name):
-    """Retrieve CRLs from Windows' cert store.
-
-store_name may be one of 'CA', 'ROOT' or 'MY'.  The system may provide
-more cert storages, too.  The function returns a list of (bytes,
-encoding_type) tuples.  The encoding_type flag can be interpreted with
-X509_ASN_ENCODING or PKCS_7_ASN_ENCODING."""
-    hStore = lib.CertOpenStore(lib.CERT_STORE_PROV_SYSTEM_A, 0, ffi.NULL,
-                               lib.CERT_STORE_READONLY_FLAG | lib.CERT_SYSTEM_STORE_LOCAL_MACHINE,
-                               bytes(store_name, "ascii"))
-    if hStore == ffi.NULL:
-        raise WindowsError(*ffi.getwinerror())
-
-    result = []
-    pCrlCtx = ffi.NULL
-    try:
-        while True:
-            pCrlCtx = lib.CertEnumCRLsInStore(hStore, pCrlCtx)
-            if pCrlCtx == ffi.NULL:
-                break
-            crl = ffi.buffer(pCrlCtx.pbCrlEncoded, pCrlCtx.cbCrlEncoded)[:]
-            enc = certEncodingType(pCrlCtx.dwCertEncodingType)
-            result.append((crl, enc))
-    finally:
-        if pCrlCtx != ffi.NULL:
-            lib.CertFreeCRLContext(pCrlCtx)
-        if not lib.CertCloseStore(hStore, 0):
-            # This error case might shadow another exception.
-            raise WindowsError(*ffi.getwinerror())
-    return result
-
-
-def certEncodingType(encodingType):
-    if encodingType == lib.X509_ASN_ENCODING:
-        return "x509_asn"
-    if encodingType == lib.PKCS_7_ASN_ENCODING:
-        return "pkcs_7_asn"
-    return encodingType
-
-def parseKeyUsage(pCertCtx, flags):
-    pSize = ffi.new("DWORD *")
-    if not lib.CertGetEnhancedKeyUsage(pCertCtx, flags, ffi.NULL, pSize):
-        error_with_message = ffi.getwinerror()
-        if error_with_message[0] == lib.CRYPT_E_NOT_FOUND:
-            return True
-        raise WindowsError(*error_with_message)
-
-    pUsageMem = ffi.new("char[]", pSize[0])
-    pUsage = ffi.cast("PCERT_ENHKEY_USAGE", pUsageMem)
-    if not lib.CertGetEnhancedKeyUsage(pCertCtx, flags, pUsage, pSize):
-        error_with_message = ffi.getwinerror()
-        if error_with_message[0] == lib.CRYPT_E_NOT_FOUND:
-            return True
-        raise WindowsError(*error_with_message)
-
-    retval = set()
-    for i in range(pUsage.cUsageIdentifier):
-        if pUsage.rgpszUsageIdentifier[i]:
-            oid = ffi.string(pUsage.rgpszUsageIdentifier[i]).decode('ascii')
-            retval.add(oid)
-    return retval
+
+
+def enum_certificates(store_name):
+    """Retrieve certificates from Windows' cert store.
+
+store_name may be one of 'CA', 'ROOT' or 'MY'.  The system may provide
+more cert storages, too.  The function returns a list of (bytes,
+encoding_type, trust) tuples.  The encoding_type flag can be interpreted
+with X509_ASN_ENCODING or PKCS_7_ASN_ENCODING. The trust setting is either
+a set of OIDs or the boolean True.
+    """
+    hStore = lib.CertOpenStore(lib.CERT_STORE_PROV_SYSTEM_A, 0, ffi.NULL,
+                               lib.CERT_STORE_READONLY_FLAG | lib.CERT_SYSTEM_STORE_LOCAL_MACHINE,
+                               bytes(store_name, "ascii"))
+    if hStore == ffi.NULL:
+        raise WindowsError(*ffi.getwinerror())
+    
+    result = []
+    pCertCtx = ffi.NULL
+    try:
+        while True:
+            pCertCtx = lib.CertEnumCertificatesInStore(hStore, pCertCtx)
+            if pCertCtx == ffi.NULL:
+                break
+            cert = ffi.buffer(pCertCtx.pbCertEncoded, pCertCtx.cbCertEncoded)[:]
+            enc = certEncodingType(pCertCtx.dwCertEncodingType)
+            keyusage = parseKeyUsage(pCertCtx, lib.CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG)
+            if keyusage is True:
+                keyusage = parseKeyUsage(pCertCtx, lib.CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG)
+            result.append((cert, enc, keyusage))
+    finally:
+        if pCertCtx != ffi.NULL:
+            lib.CertFreeCertificateContext(pCertCtx)
+        if not lib.CertCloseStore(hStore, 0):
+            # This error case might shadow another exception.
+            raise WindowsError(*ffi.getwinerror())
+    return result
+
+
+def enum_crls(store_name):
+    """Retrieve CRLs from Windows' cert store.
+
+store_name may be one of 'CA', 'ROOT' or 'MY'.  The system may provide
+more cert storages, too.  The function returns a list of (bytes,
+encoding_type) tuples.  The encoding_type flag can be interpreted with
+X509_ASN_ENCODING or PKCS_7_ASN_ENCODING."""
+    hStore = lib.CertOpenStore(lib.CERT_STORE_PROV_SYSTEM_A, 0, ffi.NULL,
+                               lib.CERT_STORE_READONLY_FLAG | lib.CERT_SYSTEM_STORE_LOCAL_MACHINE,
+                               bytes(store_name, "ascii"))
+    if hStore == ffi.NULL:
+        raise WindowsError(*ffi.getwinerror())
+
+    result = []
+    pCrlCtx = ffi.NULL
+    try:
+        while True:
+            pCrlCtx = lib.CertEnumCRLsInStore(hStore, pCrlCtx)
+            if pCrlCtx == ffi.NULL:
+                break


More information about the pypy-commit mailing list