Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b04ded4

Browse files
committed
Also fixes test_hashlib for the different extension module names in py3k.
Merged revisions 77251 via svnmerge from svn+ssh://[email protected]/python/trunk ........ r77251 | gregory.p.smith | 2010-01-02 14:25:29 -0800 (Sat, 02 Jan 2010) | 6 lines Always compile the all versions of the hashlib algorithm modules when Python was compiled with Py_DEBUG defined. Otherwise the builtins are not compiled by default for many developers due to OpenSSL being present, making it easier for bugs to slip by. A future commit will add test code compare the behaviors of all implementations when they are all available. ........
1 parent cd54e54 commit b04ded4

2 files changed

Lines changed: 16 additions & 10 deletions

File tree

Lib/test/test_hashlib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ def _test_algorithm_via_hashlib_new(data=None, _alg=algorithm):
7878

7979
_md5 = self._conditional_import_module('_md5')
8080
if _md5:
81-
self.constructors_to_test['md5'].add(_md5.new)
82-
_sha = self._conditional_import_module('_sha')
83-
if _sha:
84-
self.constructors_to_test['sha1'].add(_sha.new)
81+
self.constructors_to_test['md5'].add(_md5.md5)
82+
_sha1 = self._conditional_import_module('_sha1')
83+
if _sha1:
84+
self.constructors_to_test['sha1'].add(_sha1.sha1)
8585
_sha256 = self._conditional_import_module('_sha256')
8686
if _sha256:
8787
self.constructors_to_test['sha224'].add(_sha256.sha224)

setup.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
from distutils.command.install import install
1616
from distutils.command.install_lib import install_lib
1717

18+
# Were we compiled --with-pydebug or with #define Py_DEBUG?
19+
COMPILED_WITH_PYDEBUG = hasattr(sys, 'gettotalrefcount')
20+
1821
# This global variable is used to hold the list of modules to be disabled.
1922
disabled_module_list = []
2023

@@ -593,9 +596,13 @@ def detect_modules(self):
593596
break
594597

595598
#print('openssl_ver = 0x%08x' % openssl_ver)
599+
min_openssl_ver = 0x00907000
600+
have_any_openssl = ssl_incs is not None and ssl_libs is not None
601+
have_usable_openssl = (have_any_openssl and
602+
openssl_ver >= min_openssl_ver)
596603

597-
if ssl_incs is not None and ssl_libs is not None:
598-
if openssl_ver >= 0x00907000:
604+
if have_any_openssl:
605+
if have_usable_openssl:
599606
# The _hashlib module wraps optimized implementations
600607
# of hash functions from the OpenSSL library.
601608
exts.append( Extension('_hashlib', ['_hashopenssl.c'],
@@ -606,15 +613,14 @@ def detect_modules(self):
606613
print("warning: openssl 0x%08x is too old for _hashlib" %
607614
openssl_ver)
608615
missing.append('_hashlib')
609-
else:
610-
missing.append('_hashlib')
611616

612-
if openssl_ver < 0x00908000:
617+
min_sha2_openssl_ver = 0x00908000
618+
if COMPILED_WITH_PYDEBUG or openssl_ver < min_sha2_openssl_ver:
613619
# OpenSSL doesn't do these until 0.9.8 so we'll bring our own hash
614620
exts.append( Extension('_sha256', ['sha256module.c']) )
615621
exts.append( Extension('_sha512', ['sha512module.c']) )
616622

617-
if openssl_ver < 0x00907000:
623+
if COMPILED_WITH_PYDEBUG or openssl_ver < min_openssl_ver:
618624
# no openssl at all, use our own md5 and sha1
619625
exts.append( Extension('_md5', ['md5module.c']) )
620626
exts.append( Extension('_sha1', ['sha1module.c']) )

0 commit comments

Comments
 (0)