Re: Setting G_SLICE=always_malloc at runtime
Okay, I've figured out why g_slice_set_config wasn't working...at some point g_quark_from_static_string was being called before g_slice_set_config, hence the error. On 6/8/07, Raja Mukherji <[EMAIL PROTECTED]> wrote: > Do I set the environment variable? Because code like > > setenv("G_SLICE", "always_malloc", 1); > g_thread_init(0); > > doesn;t seem to work. > I noticed the g_slice_set_config functions in gslice.h and tried > > g_slice_set_config(G_SLICE_CONFIG_ALWAYS_MALLOC, 1); > > but this gives me the error > > (process:6533): GLib-CRITICAL **: g_slice_set_config: assertion > `sys_page_size == 0' failed > > and also does not work. > What am I doing wrong? > > Raja > > > On 6/7/07, David Nečas (Yeti) <[EMAIL PROTECTED]> wrote: > > On Thu, Jun 07, 2007 at 08:04:08PM +0100, Raja Mukherji wrote: > > > I'm writing a binding for Gtk to my programming language Wrapl, and > > > want to make sure that all memory is allocated by the Hans-Boehm > > > garbage collector. The glib/gobject shared libraries are loaded > > > dynamically and I call g_mem_set_vtable to change to GC_malloc, > > > GC_realloc, GC_free, etc. However g_slice doesn't use these. I know > > > that setting the environment variable G_SLICE to "always_malloc" will > > > solve this, but I want to do this at runtime, just after the relevant > > > shared libraries are loaded, but before they are used (basically at > > > the same time as when I'd call g_mem_set_vtable). > > > Is this possible? > > > > GSlice is initialized, i.e. it looks at G_SLICE, on the > > first use or when thread support is initialized. So just > > set the variable before that. > > > > Yeti > > > > -- > > http://gwyddion.net/ > > ___ > > gtk-app-devel-list mailing list > > gtk-app-devel-list@gnome.org > > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > > > ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: drawing to textview's gdk_window
Luka, Sounds like an expose event needs to be signaled. I use GDK only and not GTK so I am not sure how much of GTK is doing event processing. Chris > Hello. I'm trying to draw a rectangle of a textview's background > GdkWindow. First I get the gdk_window of the textview and and then try > ot draw on it. But it doesn't work. Why? > > - > #include > > int main(int argc, char **argv) > { > > GtkWidget *window; > GtkWidget *text; > GdkGC *gc; > GdkColor color1, color2; > GdkWindow *win; > gtk_init(&argc, &argv); > > window = gtk_window_new(GTK_WINDOW_TOPLEVEL); > text = gtk_text_view_new(); > gtk_widget_show(text); > gtk_container_add(window, text); > gtk_widget_show_all(window); > gtk_widget_realize(text); > > win = gtk_text_view_get_window(text, GTK_TEXT_WINDOW_WIDGET); > gc = gdk_gc_new(win); > gdk_color_parse("red", &color1); > gdk_gc_set_foreground(gc, &color1); > gdk_color_parse("black", &color2); > gdk_gc_set_background(gc, &color2); > gdk_gc_set_fill(gc, GDK_SOLID); > > gdk_draw_rectangle(win, gc, TRUE, 1, 1, 20, 20); > > gtk_widget_set_size_request(window, 500, 400); > gtk_main(); > return 0; > } > --- > > > Greets, > Luka > > > > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
drawing to textview's gdk_window
Hello. I'm trying to draw a rectangle of a textview's background GdkWindow. First I get the gdk_window of the textview and and then try ot draw on it. But it doesn't work. Why? - #include int main(int argc, char **argv) { GtkWidget *window; GtkWidget *text; GdkGC *gc; GdkColor color1, color2; GdkWindow *win; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); text = gtk_text_view_new(); gtk_widget_show(text); gtk_container_add(window, text); gtk_widget_show_all(window); gtk_widget_realize(text); win = gtk_text_view_get_window(text, GTK_TEXT_WINDOW_WIDGET); gc = gdk_gc_new(win); gdk_color_parse("red", &color1); gdk_gc_set_foreground(gc, &color1); gdk_color_parse("black", &color2); gdk_gc_set_background(gc, &color2); gdk_gc_set_fill(gc, GDK_SOLID); gdk_draw_rectangle(win, gc, TRUE, 1, 1, 20, 20); gtk_widget_set_size_request(window, 500, 400); gtk_main(); return 0; } --- Greets, Luka ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: drawing to textview's gdk_window
I now connected the expose-event signal to a callback function that draws a rectangle to the widget. The problem is that the font is under the rect. if I call g_signal_connect_after() and no text appears if I call g_signal_connect() but the rect is visible. I get the GdkWindow of the textview using: win = gtk_text_view_get_window(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_TEXT); I want the rect to be in the background of the textview. Is there any way to do that? Greets, Luka Dne 08.06.2007 (pet) ob 08:32 -0700 je Chris Sparks zapisal(a): > Luka, > > Sounds like an expose event needs to be signaled. I use GDK only and > not GTK so I am not sure > how much of GTK is doing event processing. > > Chris > > Hello. I'm trying to draw a rectangle of a textview's background > > GdkWindow. First I get the gdk_window of the textview and and then try > > ot draw on it. But it doesn't work. Why? > > > > - > > #include > > > > int main(int argc, char **argv) > > { > > > > GtkWidget *window; > > GtkWidget *text; > > GdkGC *gc; > > GdkColor color1, color2; > > GdkWindow *win; > > gtk_init(&argc, &argv); > > > > window = gtk_window_new(GTK_WINDOW_TOPLEVEL); > > text = gtk_text_view_new(); > > gtk_widget_show(text); > > gtk_container_add(window, text); > > gtk_widget_show_all(window); > > gtk_widget_realize(text); > > > > win = gtk_text_view_get_window(text, GTK_TEXT_WINDOW_WIDGET); > > gc = gdk_gc_new(win); > > gdk_color_parse("red", &color1); > > gdk_gc_set_foreground(gc, &color1); > > gdk_color_parse("black", &color2); > > gdk_gc_set_background(gc, &color2); > > gdk_gc_set_fill(gc, GDK_SOLID); > > > > gdk_draw_rectangle(win, gc, TRUE, 1, 1, 20, 20); > > > > gtk_widget_set_size_request(window, 500, 400); > > gtk_main(); > > return 0; > > } > > --- > > > > > > Greets, > > Luka > > > > > > > > ___ > > gtk-app-devel-list mailing list > > gtk-app-devel-list@gnome.org > > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Building portable apps with portaccess unter qtk/glib
I want to build a widget to communicate over com, lpt and usb under the cygwin32/windowsport oft glib/gtk with a gtk-widget that set parameters for the interface, but plattform-independend and handle communikation. Does a method for the gtk/lib-windowsport exist to do this? Under linux /dev/ttyS0 work fine, but this is not portable. I need a port-dialogue-widget, that is widely portable. I think is the same procedure as portaccess via a pci-card. In linux is this only a fileoperation, but under windowsport this part may a major problem. best regards ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: drawing to textview's gdk_window
Hi, Using g_signal_connect(), make your callback return false, so that the original callback (that obviously renders the text) will then be called also. Jonathan On 6/8/07, Luka Napotnik <[EMAIL PROTECTED]> wrote: > > I now connected the expose-event signal to a callback function that > draws a rectangle to the widget. The problem is that the font is under > the rect. if I call g_signal_connect_after() and no text appears if I > call g_signal_connect() but the rect is visible. > I get the GdkWindow of the textview using: > win = gtk_text_view_get_window(GTK_TEXT_VIEW(widget), > GTK_TEXT_WINDOW_TEXT); > > I want the rect to be in the background of the textview. Is there any > way to do that? > > Greets, > Luka > > Dne 08.06.2007 (pet) ob 08:32 -0700 je Chris Sparks zapisal(a): > > Luka, > > > > Sounds like an expose event needs to be signaled. I use GDK only and > > not GTK so I am not sure > > how much of GTK is doing event processing. > > > > Chris > > > Hello. I'm trying to draw a rectangle of a textview's background > > > GdkWindow. First I get the gdk_window of the textview and and then try > > > ot draw on it. But it doesn't work. Why? > > > > > > - > > > #include > > > > > > int main(int argc, char **argv) > > > { > > > > > > GtkWidget *window; > > > GtkWidget *text; > > > GdkGC *gc; > > > GdkColor color1, color2; > > > GdkWindow *win; > > > gtk_init(&argc, &argv); > > > > > > window = gtk_window_new(GTK_WINDOW_TOPLEVEL); > > > text = gtk_text_view_new(); > > > gtk_widget_show(text); > > > gtk_container_add(window, text); > > > gtk_widget_show_all(window); > > > gtk_widget_realize(text); > > > > > > win = gtk_text_view_get_window(text, GTK_TEXT_WINDOW_WIDGET); > > > gc = gdk_gc_new(win); > > > gdk_color_parse("red", &color1); > > > gdk_gc_set_foreground(gc, &color1); > > > gdk_color_parse("black", &color2); > > > gdk_gc_set_background(gc, &color2); > > > gdk_gc_set_fill(gc, GDK_SOLID); > > > > > > gdk_draw_rectangle(win, gc, TRUE, 1, 1, 20, 20); > > > > > > gtk_widget_set_size_request(window, 500, 400); > > > gtk_main(); > > > return 0; > > > } > > > --- > > > > > > > > > Greets, > > > Luka > > > > > > > > > > > > > ___ > > > gtk-app-devel-list mailing list > > > gtk-app-devel-list@gnome.org > > > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > > > > ___ > > gtk-app-devel-list mailing list > > gtk-app-devel-list@gnome.org > > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Deriving from GtkWindow and libglade
I want to derive a new class from GtkWindow to represent a top-level window which contains objects from a Glade XML file. Since the glade_xml_get_widget functions returns a new object, I'm not sure what to do in the object's "init_instance" function to copy the properties (and children) of the returned top-level window to the object itself. I thought of using child = glade_xml_get_widget to get the child of the top-level window, then use gtk_container_add(self, child). However, the new top-level window won't have the properties set within the glade file. Any insights are appreciated. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: drawing to textview's gdk_window
Thanks it works now. Greets, Luka Dne 08.06.2007 (pet) ob 19:14 +0200 je Jonathan Winterflood zapisal(a): > Hi, > > Using g_signal_connect(), make your callback return false, so that > the original callback (that obviously > renders the text) will then be called also. > > Jonathan > > On 6/8/07, Luka Napotnik <[EMAIL PROTECTED]> wrote: > I now connected the expose-event signal to a callback function > that > draws a rectangle to the widget. The problem is that the font > is under > the rect. if I call g_signal_connect_after() and no text > appears if I > call g_signal_connect() but the rect is visible. > I get the GdkWindow of the textview using: > win = gtk_text_view_get_window(GTK_TEXT_VIEW(widget), > GTK_TEXT_WINDOW_TEXT); > > I want the rect to be in the background of the textview. Is > there any > way to do that? > > Greets, > Luka > > Dne 08.06.2007 (pet) ob 08:32 -0700 je Chris Sparks > zapisal(a): > > Luka, > > > > Sounds like an expose event needs to be signaled. I use GDK > only and > > not GTK so I am not sure > > how much of GTK is doing event processing. > > > > Chris > > > Hello. I'm trying to draw a rectangle of a textview's > background > > > GdkWindow. First I get the gdk_window of the textview and > and then try > > > ot draw on it. But it doesn't work. Why? > > > > > > - > > > #include > > > > > > int main(int argc, char **argv) > > > { > > > > > > GtkWidget *window; > > > GtkWidget *text; > > > GdkGC *gc; > > > GdkColor color1, color2; > > > GdkWindow *win; > > > gtk_init(&argc, &argv); > > > > > > window = gtk_window_new(GTK_WINDOW_TOPLEVEL); > > > text = gtk_text_view_new(); > > > gtk_widget_show(text); > > > gtk_container_add(window, text); > > > gtk_widget_show_all(window); > > > gtk_widget_realize(text); > > > > > > win = gtk_text_view_get_window(text, > GTK_TEXT_WINDOW_WIDGET); > > > gc = gdk_gc_new(win); > > > gdk_color_parse("red", &color1); > > > gdk_gc_set_foreground(gc, &color1); > > > gdk_color_parse("black", &color2); > > > gdk_gc_set_background(gc, &color2); > > > gdk_gc_set_fill(gc, GDK_SOLID); > > > > > > gdk_draw_rectangle(win, gc, TRUE, 1, 1, 20, 20); > > > > > > gtk_widget_set_size_request(window, 500, 400); > > > gtk_main(); > > > return 0; > > > } > > > --- > > > > > > > > > Greets, > > > Luka > > > > > > > > > > > > > > ___ > > > gtk-app-devel-list mailing list > > > gtk-app-devel-list@gnome.org > > > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > > > > ___ > > gtk-app-devel-list mailing list > > gtk-app-devel-list@gnome.org > > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: multi thread app and often variable accessing
> On 6/8/07, Tomasz Jankowski <[EMAIL PROTECTED] > wrote: > > > > Hi! > > > > I'm working on small multi thread application based on Gobject. In one of > > my > > objects I have integer variable, which determine current object's status. > > The problem is, that I need to read it's status really often, so it will > > be > > to expensive to lock and unlock mutex all the time. Can I use there atomic > > operations provided by GLib instead of mutex locking and unlocking system? > > I > > mean, if g_atomic_get and g_atomic_set would not occur any problems, when > > I > > will try to access the same variable from two thread at the same time? > > > > -- > > Cya! > > Tom On 6/8/07, Jonathan Winterflood <[EMAIL PROTECTED]> wrote: > Hi, > > As far as I understand, g_atomic_int_get/set will do the job > just fine, as long as you're sure the only part that needs to be > atomic is the getting and setting. > However, if the hardware you are running on does not provide an atomic way > of getting/setting an int, (eg: int is an int32 and the hardware is 8-bit), > you will end up locking and unlocking mutexes anyways (but most systems > nowadays are 32bit+ anyways) > > Jonathan > Also, the hardware must have something like the Pentium CMPXCHG8B or it's newer cousins to do this "efficiently". I'm not sure exactly how it's done in glib, but normally, if such instructions dont exist, you need to issue standard MOV instructions with a bus-lock prefix, which is slow. -Jim PS, please don't top-post. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: multi thread app and often variable accessing
Hi, As far as I understand, g_atomic_int_get/set will do the job just fine, as long as you're sure the only part that needs to be atomic is the getting and setting. However, if the hardware you are running on does not provide an atomic way of getting/setting an int, (eg: int is an int32 and the hardware is 8-bit), you will end up locking and unlocking mutexes anyways (but most systems nowadays are 32bit+ anyways) Jonathan On 6/8/07, Tomasz Jankowski <[EMAIL PROTECTED] > wrote: > > Hi! > > I'm working on small multi thread application based on Gobject. In one of > my > objects I have integer variable, which determine current object's status. > The problem is, that I need to read it's status really often, so it will > be > to expensive to lock and unlock mutex all the time. Can I use there atomic > operations provided by GLib instead of mutex locking and unlocking system? > I > mean, if g_atomic_get and g_atomic_set would not occur any problems, when > I > will try to access the same variable from two thread at the same time? > > -- > Cya! > Tom > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: multi thread app and often variable accessing
On 6/8/07, Tomasz Jankowski <[EMAIL PROTECTED]> wrote: > > In fact I write library, but it's based on GLIb, so my library will be > available only on platforms where GLib is available - problem resolved > itself ;P Returning to main problem, maybe for sure, I will add another > mutex used only for reading or changing status variable. It will be more > expensive but maybe safer. > -- > Cya! > Tom > available only on platforms where GLib is available there's nothing stopping Glib being available on 8-bit systems [not the fact they are 8-bit at any rate] > you will end up locking and unlocking mutexes anyways I meant that g_atomic* will do the locking for you > I will add another mutex used only for reading or changing status variable. It will be more expensive but maybe safer. I think glib will be fine, just that you will revert to low performance on really old/rare/weird systems googling to find the atomic functions, I stumbled upon this: http://www.nabble.com/Mutex-or-atomic-operations-for-multithread-app--t2612916.html > If you don't know what memory ordering, barriers, etc. [...] Indeed I don't know what these are either. Any chance that someone does? Begin Curiosity: > Also, the hardware must have something like the Pentium CMPXCHG8B [...] Is it not sufficient to be able to write an int in one single bus access? ie have a 32-bit wide data bus Or is that exactly the point? :D >MOV instructions with a bus-lock prefix, which is slow. OK, I guess it'd be faster (and leaner) than using a mutex though But that can't be done in pure C, right? End curiosity Cheers, Jonathan -- linux, c'est une question de VI ou de MORE ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: multi thread app and often variable accessing
On Fri, Jun 08, 2007 at 09:27:38PM +0200, David Nečas (Yeti) wrote: > > Attempts to use atomic operations without considering memory [*] > access ordering guarantee subtle bugs... [*] as a substitute for locking. Yeti -- http://gwyddion.net/ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: multi thread app and often variable accessing
On Fri, Jun 08, 2007 at 08:51:08PM +0200, Jonathan Winterflood wrote: > > > If you don't know what memory ordering, barriers, etc. [...] > Indeed I don't know what these are either. Any chance that someone does? See Documentation/memory-barriers.txt in Linux source code, on-line available for instance at http://www.mjmwired.net/kernel/Documentation/memory-barriers.txt for a good overview of the concepts and issues. The later parts of the document are kernel specific, but you may get more information than you want even before you get to these parts. Attempts to use atomic operations without considering memory access ordering guarantee subtle bugs... Yeti -- http://gwyddion.net/ ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: multi thread app and often variable accessing
> Begin Curiosity: > > Also, the hardware must have something like the Pentium CMPXCHG8B [...] > Is it not > sufficient to be able to write an int in one single bus access? ie > have a 32-bit wide data bus > Or is that exactly the point? :D > No, in most cases, if you want to atomically increment or decrement a value (for example, a semaphore or ref count) without locking, you have to read the value, increment it, then write it only if it's not changed. The write and check to see if it's not changed must be atomic, this is where CMPXCHG comes in. > >MOV instructions with a bus-lock prefix, which is slow. > OK, I guess it'd be faster (and leaner) than using a mutex though > But that can't be done in pure C, right? > Maybe, but I don't see how any end-user program (such as one with a GTK interface) would benefit from the small speed increase. Put such stuff in another program which merely reports its progress to the gtk GUI program through a socket or pipe. > End curiosity And Yeti's right, this stuff can lead to months of head scratching unless you know what you're doing. I know I don't, so I'll not potentially mislead you any more. ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list