diff -r d07d0afea9a7 Doc/library/zlib.rst --- a/Doc/library/zlib.rst Mon Jun 13 16:19:06 2011 +0200 +++ b/Doc/library/zlib.rst Mon Jun 13 20:29:27 2011 +0200 @@ -213,6 +213,13 @@ seeks into the stream at a future point. +.. data:: ZLIB_RUNTIME_VERSION + + The version string of the zlib library actually loaded by the interpreter. + + .. versionadded:: 3.3 + + .. seealso:: Module :mod:`gzip` diff -r d07d0afea9a7 Lib/test/test_zlib.py --- a/Lib/test/test_zlib.py Mon Jun 13 16:19:06 2011 +0200 +++ b/Lib/test/test_zlib.py Mon Jun 13 20:29:27 2011 +0200 @@ -13,6 +13,16 @@ mmap = None +class VersionTestCase(unittest.TestCase): + + def test_library_version(self): + # On the build system, ZLIB_RUNTIME_VERSION and ZLIB_VERSION should match. + # ZLIB_RUNTIME_VERSION is the actual library version while ZLIB_VERSION is + # the version from the header file. On the build system, the headers + # should match with the library exactly. At runtime, only the first + # digit is required to match. + self.assertEqual(zlib.ZLIB_RUNTIME_VERSION, zlib.ZLIB_VERSION) + class ChecksumTestCase(unittest.TestCase): # checksum test cases def test_crc32start(self): @@ -627,6 +637,7 @@ def test_main(): support.run_unittest( + VersionTestCase, ChecksumTestCase, ChecksumBigBufferTestCase, ExceptionTestCase, diff -r d07d0afea9a7 Modules/zlibmodule.c --- a/Modules/zlibmodule.c Mon Jun 13 16:19:06 2011 +0200 +++ b/Modules/zlibmodule.c Mon Jun 13 20:29:27 2011 +0200 @@ -1158,6 +1158,10 @@ if (ver != NULL) PyModule_AddObject(m, "ZLIB_VERSION", ver); + ver = PyUnicode_FromString(zlibVersion()); + if (ver != NULL) + PyModule_AddObject(m, "ZLIB_RUNTIME_VERSION", ver); + PyModule_AddStringConstant(m, "__version__", "1.0"); return m;