Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void
- infpy_dealloc (PyObject *obj)
- {
- /* This dealloc is for a special case. Normally inferiors are added
- to our internal inferior list by the inferior add observers.
- Even when the GDB inferior is removed with remove-inferior, and
- the corresponding call to py_free_inferior is invoked, the Python
- inferior object is not deleted, but now represents an invalid
- inferior (the Python object still has a ref count of 1, being a
- member of the inferior list. We cannot delete this inferior
- object, even though it points to a defunct inferior as the user
- might reference it. This is legal. In the case of a GDB that is not
- running any "real" inferiors, there is still one dummy inferior.
- This dummy inferior is never notified to observers so we do not
- track it in our internal inferior list. The problem lies when
- the user does: py print gdb.current_inferior (). This create a
- new Python inferior, calls set_inferior_data to attach this
- inferior to this Python Object. However, immediately after
- printing the reference count for this object reaches zero, and
- the object garbage collected. However the reference set in
- set_inferior_data still points to this now defunct object. As
- the model for inferiors is one inferior object per inferior, any
- existing inferior object is returned by inferior_data. In this
- case it will now be the bogus garbage collected inferior object.
- In all cases but the dummy inferior this will not happen as there
- is a reference in the internal inferior list. */
- inferior_object *inf_obj = (inferior_object *) obj;
- struct inferior *inf = inf_obj->inferior;
- if (! inf)
- return;
- set_inferior_data (inf, infpy_inf_data_key, NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement