Proposal: changes to _interp functions




Problem: 
-------

With the current _interp() functions, it is not possible to notified
when the handler is removed, and then free the data, without also
using the full marshalling mechanism.

("Full marshalling mechanism" means that instead of supplying a 
normal C language callback, you supply "GtkCallbackMarshall"
function, which takes a GtkArg array; giving both type information
and a value.)

This requirement is a pain both for applications and for 
statically typed language bindings. Dynamic type is not useful;
notification when the callback data is no longer needed is
still needed.

Proposal:
--------

A typical _interp function currently looks like:

  gint
  gtk_timeout_add_interp (guint32            interval,
                          GtkCallbackMarshal function,
                          gpointer           data,
                          GtkDestroyNotify   destroy);

The simplest change would be to add a flag indicating whether
'function' is a C callback function or a marshal function.

  gint
  gtk_timeout_add_interp (guint32            interval,
                          GtkFunction        function,
                          gboolean           is_marshal,
                          gpointer           data,
                          GtkDestroyNotify   destroy);

This, however means that 'function' will have a different type
signature depending on is_marshal. So it might be better to
do:


  gint
  gtk_timeout_add_interp (guint32            interval,
                          GtkFunction        function,
                          GtkCallbackMarshal marshal,
                          gpointer           data,
                          GtkDestroyNotify   destroy);

And specify that 'function' is ignored if 'marshal' is
given. Marius actually proposed a variant on this where 
both 'function' and 'marshal_func' have meanings (see below).
I tend to think that that is an unnecessary complication.


I'd actually also like to change the name of the _interp functions -
since they'll no longer be just for interpreted languages, and the
suffix is confusing to begin with. My preference would be simply:

  gtk_timeout_add_full (...)

Regards,
                                        Owen

===============

Subject: Re: _interp functions
From: Marius Vollmer <mvo@zagadka.ping.de>
Date: 23 Oct 1997 11:48:09 +0200

[...]

Here is something off the top of my head.  I have not tried it, in
fact I have not even written it down and looked at it from a distance.

A GtkCallbackMarshal gets two additional arguments, the `c
marshaller' and the `c func'.

    typedef void (*GtkCallbackMarshal) (GtkObject          *object,
                                        gpointer            data,
                                        int                 n_args,
                                        GtkArg             *args,
                                        GtkSignalMarshaller c_marshal,
                                        GtkFunction         c_func);

All *_interp functions that accept callbacks as arguments take the `c
func' in addition to the CallbackMarshal.

Like this:

    gint gtk_timeout_add_interp (guint32            interval,
                                 GtkCallbackMarshal marshal,
                                 GtkFunction        c_func,
                                 gpointer           data,
                                 GtkDestroyNotify   notify);

Now, when the callback is actually invoked, the callback marshaler
receives a suitable c_marshaler and can just do

    void gtk_default_callback_marshaller (...)
    {
        c_marshal (object, c_func, data, args);
    }

to invoke the C function.

This would be the default behaviour when you pass NULL as the
`marshal' argument to gtk_timeout_add_interp.

This is quite general and allows for run-time decisions whether a
c_func is invoked or not, for example.  I'm not sure if this is really
needed, but it wouldn't require too much overhead to implement I
think.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]