On Fri, Aug 13, 2010 at 04:41:51PM +0530, Balbir Singh wrote: > On Fri, Aug 13, 2010 at 12:43 PM, Balbir Singh > <[email protected]> wrote: > > On Wed, Aug 11, 2010 at 8:25 AM, Dhaval Giani <[email protected]> > > wrote: > >> > >> On Tue, Aug 10, 2010 at 9:38 PM, Jason Baron <[email protected]> wrote: > >> > Hi, > >> > > >> > I was playing around with the language bindings mentioned in: Subject: > >> > [Libcg-devel] [hack] Language bindings for libcgroup > >> > > >> > I was just trying to figure out how to call the > >> > "cgroup_read_stats_begin()" function from python. The third argument > >> > takes a 'void **'. How can I call this function in python? > >> > > >> > I've posted my full test script (building on the one you posted) below. > >> > The error I'm currently getting is: > >> > > >> > Traceback (most recent call last): > >> > File "./tester.py", line 20, in <module> > >> > cgroup_read_stats_begin("cpu", "/cgroup/test", byref(handle), cg_stat) > >> > TypeError: in method 'cgroup_read_stats_begin', argument 3 of type 'void > >> > **' > >> > > >> > >> I i read your script corectly, you are passing a void * as opposed to > >> a void **. Not sure hwo to fix it in python though. > >> > > > > No, that's not it, we need to create typemaps. Jason could you please > > add the following typemap in libcgroup.i before the "C" prototypes and > > structures > > > > %typemap (in) void** (void *temp) { > > void *arg; > > if ((arg = PyCObject_AsVoidPtr($input)) != NULL) { > > $1 = &arg; > > } else > > $1 = &temp; > > } > > > > %typemap (argout) void** { > > PyObject *obj = PyCObject_FromVoidPtr(*$1, NULL); > > $result = PyTuple_Pack(2, $result, obj); > > } > > > > Recompile the swig module and the libcgroup_wrap.c file. > > > > Then could you try the following python script > > > > #!/usr/bin/python > > > > from libcgroup import * > > from ctypes import * > > > > cgroup_init() > > # > > # Add the correct controllers based on the mount point > > # > > cg_stat = cgroup_stat() > > p = c_void_p() > > ret, p = cgroup_read_stats_begin("memory", "/", p, cg_stat) > > while ret != ECGEOF: > > print "%s:%s" %(cg_stat.name, cg_stat.value) > > ret, p = cgroup_read_stats_next(p, cg_stat) > > > > cgroup_read_stats_end(p) > > > > NOTE: The return values are twisted, the void **handle needs to be > > reloaded back using ret, p > > NOTE: I've not checked the program for leaks at the moment > > > > Please do report back if this works for you. This should potentially > > solve most of the void** issues we have passing data between libcgroup > > and python wrappers back and forth > > I have the python wrapper working to a large degree >
cool! > 1. Please provide input if it works at your end hmmm...I'm getting a Segmentation fault, which is coming from the inner read stats loop. If I comment out the inner loop, I get a correct listing of the directories. Haven't been able to narrow it down more than that yet...using libcgroup libcgroup-0.36.2-2.fc15.i686. However, my python pkg might be outdated i'm using: Python 2.6.4. I'll re-test after upgrading. thanks, -Jason ------------------------------------------------------------------------------ This SF.net email is sponsored by Make an app they can't live without Enter the BlackBerry Developer Challenge http://p.sf.net/sfu/RIM-dev2dev _______________________________________________ Libcg-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libcg-devel
