GNOME Bugzilla – Bug 620675
Variadic constructors don't work
Last modified: 2012-07-30 15:43:33 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); }
Eh, that's a problem, it's not possible to pass variadic arguments in C. We should create constructors with valist.
*** Bug 647097 has been marked as a duplicate of this bug. ***
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.
Created attachment 218184 [details] [review] patch
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'.
Created attachment 219876 [details] [review] Updated patch
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.