New submission from Brett Cannon: GCC defines an __attribute__ called 'cleanup' which attaches to a variable declaration and specifies a function to execute with an argument of a pointer to the variable when the block scope is left. Typically this is used to automate cleanup (much like smart pointers in C++), but we can't do that if we want to support compilers other than GCC (and Clang based on my testing). Cleanup's definition can be found at http://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html .
But what we can use it for is refcount verification. So if we defined a freed(PyObject **) cleanup function we could verify in a debug build that the memory in fact was erased with the memory pattern that a debug build overwrites memory with. If something is expected to have <= 1 refcount (i.e. the variable's value is to be returned assuming nothing went wrong) then we could check if it was freed or if it had exactly a refcount of 1. This obviously only works for local variables which are assigned fresh objects (since there is no way to measure the delta of a refcount from assignment to block exit), but it would still help detect some refleaks. It would also potentially help with Dave Malcolm's gcc refleak detector by providing hints as to what the expected outcome is. Credit to David Stutzbach for suggesting this usage. ---------- components: Extension Modules, Interpreter Core messages: 200423 nosy: brett.cannon, dmalcolm, stutzbach priority: normal severity: normal stage: test needed status: open title: Use __atribute__(cleanup ...) to detect refleaks type: enhancement _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19298> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com