Re: Memory question

2005-09-28 Thread Roger Leigh
David Rosal [EMAIL PROTECTED] writes:

 Allin Cottrell wrote:

 gchar *text = g_strdup_printf(banana %d, i);
 gtk_entry_set_text(GTK_ENTRY(entry), text);
 g_free(text);

 Is the above code really safe?

 You're passing the address of text to the function 
 gtk_entry_set_text(). Next you g_free() that address, so AFAIK the 
 memory manager marks it as free.
 Isn't it dangerous? I mean, after g_free() any call that requests for 
 memory (g_strdup, g_malloc, ...) can overwrite that memory chunk, 
 changing the text in the GtkEntry. Am I right?

No.  gtk_entry_set_text() will keep its own copy of the text
internally, which is contained within the GtkEntry object.  Once you
set the text, you can safely free your copy.  If it didn't work this
way, you would quickly run into all sorts of memory leaks.


Regards,
Roger

-- 
Roger Leigh
Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
Debian GNU/Linuxhttp://www.debian.org/
GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Memory question

2005-09-28 Thread David Rosal

Colossus wrote:

Hi,

Am I doing the same ( memory leaking ) with g_strdup_printf ?
If so what is the better way to write the following code: ?

response = ShowGtkMessageDialog (GTK_WINDOW 
(MainWindow),GTK_DIALOG_MODAL,GTK_MESSAGE_ERROR,GTK_BUTTONS_OK,

g_strdup_printf (%s,g_strerror(errno)) );
return;


gchar *msg = g_strdup_printf(%s, g_strerror(errno));
response = ShowGtkMessageDialog(GTK_WINDOW(MainWindow), 
GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, msg);

g_free(msg);
return;


Cheers,

~david
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Error while cross-compiling x11

2005-09-28 Thread sadhees kumar
Hi friends,
 Im now trying to cross-compile the x-11 source to tiny-x for
arm-architecture.What i did was in path x11/xc/config/cf/ i included the
host.def file and also changed the cross.def file, but it shows error while
compiling. Is there any seperate tool-chains for this?.Plz let me know
if anybody have experienced this problem.
 Thanks in advance.
 regards,
sadheeskumar
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Error while cross-compiling x11

2005-09-28 Thread Gian Mario Tagliaretti
2005/9/28, sadhees kumar [EMAIL PROTECTED]:
 Hi friends,

Hi

  Im now trying to cross-compile the x-11 source to tiny-x for
 arm-architecture.What i did was in path x11/xc/config/cf/ i included the
 host.def file and also changed the cross.def file, but it shows error while
 compiling. Is there any seperate tool-chains for this?.Plz let me know
 if anybody have experienced this problem.

sorry, what this has to do with a ML gtk-app-devel Writing Apps with GTK+ ?

--
Gian Mario Tagliaretti
PyGTK GUI programming
http://www.parafernalia.org/pygtk/
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


gtk label problem

2005-09-28 Thread Suganya
Hi all,

I am very new to developing applications with gtk.

I am developing SIP stack as a gui using gtk+-devel-1.2.10

I have a label widget which displays a text (in my case, it is the
status of the SIP call)

Depending on the status of the call, the text in the label widget should
change.

The problem I am facing is that the text is changing some times and not
changing other times.

Do I need to do a refresh for the label widget/entire window?

I tried with gtk_widget_queue_draw(GTK_WIDGET(label)), but in vain.

Suggestions are required.

Thanks in advance,
B.Suganya

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Memory question

2005-09-28 Thread Allin Cottrell

On Wed, 28 Sep 2005, David Rosal wrote:


Allin Cottrell wrote:


gchar *text = g_strdup_printf(banana %d, i);
gtk_entry_set_text(GTK_ENTRY(entry), text);
g_free(text);


Is the above code really safe?


Yes!  A function such as gtk_entry_set_text() is bound to make a 
copy of the string offered by the caller.  Or at any rate it is 
bound _not_ to attempt to free that string.


Think about it: suppose you pass gtk_entry_set_text() a string 
literal:


gtk_entry_set_text(GTK_ENTRY(entry), foo);

If gtk tried to free foo you'd get an immediate crash, since this 
is not storage obtained via malloc.  So we can infer that gtk (which 
is designed by wise and sane coders!) will not attempt to free 
strings that we pass into such functions.


So we can further infer that it is our business as callers of gtk 
functions to free strings that we pass to such functions, if we 
created these strings via functions that allocate storage -- i.e. 
that directly or indirectly call the C library function malloc() -- 
e.g. g_strdup(), g_strdup_printf() and friends.


Allin Cottrell
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list