Author: Armin Rigo <[email protected]>
Branch:
Changeset: r1230:292e7e661406
Date: 2013-04-04 16:39 +0200
http://bitbucket.org/cffi/cffi/changeset/292e7e661406/
Log: Add CFFI_MEM_DEBUG and CFFI_MEM_LEAK defines, to build versions of
_cffi_backend that help in debugging early frees.
diff --git a/c/_cffi_backend.c b/c/_cffi_backend.c
--- a/c/_cffi_backend.c
+++ b/c/_cffi_backend.c
@@ -1382,7 +1382,9 @@
PyObject_ClearWeakRefs((PyObject *) cd);
Py_DECREF(cd->c_type);
+#ifndef CFFI_MEM_LEAK /* never release anything, tests only */
PyObject_Del(cd);
+#endif
}
static void cdataowning_dealloc(CDataObject *cd)
@@ -1397,6 +1399,19 @@
Py_XDECREF(args);
cffi_closure_free(closure);
}
+#if defined(CFFI_MEM_DEBUG) || defined(CFFI_MEM_LEAK)
+ if (cd->c_type->ct_flags & (CT_PRIMITIVE_ANY | CT_STRUCT | CT_UNION)) {
+ assert(cd->c_type->ct_size >= 0);
+ memset(cd->c_data, 0xDD, cd->c_type->ct_size);
+ }
+ else if (cd->c_type->ct_flags & CT_ARRAY) {
+ Py_ssize_t x = get_array_length(cd);
+ assert(x >= 0);
+ x *= cd->c_type->ct_itemdescr->ct_size;
+ assert(x >= 0);
+ memset(cd->c_data, 0xDD, x);
+ }
+#endif
cdata_dealloc(cd);
}
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit