[pygobject] _struct_dealloc: handle being called with an error set



commit 288ad4c7e0a13a43992014f5fff55636c7c8fcfd
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sun Mar 11 13:13:30 2018 +0100

    _struct_dealloc: handle being called with an error set
    
    With Python 3.7 it gets called with an error set and tp_dealloc
    implementations need to handle that.
    Fix by saving and restoring the error.

 gi/pygi-struct.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
---
diff --git a/gi/pygi-struct.c b/gi/pygi-struct.c
index 4d5b5411..e2906e0a 100644
--- a/gi/pygi-struct.c
+++ b/gi/pygi-struct.c
@@ -61,7 +61,14 @@ out:
 static void
 _struct_dealloc (PyGIStruct *self)
 {
-    GIBaseInfo *info = _struct_get_info ( (PyObject *) self );
+    GIBaseInfo *info;
+    PyObject *error_type, *error_value, *error_traceback;
+    gboolean have_error = !!PyErr_Occurred ();
+
+    if (have_error)
+        PyErr_Fetch (&error_type, &error_value, &error_traceback);
+
+    info = _struct_get_info ( (PyObject *) self );
 
     if (info != NULL && g_struct_info_is_foreign ( (GIStructInfo *) info)) {
         pygi_struct_foreign_release (info, pyg_pointer_get_ptr (self));
@@ -73,6 +80,9 @@ _struct_dealloc (PyGIStruct *self)
         g_base_info_unref (info);
     }
 
+    if (have_error)
+        PyErr_Restore (error_type, error_value, error_traceback);
+
     Py_TYPE (self)->tp_free ((PyObject *)self);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]