Why does GObject method still get called even if callback arguments don't match those in XML?

Asked
Active3 hr before
Viewed126 times

5 Answers

calledmatch
90%

Why does my method, child_test_set_age(), still get called on DBus even if the callback arguments don't match the one specified in my XML? For example if I add another argument after guint ageIn, like a char* or guint or some other random type?,I've noticed that this won't work if the DBus function includes members with direction OUT. It seems that any argument of type IN that's unnecessary gets discarded and the call is done as usual.,However, if you manage to get through the function without a segfault, then the caller will neatly pop three arguments off the stack after the function returns and everything will be back to normal. So that's why your program still seems to work.,Now, however, if you give your function a different type than the DBus signature in the XML, let's say child_test_set_age(ChildTest *childTest, guint ageIn, guint otherNumberIn, GError **error), let's say the same arguments get pushed onto the stack, but your function interprets them differently:

You've hit on an interesting detail that exists because of the C language. Functions in C are strongly typed, and so strictly speaking you'd have to have functions to deal with every single possible type of callback, something like the following nightmare:

g_signal_connect_callback_void__void(GObject * object, gchar * signal,
   void( * callback)(GObject * , gpointer), gpointer data);
g_signal_connect_callback_void__guint(GObject * object, gchar * signal,
   void( * callback)(GObject * , guint, gpointer), gpointer data);
g_signal_connect_callback_gboolean__gdkevent(GObject * object, gchar * signal,
   gboolean( * callback)(GObject * , GdkEvent * , gpointer), gpointer data);
load more v
88%

Why does GObject method still get called even if callback arguments don't match those in XML?, NSAttributedString initWithData:options:documentAttributes:error: documentAttributes not retained in ARC None | 3 months ago

1.2.g_signal_connect_callback_void__void(GObject * object, gchar * signal, 3. void( * callback)(GObject * , gpointer), gpointer data);
4. g_signal_connect_callback_void__guint(GObject * object, gchar * signal, 5. void( * callback)(GObject * , guint, gpointer), gpointer data);
6. g_signal_connect_callback_gboolean__gdkevent(GObject * object, gchar * signal, 7. gboolean( * callback)(GObject * , GdkEvent * , gpointer), gpointer data);
8.9. + -- -- -- -- -- -- + 10. | & childTest | arg111. + -- -- -- -- -- -- + 12. | 25 | arg213. + -- -- -- -- -- -- + 14. | NULL | arg315. + -- -- -- -- -- -- + 16.17. + -- -- -- -- -- -- + 18. | & childTest | ChildTest * childTest19. + -- -- -- -- -- -- + 20. | 25 | guint ageIn21. + -- -- -- -- -- -- + 22. | NULL | GError ** error23. + -- -- -- -- -- -- + 24.25. + -- -- -- -- -- -- + 26. | & childTest | ChildTest * childTest...OK so far27. + -- -- -- -- -- -- + 28. | 25 | guint ageIn...still OK29. + -- -- -- -- -- -- + 30. | NULL | guint otherNumberIn...will be 0
if you
try to read it, but OK31. + -- -- -- -- -- -- + 32. | undefined | GError ** error...will be garbage!33. | behavior | 34. | land!! | 35. | ... | 36.
72%

This is a very convenient way to store your own data associated with the various objects exported by GPS. These data cease to exist when the GPS object itself is destroyed (for instance when the editor is closed in the example above).,For all functions, the list of parameters is specified. The first parameter is often called “self”, and refers to the instance of the class to which the method applies. In Python, the parameter is generally put before the method’s name, as in:,Return the list of entities that extend self (in the object-oriented sense),Get the default value for the parameter identified by the given name.

self.method(arg1, arg2)
load more v
65%

load more v
75%

GLib is a general-purpose, portable utility library, which provides many useful data types, macros, type conversions, string utilities, file utilities, a mainloop abstraction, and so on.,The type of functions which are used to translate user-visible strings, for —help output.,Log a message with structured data, accepting the data within a GVariant. This version is especially useful for use in other languages, via introspection.,Obtains the character set used by the console attached to the process, which is suitable for printing output to the terminal.

load more v

Other "called-match" queries related to "Why does GObject method still get called even if callback arguments don't match those in XML?"