[pypy-commit] pypy py3.6: merge default into py3.6
mattip
pypy.commits at gmail.com
Mon May 27 00:43:18 EDT 2019
Author: Matti Picus <matti.picus at gmail.com>
Branch: py3.6
Changeset: r96692:6912df235ecc
Date: 2019-05-27 07:36 +0300
http://bitbucket.org/pypy/pypy/changeset/6912df235ecc/
Log: merge default into py3.6
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;
@@ -73,6 +78,7 @@
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;
@@ -560,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
@@ -20,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':
@@ -221,6 +222,7 @@
def _new__ssl_socket(sslctx, sock, socket_type, server_hostname, inbio, outbio):
self = _SSLSocket(sslctx)
ctx = sslctx.ctx
+ self.owner = ssl_sock # weakref
if server_hostname:
self.server_hostname = server_hostname.decode('idna', 'strict')
@@ -289,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):
@@ -311,9 +314,6 @@
return self.socket_type == SSL_SERVER
def do_handshake(self):
- # delay to prevent circular imports
- import socket
-
sock = self.get_socket_or_connection_gone()
ssl = self.ssl
timeout = _socket_timeout(sock)
@@ -385,9 +385,6 @@
return _decode_certificate(self.peer_cert)
def write(self, bytestring):
- # delay to prevent circular imports
- import socket
-
deadline = 0
b = _str_to_ffi_buffer(bytestring)
sock = self.get_socket_or_connection_gone()
@@ -446,9 +443,6 @@
raise pyssl_error(self, length)
def read(self, length, buffer_into=None):
- # delay to prevent circular imports
- import socket
-
ssl = self.ssl
if length < 0 and buffer_into is None:
@@ -589,9 +583,6 @@
return sock
def shutdown(self):
- # delay to prevent circular imports
- import socket
-
sock = self.get_socket_or_None()
nonblocking = False
ssl = self.ssl
@@ -1068,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:
@@ -1577,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
@@ -26,6 +26,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/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))
+ 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))
+ 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
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
@@ -34,3 +34,7 @@
Move _ssl and _hashlib from rpython to a cffi-based module, like on python3.
Reduces the number of problematic linked-in libraries (libssl, libcrypto)
+
+.. branch: fix-vmprof-memory-tracking
+
+Fix a bug that prevent memory-tracking in vmprof working on PyPy.
diff --git a/pypy/module/_vmprof/interp_vmprof.py b/pypy/module/_vmprof/interp_vmprof.py
--- a/pypy/module/_vmprof/interp_vmprof.py
+++ b/pypy/module/_vmprof/interp_vmprof.py
@@ -60,11 +60,6 @@
'interval' is a float representing the sampling interval, in seconds.
Must be smaller than 1.0
"""
- w_modules = space.sys.get('modules')
- #if space.contains_w(w_modules, space.newtext('_continuation')):
- # space.warn(space.newtext("Using _continuation/greenlet/stacklet together "
- # "with vmprof will crash"),
- # space.w_RuntimeWarning)
try:
rvmprof.enable(fileno, period, memory, native, real_time)
except rvmprof.VMProfError as e:
diff --git a/rpython/jit/metainterp/test/test_ajit.py b/rpython/jit/metainterp/test/test_ajit.py
--- a/rpython/jit/metainterp/test/test_ajit.py
+++ b/rpython/jit/metainterp/test/test_ajit.py
@@ -3989,55 +3989,6 @@
# here it works again
self.check_operations_history(guard_class=0, record_exact_class=1)
- def test_record_exact_class_nonconst(self):
- class Base(object):
- def f(self):
- raise NotImplementedError
- def g(self):
- raise NotImplementedError
- class A(Base):
- def f(self):
- return self.a
- def g(self):
- return self.a + 1
- class B(Base):
- def f(self):
- return self.b
- def g(self):
- return self.b + 1
- class C(B):
- def f(self):
- self.c += 1
- return self.c
- def g(self):
- return self.c + 1
- @dont_look_inside
- def make(x):
- if x > 0:
- a = A()
- a.a = x + 1
- elif x < 0:
- a = B()
- a.b = -x
- else:
- a = C()
- a.c = 10
- return a, type(a)
- def f(x):
- a, cls = make(x)
- record_exact_class(a, cls)
- if x > 0:
- z = a.f()
- elif x < 0:
- z = a.f()
- else:
- z = a.f()
- return z + a.g()
- res1 = f(6)
- res2 = self.interp_operations(f, [6])
- assert res1 == res2
- self.check_operations_history(guard_class=1, record_exact_class=0)
-
def test_generator(self):
def g(n):
yield n+1
@@ -4889,3 +4840,52 @@
res = self.meta_interp(f, [0])
assert res == f(0)
+
+ def test_record_exact_class_nonconst(self):
+ class Base(object):
+ def f(self):
+ raise NotImplementedError
+ def g(self):
+ raise NotImplementedError
+ class A(Base):
+ def f(self):
+ return self.a
+ def g(self):
+ return self.a + 1
+ class B(Base):
+ def f(self):
+ return self.b
+ def g(self):
+ return self.b + 1
+ class C(B):
+ def f(self):
+ self.c += 1
+ return self.c
+ def g(self):
+ return self.c + 1
+ @dont_look_inside
+ def make(x):
+ if x > 0:
+ a = A()
+ a.a = x + 1
+ elif x < 0:
+ a = B()
+ a.b = -x
+ else:
+ a = C()
+ a.c = 10
+ return a, type(a)
+ def f(x):
+ a, cls = make(x)
+ record_exact_class(a, cls)
+ if x > 0:
+ z = a.f()
+ elif x < 0:
+ z = a.f()
+ else:
+ z = a.f()
+ return z + a.g()
+ res1 = f(6)
+ res2 = self.interp_operations(f, [6])
+ assert res1 == res2
+ self.check_operations_history(guard_class=1, record_exact_class=0)
diff --git a/rpython/rlib/_rsocket_rffi.py b/rpython/rlib/_rsocket_rffi.py
--- a/rpython/rlib/_rsocket_rffi.py
+++ b/rpython/rlib/_rsocket_rffi.py
@@ -225,6 +225,7 @@
('SOL_UDP', 17),
('SOMAXCONN', 5),
('IPPROTO_IP', 6),
+ ('IPPROTO_IPV6', 41),
('IPPROTO_ICMP', 1),
('IPPROTO_TCP', 6),
('IPPROTO_UDP', 17),
diff --git a/rpython/rlib/rvmprof/rvmprof.py b/rpython/rlib/rvmprof/rvmprof.py
--- a/rpython/rlib/rvmprof/rvmprof.py
+++ b/rpython/rlib/rvmprof/rvmprof.py
@@ -143,7 +143,7 @@
native = 0 # force disabled on Windows
lines = 0 # not supported on PyPy currently
- p_error = self.cintf.vmprof_init(fileno, interval, lines, memory, "pypy", native, real_time)
+ p_error = self.cintf.vmprof_init(fileno, interval, memory, lines, "pypy", native, real_time)
if p_error:
raise VMProfError(rffi.charp2str(p_error))
diff --git a/rpython/rlib/rvmprof/test/test_rvmprof.py b/rpython/rlib/rvmprof/test/test_rvmprof.py
--- a/rpython/rlib/rvmprof/test/test_rvmprof.py
+++ b/rpython/rlib/rvmprof/test/test_rvmprof.py
@@ -98,12 +98,12 @@
self.tmpfilename = str(self.tmpfile)
super(RVMProfSamplingTest, self).init()
- ENTRY_POINT_ARGS = (int, float)
- def entry_point(self, value, delta_t):
+ ENTRY_POINT_ARGS = (int, float, int)
+ def entry_point(self, value, delta_t, memory=0):
code = self.MyCode('py:code:52:test_enable')
rvmprof.register_code(code, self.MyCode.get_name)
fd = os.open(self.tmpfilename, os.O_WRONLY | os.O_CREAT, 0666)
- rvmprof.enable(fd, self.SAMPLING_INTERVAL)
+ rvmprof.enable(fd, self.SAMPLING_INTERVAL, memory=memory)
start = time.time()
res = 0
while time.time() < start+delta_t:
@@ -128,17 +128,25 @@
def test(self):
from vmprof import read_profile
- assert self.entry_point(10**4, 0.1) == 99990000
+ assert self.entry_point(10**4, 0.1, 0) == 99990000
assert self.tmpfile.check()
self.tmpfile.remove()
#
- assert self.rpy_entry_point(10**4, 0.5) == 99990000
+ assert self.rpy_entry_point(10**4, 0.5, 0) == 99990000
assert self.tmpfile.check()
prof = read_profile(self.tmpfilename)
tree = prof.get_tree()
assert tree.name == 'py:code:52:test_enable'
assert self.approx_equal(tree.count, 0.5/self.SAMPLING_INTERVAL)
+ def test_mem(self):
+ from vmprof import read_profile
+ assert self.rpy_entry_point(10**4, 0.5, 1) == 99990000
+ assert self.tmpfile.check()
+ prof = read_profile(self.tmpfilename)
+ assert prof.profile_memory
+ assert all(p[-1] > 0 for p in prof.profiles)
+
class TestNative(RVMProfSamplingTest):
@@ -177,7 +185,7 @@
def test(self):
from vmprof import read_profile
# from vmprof.show import PrettyPrinter
- assert self.rpy_entry_point(3, 0.5) == 42000
+ assert self.rpy_entry_point(3, 0.5, 0) == 42000
assert self.tmpfile.check()
prof = read_profile(self.tmpfilename)
More information about the pypy-commit
mailing list