]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use available *_unref functions in G_DEFINE_AUTOPTR_CLEANUP_FUNC
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 25 Mar 2019 19:59:25 +0000 (20:59 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 25 Mar 2019 20:08:00 +0000 (21:08 +0100)
Compact classes might have a unref_function in external packages. Therefore
subclassing them resulted in an errornous reference to free_function.

codegen/valagtypemodule.vala
tests/Makefile.am
tests/objects/compact-class-refcount.vala [new file with mode: 0644]

index a8c98cdcfd3fb7da7f545c5cb69159b80bddd3a9..6b0c3b310c33e59bf67fd6d93b986c5311b20be3 100644 (file)
@@ -196,10 +196,10 @@ public class Vala.GTypeModule : GErrorModule {
                        base_class = base_class.base_class;
                }
                string autoptr_cleanup_func;
-               if (!is_gtypeinstance && !is_gsource) {
-                       autoptr_cleanup_func = get_ccode_free_function (base_class);
-               } else {
+               if (is_reference_counting (base_class)) {
                        autoptr_cleanup_func = get_ccode_unref_function (base_class);
+               } else {
+                       autoptr_cleanup_func = get_ccode_free_function (base_class);
                }
                if (autoptr_cleanup_func == null || autoptr_cleanup_func == "") {
                        Report.error (cl.source_reference, "internal error: autoptr_cleanup_func not available");
index 72e09201be86f6a115523d3a1491b9352e015207..abd7cb85c1aea51d4877666b92c1de96df291810 100644 (file)
@@ -287,6 +287,7 @@ TESTS = \
        objects/classes-implicit-implementation.vala \
        objects/compact-class.vala \
        objects/compact-class-destructor.vala \
+       objects/compact-class-refcount.vala \
        objects/constructor-abstract-public.test \
        objects/constructor-variadic.test \
        objects/constructors.vala \
diff --git a/tests/objects/compact-class-refcount.vala b/tests/objects/compact-class-refcount.vala
new file mode 100644 (file)
index 0000000..1b8637e
--- /dev/null
@@ -0,0 +1,12 @@
+class FooRegex : Regex {
+       public FooRegex () throws RegexError {
+               base ("^:*$");
+       }
+}
+
+void main () {
+       try {
+               var foo = new FooRegex ();
+       } catch {
+       }
+}