Skip to content

Commit

Permalink
Let struct bindings allocated on help to obey -Ddebugmemory flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
hugopl committed May 9, 2023
1 parent 81a3f8a commit d5f30dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ecr/heap_wrapper_struct.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>
Expand Down
9 changes: 9 additions & 0 deletions spec/boxed_struct_spec.cr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d5f30dc

Please sign in to comment.