]> granicus.if.org Git - python/commitdiff
Patch #1503046, Conditional compilation of zlib.(de)compressobj.copy
authorNeal Norwitz <nnorwitz@gmail.com>
Mon, 12 Jun 2006 03:33:09 +0000 (03:33 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Mon, 12 Jun 2006 03:33:09 +0000 (03:33 +0000)
copy is only in newer versions of zlib.  This should allow zlibmodule
to work with older versions like the Tru64 buildbot.

Lib/test/test_zlib.py
Misc/ACKS
Modules/zlibmodule.c
configure
configure.in
pyconfig.h.in

index ccbc8fd0b2d27ed30a576692f9b5b095014907c7..4440942ac9d7939c84415eed89be2885f9c52345 100644 (file)
@@ -302,63 +302,65 @@ class CompressObjectTestCase(unittest.TestCase):
         dco = zlib.decompressobj()
         self.assertEqual(dco.flush(), "") # Returns nothing
 
-    def test_compresscopy(self):
-        # Test copying a compression object
-        data0 = HAMLET_SCENE
-        data1 = HAMLET_SCENE.swapcase()
-        c0 = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
-        bufs0 = []
-        bufs0.append(c0.compress(data0))
-
-        c1 = c0.copy()
-        bufs1 = bufs0[:]
-
-        bufs0.append(c0.compress(data0))
-        bufs0.append(c0.flush())
-        s0 = ''.join(bufs0)
-
-        bufs1.append(c1.compress(data1))
-        bufs1.append(c1.flush())
-        s1 = ''.join(bufs1)
-
-        self.assertEqual(zlib.decompress(s0),data0+data0)
-        self.assertEqual(zlib.decompress(s1),data0+data1)
-
-    def test_badcompresscopy(self):
-        # Test copying a compression object in an inconsistent state
-        c = zlib.compressobj()
-        c.compress(HAMLET_SCENE)
-        c.flush()
-        self.assertRaises(ValueError, c.copy)
-
-    def test_decompresscopy(self):
-        # Test copying a decompression object
-        data = HAMLET_SCENE
-        comp = zlib.compress(data)
-
-        d0 = zlib.decompressobj()
-        bufs0 = []
-        bufs0.append(d0.decompress(comp[:32]))
-
-        d1 = d0.copy()
-        bufs1 = bufs0[:]
-
-        bufs0.append(d0.decompress(comp[32:]))
-        s0 = ''.join(bufs0)
-
-        bufs1.append(d1.decompress(comp[32:]))
-        s1 = ''.join(bufs1)
-
-        self.assertEqual(s0,s1)
-        self.assertEqual(s0,data)
-
-    def test_baddecompresscopy(self):
-        # Test copying a compression object in an inconsistent state
-        data = zlib.compress(HAMLET_SCENE)
-        d = zlib.decompressobj()
-        d.decompress(data)
-        d.flush()
-        self.assertRaises(ValueError, d.copy)
+    if hasattr(zlib.compressobj(), "copy"):
+        def test_compresscopy(self):
+            # Test copying a compression object
+            data0 = HAMLET_SCENE
+            data1 = HAMLET_SCENE.swapcase()
+            c0 = zlib.compressobj(zlib.Z_BEST_COMPRESSION)
+            bufs0 = []
+            bufs0.append(c0.compress(data0))
+
+            c1 = c0.copy()
+            bufs1 = bufs0[:]
+
+            bufs0.append(c0.compress(data0))
+            bufs0.append(c0.flush())
+            s0 = ''.join(bufs0)
+
+            bufs1.append(c1.compress(data1))
+            bufs1.append(c1.flush())
+            s1 = ''.join(bufs1)
+
+            self.assertEqual(zlib.decompress(s0),data0+data0)
+            self.assertEqual(zlib.decompress(s1),data0+data1)
+
+        def test_badcompresscopy(self):
+            # Test copying a compression object in an inconsistent state
+            c = zlib.compressobj()
+            c.compress(HAMLET_SCENE)
+            c.flush()
+            self.assertRaises(ValueError, c.copy)
+
+    if hasattr(zlib.decompressobj(), "copy"):
+        def test_decompresscopy(self):
+            # Test copying a decompression object
+            data = HAMLET_SCENE
+            comp = zlib.compress(data)
+
+            d0 = zlib.decompressobj()
+            bufs0 = []
+            bufs0.append(d0.decompress(comp[:32]))
+
+            d1 = d0.copy()
+            bufs1 = bufs0[:]
+
+            bufs0.append(d0.decompress(comp[32:]))
+            s0 = ''.join(bufs0)
+
+            bufs1.append(d1.decompress(comp[32:]))
+            s1 = ''.join(bufs1)
+
+            self.assertEqual(s0,s1)
+            self.assertEqual(s0,data)
+
+        def test_baddecompresscopy(self):
+            # Test copying a compression object in an inconsistent state
+            data = zlib.compress(HAMLET_SCENE)
+            d = zlib.decompressobj()
+            d.decompress(data)
+            d.flush()
+            self.assertRaises(ValueError, d.copy)
 
 def genblock(seed, length, step=1024, generator=random):
     """length-byte stream of random data from a seed (in step-byte blocks)."""
index e30cc6147cb243e3afe805660dfb4c39c9cbe058..4e29c7a2ca319a2cc8e93fd123c65e7c21238374 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -24,6 +24,7 @@ Ross Andrus
 Jason Asbahr
 David Ascher
 Peter Åstrand
+Chris AtLee
 John Aycock
 Donovan Baarda
 Attila Babo
index 06b0690ecf8ae2b592a53e8b880ec933dce7273a..da31e8b2827d48c63bdb5d314ccc1d74e9695385 100644 (file)
@@ -653,6 +653,7 @@ PyZlib_flush(compobject *self, PyObject *args)
     return RetVal;
 }
 
