Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. static void
  2. infpy_dealloc (PyObject *obj)
  3. {
  4. /* This dealloc is for a special case. Normally inferiors are added
  5. to our internal inferior list by the inferior add observers.
  6. Even when the GDB inferior is removed with remove-inferior, and
  7. the corresponding call to py_free_inferior is invoked, the Python
  8. inferior object is not deleted, but now represents an invalid
  9. inferior (the Python object still has a ref count of 1, being a
  10. member of the inferior list. We cannot delete this inferior
  11. object, even though it points to a defunct inferior as the user
  12. might reference it. This is legal. In the case of a GDB that is not
  13. running any "real" inferiors, there is still one dummy inferior.
  14. This dummy inferior is never notified to observers so we do not
  15. track it in our internal inferior list. The problem lies when
  16. the user does: py print gdb.current_inferior (). This create a
  17. new Python inferior, calls set_inferior_data to attach this
  18. inferior to this Python Object. However, immediately after
  19. printing the reference count for this object reaches zero, and
  20. the object garbage collected. However the reference set in
  21. set_inferior_data still points to this now defunct object. As
  22. the model for inferiors is one inferior object per inferior, any
  23. existing inferior object is returned by inferior_data. In this
  24. case it will now be the bogus garbage collected inferior object.
  25. In all cases but the dummy inferior this will not happen as there
  26. is a reference in the internal inferior list. */
  27.  
  28. inferior_object *inf_obj = (inferior_object *) obj;
  29. struct inferior *inf = inf_obj->inferior;
  30. if (! inf)
  31. return;
  32.  
  33. set_inferior_data (inf, infpy_inf_data_key, NULL);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement