Author: Manuel Jacob <m...@manueljacob.de> Branch: py3.6 Changeset: r92170:3cbf980069f5 Date: 2017-07-22 03:37 +0200 http://bitbucket.org/pypy/pypy/changeset/3cbf980069f5/
Log: hg merge py3.5 diff --git a/lib_pypy/_cffi_ssl/README.md b/lib_pypy/_cffi_ssl/README.md --- a/lib_pypy/_cffi_ssl/README.md +++ b/lib_pypy/_cffi_ssl/README.md @@ -5,9 +5,15 @@ it renames the compiled shared object to _pypy_openssl.so (which means that cryptography can ship their own cffi backend) -NOTE: currently, we have changed ``_cffi_src/openssl/callbacks.py`` to -not rely on the CPython C API, and ``_cffi_src/utils.py`` for issue #2575 -(29c9a89359e4). (The first change is now backported.) +NOTE: currently, we have the following changes: + +* ``_cffi_src/openssl/callbacks.py`` to not rely on the CPython C API + (this change is now backported) + +* ``_cffi_src/utils.py`` for issue #2575 (29c9a89359e4) + +* ``_cffi_src/openssl/x509_vfy.py`` for issue #2605 (ca4d0c90f5a1) + # Tests? diff --git a/lib_pypy/_cffi_ssl/_cffi_src/openssl/x509_vfy.py b/lib_pypy/_cffi_ssl/_cffi_src/openssl/x509_vfy.py --- a/lib_pypy/_cffi_ssl/_cffi_src/openssl/x509_vfy.py +++ b/lib_pypy/_cffi_ssl/_cffi_src/openssl/x509_vfy.py @@ -221,10 +221,16 @@ static const long X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM = 0; static const long X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED = 0; static const long X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 = 0; +#ifndef X509_V_ERR_HOSTNAME_MISMATCH static const long X509_V_ERR_HOSTNAME_MISMATCH = 0; +#endif +#ifndef X509_V_ERR_EMAIL_MISMATCH static const long X509_V_ERR_EMAIL_MISMATCH = 0; +#endif +#ifndef X509_V_ERR_IP_ADDRESS_MISMATCH static const long X509_V_ERR_IP_ADDRESS_MISMATCH = 0; #endif +#endif /* OpenSSL 1.0.2beta2+ verification parameters */ #if CRYPTOGRAPHY_OPENSSL_102BETA2_OR_GREATER && \ diff --git a/pypy/module/cpyext/object.py b/pypy/module/cpyext/object.py --- a/pypy/module/cpyext/object.py +++ b/pypy/module/cpyext/object.py @@ -462,6 +462,12 @@ fwrite(buf, 1, count, fp) return 0 +@cts.decl(""" + Py_ssize_t PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)""", + error=-1) +def PyObject_LengthHint(space, w_o, defaultvalue): + return space.length_hint(w_o, defaultvalue) + @cpython_api([lltype.Signed], lltype.Void) def _PyPyGC_AddMemoryPressure(space, report): from rpython.rlib import rgc diff --git a/pypy/module/cpyext/test/test_object.py b/pypy/module/cpyext/test/test_object.py --- a/pypy/module/cpyext/test/test_object.py +++ b/pypy/module/cpyext/test/test_object.py @@ -349,6 +349,27 @@ assert type(module.asbytes(sub1(b''))) is bytes assert type(module.asbytes(sub2(b''))) is sub2 + def test_LengthHint(self): + import operator + class WithLen: + def __len__(self): + return 1 + def __length_hint__(self): + return 42 + class NoLen: + def __length_hint__(self): + return 2 + module = self.import_extension('test_LengthHint', [ + ('length_hint', 'METH_VARARGS', + """ + PyObject *obj = PyTuple_GET_ITEM(args, 0); + Py_ssize_t i = PyLong_AsSsize_t(PyTuple_GET_ITEM(args, 1)); + return PyLong_FromSsize_t(PyObject_LengthHint(obj, i)); + """)]) + assert module.length_hint(WithLen(), 5) == operator.length_hint(WithLen(), 5) == 1 + assert module.length_hint(NoLen(), 5) == operator.length_hint(NoLen(), 5) == 2 + assert module.length_hint(object(), 5) == operator.length_hint(object(), 5) == 5 + def test_add_memory_pressure(self): self.reset_memory_pressure() # for the potential skip module = self.import_extension('foo', [ @@ -528,4 +549,3 @@ Py_RETURN_NONE; """)]) assert module.release() is None - 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 @@ -365,8 +365,8 @@ characters, all remaining cased characters have lowercase. """ - @unwrap_spec(w_deletechars=WrappedDefault('')) - def descr_translate(self, space, w_table, w_deletechars): + @unwrap_spec(w_delete=WrappedDefault('')) + def descr_translate(self, space, w_table, w_delete): """B.translate(table[, deletechars]) -> copy of B Return a copy of the string B, where all characters occurring diff --git a/pypy/objspace/std/stringmethods.py b/pypy/objspace/std/stringmethods.py --- a/pypy/objspace/std/stringmethods.py +++ b/pypy/objspace/std/stringmethods.py @@ -742,8 +742,8 @@ DEFAULT_NOOP_TABLE = ''.join([chr(i) for i in range(256)]) # for bytes and bytearray, overridden by unicode - @unwrap_spec(w_deletechars=WrappedDefault('')) - def descr_translate(self, space, w_table, w_deletechars): + @unwrap_spec(w_delete=WrappedDefault('')) + def descr_translate(self, space, w_table, w_delete): if space.is_w(w_table, space.w_None): table = self.DEFAULT_NOOP_TABLE else: @@ -753,7 +753,7 @@ "translation table must be 256 characters long") string = self._val(space) - deletechars = self._op_val(space, w_deletechars) + deletechars = self._op_val(space, w_delete) if len(deletechars) == 0: buf = self._builder(len(string)) for char in string: diff --git a/rpython/translator/c/genc.py b/rpython/translator/c/genc.py --- a/rpython/translator/c/genc.py +++ b/rpython/translator/c/genc.py @@ -382,6 +382,80 @@ if self.config.translation.profopt: if self.config.translation.profoptargs is None: raise Exception("No profoptargs specified, neither in the command line, nor in the target. If the target is not PyPy, please specify profoptargs") + + # Set the correct PGO params based on OS and CC + profopt_gen_flag = "" + profopt_use_flag = "" + profopt_merger = "" + profopt_file = "" + llvm_profdata = "" + + cc = self.translator.platform.cc + + # Locate llvm-profdata + if "clang" in cc: + clang_bin = cc + path = os.environ.get("PATH").split(":") + profdata_found = False + + # Try to find it in $PATH (Darwin and Linux) + for dir in path: + bin = "%s/llvm-profdata" % dir + if os.path.isfile(bin): + llvm_profdata = bin + profdata_found = True + break + + # If not found, try to find it where clang is actually installed (Darwin and Linux) + if not profdata_found: + # If the full path is not given, find where clang is located + if not os.path.isfile(clang_bin): + for dir in path: + bin = "%s/%s" % (dir, cc) + if os.path.isfile(bin): + clang_bin = bin + break + # Some systems install clang elsewhere as a symlink to the real path, + # which is where the related llvm tools are located. + if os.path.islink(clang_bin): + clang_bin = os.path.realpath(clang_bin) # the real clang binary + # llvm-profdata must be in the same directory as clang + llvm_profdata = "%s/llvm-profdata" % os.path.dirname(clang_bin) + profdata_found = os.path.isfile(llvm_profdata) + + # If not found, and Darwin is used, try to find it in the development environment + # More: https://apple.stackexchange.com/questions/197053/ + if not profdata_found and sys.platform == 'darwin': + code = os.system("/usr/bin/xcrun -find llvm-profdata 2>/dev/null") + if code == 0: + llvm_profdata = "/usr/bin/xcrun llvm-profdata" + profdata_found = True + + # If everything failed, throw Exception, sorry + if not profdata_found: + raise Exception( + "Error: Cannot perform profopt build because llvm-profdata was not found in PATH. " + "Please add it to PATH and run the translation again.") + + # Set the PGO flags + if "clang" in cc: + # Any changes made here should be reflected in the GCC+Darwin case below + profopt_gen_flag = "-fprofile-instr-generate" + profopt_use_flag = "-fprofile-instr-use=code.profclangd" + profopt_merger = "%s merge -output=code.profclangd *.profclangr" % llvm_profdata + profopt_file = 'LLVM_PROFILE_FILE="code-%p.profclangr"' + elif "gcc" in cc: + if sys.platform == 'darwin': + profopt_gen_flag = "-fprofile-instr-generate" + profopt_use_flag = "-fprofile-instr-use=code.profclangd" + profopt_merger = "%s merge -output=code.profclangd *.profclangr" % llvm_profdata + profopt_file = 'LLVM_PROFILE_FILE="code-%p.profclangr"' + else: + profopt_gen_flag = "-fprofile-generate" + profopt_use_flag = "-fprofile-use -fprofile-correction" + profopt_merger = "true" + profopt_file = "" + if self.config.translation.shared: mk.rule('$(PROFOPT_TARGET)', '$(TARGET) main.o', '$(CC_LINK) $(LDFLAGS_LINK) main.o -L. -l$(SHARED_IMPORT_LIB) -o $@ $(RPATH_FLAGS) -lgcov') @@ -390,10 +464,11 @@ rules.append( ('profopt', '', [ - '$(MAKE) CFLAGS="-fprofile-generate -fPIC $(CFLAGS) -fno-lto" LDFLAGS="-fprofile-generate $(LDFLAGS) -fno-lto" $(PROFOPT_TARGET)', - '%s %s ' % (exe_name, self.config.translation.profoptargs), + '$(MAKE) CFLAGS="%s -fPIC $(CFLAGS)" LDFLAGS="%s $(LDFLAGS)" $(PROFOPT_TARGET)' % (profopt_gen_flag, profopt_gen_flag), + '%s %s %s ' % (profopt_file, exe_name, self.config.translation.profoptargs), + '%s' % (profopt_merger), '$(MAKE) clean_noprof', - '$(MAKE) CFLAGS="-fprofile-use -fprofile-correction -fPIC $(CFLAGS) -fno-lto" LDFLAGS="-fprofile-use $(LDFLAGS) -fno-lto" $(PROFOPT_TARGET)', + '$(MAKE) CFLAGS="%s -fPIC $(CFLAGS)" LDFLAGS="%s $(LDFLAGS)" $(PROFOPT_TARGET)' % (profopt_use_flag, profopt_use_flag), ])) for rule in rules: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit