[Python-checkins] cpython: audioop: adpcm2lin() and lin2adpcm() now raises a TypeError instead of a

victor.stinner python-checkins at python.org
Fri Jan 3 03:27:04 CET 2014


http://hg.python.org/cpython/rev/dee33603a5fa
changeset:   88267:dee33603a5fa
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Jan 03 03:26:47 2014 +0100
summary:
  audioop: adpcm2lin() and lin2adpcm() now raises a TypeError instead of a
SystemError if the state type is invalid.

files:
  Lib/test/test_audioop.py |  5 +++++
  Modules/audioop.c        |  6 ++++++
  2 files changed, 11 insertions(+), 0 deletions(-)


diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py
--- a/Lib/test/test_audioop.py
+++ b/Lib/test/test_audioop.py
@@ -269,6 +269,11 @@
             self.assertEqual(audioop.lin2adpcm(b'\0' * w * 10, w, None),
                              (b'\0' * 5, (0, 0)))
 
+    def test_invalid_adpcm_state(self):
+        # state must be a tuple or None, not an integer
+        self.assertRaises(TypeError, audioop.adpcm2lin, b'\0', 1, 555)
+        self.assertRaises(TypeError, audioop.lin2adpcm, b'\0', 1, 555)
+
     def test_lin2alaw(self):
         self.assertEqual(audioop.lin2alaw(datas[1], 1),
                          b'\xd5\x87\xa4\x24\xaa\x2a\x5a')
diff --git a/Modules/audioop.c b/Modules/audioop.c
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1525,6 +1525,9 @@
         /* First time, it seems. Set defaults */
         valpred = 0;
         index = 0;
+    } else if (!PyTuple_Check(state)) {
+        PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
+        goto exit;
     } else if (!PyArg_ParseTuple(state, "ii", &valpred, &index))
         goto exit;
 
@@ -1631,6 +1634,9 @@
         /* First time, it seems. Set defaults */
         valpred = 0;
         index = 0;
+    } else if (!PyTuple_Check(state)) {
+        PyErr_SetString(PyExc_TypeError, "state must be a tuple or None");
+        goto exit;
     } else if (!PyArg_ParseTuple(state, "ii", &valpred, &index))
         goto exit;
 

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


More information about the Python-checkins mailing list