Open davidmalcolm opened 7 years ago
Imported from trac issue 18. Created by tromey on 2012-01-04T16:45:16, last modified: 2013-04-18T14:29:35
Trac comment by tromey on 2013-04-18 14:29:35:
One idea is a builtin function or pragma to mark a spot where a reference is stolen. Then we could change code like this:
obj = ... new ref; wrapper->field = obj;
to
wrapper->field = ASSUME_STOLEN_REF (obj);
In gdb, most Python wrapper classes maintain a kind of weak reference to the underlying gdb object. This is done because the object lifetimes are different, and some of the gdb objects are quite large; so keeping them live due to a reference from Python is not a good solution.
These "weak references" are implemented by things like linked lists in gdb, pointing to the Python wrapper objects. When the gdb object dies, we traverse the list and set an internal field (the back-pointer to the gdb object) to NULL.
We also have code in the Python object's destructor to remove the objects from the list.
In this situation the code to add the object to the linked list can cause false errors. E.g.:
../../archer/gdb/python/py-block.c: In function ‘set_block’: ../../archer/gdb/python/py-block.c:265:1: error: ob_refcnt of '*obj' is 1 too low [-Werror] ../../archer/gdb/python/py-block.c:265:1: note: was expecting final ob_refcnt to be N + 1 (for some unknown N)
It would be nice to have an attribute we could use to tell the checker that the usual rules don't apply somehow.