Ticket #16 (closed defect: fixed)

Opened 1 year ago

Last modified 4 months ago

Wrapper does not handle varargs

Reported by: keinfarbton Assigned to: Mike Wey
Priority: major Milestone: RC 1
Component: Wrapper Version: TRUNK
Keywords: varargs variable argument Cc:

Description

[19:20] <keinfarbton> pseus: TreeViewColumn.d line 276, the varargs are not used, do you know something about that?
[19:21] <pseus> let me check
[19:22] <pseus> yes
[19:22] <keinfarbton> hm, i think i can use multiple calls to addAttibute
[19:22] <pseus> apparently the wrapper does not handle varargs properly, yet
[19:23] <pseus> a ticket should probably be created
[19:23] <keinfarbton> ok, i do

Attachments

glib_Util.d.patch (1.2 kB) - added by potyl on 07/23/08 15:15:31.
Fix Util.buildFilename()

Change History

12/30/07 13:32:46 changed by Pse

  • keywords set to varargs variable argument.
  • owner changed from JJR to Pse.
  • milestone set to Release 1.0.

12/30/07 13:32:54 changed by Pse

  • status changed from new to assigned.

12/30/07 18:47:07 changed by Mike Wey

Looking at the gtk source it looks like most functions have an alternative that accepts a array or a va_list. altough only GtkListStore? has them documented.
I also checked to see how gtkmm handled this, They seem to just ignore the variadic functions not wrapping them.

01/15/08 23:51:03 changed by Pse

  • status changed from assigned to new.

06/28/08 11:10:42 changed by okibi

  • version changed from Pre-release 7 to TRUNK.
  • milestone changed from Release 1.0 to RC 1.

07/09/08 06:54:54 changed by okibi

Is this something we need to work on? Like Mike said, gtkmm doesn't handle them, so should gtkD?

07/09/08 13:40:15 changed by Mike Wey

We could do something like this:

public void setAttributes(CellRenderer, T...)(CellRenderer cell, T t )
{
	// void gtk_cell_layout_set_attributes (GtkCellLayout *cell_layout,  GtkCellRenderer *cell,  ...);
	gtk_cell_layout_set_attributes(getCellLayoutTStruct(), (cell is null) ? null : cell.getCellRendererStruct(), t);
}

but then you'll need to pass C strings to the functions with varargs, or we need to find a way to change those in the function.

07/17/08 15:06:23 changed by Mike Wey

I tried a few thing to change the char[] in the tuple to a char*, all tries result in a: Can't evaluate X at runtime. error or something similar.

07/23/08 15:14:44 changed by potyl

Some of the glib functions like g_build_filename and g_build_path also use varargs and cause a runtime error when used because the varargs are never passed to the underlying C function. I've created a patch buildFilename that uses varargs and it seems to work. I would be great if the patch could be reviewed.

In my opinion, the following function could be added to glib.Str: public static char** toStringzArray(...)

This way the it will be easier to use this new functions in order to transform D varags into a their glib/gtk equivalent gchar**.

07/23/08 15:15:31 changed by potyl

  • attachment glib_Util.d.patch added.

Fix Util.buildFilename()

(follow-up: ↓ 12 ) 07/23/08 15:24:17 changed by potyl

In my patch, I've only changed the code to buildFilename even though buildPath is in the same nasty situation. This is because I wanted your feed back first, I will be glad to apply the same changes to buildPath if the code is good and to resubmit a final patch.

(follow-up: ↓ 14 ) 07/23/08 15:51:28 changed by Mike Wey

If i could suggest something:

public static string buildFilename(string[] firstElement ... )
{
	// gchar* g_build_filename (const gchar *first_element,  ...);
	return buildFilenamev(Str.toStringzArray(firstElement));
}

That still has the problem that the char* returned by Gtk isn't freed as you noted on IRC, this probably has something to do with ticket #14, before svn r353 strings returned by Gtk were not duped but GtkD would return a slice of the original string nimus the trailing \0.

(in reply to: ↑ 10 ) 07/23/08 15:53:03 changed by Mike Wey

Replying to potyl:

This is because I wanted your feed back first, I will be glad to apply the same changes to buildPath if the code is good and to resubmit a final patch.

We would rather have an solution that could be handled by the wrapper, if possible.

07/23/08 17:36:19 changed by mandel

gtkD+demos svn build fine with this patch using Tango svn (with dmd and "dsss build"). Is there a way this should also be tested?

I haven't found a place in the gtkD source code where this function is used.

(in reply to: ↑ 11 ; follow-up: ↓ 15 ) 07/24/08 01:27:07 changed by potyl

Replying to Mike Wey:

If i could suggest something: {{{ #!d public static string buildFilename(string[] firstElement ... ) { // gchar* g_build_filename (const gchar *first_element, ...); return buildFilenamev(Str.toStringzArray(firstElement)); } }}}

I'm confused with this suggestion. I think that firstElement should be of type string and not string[]. Using varargs in D has an advantage it makes the code easier to write:

import glib.Util;
Uitl.buildFilename("a", "b", "c");

Of course there's no more type checking thus there's no guaranty that everything passed as an argument is a string.

(in reply to: ↑ 14 ) 07/24/08 02:01:50 changed by potyl

Replying to potyl:

Replying to Mike Wey:

If i could suggest something: {{{ #!d public static string buildFilename(string[] firstElement ... ) { // gchar* g_build_filename (const gchar *first_element, ...); return buildFilenamev(Str.toStringzArray(firstElement)); } }}}

I'm confused with this suggestion. I think that firstElement should be of type string and not string[]. Using varargs in D has an advantage it makes the code easier to write: {{{ import glib.Util; Uitl.buildFilename("a", "b", "c"); }}} Of course there's no more type checking thus there's no guaranty that everything passed as an argument is a string.

Please forget my last comment. I wasn't aware of the construct string[] var ... , which by the way is quite neat as it fixes the type checking!

07/29/08 16:45:55 changed by Mike Wey

  • owner changed from Pse to Mike Wey.

The best option currently looks like to remove the functions that accept varargs, and ad some of them back manually on a need basis.

07/31/08 06:46:09 changed by okibi

Is this something you guys feel needs attention in prior to the 1.0 release, or something that should be discussed for the 2.x series coming later? I've given my opinion earlier, please let me know what you guys think.

Also, sorry for my absence over the past week. I've had a lot going on!

07/31/08 14:29:11 changed by Mike Wey

Leaving functions that throw an segfault in the 1.0 release doesn't sound like a good idea.

07/31/08 17:48:43 changed by Mike Wey

  • status changed from new to assigned.

I'll look into the option of omitting the functions with varargs in gtkD.

08/01/08 09:48:09 changed by okibi

Omitting is actually what I meant when I said not working on implementing them into the wrapper. Sorry for the confusion!

Anyways, point being, after omitted, should we create a ticket for 2.x to include varargs?

08/01/08 15:30:45 changed by Mike Wey

  • status changed from assigned to closed.
  • resolution set to fixed.

with svn r552 there is no cdeo generated for functions with varargs.

Feel free to report vararg functions that are now missing but are still needed.