From: Lorenz Wildberg Date: Tue, 6 Jun 2023 09:00:51 +0000 (+0200) Subject: girparser: Support glib:ref-func, glib:unref-func, copy-function and free-function X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22679692ff8f60baade6c481cd54881cd6b42be2;p=thirdparty%2Fvala.git girparser: Support glib:ref-func, glib:unref-func, copy-function and free-function --- diff --git a/tests/Makefile.am b/tests/Makefile.am index b072ba7e6..f75a602e9 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -885,6 +885,7 @@ TESTS = \ gir/async-sync-out.gir \ gir/class.gir \ gir/class-final.gir \ + gir/class-ref-unref-function.gir \ gir/constant.gir \ gir/delegate-alias-without-target.gir \ gir/delegate-anonymous.gir \ @@ -902,6 +903,7 @@ TESTS = \ gir/parameter-nullable-out-simple-type.gir \ gir/property-non-readable.gir \ gir/signal-virtual.gir \ + gir/record-copy-free-func.gir \ gir/symbol-redefined.gir \ gir/symbol-type-csuffix.gir \ gir/symbol-without-name.gir \ diff --git a/tests/gir/class-ref-unref-function.gir b/tests/gir/class-ref-unref-function.gir new file mode 100644 index 000000000..4d849303d --- /dev/null +++ b/tests/gir/class-ref-unref-function.gir @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/gir/class-ref-unref-function.vapi-expected b/tests/gir/class-ref-unref-function.vapi-expected new file mode 100644 index 000000000..4633301f7 --- /dev/null +++ b/tests/gir/class-ref-unref-function.vapi-expected @@ -0,0 +1,9 @@ +[CCode (cprefix = "Test", gir_namespace = "Test", gir_version = "1.0", lower_case_cprefix = "test_")] +namespace Test { + [CCode (cheader_filename = "test.h", ref_function = "foo_custom_ref_function", type_id = "test_foo_get_type ()", unref_function = "foo_custom_unref_function")] + public class Foo { + public uint u; + [CCode (has_construct_function = false)] + protected Foo (); + } +} diff --git a/tests/gir/record-copy-free-func.gir b/tests/gir/record-copy-free-func.gir new file mode 100644 index 000000000..4aa1e582a --- /dev/null +++ b/tests/gir/record-copy-free-func.gir @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/tests/gir/record-copy-free-func.vapi-expected b/tests/gir/record-copy-free-func.vapi-expected new file mode 100644 index 000000000..5377957c6 --- /dev/null +++ b/tests/gir/record-copy-free-func.vapi-expected @@ -0,0 +1,8 @@ +[CCode (cprefix = "Test", gir_namespace = "Test", gir_version = "1.0", lower_case_cprefix = "test_")] +namespace Test { + [CCode (cheader_filename = "test.h", copy_function = "foo_custom_copy_func", free_function = "foo_custom_free_func", type_id = "test_foo_get_type ()")] + [Compact] + public class Foo { + public uint u; + } +} diff --git a/tests/girwriter/girtest.vapigen-expected b/tests/girwriter/girtest.vapigen-expected index a3f579324..00ddb4503 100644 --- a/tests/girwriter/girtest.vapigen-expected +++ b/tests/girwriter/girtest.vapigen-expected @@ -28,7 +28,7 @@ namespace GirTest { [CCode (has_construct_function = false)] public CompactClass (); } - [CCode (cheader_filename = "girtest.h", type_id = "gir_test_deprecated_class_test_get_type ()")] + [CCode (cheader_filename = "girtest.h", ref_function = "gir_test_deprecated_class_test_ref", type_id = "gir_test_deprecated_class_test_get_type ()", unref_function = "gir_test_deprecated_class_test_unref")] [Version (deprecated = true, deprecated_since = "0.1.2", since = "0.1.0")] public class DeprecatedClassTest { public int ref_count; @@ -53,7 +53,7 @@ namespace GirTest { [NoAccessorMethod] public GLib.Type t_type { get; construct; } } - [CCode (cheader_filename = "girtest.h", type_id = "gir_test_generics_test_get_type ()")] + [CCode (cheader_filename = "girtest.h", ref_function = "gir_test_generics_test_ref", type_id = "gir_test_generics_test_get_type ()", unref_function = "gir_test_generics_test_unref")] public class GenericsTest { public int ref_count; [CCode (has_construct_function = false)] @@ -142,7 +142,7 @@ namespace GirTest { public virtual signal void signal_with_default_handlder (int i1); public signal void some_signal (int param); } - [CCode (cheader_filename = "girtest.h", cname = "GirTestNamedClass", lower_case_csuffix = "namedclass", type_id = "gir_test_namedclass_get_type ()")] + [CCode (cheader_filename = "girtest.h", cname = "GirTestNamedClass", lower_case_csuffix = "namedclass", ref_function = "gir_test_namedclass_ref", type_id = "gir_test_namedclass_get_type ()", unref_function = "gir_test_namedclass_unref")] public class RenamedClass { public int ref_count; [CCode (has_construct_function = false)] @@ -167,7 +167,7 @@ namespace GirTest { [CCode (has_construct_function = false)] public SubTypeTest (); } - [CCode (cheader_filename = "girtest.h", type_id = "gir_test_typetest_get_type ()")] + [CCode (cheader_filename = "girtest.h", ref_function = "gir_test_typetest_ref", type_id = "gir_test_typetest_get_type ()", unref_function = "gir_test_typetest_unref")] public class TypeTest { public int ref_count; [CCode (has_construct_function = false)] diff --git a/vala/valagirparser.vala b/vala/valagirparser.vala index fa4337019..3f5cc8424 100644 --- a/vala/valagirparser.vala +++ b/vala/valagirparser.vala @@ -3065,12 +3065,16 @@ public class Vala.GirParser : CodeVisitor { if (metadata.has_argument (ArgumentType.REF_FUNCTION)) { cl.set_attribute_string ("CCode", "ref_function", metadata.get_string (ArgumentType.REF_FUNCTION)); + } else if (reader.has_attribute ("glib:ref-func")) { + cl.set_attribute_string ("CCode", "ref_function", reader.get_attribute ("glib:ref-func")); } if (metadata.has_argument (ArgumentType.REF_SINK_FUNCTION)) { cl.set_attribute_string ("CCode", "ref_sink_function", metadata.get_string (ArgumentType.REF_SINK_FUNCTION)); } if (metadata.has_argument (ArgumentType.UNREF_FUNCTION)) { cl.set_attribute_string ("CCode", "unref_function", metadata.get_string (ArgumentType.UNREF_FUNCTION)); + } else if (reader.has_attribute ("glib:unref-func")) { + cl.set_attribute_string ("CCode", "unref_function", reader.get_attribute ("glib:unref-func")); } if (metadata.has_argument (ArgumentType.TYPE_PARAMETERS)) { parse_type_parameters_from_string (cl, metadata.get_string (ArgumentType.TYPE_PARAMETERS), metadata.get_source_reference (ArgumentType.TYPE_PARAMETERS)); @@ -3709,18 +3713,26 @@ public class Vala.GirParser : CodeVisitor { } if (metadata.has_argument (ArgumentType.COPY_FUNCTION)) { cl.set_attribute_string ("CCode", "copy_function", metadata.get_string (ArgumentType.COPY_FUNCTION)); + } else if (reader.has_attribute ("copy-function")) { + cl.set_attribute_string ("CCode", "copy_function", reader.get_attribute ("copy-function")); } if (metadata.has_argument (ArgumentType.FREE_FUNCTION)) { cl.set_attribute_string ("CCode", "free_function", metadata.get_string (ArgumentType.FREE_FUNCTION)); + } else if (reader.has_attribute ("free-function")) { + cl.set_attribute_string ("CCode", "free_function", reader.get_attribute ("free-function")); } if (metadata.has_argument (ArgumentType.REF_FUNCTION)) { cl.set_attribute_string ("CCode", "ref_function", metadata.get_string (ArgumentType.REF_FUNCTION)); + } else if (reader.has_attribute ("glib:ref-func")) { + cl.set_attribute_string ("CCode", "ref_function", reader.get_attribute ("glib:ref-func")); } if (metadata.has_argument (ArgumentType.REF_SINK_FUNCTION)) { cl.set_attribute_string ("CCode", "ref_sink_function", metadata.get_string (ArgumentType.REF_SINK_FUNCTION)); } if (metadata.has_argument (ArgumentType.UNREF_FUNCTION)) { cl.set_attribute_string ("CCode", "unref_function", metadata.get_string (ArgumentType.UNREF_FUNCTION)); + } else if (reader.has_attribute ("glib:unref-func")) { + cl.set_attribute_string ("CCode", "unref_function", reader.get_attribute ("glib:unref-func")); } next ();