talloc: Add python talloc module, move convenience functions to it.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 5 Nov 2010 02:00:45 +0000 (03:00 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 5 Nov 2010 02:48:21 +0000 (02:48 +0000)
Autobuild-User: Jelmer Vernooij <jelmer@samba.org>
Autobuild-Date: Fri Nov  5 02:48:21 UTC 2010 on sn-devel-104

lib/talloc/pytalloc.c [new file with mode: 0644]
lib/talloc/wscript
source4/scripting/python/pyglue.c
source4/scripting/python/samba/__init__.py
source4/scripting/python/samba/join.py
source4/scripting/python/samba/tests/dcerpc/rpc_talloc.py
source4/scripting/python/samba/tests/dcerpc/testrpc.py

diff --git a/lib/talloc/pytalloc.c b/lib/talloc/pytalloc.c
new file mode 100644 (file)
index 0000000..69a2c2f
--- /dev/null
@@ -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;
+}
index d2968409ef06c1e9ba049faeaea20c8bd6992ce6..264c34567af1a8ada4734de48b5d0dacf8b94b9f 100644 (file)
@@ -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
index 627443dee5f0bda511482ab5ba0b5f6c82928091..b77ce2bda53b47c242f5480557ce459130b30ec2 100644 (file)
@@ -166,50 +166,6 @@ static PyObject *py_interface_ips(PyObject *self, PyObject *args)
        return pylist;
 }
 
-/* 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 py_misc_methods[] = {
        { "generate_random_str", (PyCFunction)py_generate_random_str, METH_VARARGS,
                "generate_random_str(len) -> string\n"
@@ -227,12 +183,6 @@ 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"},
-       { "talloc_total_blocks", (PyCFunction)py_talloc_total_blocks, METH_VARARGS,
-               "return talloc block count"},
        { NULL }
 };
 
index 5a9df506270c92132f2a5b56de62907e60f0c743..079dad7351a4211677f940e4ad0fbd60a9f52f47 100644 (file)
@@ -327,6 +327,3 @@ 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
-talloc_total_blocks = _glue.talloc_total_blocks
index 2e6edca2a45e1cd94d2745e7752bafff6f66b2d9..4fe0774f83a6e4cce6b6b54c5d74e645a42a14a3 100644 (file)
@@ -32,9 +32,10 @@ from samba.net import Net
 import logging
 from samba.drs_utils import drs_Replicate
 from samba.dsdb import DS_DOMAIN_FUNCTION_2008_R2
+import talloc
 
 # this makes debugging easier
-samba.talloc_enable_null_tracking()
+talloc.enable_null_tracking()
 
 class join_ctx:
     '''hold join context variables'''
index 5058e08960d60a63fdb31fdd71720613df4c4488..d561dde514cf6449af11db133851672291cbdbfc 100755 (executable)
@@ -17,15 +17,16 @@ sys.path.insert(0, "bin/python")
 import samba
 import samba.tests
 from samba.dcerpc import drsuapi
+import talloc
 
-samba.talloc_enable_null_tracking()
+talloc.enable_null_tracking()
 
 class TallocTests(samba.tests.TestCase):
     '''test talloc behaviour of pidl generated python code'''
 
     def check_blocks(self, object, num_expected):
         '''check that the number of allocated blocks is correct'''
-        nblocks = samba.talloc_total_blocks(object)
+        nblocks = talloc.total_blocks(object)
         if object is None:
             nblocks -= self.initial_blocks
         self.assertEquals(nblocks, num_expected)
@@ -61,7 +62,7 @@ class TallocTests(samba.tests.TestCase):
         self.check_blocks(None, 6)
 
     def test_run(self):
-        self.initial_blocks = samba.talloc_total_blocks(None)
+        self.initial_blocks = talloc.total_blocks(None)
         self.check_blocks(None, 0)
         self.pas_test()
         self.check_blocks(None, 0)
index d432d5abe17dd87e6eb751e9939290b6d403e17f..2f3a6a0aefd2f7bd51d09635ea8a20e8b2d0ad36 100644 (file)
@@ -10,15 +10,16 @@ sys.path.insert(0, "bin/python")
 import samba
 import samba.tests
 from samba.dcerpc import drsuapi
+import talloc
 
-samba.talloc_enable_null_tracking()
+talloc.enable_null_tracking()
 
 class RpcTests(object):
     '''test type behaviour of pidl generated python RPC code'''
 
     def check_blocks(self, object, num_expected):
         '''check that the number of allocated blocks is correct'''
-        nblocks = samba.talloc_total_blocks(object)
+        nblocks = talloc.total_blocks(object)
         if object is None:
             nblocks -= self.initial_blocks
         leaked_blocks = (nblocks - num_expected)
@@ -89,7 +90,7 @@ class RpcTests(object):
                 pass
             elif isinstance(value, type):
                 try:
-                    initial_blocks = samba.talloc_total_blocks(None)
+                    initial_blocks = talloc.total_blocks(None)
                     self.check_type(interface, n, value)
                     self.check_blocks(None, initial_blocks)
                 except Exception, e:
@@ -110,12 +111,12 @@ class RpcTests(object):
                 continue
             print "Checking interface %s" % iname
             iface = getattr(samba.dcerpc, iname)
-            initial_blocks = samba.talloc_total_blocks(None)
+            initial_blocks = talloc.total_blocks(None)
             self.check_interface(iface, iname)
             self.check_blocks(None, initial_blocks)
 
     def run(self):
-        self.initial_blocks = samba.talloc_total_blocks(None)
+        self.initial_blocks = talloc.total_blocks(None)
         self.errcount = 0
         self.check_all_interfaces()
         return self.errcount