summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/talloc/pytalloc.c84
-rw-r--r--lib/talloc/wscript7
-rw-r--r--source4/scripting/python/pyglue.c50
-rw-r--r--source4/scripting/python/samba/__init__.py3
-rw-r--r--source4/scripting/python/samba/join.py3
-rwxr-xr-xsource4/scripting/python/samba/tests/dcerpc/rpc_talloc.py7
-rw-r--r--source4/scripting/python/samba/tests/dcerpc/testrpc.py11
7 files changed, 102 insertions, 63 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
diff --git a/source4/scripting/python/pyglue.c b/source4/scripting/python/pyglue.c
index 627443dee5..b77ce2bda5 100644
--- a/source4/scripting/python/pyglue.c
+++ b/source4/scripting/python/pyglue.c
@@ -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 }
};
diff --git a/source4/scripting/python/samba/__init__.py b/source4/scripting/python/samba/__init__.py
index 5a9df50627..079dad7351 100644
--- a/source4/scripting/python/samba/__init__.py
+++ b/source4/scripting/python/samba/__init__.py
@@ -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
diff --git a/source4/scripting/python/samba/join.py b/source4/scripting/python/samba/join.py
index 2e6edca2a4..4fe0774f83 100644
--- a/source4/scripting/python/samba/join.py
+++ b/source4/scripting/python/samba/join.py
@@ -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'''
diff --git a/source4/scripting/python/samba/tests/dcerpc/rpc_talloc.py b/source4/scripting/python/samba/tests/dcerpc/rpc_talloc.py
index 5058e08960..d561dde514 100755
--- a/source4/scripting/python/samba/tests/dcerpc/rpc_talloc.py
+++ b/source4/scripting/python/samba/tests/dcerpc/rpc_talloc.py
@@ -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)
diff --git a/source4/scripting/python/samba/tests/dcerpc/testrpc.py b/source4/scripting/python/samba/tests/dcerpc/testrpc.py
index d432d5abe1..2f3a6a0aef 100644
--- a/source4/scripting/python/samba/tests/dcerpc/testrpc.py
+++ b/source4/scripting/python/samba/tests/dcerpc/testrpc.py
@@ -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