From: Rico Tzschichholz Date: Mon, 25 Mar 2019 19:59:25 +0000 (+0100) Subject: codegen: Use available *_unref functions in G_DEFINE_AUTOPTR_CLEANUP_FUNC X-Git-Tag: 0.45.1~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6d718504c77801fb8420130e0d83bf46549faed5;p=thirdparty%2Fvala.git codegen: Use available *_unref functions in G_DEFINE_AUTOPTR_CLEANUP_FUNC Compact classes might have a unref_function in external packages. Therefore subclassing them resulted in an errornous reference to free_function. --- diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala index a8c98cdcf..6b0c3b310 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -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"); diff --git a/tests/Makefile.am b/tests/Makefile.am index 72e09201b..abd7cb85c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..1b8637e8b --- /dev/null +++ b/tests/objects/compact-class-refcount.vala @@ -0,0 +1,12 @@ +class FooRegex : Regex { + public FooRegex () throws RegexError { + base ("^:*$"); + } +} + +void main () { + try { + var foo = new FooRegex (); + } catch { + } +}