Re: [anjuta-devel] New project interface and introspection



Hi,
              في ح، 05-09-2010 عند 19:50 +0200 ، كتب Sébastien Granjoux:

Yes, a gpointer parameter gets passed a python object as is, you just
need to add some get_extra_data function or something.

I have tried this but how can I get back the object in python ?

I have written in python

class NodeData:
      def __init__(self):
              self.data = 0

data = NodeData()
node = Anjuta.project_generic_node_new (0, None, "noname", data)
You did add allow-none for the file, right? (still It seems weird it
didn't complain about passing 0 instead of an enum value)
pointer = Anjuta.project_generic_node_get_user_data (node)

But pointer is gi.FunctionInfo, how can I convert it back to NodeData ?

Well, you've probably hit a bug in PyGObject. Do you have some code I
can try?


2. I can try to check what is the difference between creating a
AnjutaProjectNode like it is now and a GObject representing a node.

I have try to create and free 1000000 project nodes using the current C 
structure or a GObject. It's roughly 2.5 time slower with GObject which 
is faster than what I expect.

If I'm doing the same in python it's 250 time slower for C structure and 
could be almost 160 time slower with GObject. The issue with GObject in 
python is that the finalize function is never called. Do you know how I 
can be sure that the free function is called ?
It should be called when there are no more refernces to the object,
neither from python nor from C. It may help to run the gc.


I have tried:
      node = Anjuta.ProjectGObjectNode.new (0, None, "noname", 0)
      node = None
Or
      node = Anjuta.ProjectGObjectNode.new (0, None, "noname", 0)
      node.free ()
This last piece of code give an error, because python is not aware that 
node shouldn't be used after calling node.free.
I think you shouldn't worry about this, if there is no reference leak it
should be freed at some point.

I haven't decided if I will use GObject for project node, here is a 
summarize of all issues.

1. Use C structures
+ Already working fine
+ No need to rewrite GNode functions
+ 2.5 faster than GObject (for very simple node)
- free function has to be called manually even in language with a GC

2. Use of a Boxed type
+ Same advantage than C structure
- I don't know if I can define a boxed type incrementing the reference 
count on copy and decrease it on free.
- I don't know if I can use this type in introspection annotation 
without changing the C code.
It should be ok. There may be bugs in the bindings since this is not
often used, but it should work. (actually, I believe GIOChannel is a
Boxed type)


3. Use GObject
+ Deallocation can be done automatically in language like python
+ AnjutaProjectNode and AnjutaProjectNodeData are the same
+ Nodes could replace the project object.
- 2.5 slower than C structures
- Need to rewrite all GNode functions

What do you think ?
Well, I'd prefer using GObject if it isn't too much for you. The
"slowness" isn't that bad, and the benefits are easier project backends
(we could even try to implement backends for popular IDE formats).

Regards,
Abderrahim




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