@@ -2105,27 +2105,29 @@ static PyObject* get_value(PyObject* self, const char* buffer, unsigned* positio
21052105 * Calling _error clears the error state, so fetch it first.
21062106 */
21072107 PyErr_Fetch (& etype , & evalue , & etrace );
2108- InvalidBSON = _error ("InvalidBSON" );
2109- if (InvalidBSON ) {
2110- if (!PyErr_GivenExceptionMatches (etype , InvalidBSON )) {
2111- /*
2112- * Raise InvalidBSON(str(e)).
2113- */
2114- Py_DECREF (etype );
2115- etype = InvalidBSON ;
2116-
2117- if (evalue ) {
2118- PyObject * msg = PyObject_Str (evalue );
2119- Py_DECREF (evalue );
2120- evalue = msg ;
2108+ if (PyErr_GivenExceptionMatches (etype , PyExc_Exception )) {
2109+ InvalidBSON = _error ("InvalidBSON" );
2110+ if (InvalidBSON ) {
2111+ if (!PyErr_GivenExceptionMatches (etype , InvalidBSON )) {
2112+ /*
2113+ * Raise InvalidBSON(str(e)).
2114+ */
2115+ Py_DECREF (etype );
2116+ etype = InvalidBSON ;
2117+
2118+ if (evalue ) {
2119+ PyObject * msg = PyObject_Str (evalue );
2120+ Py_DECREF (evalue );
2121+ evalue = msg ;
2122+ }
2123+ PyErr_NormalizeException (& etype , & evalue , & etrace );
2124+ } else {
2125+ /*
2126+ * The current exception matches InvalidBSON, so we don't
2127+ * need this reference after all.
2128+ */
2129+ Py_DECREF (InvalidBSON );
21212130 }
2122- PyErr_NormalizeException (& etype , & evalue , & etrace );
2123- } else {
2124- /*
2125- * The current exception matches InvalidBSON, so we don't need
2126- * this reference after all.
2127- */
2128- Py_DECREF (InvalidBSON );
21292131 }
21302132 }
21312133 /* Steals references to args. */
0 commit comments