From d5f30dc29e322bcc6c335625733797aed15b127e Mon Sep 17 00:00:00 2001 From: Hugo Parente Lima Date: Sun, 7 May 2023 23:30:56 -0300 Subject: [PATCH] Let struct bindings allocated on help to obey `-Ddebugmemory` flag. --- ecr/heap_wrapper_struct.ecr | 3 +++ spec/boxed_struct_spec.cr | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/ecr/heap_wrapper_struct.ecr b/ecr/heap_wrapper_struct.ecr index e6a9d4a..1a91904 100644 --- a/ecr/heap_wrapper_struct.ecr +++ b/ecr/heap_wrapper_struct.ecr @@ -29,6 +29,9 @@ module <%= namespace_name %> <% if object.boxed? %> def finalize + {% if flag?(:debugmemory) %} + LibC.printf("~%s at %p\n", self.class.name, self) + {% end %} LibGObject.g_boxed_free(<%= type_name %>.g_type, self) end <% end %> diff --git a/spec/boxed_struct_spec.cr b/spec/boxed_struct_spec.cr index 1c60673..96aba5a 100644 --- a/spec/boxed_struct_spec.cr +++ b/spec/boxed_struct_spec.cr @@ -1,4 +1,13 @@ require "./spec_helper" +@[NoInline] +private def create_boxed : Nil + Test::BoxedStruct.return_boxed_struct("hey") +end + describe "Boxed Struct bindings" do + it "doesn't crash on finalize method" do + create_boxed + GC.collect + end end