Merge branch 'master' into fix/setbiquad
authorPaul Brossier <piem@piem.org>
Fri, 28 Jun 2019 13:03:56 +0000 (15:03 +0200)
committerPaul Brossier <piem@piem.org>
Fri, 28 Jun 2019 13:03:56 +0000 (15:03 +0200)
python/ext/py-filter.c

index 861f8cd..19dcc60 100644 (file)
@@ -156,8 +156,15 @@ Py_filter_set_c_weighting (Py_filter * self, PyObject *args)
 
   err = aubio_filter_set_c_weighting (self->o, samplerate);
   if (err > 0) {
-    PyErr_SetString (PyExc_ValueError,
-        "error when setting filter to C-weighting");
+    if (PyErr_Occurred() == NULL) {
+      PyErr_SetString (PyExc_ValueError,
+          "error when setting filter to C-weighting");
+    } else {
+      // change the RuntimeError into ValueError
+      PyObject *type, *value, *traceback;
+      PyErr_Fetch(&type, &value, &traceback);
+      PyErr_Restore(PyExc_ValueError, value, traceback);
+    }
     return NULL;
   }
   Py_RETURN_NONE;
@@ -174,8 +181,15 @@ Py_filter_set_a_weighting (Py_filter * self, PyObject *args)
 
   err = aubio_filter_set_a_weighting (self->o, samplerate);
   if (err > 0) {
-    PyErr_SetString (PyExc_ValueError,
-        "error when setting filter to A-weighting");
+    if (PyErr_Occurred() == NULL) {
+      PyErr_SetString (PyExc_ValueError,
+          "error when setting filter to A-weighting");
+    } else {
+      // change the RuntimeError into ValueError
+      PyObject *type, *value, *traceback;
+      PyErr_Fetch(&type, &value, &traceback);
+      PyErr_Restore(PyExc_ValueError, value, traceback);
+    }
     return NULL;
   }
   Py_RETURN_NONE;
@@ -192,8 +206,15 @@ Py_filter_set_biquad(Py_filter * self, PyObject *args)
 
   err = aubio_filter_set_biquad (self->o, b0, b1, b2, a1, a2);
   if (err > 0) {
-    PyErr_SetString (PyExc_ValueError,
-        "error when setting filter with biquad coefficients");
+    if (PyErr_Occurred() == NULL) {
+      PyErr_SetString (PyExc_ValueError,
+          "error when setting filter with biquad coefficients");
+    } else {
+      // change the RuntimeError into ValueError
+      PyObject *type, *value, *traceback;
+      PyErr_Fetch(&type, &value, &traceback);
+      PyErr_Restore(PyExc_ValueError, value, traceback);
+    }
     return NULL;
   }
   Py_RETURN_NONE;