+#ifdef HAVE_ZLIB_COPY
 PyDoc_STRVAR(comp_copy__doc__,
 "copy() -- Return a copy of the compression object.");
 
@@ -754,6 +755,7 @@ error:
     Py_XDECREF(retval);
     return NULL;
 }
+#endif
 
 PyDoc_STRVAR(decomp_flush__doc__,
 "flush( [length] ) -- Return a string containing any remaining\n"
@@ -827,8 +829,10 @@ static PyMethodDef comp_methods[] =
                  comp_compress__doc__},
     {"flush", (binaryfunc)PyZlib_flush, METH_VARARGS,
               comp_flush__doc__},
+#ifdef HAVE_ZLIB_COPY
     {"copy",  (PyCFunction)PyZlib_copy, METH_NOARGS,
               comp_copy__doc__},
+#endif
     {NULL, NULL}
 };
 
@@ -838,8 +842,10 @@ static PyMethodDef Decomp_methods[] =
                    decomp_decompress__doc__},
     {"flush", (binaryfunc)PyZlib_unflush, METH_VARARGS,
               decomp_flush__doc__},
+#ifdef HAVE_ZLIB_COPY
     {"copy",  (PyCFunction)PyZlib_uncopy, METH_NOARGS,
               decomp_copy__doc__},
+#endif
     {NULL, NULL}
 };
 
index b698807968dfe21b942c1a22c039634fb1d4b607..ca50d4b00268e59761004422d83bedac7b034b47 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 46720 .
+# From configure.in Revision: 46879 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.59 for python 2.5.
 #
 fi
 
 
+echo "$as_me:$LINENO: checking for inflateCopy in -lz" >&5
+echo $ECHO_N "checking for inflateCopy in -lz... $ECHO_C" >&6
+if test "${ac_cv_lib_z_inflateCopy+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lz  $LIBS"
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any gcc2 internal prototype to avoid an error.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+/* We use char because int might match the return type of a gcc2
+   builtin and then its argument prototype would still apply.  */
+char inflateCopy ();
+int
+main ()
+{
+inflateCopy ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+  (eval $ac_link) 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+        { ac_try='test -z "$ac_c_werror_flag"
+                        || test ! -s conftest.err'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; } &&
+        { ac_try='test -s conftest$ac_exeext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+  ac_cv_lib_z_inflateCopy=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_lib_z_inflateCopy=no
+fi
+rm -f conftest.err conftest.$ac_objext \
+      conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+echo "$as_me:$LINENO: result: $ac_cv_lib_z_inflateCopy" >&5
+echo "${ECHO_T}$ac_cv_lib_z_inflateCopy" >&6
+if test $ac_cv_lib_z_inflateCopy = yes; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_ZLIB_COPY 1
+_ACEOF
+
+fi
+
+
 echo "$as_me:$LINENO: checking for hstrerror" >&5
 echo $ECHO_N "checking for hstrerror... $ECHO_C" >&6
 cat >conftest.$ac_ext <<_ACEOF
@@ -22056,10 +22129,9 @@ for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
   # 1. Remove the extension, and $U if already installed.
   ac_i=`echo "$ac_i" |
         sed 's/\$U\././;s/\.o$//;s/\.obj$//'`
-  # 2. Prepend LIBOBJDIR.  When used with automake>=1.10 LIBOBJDIR
-  #    will be set to the directory where LIBOBJS objects are built.
-  ac_libobjs="$ac_libobjs \${LIBOBJDIR}$ac_i\$U.$ac_objext"
-  ac_ltlibobjs="$ac_ltlibobjs \${LIBOBJDIR}$ac_i"'$U.lo'
+  # 2. Add them.
+  ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext"
+  ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo'
 done
 LIBOBJS=$ac_libobjs
 
index cca20a845565ce92b0765b13b0891f251e82280a..1b7b57e0a8bba495bca6e4b5d49327c9790fde48 100644 (file)
@@ -2351,6 +2351,9 @@ AC_CHECK_LIB(c, inet_aton, [$ac_cv_prog_TRUE],
   AC_CHECK_LIB(resolv, inet_aton)
 )
 
+dnl Check if system zlib has *Copy() functions
+AC_CHECK_LIB(z, inflateCopy, AC_DEFINE(HAVE_ZLIB_COPY, 1, Define if the zlib library has inflateCopy))
+
 AC_MSG_CHECKING(for hstrerror)
 AC_TRY_LINK([
 #include "confdefs.h" 
index e8f0d8b0626b0157111865ac5ebc3f2b9a4f0215..84486ca522d7c96d33edf56b5ba60ae04132bdcb 100644 (file)
    */
 #undef HAVE_WORKING_TZSET
 
+/* Define if the zlib library has inflateCopy */
+#undef HAVE_ZLIB_COPY
+
 /* Define to 1 if you have the `_getpty' function. */
 #undef HAVE__GETPTY