GNOME Bugzilla – Bug 603754
Make arguments annotated as 'closure' optional
Last modified: 2010-02-19 16:32:59 UTC
The user_data argument to methods with callback parameter should hardly be used in the binding - allow for omission in this case rather than enforcing to pass in null.
Created attachment 149064 [details] [review] Make arguments annotated as 'closure' optional With this change, methods with callback parameters follow the same syntax as Mainloop.timeout_add or Signal.connect.
Comment on attachment 149064 [details] [review] Make arguments annotated as 'closure' optional This will need additional tests. Can internal_argc be merged with argc?
Created attachment 149115 [details] [review] Make arguments annotated as 'closure' optional Added a test case for a callback with omitted user_data parameter. A simple merge of internal_argc with argc results in a failed assertion in line 678, I'll keep looking into it though.
Hmm; this inherently assumes that functions only have user_datas at the end of the function, but I'm pretty sure there are functions somewhere in the stack that take multiple callbacks, like: void foo (GFoo *self, FooSomeCallback callback, gpointer user_data, FooOtherCallback, gpointer other_data, GDestroyNotify destroy_notify). Maybe we could detect this case though and make them mandatory. Personally though, I'd rather we always deleted user_data arguments, and fixed e.g. Lang.bind to allow currying, like: foo.connect('changed', Lang.bind(this, this._onChanged, someData, otherData)); where someData and otherData are passed to onChanged too.
Lang.bind already does allow that
Ok; so what are the thoughts on deleting the user_data params?
I don't know why/how you'd use user data from JS
Comment on attachment 149115 [details] [review] Make arguments annotated as 'closure' optional Patch does no longer apply to master, and as it makes much more sense deleting user_data arguments altogether i'm marking this obsolete