mirror of
https://github.com/samba-team/samba.git
synced 2025-07-19 04:59:10 +03:00
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
This commit is contained in:
@ -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 }
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
@ -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'''
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user