[DISCUSSION] PyFalkon can dangerously own some pointers
Hi everyone!
This is more a discussion than a real issue.
I'm currently developing a Falkon python plugin to sync Falkon history, bookmarks and tabs with Firefox Sync. This would be amazing for me as it is what it's really holding me back from using Falkon.
However there could be critical memory issues with this: if we create a *BookmarkItem
and then store it with bookmarks().addBookmark()
(this is just an example, we could create pointers to several other objects) from a python plugin, the python plugin will be the owner of the
pointer. What this means is that, should that pointer be garbage collected, Falkon will crash with a segmentation fault when accessing that *BookmarkItem
.
A "simple" solution is to store these pointers as member of the python plugin main class, which means they will live as long as the
python class will live (i.e., some time after unload()
is called). However, this solution can also be dangerous if we cannot guarantee that those pointers will not be accessed by Falkon after the plugin is destroyed. Keeping the bookmarks example, this means that we should guarantee that, e.g.,
the bookmarks created by python have been saved and there is no call to ~Bookmarks
destructor after the plugin is destroyed.
Could there be any solution to make it so that any such pointers are owned by C++ and not python?
Cheers!
PS. notice that, at the moment, storing the pointer as member of the main python plugin class seems to work and doesn't cause segmentation faults...but is this really guaranteed?