After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 620675 - Variadic constructors don't work
Variadic constructors don't work
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Code Generator
0.8.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
invalid-c-code test-case
: 647097 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2010-06-05 17:28 UTC by Evan Nemerson
Modified: 2012-07-30 15:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
test case (297 bytes, text/plain)
2010-06-05 17:28 UTC, Evan Nemerson
  Details
Patch (10.43 KB, patch)
2012-07-03 16:02 UTC, Siegfried Gevatter (RainCT)
none Details | Review
patch (11.76 KB, patch)
2012-07-06 14:47 UTC, Siegfried Gevatter (RainCT)
needs-work Details | Review
Updated patch (12.95 KB, patch)
2012-07-30 10:59 UTC, Siegfried Gevatter (RainCT)
committed Details | Review

Description Evan Nemerson 2010-06-05 17:28:49 UTC
Created attachment 162817 [details]
test case

When writing a class with a variadic constructor, the optional parts are not passed. The attached test case generates this:

Foo* foo_new (const char* msg, ...) {
	return foo_construct (TYPE_FOO, msg);
}
Comment 1 Luca Bruno 2010-06-06 08:30:16 UTC
Eh, that's a problem, it's not possible to pass variadic arguments in C. We should create constructors with valist.
Comment 2 Evan Nemerson 2012-06-29 17:13:41 UTC
*** Bug 647097 has been marked as a duplicate of this bug. ***
Comment 3 Siegfried Gevatter (RainCT) 2012-07-03 16:02:01 UTC
Created attachment 217940 [details] [review]
Patch

I'm attaching a first patch for this. Still need to do some proper testing, but the attached test case works fine with it.
Comment 4 Siegfried Gevatter (RainCT) 2012-07-06 14:47:21 UTC
Created attachment 218184 [details] [review]
patch
Comment 5 Jürg Billeter 2012-07-28 11:19:40 UTC
Review of attachment 218184 [details] [review]:

Thanks for the patch.

::: codegen/valaccodemethodmodule.vala
@@ +219,3 @@
+		const string infix = "constructv";
+
+		// FIXME: DOVA?

Dova doesn't use this code generator module.

@@ +292,1 @@
 	public override void visit_method (Method m) {

The _constructv function should always be static. The forward declaration is already correct but the definition isn't.

@@ +1179,2 @@
+			bool first = true;
+			foreach (var func_name in extra_functions) {

As mentioned on IRC, I think that the code would be easier to understand if we defined a helper function which we call twice instead of using a loop.

@@ +1191,2 @@
+				var vcall = new CCodeFunctionCall (new CCodeIdentifier (constructor));
+				vcall.add_argument (new CCodeIdentifier (get_ccode_type_id (current_class)));

The _construct function should use the 'object_type' parameter instead of 'TYPE_FOO'.
Comment 6 Siegfried Gevatter (RainCT) 2012-07-30 10:59:13 UTC
Created attachment 219876 [details] [review]
Updated patch
Comment 7 Jürg Billeter 2012-07-30 15:43:11 UTC
commit 94dbe36a66c6ca496ef753cca0a48d0cb9dd5408
Author: Siegfried-Angel Gevatter Pujals <siegfried.gevatter@collabora.co.uk>
Date:   Fri Jul 6 16:44:39 2012 +0200

    codegen: Fix variadic constructors
    
    Fixes bug 620675.