Re: g_main_dispatch frees objects for input_callback before using them (how to prevent it?)

2014-10-11 Thread Thomas DEBESSE
Hi, I got it !

As seen on https://git.gnome.org/browse/glib/tree/glib/giounix.c#n165

The old callback for file descriptor takes (gpointer *user_data, int fd,
GdkInputCondition condition).
The new callback for channels takes (GIOChannel *chan, GIOCondition
condition, gpointer *user_data)!

The objects user_data, condition and chan were not expected to be at the
same place !

Thank you for directing me to the right direction! If the callback have a
return today, perhaps there is a reason for arguments to change too.

After that I find easily there was two calls of g_source_remove of the same
object.

So:
1. This part of this code is not deprecated anymore.
2. I found and fixed the bug that motivated my cleaning.

--
Thomas DEBESSE
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: g_main_dispatch frees objects for input_callback before using them (how to prevent it?)

2014-10-11 Thread Thomas DEBESSE
Thank you for your responses!

2014-10-10 22:54 GMT+02:00 Chris Vine :
> If stat_master_input_callback() is a call back for a GIOChannel watch,
> then by returning void the callback is definitely defective.  That may
> well explain your observations.

I changed that, the diff is now:
https://github.com/XQF/xqf/compare/master...g_io

But the bug is still there. ;-)

The problem is when I call "g_io_addwatch (chan, condition, callback,
user_data)",
"g_io_add_watch" calls "g_io_add_watch_full (chan, condition, callback,
user_data, and more)", ok.

But after that, g_main_dispatch calls "callback(bad pointer user_data, bad
pointer condition)", not ok.

I fixed the return of the callback, but the callback fails before returning
anything… g_main_dispatch pass wrongs arguments to the callback. :/

It seems something is lost somewhere…

(and yes it is a very old and very deprecated code, that's why I'm working
on it. :D)

--
Thomas DEBESSE
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: g_main_dispatch frees objects for input_callback before using them (how to prevent it?)

2014-10-10 Thread Chris Vine
On Fri, 10 Oct 2014 21:17:18 +0200
Thomas DEBESSE  wrote:
> 2014-10-10 14:07 GMT+02:00 Chris Vine :
> > This may not be an issue in your code but note that a callback
> > function used as an io watch must return gboolean, and the return
> > value is used to determine whether the io watch is removed from the
> > list of sources. If you cast a function returning void to GIOFunc,
> > you will get random and undefined results.
> >
> > Chris
> 
> Hum, it's really interesting, the problem may be there!
> I'll try to change that.

If stat_master_input_callback() is a call back for a GIOChannel watch,
then by returning void the callback is definitely defective.  That may
well explain your observations.

Chris
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: g_main_dispatch frees objects for input_callback before using them (how to prevent it?)

2014-10-10 Thread Thomas DEBESSE
2014-10-10 14:07 GMT+02:00 Chris Vine :
> No, but this change can't be right:
>
>   -
>   -static void stat_master_input_callback (struct stat_conn *conn, int fd,
>   -GdkInputCondition condition) {
>   +static GIOFunc stat_master_input_callback (struct stat_conn *conn, int
fd,
>   +   GIOCondition condition) {
>
> because you do not appear actually to change the return statement in the
> function stat_master_input_callback(), which was void before (unless this
> is in a different commit).  Is this now a callback factory function - it
> didn't appear to be so before.

Thanks a lot, you are right ! And this was not the only typing mistake I
have done…
I fix that:
https://github.com/XQF/xqf/commit/0e17fd9ea61c7a10d4a2d0cfdc275e0c09b33fd2

It does not solve my problem yet, but it will be better that way! :D
Thanks for your help.

So, that is the current diff between my master branch and my g_io branch:
https://github.com/XQF/xqf/compare/master...g_io

The fact that glib loses my pointer is still a great mystery to me.
There's certainly something I've forgotten, but I do not know what!

> This may not be an issue in your code but note that a callback function
> used as an io watch must return gboolean, and the return value is used to
> determine whether the io watch is removed from the list of sources.
> If you cast a function returning void to GIOFunc, you will get random
> and undefined results.
>
> Chris

Hum, it's really interesting, the problem may be there!
I'll try to change that.

Thank you for your help.


--
Thomas DEBESSE
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


Re: g_main_dispatch frees objects for input_callback before using them (how to prevent it?)

2014-10-10 Thread Chris Vine
On Fri, 10 Oct 2014 03:11:41 +0200
Thomas DEBESSE  wrote:
> Hi everyone, I'm trying to revive a very old project: XQF, a
> graphical game server browser.
> 
> Many things are deprecated in this old code, but there is one that
> particularly bothers me: I try to port gdk_input_* calls to g_io.
> 
> I do something like that:
> https://github.com/XQF/xqf/commit/cf2b506547755c6f7176979cf8b7db189c14c7e4
> 
> I rewrite some callbacks with new functions, new types,
> gdk_input_remove is replaced by g_source_remove, gdk_input_add is
> replaced by g_io_add_watch and I use GioChannel, etc.
> 
> So everything seems to work… until g_main_dispatch calls my callback.
> 
> You can read all my investigations here:
> https://github.com/XQF/xqf/issues/4
> 
> I see g_io_add_watch add a callback on a channel with a user_data
> reference, and yes, It works when I trace the code with gdb. The
> callback is added with the pointer to user_data, and when I trace the
> execution, pointers are the good ones.
> 
> But when g_io_add_watch returns to the main loop, g_main_dispatch
> frees some objects and then call the callback… and segfaults because
> the callback was launched with a null pointer user_data!
> 
> You can read a complete walktrough here :
> https://github.com/XQF/xqf/issues/4#issuecomment-58442986
> 
> I'm looking for a way to prevent g_main_dispatch to forget the
> user_data and conditions before the call of my input_callback.
> 
> Is anyone have any idea what's going on?

No, but this change can't be right:

  -
  -static void stat_master_input_callback (struct stat_conn *conn, int fd,
  -GdkInputCondition condition) {
  +static GIOFunc stat_master_input_callback (struct stat_conn *conn, int fd,
  +   GIOCondition condition) {

because you do not appear actually to change the return statement in the
function stat_master_input_callback(), which was void before (unless this
is in a different commit).  Is this now a callback factory function - it
didn't appear to be so before.

This may not be an issue in your code but note that a callback function
used as an io watch must return gboolean, and the return value is used to
determine whether the io watch is removed from the list of sources.
If you cast a function returning void to GIOFunc, you will get random
and undefined results.

Chris
___
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list