Skip to content

Instantly share code, notes, and snippets.

@bukzor
Created December 19, 2011 08:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bukzor/1496028 to your computer and use it in GitHub Desktop.
Save bukzor/1496028 to your computer and use it in GitHub Desktop.
Debugging dict refcount issue.
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 5cf9ad1..d6b9c8d 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -8,6 +8,7 @@
*/
#include "Python.h"
+#include "frameobject.h"
/* Set a key error with the specified argument, wrapping it in a
@@ -266,6 +267,19 @@ PyDict_New(void)
++created;
#endif
_PyObject_GC_TRACK(mp);
+
+ printf("New dict: %#012x\n", mp);
+ PyInterpreterState *interp = PyThreadState_GET()->interp;
+ PyThreadState *thread_state = interp->tstate_head;
+ PyFrameObject *frame = thread_state->frame;
+ if ( frame == NULL ) {
+ printf(" (no frame)\n");
+ } else {
+ PyCodeObject *current_code = frame->f_code;
+ printf(" %s:%i\n", PyString_AsString(current_code->co_filename), current_code->co_firstlineno);
+ }
+
+
return (PyObject *)mp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment