Re: Gee libgee and PyGI



On Sat, 2012-01-28 at 10:43 +0100, Frederik Elwert wrote:
> Hello,
> 

Hi,

> I am currently trying to write a libfolks client in Python using the
> GObject Introspection system. Thanks to the help of the telepathy team,
> accessing libfolks itself basically works now.
> 
> However, I am currently stuck with accessing the actual data. Libfolks
> returns libgee data structures. When trying to access these, I am
> getting segfaults. Since I could not find any example of how one could
> use libgee objects from Python at all, I am struggling with creating a
> minimal test case that could help identifying the root cause of the
> crash.
> 
> Here is my current attempt:
> 
> ----8<----
> from gi.repository import GObject
> from gi.repository import Folks
> 
> 
> def list_individuals():
>     iterator = aggregator.props.individuals.props.keys.iterator()
>     while iterator.next():
>         key = iterator.get()

It seems that "print key" breaks here. I guess you'll get more help on
pygi/vala/gir mailing lists (especially the first one if problem is on
pygi side and second one if it is on vala side) then here.

>         print aggregator.props.individuals.get(key)
> 

As side point - more efficient way would be:

def list_individuals():
	iterator = aggregator.props.individuals.iterator()
	while iterator.next():
		# key = iterator.get().props.key;
		print iterator.get().props.value;
	

> aggregator = Folks.IndividualAggregator.new()
> aggregator.prepare(None, None)
> 
> GObject.timeout_add(2000, list_individuals)
> 
> main_loop = GObject.MainLoop()
> main_loop.run()
> ---->8----
> 
> The current conversation on the telepathy list is here:
> http://lists.freedesktop.org/archives/telepathy/2012-January/005951.html
> 
> Maybe someone with deeper knowledge of libgee could help?
> 
> Regards
> Frederik
> 

It looks like the value returned by "iterator.get()" was 'invalid'. It
works in vala and it is denoted correctly in gir.

The problem may be that the type of individuals is:

public Gee.Map<string,Folks.Individual> individuals { get; private
set; }

I guess that python doesn't have information how to free the string
which happens to be 40 bytes string located somewhere). I guess that it
interprets void * as GObject - while printing/passing it might want to
check type - i.e. ((GTypeInstance *)key)->g_class->g_type. Key is say 
0b9a27021d2bd8445587f548cf99cc12a971d9c7. Transfering it into
hexadecimal value it is:

0x30623961323730323164326264383434353538376635343863663939636331326139373164396337

Hence the g_class is value:

On x86:            0x61396230
On x86-64: 0x3230373261396230

Which is random point in memory. When we try to dereference it we get
segfault (probable if our space is 'empty') or we are accessing
something.

EDIT: It seems that the problem is also with Map.Entry so above
explanation is partially wrong. PyGI basicly doesn't accept the gpointer
as type because it does not know how to handle it. Gir probably cannot
provide this information in its format.

Regards



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]