Kristján V. Jónsson wrote: > Hello there. > > I am trying to insert a hook into python enabling a callback for all > just-created objects. The intention is to debug and find memory leaks, > e.g. by having the hook function insert the object into a WeakKeyDictionary. > > I have already added a method to “object” to set such a hook, and > “object_new” now calls it upon completion, but this is far from covering > all places. Initially, I thought object_init were the place, but almost > no classes call object.__init__ from their __init__ method. Then there > is the separate case of old-style classes. > > I suppose there's no requirement on C-defined types to actually call object_new, so you will need to audit them and make sure they do.
PyClass_New in classobject.c is another obvious place - the creation of old-style instances doesn't appear to involve object_new. > > Any suggestions on how to do a global object creation hook in python? > Nothing other than the above. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Blog of Note: http://holdenweb.blogspot.com _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com