[pygobject] struct: fetch the base info from the struct type and not the instance



commit fe74a5a989a8bd9b8b69ab1d160bc7215a6c6bbf
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Sat Mar 31 14:00:48 2018 +0200

    struct: fetch the base info from the struct type and not the instance
    
    We need the base info in the struct tp_dealloc and PyPy doesn't like
    when the instance escapes there by passing it to some Python API.
    
    Since the base info is stored on the class anyway get it from there instead.
    
    This allows the test suite to run without crashes under PyPy.

 gi/pygi-struct.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
---
diff --git a/gi/pygi-struct.c b/gi/pygi-struct.c
index 0160b2fd..3c0c89fd 100644
--- a/gi/pygi-struct.c
+++ b/gi/pygi-struct.c
@@ -31,12 +31,12 @@
 
 
 static GIBaseInfo *
-_struct_get_info (PyObject *self)
+_struct_get_info (PyTypeObject *type)
 {
     PyObject *py_info;
     GIBaseInfo *info = NULL;
 
-    py_info = PyObject_GetAttrString (self, "__info__");
+    py_info = PyObject_GetAttrString ((PyObject *)type, "__info__");
     if (py_info == NULL) {
         return NULL;
     }
@@ -68,7 +68,7 @@ _struct_dealloc (PyGIStruct *self)
     if (have_error)
         PyErr_Fetch (&error_type, &error_value, &error_traceback);
 
-    info = _struct_get_info ( (PyObject *) self );
+    info = _struct_get_info (Py_TYPE (self));
 
     if (info != NULL && g_struct_info_is_foreign ( (GIStructInfo *) info)) {
         pygi_struct_foreign_release (info, pyg_pointer_get_ptr (self));
@@ -102,7 +102,7 @@ _struct_new (PyTypeObject *type,
         return NULL;
     }
 
-    info = _struct_get_info ( (PyObject *) type );
+    info = _struct_get_info ( type );
     if (info == NULL) {
         if (PyErr_ExceptionMatches (PyExc_AttributeError)) {
             PyErr_Format (PyExc_TypeError, "missing introspection information");
@@ -212,7 +212,7 @@ _struct_repr(PyGIStruct *self)
     GIBaseInfo *info;
     PyGPointer *pointer = (PyGPointer *)self;
 
-    info = _struct_get_info ((PyObject *)self);
+    info = _struct_get_info (Py_TYPE (self));
     if (info == NULL)
         return NULL;
 


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