@@ -1649,7 +1649,7 @@ static int write_raw_doc(buffer_t buffer, PyObject* raw, PyObject* _raw_str) {
16491649 */
16501650void handle_invalid_doc_error (PyObject * dict ) {
16511651 PyObject * etype = NULL , * evalue = NULL , * etrace = NULL ;
1652- PyObject * msg = NULL , * dict_str = NULL , * new_msg = NULL ;
1652+ PyObject * msg = NULL , * new_msg = NULL , * new_evalue = NULL ;
16531653 PyErr_Fetch (& etype , & evalue , & etrace );
16541654 PyObject * InvalidDocument = _error ("InvalidDocument" );
16551655 if (InvalidDocument == NULL ) {
@@ -1659,19 +1659,19 @@ void handle_invalid_doc_error(PyObject* dict) {
16591659 if (evalue && PyErr_GivenExceptionMatches (etype , InvalidDocument )) {
16601660 PyObject * msg = PyObject_Str (evalue );
16611661 if (msg ) {
1662- // Add doc to the error class as a property.
1663- PyObject_SetAttrString (InvalidDocument , "document" , dict );
16641662 const char * msg_utf8 = PyUnicode_AsUTF8 (msg );
16651663 if (msg_utf8 == NULL ) {
16661664 goto cleanup ;
16671665 }
16681666 PyObject * new_msg = PyUnicode_FromFormat ("Invalid document: %s" , msg_utf8 );
1667+ // Add doc to the error instance as a property.
1668+ PyObject * new_evalue = PyObject_CallFunctionObjArgs (InvalidDocument , new_msg , dict , NULL );
16691669 Py_DECREF (evalue );
16701670 Py_DECREF (etype );
16711671 etype = InvalidDocument ;
16721672 InvalidDocument = NULL ;
1673- if (new_msg ) {
1674- evalue = new_msg ;
1673+ if (new_evalue ) {
1674+ evalue = new_evalue ;
16751675 } else {
16761676 evalue = msg ;
16771677 }
@@ -1682,7 +1682,7 @@ void handle_invalid_doc_error(PyObject* dict) {
16821682 PyErr_Restore (etype , evalue , etrace );
16831683 Py_XDECREF (msg );
16841684 Py_XDECREF (InvalidDocument );
1685- Py_XDECREF (dict_str );
1685+ Py_XDECREF (new_evalue );
16861686 Py_XDECREF (new_msg );
16871687}
16881688
0 commit comments