]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #12306: Add ZLIB_RUNTIME_VERSION to the zlib module.
authorNadeem Vawda <nadeem.vawda@gmail.com>
Sun, 11 Sep 2011 22:04:13 +0000 (00:04 +0200)
committerNadeem Vawda <nadeem.vawda@gmail.com>
Sun, 11 Sep 2011 22:04:13 +0000 (00:04 +0200)
While we're at it, also document ZLIB_VERSION.

Patch by Torsten Landschoff.

Doc/library/zlib.rst
Lib/test/test_zlib.py
Misc/NEWS
Modules/zlibmodule.c

index 54835e7f7ee3fc4b6c1842a1e7618261163177aa..aab9ec7b2649bad9e3b1b6ebbee1902d1d53059f 100644 (file)
@@ -122,6 +122,7 @@ The available exception and functions in this module are:
    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 @@ Decompression objects support the following methods and attributes:
    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`
index dddde47f8cf30e6644f47b464eca8916599a2bda..8d137ac223f74dd2b44330314e7417bace36b766 100644 (file)
@@ -13,6 +13,17 @@ except ImportError:
     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 @@ LAERTES
 
 def test_main():
     support.run_unittest(
+        VersionTestCase,
         ChecksumTestCase,
         ChecksumBigBufferTestCase,
         ExceptionTestCase,
index d94f33c73fe0bf8abf004d3b27dda4eb45318cee..96e9ff5020f9a23b2db661c4f49052b160fa3404 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -274,6 +274,9 @@ Core and Builtins
 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
index f1f84e3b22578ce008226814a943136eb4b460d6..a6da056ea1b36237ab6ff4d6c0e33e5abb2cb59b 100644 (file)
@@ -1169,6 +1169,10 @@ PyInit_zlib(void)
     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;