From 843b22f829c4ccf31487fee9065282c00b695c6f Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sat, 29 Jun 2019 12:48:50 +0200 Subject: [PATCH 1/1] [py] incref exception type before restoring it --- python/ext/py-filterbank.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/python/ext/py-filterbank.c b/python/ext/py-filterbank.c index 0bd00d04..fbe0e26e 100644 --- a/python/ext/py-filterbank.c +++ b/python/ext/py-filterbank.c @@ -326,7 +326,10 @@ Py_filterbank_set_triangle_bands (Py_filterbank * self, PyObject *args) // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - PyErr_Restore(PyExc_ValueError, value, traceback); + Py_XDECREF(type); + type = PyExc_ValueError; + Py_XINCREF(type); + PyErr_Restore(type, value, traceback); } return NULL; } @@ -351,7 +354,10 @@ Py_filterbank_set_mel_coeffs_slaney (Py_filterbank * self, PyObject *args) // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - PyErr_Restore(PyExc_ValueError, value, traceback); + Py_XDECREF(type); + type = PyExc_ValueError; + Py_XINCREF(type); + PyErr_Restore(type, value, traceback); } return NULL; } @@ -380,7 +386,10 @@ Py_filterbank_set_mel_coeffs (Py_filterbank * self, PyObject *args) // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - PyErr_Restore(PyExc_ValueError, value, traceback); + Py_XDECREF(type); + type = PyExc_ValueError; + Py_XINCREF(type); + PyErr_Restore(type, value, traceback); } return NULL; } @@ -409,7 +418,10 @@ Py_filterbank_set_mel_coeffs_htk (Py_filterbank * self, PyObject *args) // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - PyErr_Restore(PyExc_ValueError, value, traceback); + Py_XDECREF(type); + type = PyExc_ValueError; + Py_XINCREF(type); + PyErr_Restore(type, value, traceback); } return NULL; } @@ -463,7 +475,10 @@ Py_filterbank_set_power(Py_filterbank *self, PyObject *args) // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - PyErr_Restore(PyExc_ValueError, value, traceback); + Py_XDECREF(type); + type = PyExc_ValueError; + Py_XINCREF(type); + PyErr_Restore(type, value, traceback); } return NULL; } @@ -493,7 +508,10 @@ Py_filterbank_set_norm(Py_filterbank *self, PyObject *args) // change the RuntimeError into ValueError PyObject *type, *value, *traceback; PyErr_Fetch(&type, &value, &traceback); - PyErr_Restore(PyExc_ValueError, value, traceback); + Py_XDECREF(type); + type = PyExc_ValueError; + Py_XINCREF(type); + PyErr_Restore(type, value, traceback); } return NULL; } -- 2.11.0