]> granicus.if.org Git - python/commitdiff
Merged revisions 61834,61841-61842,61851-61853,61863-61864,61869-61870,61874,61889...
authorChristian Heimes <christian@cheimes.de>
Tue, 25 Mar 2008 14:56:36 +0000 (14:56 +0000)
committerChristian Heimes <christian@cheimes.de>
Tue, 25 Mar 2008 14:56:36 +0000 (14:56 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r61834 | raymond.hettinger | 2008-03-24 07:07:49 +0100 (Mon, 24 Mar 2008) | 1 line

  Tighten documentation for Random.triangular.
........
  r61841 | raymond.hettinger | 2008-03-24 09:17:39 +0100 (Mon, 24 Mar 2008) | 1 line

  Issue 2460: Make Ellipsis objects copyable.
........
  r61842 | georg.brandl | 2008-03-24 10:34:34 +0100 (Mon, 24 Mar 2008) | 2 lines

  #1700821: add a note to audioop docs about signedness of sample formats.
........
  r61851 | christian.heimes | 2008-03-24 20:57:42 +0100 (Mon, 24 Mar 2008) | 1 line

  Added quick hack for bzr
........
  r61852 | christian.heimes | 2008-03-24 20:58:17 +0100 (Mon, 24 Mar 2008) | 1 line

  Added quick hack for bzr
........
  r61853 | amaury.forgeotdarc | 2008-03-24 22:04:10 +0100 (Mon, 24 Mar 2008) | 4 lines

  Issue2469: Correct a typo I introduced at r61793: compilation error with UCS4 builds.

  All buildbots compile with UCS2...
........
  r61863 | neal.norwitz | 2008-03-25 05:17:38 +0100 (Tue, 25 Mar 2008) | 2 lines

  Fix a bunch of UnboundLocalErrors when the tests fail.
........
  r61864 | neal.norwitz | 2008-03-25 05:18:18 +0100 (Tue, 25 Mar 2008) | 2 lines

  Try to fix a bunch of compiler warnings on Win64.
........
  r61869 | neal.norwitz | 2008-03-25 07:35:10 +0100 (Tue, 25 Mar 2008) | 3 lines

  Don't try to close a non-open file.
  Don't let file removal cause the test to fail.
........
  r61870 | neal.norwitz | 2008-03-25 08:00:39 +0100 (Tue, 25 Mar 2008) | 7 lines

  Try to get this test to be more stable:
   * disable gc during the test run because we are spawning objects and there
     was an exception when calling Popen.__del__
   * Always set an alarm handler so the process doesn't exit if the test fails
     (should probably add assertions on the value of hndl_called in more places)
   * Using a negative time causes Linux to treat it as zero, so disable that test.
........
  r61874 | gregory.p.smith | 2008-03-25 08:31:28 +0100 (Tue, 25 Mar 2008) | 2 lines

  Use a 32-bit unsigned int here, a long is not needed.
........
  r61889 | georg.brandl | 2008-03-25 12:59:51 +0100 (Tue, 25 Mar 2008) | 2 lines

  Move declarations to block start.
........

12 files changed:
Doc/library/audioop.rst
Doc/library/random.rst
Lib/copy.py
Lib/test/test_deque.py
Lib/test/test_set.py
Lib/test/test_signal.py
Modules/binascii.c
Modules/zlibmodule.c
Objects/unicodeobject.c
PC/_winreg.c
PC/w9xpopen.c
Python/peephole.c

index 8ee2795a9eba04e9ee0322dfd5c495a70208f7bb..9eb315fdf530a40d732432459a19e3eb3c0c23d9 100644 (file)
@@ -136,6 +136,18 @@ The module defines the following variables and functions:
 
    Convert samples between 1-, 2- and 4-byte formats.
 
+   .. note::
+
+      In some audio formats, such as .WAV files, 16 and 32 bit samples are
+      signed, but 8 bit samples are unsigned.  So when converting to 8 bit wide
+      samples for these formats, you need to also add 128 to the result::
+
+         new_frames = audioop.lin2lin(frames, old_width, 1)
+         new_frames = audioop.bias(new_frames, 1, 128)
+
+      The same, in reverse, has to be applied when converting from 8 to 16 or 32
+      bit width samples.
+
 
 .. function:: lin2ulaw(fragment, width)
 
index 0b82bf47bb69986b449659f6d175cd7fb0885ee7..86a9a9549a15286cc37b05f856fb8dfd197ec77e 100644 (file)
@@ -155,13 +155,13 @@ be found in any statistics text.
 
 .. function:: triangular(low, high, mode)
 
-   Return a random floating point number *N* such that ``low <= N < high``
-   and with the specified *mode* between those bounds.
+   Return a random floating point number *N* such that ``low <= N < high`` and
+   with the specified *mode* between those bounds.  The *low* and *high* bounds
+   default to zero and one.  The *mode* argument defaults to the midpoint
+   between the bounds, giving a symmetric distribution.
 
-   If *mode* is not specified or is ``None``, it defaults to the midpoint
-   between the upper and lower bounds, producing a symmetric distribution.
+   .. versionadded:: 2.6
 
-   The default values for *low* and *high* are zero and one.
 
 .. function:: betavariate(alpha, beta)
 
index 1a14f0ed7fed22001c5eee530482694ad15c9515..ec108b71335bcf6bc227928c1e69df4511271818 100644 (file)
@@ -101,7 +101,7 @@ def _copy_immutable(x):
     return x
 for t in (type(None), int, float, bool, str, tuple,
           frozenset, type, range,
-          types.BuiltinFunctionType,
+          types.BuiltinFunctionType, type(Ellipsis),
           types.FunctionType):
     d[t] = _copy_immutable
 t = getattr(types, "CodeType", None)
@@ -180,6 +180,7 @@ _deepcopy_dispatch = d = {}
 def _deepcopy_atomic(x, memo):
     return x
 d[type(None)] = _deepcopy_atomic
+d[type(Ellipsis)] = _deepcopy_atomic
 d[int] = _deepcopy_atomic
 d[float] = _deepcopy_atomic
 d[bool] = _deepcopy_atomic
index 12f77a97a1c65f95fa5abcb390b9faea192680ac..c8d0c7ec2a09d38684adcebf1707a2df0b65d6d7 100644 (file)
@@ -64,8 +64,27 @@ class TestBasic(unittest.TestCase):
         self.assertEqual(list(d), [7, 8, 9])
         d = deque(range(200), maxlen=10)
         d.append(d)
+        fo = open(test_support.TESTFN, "w")
+        try:
+            fo.write(str(d))
+            fo.close()
+            fo = open(test_support.TESTFN, "r")
+            self.assertEqual(fo.read(), repr(d))
+        finally:
+            fo.close()
+            test_support.unlink(test_support.TESTFN)
+
         d = deque(range(10), maxlen=None)
         self.assertEqual(repr(d), 'deque([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])')
+        fo = open(test_support.TESTFN, "w")
+        try:
+            fo.write(str(d))
+            fo.close()
+            fo = open(test_support.TESTFN, "r")
+            self.assertEqual(fo.read(), repr(d))
+        finally:
+            fo.close()
+            test_support.unlink(test_support.TESTFN)
 
     def test_comparisons(self):
         d = deque('xabc'); d.popleft()
@@ -265,13 +284,13 @@ class TestBasic(unittest.TestCase):
         d.append(d)
         try:
             fo = open(test_support.TESTFN, "w")
-            fo.write(str(d))
+            print(d, file=fo, end='')
             fo.close()
             fo = open(test_support.TESTFN, "r")
             self.assertEqual(fo.read(), repr(d))
         finally:
             fo.close()
-            os.remove(test_support.TESTFN)
+            test_support.unlink(test_support.TESTFN)
 
     def test_init(self):
         self.assertRaises(TypeError, deque, 'abc', 2, 3);
index ca3c02e383ed3b9fc4ac8533396c3d09f1d8486a..44a45afa60aba783286c26ed5740d0dbe5e4fb66 100644 (file)
@@ -295,7 +295,7 @@ class TestJointOps(unittest.TestCase):
             self.assertEqual(fo.read(), repr(s))
         finally:
             fo.close()
-            os.remove(test_support.TESTFN)
+            test_support.unlink(test_support.TESTFN)
 
     def test_do_not_rehash_dict_keys(self):
         n = 10
@@ -679,7 +679,7 @@ class TestBasicOps(unittest.TestCase):
             self.assertEqual(fo.read(), repr(self.set))
         finally:
             fo.close()
-            os.remove(test_support.TESTFN)
+            test_support.unlink(test_support.TESTFN)
 
     def test_length(self):
         self.assertEqual(len(self.set), self.length)
index 2cee626e91fe3a3fd8acbbc0ab2fb6bc32a23618..3c039a14e5d60a8eb8f4fce04eff7368351f0526 100644 (file)
@@ -1,6 +1,7 @@
 import unittest
 from test import test_support
 from contextlib import closing, nested
+import gc
 import pickle
 import select
 import signal
@@ -30,6 +31,14 @@ def exit_subprocess():
 class InterProcessSignalTests(unittest.TestCase):
     MAX_DURATION = 20   # Entire test should last at most 20 sec.
 
+    def setUp(self):
+        self.using_gc = gc.isenabled()
+        gc.disable()
+
+    def tearDown(self):
+        if self.using_gc:
+            gc.enable()
+
     def handlerA(self, *args):
         self.a_called = True
         if test_support.verbose:
@@ -263,8 +272,10 @@ class ItimerTest(unittest.TestCase):
         self.hndl_called = False
         self.hndl_count = 0
         self.itimer = None
+        self.old_alarm = signal.signal(signal.SIGALRM, self.sig_alrm)
 
     def tearDown(self):
+        signal.signal(signal.SIGALRM, self.old_alarm)
         if self.itimer is not None: # test_itimer_exc doesn't change this attr
             # just ensure that itimer is stopped
             signal.setitimer(self.itimer, 0)
@@ -303,13 +314,13 @@ class ItimerTest(unittest.TestCase):
         # XXX I'm assuming -1 is an invalid itimer, but maybe some platform
         # defines it ?
         self.assertRaises(signal.ItimerError, signal.setitimer, -1, 0)
-        # negative time
-        self.assertRaises(signal.ItimerError, signal.setitimer,
-            signal.ITIMER_REAL, -1)
+        # Negative times are treated as zero on some platforms.
+        if 0:
+            self.assertRaises(signal.ItimerError,
+                              signal.setitimer, signal.ITIMER_REAL, -1)
 
     def test_itimer_real(self):
         self.itimer = signal.ITIMER_REAL
-        signal.signal(signal.SIGALRM, self.sig_alrm)
         signal.setitimer(self.itimer, 1.0)
         if test_support.verbose:
             print("\ncall pause()...")
index b90905f4134ca75949c7e6cca9e9af62f5b6ce17..b65bdab786c442b3fe292bb4fbbb6693cbe57beb 100644 (file)
@@ -784,13 +784,15 @@ PyDoc_STRVAR(doc_crc32,
 static PyObject *
 binascii_crc32(PyObject *self, PyObject *args)
 {
-    uLong crc32val = 0;  /* crc32(0L, Z_NULL, 0) */
+    unsigned int crc32val = 0;  /* crc32(0L, Z_NULL, 0) */
     Byte *buf;
     Py_ssize_t len;
+    int signed_val;
+
     if (!PyArg_ParseTuple(args, "s#|I:crc32", &buf, &len, &crc32val))
         return NULL;
-    crc32val = crc32(crc32val, buf, len);
-    return PyLong_FromUnsignedLong(crc32val & 0xffffffffU);
+    signed_val = crc32(crc32val, buf, len);
+    return PyLong_FromUnsignedLong(signed_val & 0xffffffffU);
 }
 #else  /* USE_ZLIB_CRC32 */
 /*  Crc - 32 BIT ANSI X3.66 CRC checksum files
index cecb9cf38bbb50fe4bbb685c2bd1686337acf969..24efb00b988f00d2f30b44283a0cca467f681dcf 100644 (file)
@@ -915,7 +915,7 @@ PyDoc_STRVAR(adler32__doc__,
 static PyObject *
 PyZlib_adler32(PyObject *self, PyObject *args)
 {
-    uLong adler32val = 1;  /* adler32(0L, Z_NULL, 0) */
+    unsigned int adler32val = 1;  /* adler32(0L, Z_NULL, 0) */
     Byte *buf;
     int len;
 
@@ -934,13 +934,14 @@ PyDoc_STRVAR(crc32__doc__,
 static PyObject *
 PyZlib_crc32(PyObject *self, PyObject *args)
 {
-    uLong crc32val = 0;  /* crc32(0L, Z_NULL, 0) */
+    unsigned int crc32val = 0;  /* crc32(0L, Z_NULL, 0) */
     Byte *buf;
-    int len;
+    int len, signed_val;
+
     if (!PyArg_ParseTuple(args, "s#|I:crc32", &buf, &len, &crc32val))
        return NULL;
-    crc32val = crc32(crc32val, buf, len);
-    return PyLong_FromUnsignedLong(crc32val & 0xffffffffU);
+    signed_val = crc32(crc32val, buf, len);
+    return PyLong_FromUnsignedLong(signed_val & 0xffffffffU);
 }
 
 
index bbcb7dcadf86f1ed9ddd7797173525dde59e09a4..60cbffa59f43cf0d694e91c67d40a064bbca1fb7 100644 (file)
@@ -3204,7 +3204,7 @@ PyObject *PyUnicode_DecodeRawUnicodeEscape(const char *s,
                 /* UCS-4 character. Either store directly, or as
                    surrogate pair. */
 #ifdef Py_UNICODE_WIDE
-                *p++ = (Py_UNIC0DE) x;
+                *p++ = (Py_UNICODE) x;
 #else
                 x -= 0x10000L;
                 *p++ = 0xD800 + (Py_UNICODE) (x >> 10);
@@ -7384,7 +7384,7 @@ unicode_repeat(PyUnicodeObject *str, Py_ssize_t len)
             done = str->length;
        }
        while (done < nchars) {
-            int n = (done <= nchars-done) ? done : nchars-done;
+            Py_ssize_t n = (done <= nchars-done) ? done : nchars-done;
             Py_UNICODE_COPY(p+done, p, n);
             done += n;
        }
index 0dcade8b3457de6a059c78aa8b670efd81a8952a..5c5023d84973726e6e9e7301ebbc4cebe5d4846d 100644 (file)
@@ -703,6 +703,7 @@ countStrings(wchar_t *data, int len)
 static BOOL
 Py2Reg(PyObject *value, DWORD typ, BYTE **retDataBuf, DWORD *retDataSize)
 {
+       Py_ssize_t i,j;
        switch (typ) {
                case REG_DWORD:
                        if (value != Py_None && !PyLong_Check(value))
index f8439f218cc39ddae151fe803f07706f5bab3934..b3978dd42d9bb6a7e85a75fc4f3dee258f80d382 100644 (file)
@@ -30,7 +30,7 @@ int main(int argc, char *argv[])
     STARTUPINFO si;
     PROCESS_INFORMATION pi;
     DWORD exit_code=0;
-    int cmdlen = 0;
+    size_t cmdlen = 0;
     int i;
     char *cmdline, *cmdlinefill;
 
index a37abf93397ac6f701c57e4071a90ba9ea975adc..db5ca33fbf960cbd74284589ef8ed34e93b35511 100644 (file)
@@ -29,7 +29,7 @@
    Also works for BUILD_LIST when followed by an "in" or "not in" test.
 */
 static int
-tuple_of_constants(unsigned char *codestr, int n, PyObject *consts)
+tuple_of_constants(unsigned char *codestr, Py_ssize_t n, PyObject *consts)
 {
        PyObject *newconst, *constant;
        Py_ssize_t i, arg, len_consts;
@@ -220,7 +220,7 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
 }
 
 static unsigned int *
-markblocks(unsigned char *code, int len)
+markblocks(unsigned char *code, Py_ssize_t len)
 {
        unsigned int *blocks = (unsigned int *)PyMem_Malloc(len*sizeof(int));
        int i,j, opcode, blockcnt = 0;