From 450d34a32c940a6ad5cb21f64fba70ef7ebbb1cc Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Wed, 17 Jan 2018 15:10:37 +0100 Subject: [PATCH] codegen: Add "padding" CCode attributes for classes/interfaces New CCode attribute are: * "class_padding" and "instance_padding" of integer type * "class_padding_ctype" and "instance_padding_ctype" of string type The *_ctype attributes default to "void *" and for *_padding > 0 a field will be appended to the respective struct, e.g. "void * _vala_padding[3];". See https://gitlab.gnome.org/GNOME/vala/issues/598 --- codegen/valagtypemodule.vala | 11 +++++++++++ vala/valausedattr.vala | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index 6b60f7ef3..9227260e0 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -293,6 +293,17 @@ public class Vala.GTypeModule : GErrorModule { if (is_gtypeinstance) { if (context.abi_stability) { instance_struct.add_field ("%sPrivate *".printf (get_ccode_name (cl)), "priv"); + + var instance_padding = cl.get_attribute_integer ("CCode", "instance_padding", 0); + if (instance_padding > 0) { + var instance_padding_ctype = cl.get_attribute_string ("CCode", "instance_padding_ctype", "void *"); + instance_struct.add_field (instance_padding_ctype, "_vala_padding[%i]".printf (instance_padding)); + } + var class_padding = cl.get_attribute_integer ("CCode", "class_padding", 0); + if (class_padding > 0) { + var class_padding_ctype = cl.get_attribute_string ("CCode", "class_padding_ctype", "void *"); + type_struct.add_field (class_padding_ctype, "_vala_padding[%i]".printf (class_padding)); + } } decl_space.add_type_definition (type_struct); } diff --git a/vala/valausedattr.vala b/vala/valausedattr.vala index dab15a864..fe9d7eedc 100644 --- a/vala/valausedattr.vala +++ b/vala/valausedattr.vala @@ -40,7 +40,8 @@ public class Vala.UsedAttr : CodeVisitor { "array_length_type", "array_length", "array_length_cname", "array_length_cexpr", "array_null_terminated", "vfunc_name", "finish_vfunc_name", "finish_name", "free_function_address_of", "pos", "delegate_target", "delegate_target_cname", "array_length_pos", "delegate_target_pos", "destroy_notify_pos", "ctype", "has_new_function", "notify", "finish_instance", - "use_inplace", "feature_test_macro", "default_value_on_error", "", + "use_inplace", "feature_test_macro", "default_value_on_error", + "class_padding", "class_padding_ctype", "instance_padding", "instance_padding_ctype", "", "Immutable", "", "Compact", "", -- 2.47.2