[vala] Do not allow creation of objects without constructor
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Do not allow creation of objects without constructor
- Date: Mon, 17 Aug 2009 15:18:31 -0400 (EDT)
commit 4f03e2f0f66e6391a3043d8378beed062fd4bdca
Author: Jürg Billeter <j bitron ch>
Date: Mon Aug 17 21:16:48 2009 +0200
Do not allow creation of objects without constructor
Fixes bug 578417.
codegen/valaccodebasemodule.vala | 28 ++++++++--------------------
vala/valaobjectcreationexpression.vala | 10 +++++++---
vapi/glib-2.0.vapi | 4 ++++
3 files changed, 19 insertions(+), 23 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index a970c3a..26c5e51 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 860ccf7..f986886 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 74af2ec..8713507 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<G> {
+ 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<G> {
+ public SList ();
+
[ReturnsModifiedPointer ()]
public void append (owned G data);
[ReturnsModifiedPointer ()]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]