s4-pyglue: added talloc_report_full() and talloc_enable_null_tracking()
authorAndrew Tridgell <tridge@samba.org>
Wed, 25 Aug 2010 02:33:38 +0000 (12:33 +1000)
committerAndrew Tridgell <tridge@samba.org>
Wed, 25 Aug 2010 13:05:05 +0000 (23:05 +1000)
these are useful for tracking down leaks and bugs in python scripts

Pair-Programmed-With: Jelmer Vernooij <jelmer@samba.org>

source4/scripting/python/pyglue.c
source4/scripting/python/samba/__init__.py

index 5de024c430ec0e3363fd025ef4773b775494539f..ddd44aa7df05292ca7af03c0a9c539ca223dc709 100644 (file)
@@ -25,6 +25,7 @@
 #include "param/pyparam.h"
 #include "lib/socket/netif.h"
 #include "lib/socket/netif_proto.h"
+#include "lib/talloc/pytalloc.h"
 
 static PyObject *py_generate_random_str(PyObject *self, PyObject *args)
 {
@@ -164,6 +165,31 @@ static PyObject *py_interface_ips(PyObject *self, PyObject *args)
        return pylist;
 }
 
+/* return a talloc tree string for a talloc python object */
+static PyObject *py_talloc_report_full(PyObject *self, PyObject *args)
+{
+       PyObject *py_obj;
+       PyTypeObject *type;
+
+       if (!PyArg_ParseTuple(args, "O", &py_obj))
+               return NULL;
+
+       if (py_obj == Py_None) {
+               talloc_report_full(NULL, stdout);
+       } else {
+               type = (PyTypeObject*)PyObject_Type(py_obj);
+               talloc_report_full(py_talloc_get_mem_ctx(py_obj), stdout);
+       }
+       return Py_None;
+}
+
+/* return a talloc tree string for a talloc python object */
+static PyObject *py_talloc_enable_null_tracking(PyObject *self, PyObject *args)
+{
+       talloc_enable_null_tracking();
+       return Py_None;
+}
+
 
 static PyMethodDef py_misc_methods[] = {
        { "generate_random_str", (PyCFunction)py_generate_random_str, METH_VARARGS,
@@ -182,6 +208,10 @@ static PyMethodDef py_misc_methods[] = {
                "set debug level" },
        { "interface_ips", (PyCFunction)py_interface_ips, METH_VARARGS,
                "get interface IP address list"},
+       { "talloc_report_full", (PyCFunction)py_talloc_report_full, METH_VARARGS,
+               "show a talloc tree for an object"},
+       { "talloc_enable_null_tracking", (PyCFunction)py_talloc_enable_null_tracking, METH_VARARGS,
+               "enable tracking of the NULL object"},
        { NULL }
 };
 
index 80873dc7797b27c840f093f43c16204d7eb5e82e..fcd224202b5fabcf07cdb81b45e5adbb6da7e09f 100644 (file)
@@ -327,3 +327,5 @@ interface_ips = _glue.interface_ips
 set_debug_level = _glue.set_debug_level
 unix2nttime = _glue.unix2nttime
 generate_random_password = _glue.generate_random_password
+talloc_report_full = _glue.talloc_report_full
+talloc_enable_null_tracking = _glue.talloc_enable_null_tracking