diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2023-01-04 22:47:01 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2023-01-04 22:47:01 +0100 |
commit | f156de68664e919ee5ad1aa9f6b811512e75122c (patch) | |
tree | b2d95bbdf5ab6742986bbadf0870916d3c85cb6a | |
parent | 3c64222b6361aceb5ee42c7523c9d854a0d7f731 (diff) | |
download | vala-f156de68664e919ee5ad1aa9f6b811512e75122c.tar.gz |
codegen: Correctly handle fixed-length array initialization of fields in classes
-rw-r--r-- | codegen/valaccodebasemodule.vala | 112 | ||||
-rw-r--r-- | codegen/valagtypemodule.vala | 3 | ||||
-rw-r--r-- | tests/Makefile.am | 1 | ||||
-rw-r--r-- | tests/arrays/class-field-fixed-length-initializer.c-expected | 412 | ||||
-rw-r--r-- | tests/arrays/class-field-fixed-length-initializer.vala | 32 | ||||
-rw-r--r-- | tests/arrays/class-field-initializer.c-expected | 4 | ||||
-rw-r--r-- | tests/basic-types/bug686336.c-expected | 2 | ||||
-rw-r--r-- | tests/objects/compact-class-custom-ref.c-expected | 2 | ||||
-rw-r--r-- | tests/objects/destructors.c-expected | 2 |
9 files changed, 457 insertions, 113 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 6d4d9cd20..13759dec4 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -1293,73 +1293,15 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { var cl = f.parent_symbol as Class; bool is_gtypeinstance = (cl != null && !cl.is_compact); - CCodeExpression lhs = null; - if (f.binding == MemberBinding.INSTANCE) { - if (is_gtypeinstance && f.access == SymbolAccessibility.PRIVATE) { - lhs = new CCodeMemberAccess.pointer (new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), "priv"), get_ccode_name (f)); - } else { - lhs = new CCodeMemberAccess.pointer (new CCodeIdentifier ("self"), get_ccode_name (f)); - } - if (f.initializer != null) { push_context (instance_init_context); f.initializer.emit (this); - var rhs = get_cvalue (f.initializer); if (!is_simple_struct_creation (f, f.initializer)) { // otherwise handled in visit_object_creation_expression - - ccode.add_assignment (lhs, rhs); - - if (f.variable_type is ArrayType && get_ccode_array_length (f)) { - var array_type = (ArrayType) f.variable_type; - var field_value = get_field_cvalue (f, load_this_parameter ((TypeSymbol) f.parent_symbol)); - - var glib_value = (GLibValue) f.initializer.target_value; - if (glib_value.array_length_cvalues != null) { - for (int dim = 1; dim <= array_type.rank; dim++) { - var array_len_lhs = get_array_length_cvalue (field_value, dim); - ccode.add_assignment (array_len_lhs, get_array_length_cvalue (glib_value, dim)); - } - } else if (glib_value.array_null_terminated) { - requires_array_length = true; - var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length")); - len_call.add_argument (get_cvalue_ (glib_value)); - - ccode.add_assignment (get_array_length_cvalue (field_value, 1), len_call); - } else { - for (int dim = 1; dim <= array_type.rank; dim++) { - ccode.add_assignment (get_array_length_cvalue (field_value, dim), new CCodeConstant ("-1")); - } - } - - if (array_type.rank == 1 && f.is_internal_symbol ()) { - var lhs_array_size = get_array_size_cvalue (field_value); - var rhs_array_len = get_array_length_cvalue (field_value, 1); - ccode.add_assignment (lhs_array_size, rhs_array_len); - } - } else if (get_ccode_delegate_target (f)) { - var delegate_type = (DelegateType) f.variable_type; - if (delegate_type.delegate_symbol.has_target) { - var field_value = get_field_cvalue (f, load_this_parameter ((TypeSymbol) f.parent_symbol)); - var target_cvalue = get_delegate_target_cvalue (f.initializer.target_value); - if (target_cvalue != null) { - ccode.add_assignment (get_delegate_target_cvalue (field_value), target_cvalue); - } else { - ccode.add_assignment (get_delegate_target_cvalue (field_value), new CCodeIdentifier ("self")); - } - if (delegate_type.is_disposable ()) { - var destroy_cvalue = get_delegate_target_destroy_notify_cvalue (f.initializer.target_value); - if (destroy_cvalue != null) { - ccode.add_assignment (get_delegate_target_destroy_notify_cvalue (field_value), destroy_cvalue); - } else { - ccode.add_assignment (get_delegate_target_destroy_notify_cvalue (field_value), new CCodeConstant ("NULL")); - } - } - } - } + store_field (f, new GLibValue (null, new CCodeIdentifier ("self")), f.initializer.target_value, true, f.source_reference); } foreach (var value in temp_ref_values) { @@ -1377,22 +1319,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { pop_context (); } } else if (f.binding == MemberBinding.CLASS) { - if (f.access == SymbolAccessibility.PRIVATE) { - var ccall = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_class_get_private_function (cl))); - ccall.add_argument (new CCodeIdentifier ("klass")); - lhs = new CCodeMemberAccess (ccall, get_ccode_name (f), true); - } else { - lhs = new CCodeMemberAccess (new CCodeIdentifier ("klass"), get_ccode_name (f), true); - } - if (f.initializer != null) { push_context (class_init_context); f.initializer.emit (this); - var rhs = get_cvalue (f.initializer); - - ccode.add_assignment (lhs, rhs); + store_field (f, null, f.initializer.target_value, true, f.source_reference); foreach (var value in temp_ref_values) { ccode.add_expression (destroy_value (value)); @@ -1413,8 +1345,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } if (!f.external) { - lhs = new CCodeIdentifier (get_ccode_name (f)); - var var_decl = new CCodeVariableDeclarator (get_ccode_name (f), null, get_ccode_declarator_suffix (f.variable_type)); var_decl.initializer = default_value_for_type (f.variable_type, true); @@ -1509,43 +1439,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { var rhs = get_cvalue (f.initializer); if (!is_constant_ccode_expression (rhs)) { if (is_gtypeinstance) { - if (f.initializer is InitializerList) { - ccode.open_block (); - - var temp_decl = get_temp_variable (f.variable_type); - var vardecl = new CCodeVariableDeclarator.zero (temp_decl.name, rhs); - ccode.add_declaration (get_ccode_name (temp_decl.variable_type), vardecl); - - var tmp = get_variable_cexpression (temp_decl.name); - ccode.add_assignment (lhs, tmp); - - ccode.close (); - } else { - ccode.add_assignment (lhs, rhs); - } - - if (f.variable_type is ArrayType && get_ccode_array_length (f)) { - var array_type = (ArrayType) f.variable_type; - var field_value = get_field_cvalue (f, null); - - var glib_value = (GLibValue) f.initializer.target_value; - if (glib_value.array_length_cvalues != null) { - for (int dim = 1; dim <= array_type.rank; dim++) { - var array_len_lhs = get_array_length_cvalue (field_value, dim); - ccode.add_assignment (array_len_lhs, get_array_length_cvalue (glib_value, dim)); - } - } else if (glib_value.array_null_terminated) { - requires_array_length = true; - var len_call = new CCodeFunctionCall (new CCodeIdentifier ("_vala_array_length")); - len_call.add_argument (get_cvalue_ (glib_value)); - - ccode.add_assignment (get_array_length_cvalue (field_value, 1), len_call); - } else { - for (int dim = 1; dim <= array_type.rank; dim++) { - ccode.add_assignment (get_array_length_cvalue (field_value, dim), new CCodeConstant ("-1")); - } - } - } + store_field (f, null, f.initializer.target_value, true, f.source_reference); } else { f.error = true; Report.error (f.source_reference, "Non-constant field initializers not supported in this context"); diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index 7bc8eaf83..b3d7d247f 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -479,11 +479,10 @@ public class Vala.GTypeModule : GErrorModule { } void generate_struct_field_declaration (Field f, CCodeStruct instance_struct, CCodeStruct type_struct, CCodeFile decl_space) { - CCodeModifiers modifiers = (f.is_volatile ? CCodeModifiers.VOLATILE : 0) | (f.version.deprecated ? CCodeModifiers.DEPRECATED : 0); if (f.binding == MemberBinding.INSTANCE) { append_field (instance_struct, f, decl_space); } else if (f.binding == MemberBinding.CLASS) { - type_struct.add_field (get_ccode_name (f.variable_type), get_ccode_name (f), modifiers); + append_field (type_struct, f, decl_space); } } diff --git a/tests/Makefile.am b/tests/Makefile.am index 407bffc5b..577b926d1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -126,6 +126,7 @@ TESTS = \ namespace/unique.vala \ arrays/cast-silent-invalid.test \ arrays/cast-struct-boxed-element-access.vala \ + arrays/class-field-fixed-length-initializer.vala \ arrays/class-field-initializer.vala \ arrays/class-field-length-cname.vala \ arrays/constant-element-access.vala \ diff --git a/tests/arrays/class-field-fixed-length-initializer.c-expected b/tests/arrays/class-field-fixed-length-initializer.c-expected new file mode 100644 index 000000000..4b402f912 --- /dev/null +++ b/tests/arrays/class-field-fixed-length-initializer.c-expected @@ -0,0 +1,412 @@ +/* arrays_class_field_fixed_length_initializer.c generated by valac, the Vala compiler + * generated from arrays_class_field_fixed_length_initializer.vala, do not modify */ + +#include <glib-object.h> +#include <stdlib.h> +#include <string.h> +#include <glib.h> +#include <gobject/gvaluecollector.h> + +#if !defined(VALA_EXTERN) +#if defined(_MSC_VER) +#define VALA_EXTERN __declspec(dllexport) extern +#elif __GNUC__ >= 4 +#define VALA_EXTERN __attribute__((visibility("default"))) extern +#else +#define VALA_EXTERN extern +#endif +#endif + +#define TYPE_FOO (foo_get_type ()) +#define FOO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_FOO, Foo)) +#define FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_FOO, FooClass)) +#define IS_FOO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_FOO)) +#define IS_FOO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_FOO)) +#define FOO_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_FOO, FooClass)) + +typedef struct _Foo Foo; +typedef struct _FooClass FooClass; +typedef struct _FooPrivate FooPrivate; +typedef struct _ParamSpecFoo ParamSpecFoo; +#define _foo_unref0(var) ((var == NULL) ? NULL : (var = (foo_unref (var), NULL))) +#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); +#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; } +#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; } +#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg); + +struct _Foo { + GTypeInstance parent_instance; + volatile int ref_count; + FooPrivate * priv; + gchar* f[2]; + gint i[3]; +}; + +struct _FooClass { + GTypeClass parent_class; + void (*finalize) (Foo *self); + gchar* cf[2]; + gint ci[3]; +}; + +struct _ParamSpecFoo { + GParamSpec parent_instance; +}; + +static gpointer foo_parent_class = NULL; +VALA_EXTERN gchar* foo_sf[2]; +gchar* foo_sf[2] = {0}; +VALA_EXTERN gint foo_si[3]; +gint foo_si[3] = {0}; + +VALA_EXTERN gpointer foo_ref (gpointer instance); +VALA_EXTERN void foo_unref (gpointer instance); +VALA_EXTERN GParamSpec* param_spec_foo (const gchar* name, + const gchar* nick, + const gchar* blurb, + GType object_type, + GParamFlags flags); +VALA_EXTERN void value_set_foo (GValue* value, + gpointer v_object); +VALA_EXTERN void value_take_foo (GValue* value, + gpointer v_object); +VALA_EXTERN gpointer value_get_foo (const GValue* value); +VALA_EXTERN GType foo_get_type (void) G_GNUC_CONST ; +G_DEFINE_AUTOPTR_CLEANUP_FUNC (Foo, foo_unref) +VALA_EXTERN Foo* foo_new (void); +VALA_EXTERN Foo* foo_construct (GType object_type); +static void foo_finalize (Foo * obj); +static GType foo_get_type_once (void); +static void _vala_main (void); +static void _vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); +static void _vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func); + +Foo* +foo_construct (GType object_type) +{ + Foo* self = NULL; + self = (Foo*) g_type_create_instance (object_type); + return self; +} + +Foo* +foo_new (void) +{ + return foo_construct (TYPE_FOO); +} + +static void +value_foo_init (GValue* value) +{ + value->data[0].v_pointer = NULL; +} + +static void +value_foo_free_value (GValue* value) +{ + if (value->data[0].v_pointer) { + foo_unref (value->data[0].v_pointer); + } +} + +static void +value_foo_copy_value (const GValue* src_value, + GValue* dest_value) +{ + if (src_value->data[0].v_pointer) { + dest_value->data[0].v_pointer = foo_ref (src_value->data[0].v_pointer); + } else { + dest_value->data[0].v_pointer = NULL; + } +} + +static gpointer +value_foo_peek_pointer (const GValue* value) +{ + return value->data[0].v_pointer; +} + +static gchar* +value_foo_collect_value (GValue* value, + guint n_collect_values, + GTypeCValue* collect_values, + guint collect_flags) +{ + if (collect_values[0].v_pointer) { + Foo * object; + object = collect_values[0].v_pointer; + if (object->parent_instance.g_class == NULL) { + return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL); + } else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) { + return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL); + } + value->data[0].v_pointer = foo_ref (object); + } else { + value->data[0].v_pointer = NULL; + } + return NULL; +} + +static gchar* +value_foo_lcopy_value (const GValue* value, + guint n_collect_values, + GTypeCValue* collect_values, + guint collect_flags) +{ + Foo ** object_p; + object_p = collect_values[0].v_pointer; + if (!object_p) { + return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value)); + } + if (!value->data[0].v_pointer) { + *object_p = NULL; + } else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) { + *object_p = value->data[0].v_pointer; + } else { + *object_p = foo_ref (value->data[0].v_pointer); + } + return NULL; +} + +GParamSpec* +param_spec_foo (const gchar* name, + const gchar* nick, + const gchar* blurb, + GType object_type, + GParamFlags flags) +{ + ParamSpecFoo* spec; + g_return_val_if_fail (g_type_is_a (object_type, TYPE_FOO), NULL); + spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags); + G_PARAM_SPEC (spec)->value_type = object_type; + return G_PARAM_SPEC (spec); +} + +gpointer +value_get_foo (const GValue* value) +{ + g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_FOO), NULL); + return value->data[0].v_pointer; +} + +void +value_set_foo (GValue* value, + gpointer v_object) +{ + Foo * old; + g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_FOO)); + old = value->data[0].v_pointer; + if (v_object) { + g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_FOO)); + g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value))); + value->data[0].v_pointer = v_object; + foo_ref (value->data[0].v_pointer); + } else { + value->data[0].v_pointer = NULL; + } + if (old) { + foo_unref (old); + } +} + +void +value_take_foo (GValue* value, + gpointer v_object) +{ + Foo * old; + g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, TYPE_FOO)); + old = value->data[0].v_pointer; + if (v_object) { + g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, TYPE_FOO)); + g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value))); + value->data[0].v_pointer = v_object; + } else { + value->data[0].v_pointer = NULL; + } + if (old) { + foo_unref (old); + } +} + +static void +foo_class_init (FooClass * klass, + gpointer klass_data) +{ + gchar* _tmp0_; + gchar* _tmp1_; + gchar* _tmp2_[2] = {0}; + gint _tmp3_[3] = {0}; + gchar* _tmp4_; + gchar* _tmp5_; + gchar* _tmp6_[2] = {0}; + gint _tmp7_[3] = {0}; + foo_parent_class = g_type_class_peek_parent (klass); + ((FooClass *) klass)->finalize = foo_finalize; + _tmp0_ = g_strdup ("foo"); + _tmp1_ = g_strdup ("bar"); + _tmp2_[0] = _tmp0_; + _tmp2_[1] = _tmp1_; + memcpy (klass->cf, _tmp2_, 2 * sizeof (gchar*)); + _tmp3_[0] = 23; + _tmp3_[1] = 42; + _tmp3_[2] = 4711; + memcpy (klass->ci, _tmp3_, 3 * sizeof (gint)); + _tmp4_ = g_strdup ("foo"); + _tmp5_ = g_strdup ("bar"); + _tmp6_[0] = _tmp4_; + _tmp6_[1] = _tmp5_; + memcpy (foo_sf, _tmp6_, 2 * sizeof (gchar*)); + _tmp7_[0] = 23; + _tmp7_[1] = 42; + _tmp7_[2] = 4711; + memcpy (foo_si, _tmp7_, 3 * sizeof (gint)); +} + +static void +foo_instance_init (Foo * self, + gpointer klass) +{ + gchar* _tmp0_; + gchar* _tmp1_; + gchar* _tmp2_[2] = {0}; + gint _tmp3_[3] = {0}; + _tmp0_ = g_strdup ("foo"); + _tmp1_ = g_strdup ("bar"); + _tmp2_[0] = _tmp0_; + _tmp2_[1] = _tmp1_; + memcpy (self->f, _tmp2_, 2 * sizeof (gchar*)); + _tmp3_[0] = 23; + _tmp3_[1] = 42; + _tmp3_[2] = 4711; + memcpy (self->i, _tmp3_, 3 * sizeof (gint)); + self->ref_count = 1; +} + +static void +foo_finalize (Foo * obj) +{ + Foo * self; + self = G_TYPE_CHECK_INSTANCE_CAST (obj, TYPE_FOO, Foo); + g_signal_handlers_destroy (self); + _vala_array_destroy (self->f, 2, (GDestroyNotify) g_free); +} + +static GType +foo_get_type_once (void) +{ + static const GTypeValueTable g_define_type_value_table = { value_foo_init, value_foo_free_value, value_foo_copy_value, value_foo_peek_pointer, "p", value_foo_collect_value, "p", value_foo_lcopy_value }; + static const GTypeInfo g_define_type_info = { sizeof (FooClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) foo_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Foo), 0, (GInstanceInitFunc) foo_instance_init, &g_define_type_value_table }; + static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) }; + GType foo_type_id; + foo_type_id = g_type_register_fundamental (g_type_fundamental_next (), "Foo", &g_define_type_info, &g_define_type_fundamental_info, 0); + return foo_type_id; +} + +GType +foo_get_type (void) +{ + static volatile gsize foo_type_id__once = 0; + if (g_once_init_enter (&foo_type_id__once)) { + GType foo_type_id; + foo_type_id = foo_get_type_once (); + g_once_init_leave (&foo_type_id__once, foo_type_id); + } + return foo_type_id__once; +} + +gpointer +foo_ref (gpointer instance) +{ + Foo * self; + self = instance; + g_atomic_int_inc (&self->ref_count); + return instance; +} + +void +foo_unref (gpointer instance) +{ + Foo * self; + self = instance; + if (g_atomic_int_dec_and_test (&self->ref_count)) { + FOO_GET_CLASS (self)->finalize (self); + g_type_free_instance ((GTypeInstance *) self); + } +} + +static void +_vala_main (void) +{ + Foo* foo = NULL; + Foo* _tmp0_; + _tmp0_ = foo_new (); + foo = _tmp0_; + { + const gchar* _tmp1_; + gint _tmp2_; + _vala_assert (2 == 2, "foo.f.length == 2"); + _tmp1_ = foo->f[0]; + _vala_assert (g_strcmp0 (_tmp1_, "foo") == 0, "foo.f[0] == \"foo\""); + _vala_assert (3 == 3, "foo.i.length == 3"); + _tmp2_ = foo->i[2]; + _vala_assert (_tmp2_ == 4711, "foo.i[2] == 4711"); + } + { + const gchar* _tmp3_; + gint _tmp4_; + _vala_assert (2 == 2, "foo.cf.length == 2"); + _tmp3_ = FOO_GET_CLASS (foo)->cf[0]; + _vala_assert (g_strcmp0 (_tmp3_, "foo") == 0, "foo.cf[0] == \"foo\""); + _vala_assert (3 == 3, "foo.ci.length == 3"); + _tmp4_ = FOO_GET_CLASS (foo)->ci[2]; + _vala_assert (_tmp4_ == 4711, "foo.ci[2] == 4711"); + } + { + const gchar* _tmp5_; + gint _tmp6_; + _vala_assert (2 == 2, "Foo.sf.length == 2"); + _tmp5_ = foo_sf[0]; + _vala_assert (g_strcmp0 (_tmp5_, "foo") == 0, "Foo.sf[0] == \"foo\""); + _vala_assert (3 == 3, "Foo.si.length == 3"); + _tmp6_ = foo_si[2]; + _vala_assert (_tmp6_ == 4711, "Foo.si[2] == 4711"); + } + _foo_unref0 (foo); +} + +int +main (int argc, + char ** argv) +{ + _vala_main (); + return 0; +} + +static void +_vala_array_destroy (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + if ((array != NULL) && (destroy_func != NULL)) { + gssize i; + for (i = 0; i < array_length; i = i + 1) { + if (((gpointer*) array)[i] != NULL) { + destroy_func (((gpointer*) array)[i]); + } + } + } +} + +static void +_vala_array_free (gpointer array, + gssize array_length, + GDestroyNotify destroy_func) +{ + _vala_array_destroy (array, array_length, destroy_func); + g_free (array); +} + diff --git a/tests/arrays/class-field-fixed-length-initializer.vala b/tests/arrays/class-field-fixed-length-initializer.vala new file mode 100644 index 000000000..5552c20e6 --- /dev/null +++ b/tests/arrays/class-field-fixed-length-initializer.vala @@ -0,0 +1,32 @@ +class Foo { + public string f[2] = { "foo", "bar" }; + public int i[3] = { 23, 42, 4711 }; + + public class string cf[2] = { "foo", "bar" }; + public class int ci[3] = { 23, 42, 4711 }; + + public static string sf[2] = { "foo", "bar" }; + public static int si[3] = { 23, 42, 4711 }; +} + +void main () { + var foo = new Foo (); + { + assert (foo.f.length == 2); + assert (foo.f[0] == "foo"); + assert (foo.i.length == 3); + assert (foo.i[2] == 4711); + } + { + assert (foo.cf.length == 2); + assert (foo.cf[0] == "foo"); + assert (foo.ci.length == 3); + assert (foo.ci[2] == 4711); + } + { + assert (Foo.sf.length == 2); + assert (Foo.sf[0] == "foo"); + assert (Foo.si.length == 3); + assert (Foo.si[2] == 4711); + } +} diff --git a/tests/arrays/class-field-initializer.c-expected b/tests/arrays/class-field-initializer.c-expected index d58abb4a8..5faddf3db 100644 --- a/tests/arrays/class-field-initializer.c-expected +++ b/tests/arrays/class-field-initializer.c-expected @@ -379,6 +379,7 @@ foo_class_init (FooClass * klass, _tmp1__length1 = _tmp0__length1; foo_sf = _tmp1_; foo_sf_length1 = _tmp1__length1; + _foo_sf_size_ = foo_sf_length1; _tmp2_ = g_strdup ("baz"); _tmp3_ = g_strdup ("foo"); _tmp4_ = g_strdup ("bar"); @@ -388,6 +389,7 @@ foo_class_init (FooClass * klass, _tmp5_[2] = _tmp4_; foo_si = _tmp5_; foo_si_length1 = 3; + _foo_si_size_ = foo_si_length1; _tmp6_ = g_strdup ("baz"); _tmp7_ = manam; _tmp7__length1 = _vala_array_length (manam); @@ -400,6 +402,7 @@ foo_class_init (FooClass * klass, _tmp11_[2] = _tmp10_; foo_sa = _tmp11_; foo_sa_length1 = 3; + _foo_sa_size_ = foo_sa_length1; } static void @@ -707,6 +710,7 @@ bar_class_init (BarClass * klass, _tmp1__length1 = _tmp0__length1; bar_sf = _tmp1_; bar_sf_length1 = _tmp1__length1; + _bar_sf_size_ = bar_sf_length1; } static void diff --git a/tests/basic-types/bug686336.c-expected b/tests/basic-types/bug686336.c-expected index cec001168..f485d7871 100644 --- a/tests/basic-types/bug686336.c-expected +++ b/tests/basic-types/bug686336.c-expected @@ -306,9 +306,11 @@ foo_class_init (FooClass * klass, _tmp0_[2] = 3; foo_static_bar = _tmp0_; foo_static_bar_length1 = 3; + _foo_static_bar_size_ = foo_static_bar_length1; _tmp2_ = foo_create_array (&_tmp1_); foo_static_baz = _tmp2_; foo_static_baz_length1 = _tmp1_; + _foo_static_baz_size_ = foo_static_baz_length1; } static void diff --git a/tests/objects/compact-class-custom-ref.c-expected b/tests/objects/compact-class-custom-ref.c-expected index db323d17a..7d15c46c7 100644 --- a/tests/objects/compact-class-custom-ref.c-expected +++ b/tests/objects/compact-class-custom-ref.c-expected @@ -73,7 +73,7 @@ foo_new (void) static void foo_instance_init (Foo * self) { - self->ref_count = 1; + self->ref_count = (volatile int) 1; } void diff --git a/tests/objects/destructors.c-expected b/tests/objects/destructors.c-expected index de713d1a2..a3e969bef 100644 --- a/tests/objects/destructors.c-expected +++ b/tests/objects/destructors.c-expected @@ -2,9 +2,9 @@ * generated from objects_destructors.vala, do not modify */ #include <glib-object.h> -#include <glib.h> #include <stdlib.h> #include <string.h> +#include <glib.h> #if !defined(VALA_EXTERN) #if defined(_MSC_VER) |