]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Add "padding" CCode attributes for classes/interfaces
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 17 Jan 2018 14:10:37 +0000 (15:10 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 12 Jul 2018 07:26:20 +0000 (09:26 +0200)
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
vala/valausedattr.vala

index 6b60f7ef3ffa6ec2dce7e499fff38fa0cda1413b..9227260e029a0f0317bcb28301f064b1581c117b 100644 (file)
@@ -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);
                }
index dab15a864a08ad554d24e7f6dea7e68667ae8db4..fe9d7eedcd93fadfae0aa76df0b231aa4e2ee68b 100644 (file)
@@ -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", "",