summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2010-11-05 03:00:45 +0100
committerJelmer Vernooij <jelmer@samba.org>2010-11-05 02:48:21 +0000
commitcd172e77248968c48d2ff7f18a2366c35dd51697 (patch)
tree3aaf238aed64fb4a890aed61189e5133c1f0c932 /lib
parent4edabb3256734dcef4ad0d7a910f1729cd5c956e (diff)
downloadsamba-cd172e77248968c48d2ff7f18a2366c35dd51697.tar.gz
samba-cd172e77248968c48d2ff7f18a2366c35dd51697.tar.bz2
samba-cd172e77248968c48d2ff7f18a2366c35dd51697.zip
talloc: Add python talloc module, move convenience functions to it.
Autobuild-User: Jelmer Vernooij <jelmer@samba.org> Autobuild-Date: Fri Nov 5 02:48:21 UTC 2010 on sn-devel-104
Diffstat (limited to 'lib')
-rw-r--r--lib/talloc/pytalloc.c84
-rw-r--r--lib/talloc/wscript7
2 files changed, 90 insertions, 1 deletions
diff --git a/lib/talloc/pytalloc.c b/lib/talloc/pytalloc.c
new file mode 100644
index 0000000000..69a2c2fc13
--- /dev/null
+++ b/lib/talloc/pytalloc.c
@@ -0,0 +1,84 @@
+/*
+ Unix SMB/CIFS implementation.
+ Python Talloc Module
+ Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2010
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <Python.h>
+#include <talloc.h>
+#include <pytalloc.h>
+
+/* print a talloc tree report 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;
+}
+
+/* enable null tracking */
+static PyObject *py_talloc_enable_null_tracking(PyObject *self, PyObject *args)
+{
+ talloc_enable_null_tracking();
+ return Py_None;
+}
+
+/* return the number of talloc blocks */
+static PyObject *py_talloc_total_blocks(PyObject *self, PyObject *args)
+{
+ PyObject *py_obj;
+ PyTypeObject *type;
+
+ if (!PyArg_ParseTuple(args, "O", &py_obj))
+ return NULL;
+
+ if (py_obj == Py_None) {
+ return PyLong_FromLong(talloc_total_blocks(NULL));
+ }
+
+ type = (PyTypeObject*)PyObject_Type(py_obj);
+
+ return PyLong_FromLong(talloc_total_blocks(py_talloc_get_mem_ctx(py_obj)));
+}
+
+static PyMethodDef talloc_methods[] = {
+ { "report_full", (PyCFunction)py_talloc_report_full, METH_VARARGS,
+ "show a talloc tree for an object"},
+ { "enable_null_tracking", (PyCFunction)py_talloc_enable_null_tracking, METH_VARARGS,
+ "enable tracking of the NULL object"},
+ { "total_blocks", (PyCFunction)py_talloc_total_blocks, METH_VARARGS,
+ "return talloc block count"},
+ { NULL }
+};
+
+void inittalloc(void)
+{
+ PyObject *m;
+
+ m = Py_InitModule3("talloc", talloc_methods, "Debug utilities for talloc-wrapped objects.");
+ if (m == NULL)
+ return;
+}
diff --git a/lib/talloc/wscript b/lib/talloc/wscript
index d2968409ef..264c34567a 100644
--- a/lib/talloc/wscript
+++ b/lib/talloc/wscript
@@ -32,7 +32,7 @@ def set_options(opt):
action="store_true", dest='TALLOC_COMPAT1', default=False)
if opt.IN_LAUNCH_DIR():
opt.add_option('--disable-python',
- help=("disable the pytevent module"),
+ help=("disable the pytalloc module"),
action="store_true", dest='disable_python', default=False)
@@ -112,6 +112,11 @@ def build(bld):
vnum=VERSION,
)
bld.INSTALL_FILES('${INCLUDEDIR}', 'pytalloc.h')
+ bld.SAMBA_PYTHON('pytalloc',
+ 'pytalloc.c',
+ deps='talloc pytalloc-util',
+ enabled=True,
+ realname='talloc.so')
if not getattr(bld.env, '_SAMBA_BUILD_', 0) == 4:
# s4 already has the talloc testsuite builtin to smbtorture