Variable Argument Lists, how to handle?



What should be the preffered way to handle the methods accepting variable
argument lists?

For now some of the implemented methods use perl 'proxy' methods which are
converting arrays/hashes to references and then passing them to the
underlaying inline function/method.

e.g. passing simple array of enums:


perl 'proxy' method in ListStore.pm:

sub new
  {
    my ($class, $num, @more) = @_;
    # for (@more) { print "PTYPE = $_ \n"; }
    return $class->_new($num, [ more]);
  }


underlaying 'real' method/function in ListStore.c:

SV* gtkperl_list_store__new(char* class, int n_columns, SV* argv_ref)
{
    int i;
    AV* argv = (AV*) SvRV(argv_ref);
    GType* types = g_malloc0(n_columns * sizeof(GType));
    for (i = 0; i < n_columns; i++) {
        SV* sv = av_shift(argv);
        types[i] = SvIV(sv);
    }
    return gtk2_perl_new_object(gtk_list_store_newv(n_columns, types));
}


But there is mechanism in XS and Inline to pass variable argunemt lists
directly. So there is no need for perl 'proxy' method, it can be directly
written in Inline (as describe at
http://search.cpan.org/author/INGY/Inline-0.43/C/C-Cookbook.pod#Variable_Arg
ument_Lists):


SV* gtkperl_list_store__new(char* class, int n_columns, ...)
{
    Inline_Stack_Vars;
    int i;

    GType* types = g_malloc0(n_columns * sizeof(GType));
    for (i = 2; i < Inline_Stack_Items; i++) {
        types[i-2] = SvIV(Inline_Stack_Item(i));
    }
    return gtk2_perl_new_object(gtk_list_store_newv(n_columns, types));
}


Anyway (IMHO) Christian Borup has the point in
http://mail.gnome.org/archives/gtk-perl-list/2002-October/msg00171.html
stating that invocation for such methods should be 'perlish' and no refs
should be passed directly from perl like currently in List->append_items
(mea coulpa ;) or ListStore->set where the perl 'proxy' methods are missing.

We are at pre-alpha right now so (just like Goran likes to point out) now is
the time to rethink and refactor ;) ...

So, to refactor or not that is the question?

bb4now,
PMC





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