[nautilus-python] nautilus-python-object.c: Remove the extra reference on the PyObject file wrappers when adding them



commit 5049e1cb80c75327cf1a4f78844be4d3120614a5
Author: Michael Webster <miketwebster gmail com>
Date:   Wed Feb 3 13:42:14 2021 -0500

    nautilus-python-object.c: Remove the extra reference on the PyObject file wrappers when adding them to 
the python list
    
    PyObjects start with a refcount of 1. Adding them to a PyList adds a second - which gets removes during 
the list's destruction. The additional ref was keeping its associated NautilusFile from ever being finalized.
    
    Steps to reproduce problem:
    
    1) Install nautilus-python and some python MenuProvider extension.
    2) Create a folder with a couple of image files inside. Be sure to allow thumbs to generate.
    3) Enter the folder, select one or more files (so menus are generated). De-select and leave the folder 
(but do not close Nautilus). If you were to watch for the files' finalize to run, you'd notice it does not.
    4) touch or otherwise modify one of the image files from a terminal
    5) Re-enter the folder in nautilus.
    6) See that loading status runs forever, modified file(s) never display. Note: even if you only modify 
one file, it could cause all of the files to fail to load, depending on their order during enumeration.
    
    When no more views are displaying a file, that file should be finalized. When it's not it ends up in an 
undefined state, as it has no monitors flag it as needing to be updated.

 src/nautilus-python-object.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
---
diff --git a/src/nautilus-python-object.c b/src/nautilus-python-object.c
index 1eafa33..1e2a03c 100644
--- a/src/nautilus-python-object.c
+++ b/src/nautilus-python-object.c
@@ -87,7 +87,9 @@ int __PyInt_Check(PyObject *obj) {
         py_files = PyList_New(0);                                      \
         for (l = files; l; l = l->next)                                \
         {                                                              \
-            PyList_Append(py_files, pygobject_new((GObject*)l->data)); \
+            PyObject *item = pygobject_new ((GObject *)l->data);       \
+            PyList_Append(py_files, item);                             \
+            Py_DECREF (item);                                          \
         }                                                              \
     }
 


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