[Python-checkins] cpython: Issue #12306: Add ZLIB_RUNTIME_VERSION to the zlib module.

nadeem.vawda python-checkins at python.org
Mon Sep 12 00:07:13 CEST 2011


http://hg.python.org/cpython/rev/b21d1de6d78e
changeset:   72341:b21d1de6d78e
user:        Nadeem Vawda <nadeem.vawda at gmail.com>
date:        Mon Sep 12 00:04:13 2011 +0200
summary:
  Issue #12306: Add ZLIB_RUNTIME_VERSION to the zlib module.

While we're at it, also document ZLIB_VERSION.

Patch by Torsten Landschoff.

files:
  Doc/library/zlib.rst  |  21 +++++++++++++++++++++
  Lib/test/test_zlib.py |  12 ++++++++++++
  Misc/NEWS             |   3 +++
  Modules/zlibmodule.c  |   4 ++++
  4 files changed, 40 insertions(+), 0 deletions(-)


diff --git a/Doc/library/zlib.rst b/Doc/library/zlib.rst
--- a/Doc/library/zlib.rst
+++ b/Doc/library/zlib.rst
@@ -122,6 +122,7 @@
    won't fit into memory at once.  The *wbits* parameter controls the size of the
    window buffer.
 
+
 Compression objects support the following methods:
 
 
@@ -217,6 +218,26 @@
    seeks into the stream at a future point.
 
 
+Information about the version of the zlib library in use is available through
+the following constants:
+
+
+.. data:: ZLIB_VERSION
+
+   The version string of the zlib library that was used for building the module.
+   This may be different from the zlib library actually used at runtime, which
+   is available as :const:`ZLIB_RUNTIME_VERSION`.
+
+   .. versionadded:: 3.3
+
+
+.. data:: ZLIB_RUNTIME_VERSION
+
+   The version string of the zlib library actually loaded by the interpreter.
+
+   .. versionadded:: 3.3
+
+
 .. seealso::
 
    Module :mod:`gzip`
diff --git a/Lib/test/test_zlib.py b/Lib/test/test_zlib.py
--- a/Lib/test/test_zlib.py
+++ b/Lib/test/test_zlib.py
@@ -13,6 +13,17 @@
     mmap = None
 
 
+class VersionTestCase(unittest.TestCase):
+
+    def test_library_version(self):
+        # On the build system, ZLIB_RUNTIME_VERSION should match ZLIB_VERSION.
+        # 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):
@@ -647,6 +658,7 @@
 
 def test_main():
     support.run_unittest(
+        VersionTestCase,
         ChecksumTestCase,
         ChecksumBigBufferTestCase,
         ExceptionTestCase,
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -274,6 +274,9 @@
 Library
 -------
 
+- Issue #12306: Expose the runtime version of the zlib C library as a constant,
+  ZLIB_RUNTIME_VERSION, in the zlib module. Patch by Torsten Landschoff.
+
 - Issue #12959: Add collections.ChainMap to collections.__all__.
 
 - Issue #12567: Add curses.unget_wch() function. Push a character so the next
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -1169,6 +1169,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;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list