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



Hi Abderrahim,


Le 05/09/2010 15:05, Abderrahim Kitouni a écrit :
I don't think this is ok. "the object doesn't belong to the caller"
means that the caller doesn't need to free it, which is wrong IMHO.

I'm quite sure it's right. One of the scary warning that you get when you return a C structure ask you to set transfer mode to none because the caller doesn't know how to free the structure.


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 defined in C
AnjutaProjectGObjectNode*
anjuta_project_generic_node_new (AnjutaProjectNodeType type, GFile *file, const gchar *name, gpointer user_data)

gpointer
anjuta_project_generic_node_get_user_data (AnjutaProjectNode *node);


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)
pointer = Anjuta.project_generic_node_get_user_data (node)

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


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 ?

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 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.

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 ?


Regards,

Sébastien



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