Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed incomplete type declaration #167

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions spec/list_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,13 @@ describe "GList" do
list.each { |s| res << s }
res.should eq(%w(one two))
end

describe "ListStore" do
it "can splice an array" do
list_store = Gio::ListStore.new(Test::Subject.g_type)
one = Test::Subject.new
items = [one]
list_store.splice(position: 0_u32, n_removals: 0_u32, additions: items)
end
end
end
4 changes: 2 additions & 2 deletions src/generator/wrapper_util.cr
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module Generator
# FIXME: Possible buffer overflow... need to be sure we send a null terminated array if needed
def generate_array_to_unsafe(io : IO, identifier : String, type : TypeInfo)
param_type = type.param_type
lib_ptype = to_lib_type(param_type)
tag = param_type.tag

io << identifier << ".to_a"
Expand All @@ -26,13 +27,12 @@ module Generator
else
# FIXME: This is copying too much and can be optimized
# Main use case of this are methods receiving an array of GValues
lib_ptype = to_lib_type(param_type)
io << ".map { |_i| " << ptype_name << ".new(_i).to_unsafe.as(Pointer(" << lib_ptype << ")).value }"
end
elsif tag.interface? || tag.utf8? || tag.filename?
io << ".map(&.to_unsafe)"
end
io << ".to_unsafe\n"
io << ".to_unsafe.as(Pointer(" << lib_ptype << "))\n"
end
end
end
Loading