Re: gtk2-perl / a script to help converting basic functions



Le mar 22/10/2002 à 22:23, Guillaume Cottenceau a écrit :
Hi,

I've added gtk2-perl/genscripts/convert_funcs.pl to the CVS. It's
a script I've made because I was tired to write down by hand
the conversions of dumb/simple functions :).

So, for simple functions, you may use it if you like. It will
kind of work for simple constructors and simple get/set/do_action
functions (the heuristic for detecting constructors is not very
good, though). It won't work when we need to g_malloc structs by
hand before calling the gtk function, of course, nor when we want
to return an arrayref, or when we are dealing with more complex
functions (but it's still helpful for the function prototype and
the gtk function call).

Of course you need to double check by hand the results :).


For example, when you give it:

-=-=---=-=---=-=---=-=---=-=---=-=---=-=--
void        gtk_text_buffer_set_text        (GtkTextBuffer *buffer,
                                             const gchar *text,
                                             gint len);
gchar*      gtk_text_buffer_get_text        (GtkTextBuffer *buffer,
                                             const GtkTextIter *start,
                                             const GtkTextIter *end,
                                             gboolean include_hidden_chars);
-=-=---=-=---=-=---=-=---=-=---=-=---=-=--


It will output:

-=-=---=-=---=-=---=-=---=-=---=-=---=-=--
void gtkperl_text_buffer_set_text(SV* buffer, char* text, int len)
{
    gtk_text_buffer_set_text(SvGtkTextBuffer(buffer), text, len);
}

char* gtkperl_text_buffer_get_text(SV* buffer, SV* start, SV* end, int include_hidden_chars)
{
    return gtk_text_buffer_get_text(SvGtkTextBuffer(buffer), SvGtkTextIter(start), SvGtkTextIter(end), 
include_hidden_chars);
}
-=-=---=-=---=-=---=-=---=-=---=-=---=-=--


Which is correct, and pretty helpful :).

I don't share to point of view. The gtkperl_text_buffer_get_text
function is not correct. It will create a memory leak in Gtk2-Perl. The
gtk_text_buffer_get_text function like many other is returning an
allocated string which must be freed with g_free when we no more need
it. This is often the case for function which return char *.

I think that we must copy the string in a perl string and g_free the
return value before exiting the function. I have not the solution
("code") for now but you must be aware of that I try to correct this.

-- 
Guillaume Cottenceau - http://people.mandrakesoft.com/~gc/

Daniel Lacroix




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