Re: [introspection] struct without copy constructor



On 01/31/2012 06:06 PM, Picca Frédéric-Emmanuel wrote:
I tryed with the object himself but, I got a double free error, at the end.
the binding do not check that object are identical (save adress) and
try to free it two times. Is it a bug ?

This is because you have a free function which... frees the fake copies. The free function should always be the exact opposite of the copy function, as it will indeed be used to "undo" what the copy function did before.

- if you copy then it should free
- if you ref it should ref
- if you do nothing it should do nothing

The bindings will *never* check the output of both of those functions. It is your job to ensure everything is coherent. Don't get abused by the "copy" and "free" term, just try and understand what's the purpose of those functions (it's probably explained in the docs) and work from that.

This is not black magic, this is just telling glib how to manage your
objects as there is no way in C to duplicate a random struct or free it
(you can have pointers, etc).

Static and refcounted structs are just special cases of copy/free where
the copy is the object itself and you don't need to do anything to free
the resources.

Yes but in my case the object is not static :), it was allocated by a _new method.

Well, then either make it copyable, or make it refcounted, or ensure it will always outlive any code using it (which is very difficult to do in bindings as you depend on the gc of the target language, so better avoid it)

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