From: Jürg Billeter Date: Mon, 17 Aug 2009 19:16:48 +0000 (+0200) Subject: Do not allow creation of objects without constructor X-Git-Tag: 0.7.6~179 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4f03e2f0f66e6391a3043d8378beed062fd4bdca;p=thirdparty%2Fvala.git Do not allow creation of objects without constructor Fixes bug 578417. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index a970c3a5a..26c5e51dd 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -3144,33 +3144,21 @@ internal class Vala.CCodeBaseModule : CCodeModule { } if (expr.symbol_reference == null) { - CCodeFunctionCall creation_call = null; - // no creation method - if (expr.type_reference.data_type == glist_type || - expr.type_reference.data_type == gslist_type) { - // NULL is an empty list - expr.ccodenode = new CCodeConstant ("NULL"); - } else if (expr.type_reference.data_type is Class && expr.type_reference.data_type.is_subtype_of (gobject_type)) { - generate_class_declaration ((Class) expr.type_reference.data_type, source_declarations); - - creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_object_new")); - creation_call.add_argument (new CCodeConstant (expr.type_reference.data_type.get_type_id ())); - creation_call.add_argument (new CCodeConstant ("NULL")); - } else if (expr.type_reference.data_type is Class) { - creation_call = new CCodeFunctionCall (new CCodeIdentifier ("g_new0")); - creation_call.add_argument (new CCodeConstant (expr.type_reference.data_type.get_cname ())); - creation_call.add_argument (new CCodeConstant ("1")); - } else if (expr.type_reference.data_type is Struct) { + if (expr.type_reference.data_type is Struct) { // memset needs string.h source_declarations.add_include ("string.h"); - creation_call = new CCodeFunctionCall (new CCodeIdentifier ("memset")); + var creation_call = new CCodeFunctionCall (new CCodeIdentifier ("memset")); creation_call.add_argument (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, instance)); creation_call.add_argument (new CCodeConstant ("0")); creation_call.add_argument (new CCodeIdentifier ("sizeof (%s)".printf (expr.type_reference.get_cname ()))); - } - creation_expr = creation_call; + creation_expr = creation_call; + } + } else if (expr.type_reference.data_type == glist_type || + expr.type_reference.data_type == gslist_type) { + // NULL is an empty list + expr.ccodenode = new CCodeConstant ("NULL"); } else if (expr.symbol_reference is Method) { // use creation method var m = (Method) expr.symbol_reference; diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala index 860ccf7e9..f986886dc 100644 --- a/vala/valaobjectcreationexpression.vala +++ b/vala/valaobjectcreationexpression.vala @@ -250,10 +250,14 @@ public class Vala.ObjectCreationExpression : Expression { if (symbol_reference == null) { symbol_reference = cl.default_construction_method; - if (symbol_reference != null) { - // track usage for flow analyzer - symbol_reference.used = true; + if (symbol_reference == null) { + error = true; + Report.error (source_reference, "`%s' does not have a default constructor".printf (cl.get_full_name ())); + return false; } + + // track usage for flow analyzer + symbol_reference.used = true; } if (symbol_reference != null && symbol_reference.access == SymbolAccessibility.PRIVATE) { diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index 74af2ec81..8713507ce 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -3006,6 +3006,8 @@ namespace GLib { [Compact] [CCode (dup_function = "g_list_copy", free_function = "g_list_free")] public class List { + public List (); + [ReturnsModifiedPointer ()] public void append (owned G data); [ReturnsModifiedPointer ()] @@ -3060,6 +3062,8 @@ namespace GLib { [Compact] [CCode (dup_function = "g_slist_copy", free_function = "g_slist_free")] public class SList { + public SList (); + [ReturnsModifiedPointer ()] public void append (owned G data); [ReturnsModifiedPointer ()]