Skip to content

Commit d94555e

Browse files
committed
allow transfer=none for GLists and GSLists
1 parent 7332028 commit d94555e

File tree

8 files changed

+49
-25
lines changed

8 files changed

+49
-25
lines changed

GI/src/giimport.jl

+8-4
Original file line numberDiff line numberDiff line change
@@ -762,11 +762,15 @@ function extract_type(typeinfo::GITypeInfo,listtype::Type{T}) where {T<:GLib._LL
762762
TypeDesc{Type{GList}}(GList, :(GLib.LList{$lt{$elmtype}}),:(GLib.LList{$lt{$elmtype}}), :(Ptr{$lt{$elmtype}}))
763763
end
764764
function convert_from_c(name::Symbol, arginfo::ArgInfo, typeinfo::TypeDesc{Type{GList}})
765-
owns = (get_ownership_transfer(arginfo) == GITransfer.EVERYTHING)
766-
if get_ownership_transfer(arginfo) == GITransfer.NOTHING
767-
nothing # just return the pointer
765+
ot = get_ownership_transfer(arginfo)
766+
if ot == GITransfer.NOTHING
767+
:( GLib.GList($name, false, false) )
768+
elseif ot == GITransfer.CONTAINER
769+
:( GLib.GList($name, false) )
770+
elseif ot == GITransfer.EVERYTHING
771+
:( GLib.GList($name, true) )
768772
else
769-
:( GLib.GList($name, $owns) )
773+
error("Unknown transfer type for GList")
770774
end
771775
end
772776

src/GLib/glist.jl

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Gtk linked list
1+
# GLib linked list
22

33
## Type hierarchy information
44

@@ -21,19 +21,21 @@ eltype(::Type{L}) where {L <: _LList} = eltype(supertype(L))
2121
mutable struct GList{L <: _LList, T} <: AbstractVector{T}
2222
handle::Ptr{L}
2323
transfer_full::Bool
24-
function GList{L,T}(handle, transfer_full::Bool) where {L<:_LList,T}
25-
# if transfer_full == true, then also free the elements when finalizing the list
24+
transfer_container::Bool
25+
function GList{L,T}(handle, transfer_elements::Bool, transfer_container::Bool=true) where {L<:_LList,T}
26+
# if transfer_elements == true, then also free the elements when finalizing the list
27+
# if transfer_container == false, then do not call `g_list_free` when emptying
2628
# this function assumes the caller will take care of holding a pointer to the returned object
2729
# until it wants to be garbage collected
2830
@assert T == eltype(L)
29-
l = new{L,T}(handle, transfer_full)
31+
l = new{L,T}(handle, transfer_elements, transfer_container)
3032
finalizer(empty!, l)
3133
return l
3234
end
3335
end
3436
GList(list::Type{T}) where {T} = GList(convert(Ptr{_GList{T}}, C_NULL), true)
3537
GSList(list::Type{T}) where {T} = GList(convert(Ptr{_GSList{T}}, C_NULL), true)
36-
GList(list::Ptr{L}, transfer_full::Bool = false) where {L <: _LList} = GList{L, eltype(L)}(list, transfer_full)
38+
GList(list::Ptr{L}, transfer_full::Bool = false, transfer_container::Bool = true) where {L <: _LList} = GList{L, eltype(L)}(list, transfer_full, transfer_container)
3739

3840
const LList{L <: _LList} = Union{Ptr{L}, GList{L}}
3941
eltype(::LList{L}) where {L <: _LList} = eltype(L)
@@ -132,7 +134,9 @@ function empty!(list::GList{L}) where L <: _GSList
132134
s = next_(list, s)[2]
133135
end
134136
end
135-
#ccall((:g_slist_free, libglib), Nothing, (Ptr{L},), list)
137+
if list.transfer_container
138+
ccall((:g_slist_free, libglib), Nothing, (Ptr{L},), list)
139+
end
136140
list.handle = C_NULL
137141
end
138142
return list
@@ -146,7 +150,9 @@ function empty!(list::GList{L}) where L <: _GList
146150
s = next_(list, s)[2]
147151
end
148152
end
149-
ccall((:g_list_free, libglib), Nothing, (Ptr{L},), list)
153+
if list.transfer_container
154+
ccall((:g_list_free, libglib), Nothing, (Ptr{L},), list)
155+
end
150156
list.handle = C_NULL
151157
end
152158
return list

src/gen/gio_methods

+2-1
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,8 @@ $(Expr(:toplevel, quote
20202020
end
20212021
function get_emblems(instance::GEmblemedIcon)
20222022
ret = ccall(("g_emblemed_icon_get_emblems", libgio), Ptr{GLib._GList{Ptr{GObject}}}, (Ptr{GObject},), instance)
2023-
ret
2023+
ret2 = GLib.GList(ret, false, false)
2024+
ret2
20242025
end
20252026
function get_icon(instance::GEmblemedIcon)
20262027
ret = ccall(("g_emblemed_icon_get_icon", libgio), Ptr{GObject}, (Ptr{GObject},), instance)

src/gen/gtk4_methods

+12-3
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,8 @@ $(Expr(:toplevel, quote
13111311
end
13121312
function get_windows(instance::GtkApplication)
13131313
ret = ccall(("gtk_application_get_windows", libgtk4), Ptr{GLib._GList{Ptr{GObject}}}, (Ptr{GObject},), instance)
1314-
ret
1314+
ret2 = GLib.GList(ret, false, false)
1315+
ret2
13151316
end
13161317
function inhibit(instance::GtkApplication, _window::Maybe(GtkWindow), _flags, _reason::Maybe(Union{AbstractString, Symbol}))
13171318
_window_maybe = nothing_to_null(_window)
@@ -1400,6 +1401,9 @@ $(Expr(:toplevel, quote
14001401
function remove_action(instance::GtkApplication, _action_name::Union{AbstractString, Symbol})
14011402
remove_action(GActionMap(instance), _action_name)
14021403
end
1404+
function remove_action_entries(instance::GtkApplication, _entries)
1405+
remove_action_entries(GActionMap(instance), _entries)
1406+
end
14031407
function ApplicationWindow_new(_application::GtkApplication)
14041408
ret = ccall(("gtk_application_window_new", libgtk4), Ptr{GObject}, (Ptr{GObject},), _application)
14051409
ret2 = GtkApplicationWindowLeaf(ret, false)
@@ -1482,6 +1486,9 @@ $(Expr(:toplevel, quote
14821486
function remove_action(instance::GtkApplicationWindow, _action_name::Union{AbstractString, Symbol})
14831487
remove_action(GActionMap(instance), _action_name)
14841488
end
1489+
function remove_action_entries(instance::GtkApplicationWindow, _entries)
1490+
remove_action_entries(GActionMap(instance), _entries)
1491+
end
14851492
function get_accessible_parent(instance::GtkApplicationWindow)
14861493
get_accessible_parent(GtkAccessible(instance))
14871494
end
@@ -2569,7 +2576,8 @@ $(Expr(:toplevel, quote
25692576
end
25702577
function get_focus_siblings(instance::GtkCellArea, _renderer::GtkCellRenderer)
25712578
ret = ccall(("gtk_cell_area_get_focus_siblings", libgtk4), Ptr{GLib._GList{Ptr{GObject}}}, (Ptr{GObject}, Ptr{GObject}), instance, _renderer)
2572-
ret
2579+
ret2 = GLib.GList(ret, false, false)
2580+
ret2
25732581
end
25742582
function get_preferred_height(instance::GtkCellArea, _context::GtkCellAreaContext, _widget::GtkWidget)
25752583
m_minimum_height = Ref{Int32}()
@@ -15856,7 +15864,8 @@ $(Expr(:toplevel, quote
1585615864
end
1585715865
function get_widgets(instance::GtkSizeGroup)
1585815866
ret = ccall(("gtk_size_group_get_widgets", libgtk4), Ptr{GLib._GSList{Ptr{GObject}}}, (Ptr{GObject},), instance)
15859-
ret
15867+
ret2 = GLib.GList(ret, false, false)
15868+
ret2
1586015869
end
1586115870
function remove_widget(instance::GtkSizeGroup, _widget::GtkWidget)
1586215871
ret = ccall(("gtk_size_group_remove_widget", libgtk4), Nothing, (Ptr{GObject}, Ptr{GObject}), instance, _widget)

src/gen/pango_consts

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ $(Expr(:toplevel, quote
1111
const GLYPH_UNKNOWN_FLAG = 0x10000000
1212
const SCALE = 1024
1313
const VERSION_MAJOR = 1
14-
const VERSION_MICRO = 0
15-
const VERSION_MINOR = 51
16-
const VERSION_STRING = "1.51.0"
14+
const VERSION_MICRO = 14
15+
const VERSION_MINOR = 50
16+
const VERSION_STRING = "1.50.14"
1717
begin
1818
@cenum Alignment::Int32 Alignment_LEFT = 0 Alignment_CENTER = 1 Alignment_RIGHT = 2
1919
(GLib.g_type(::Type{T}) where T <: Alignment) = begin

src/gen/pango_methods

+4-2
Original file line numberDiff line numberDiff line change
@@ -1445,11 +1445,13 @@ $(Expr(:toplevel, quote
14451445
end
14461446
function get_lines(instance::PangoLayout)
14471447
ret = ccall(("pango_layout_get_lines", libpango), Ptr{GLib._GSList{_PangoLayoutLine}}, (Ptr{GObject},), instance)
1448-
ret
1448+
ret2 = GLib.GList(ret, false, false)
1449+
ret2
14491450
end
14501451
function get_lines_readonly(instance::PangoLayout)
14511452
ret = ccall(("pango_layout_get_lines_readonly", libpango), Ptr{GLib._GSList{_PangoLayoutLine}}, (Ptr{GObject},), instance)
1452-
ret
1453+
ret2 = GLib.GList(ret, false, false)
1454+
ret2
14531455
end
14541456
function get_log_attrs(instance::PangoLayout)
14551457
m_attrs = Ref{Ptr{_PangoLogAttr}}()

test/gui/misc.jl

+6-4
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,13 @@ push!(b4; filename="test.ui")
160160
win = b4["a_window"]
161161
destroy(win)
162162

163-
b5 = GtkBuilder()
164-
Sys.WORD_SIZE == 64 && push!(b5; buffer=s)
163+
if Sys.WORD_SIZE == 64
164+
b5 = GtkBuilder()
165+
push!(b5; buffer=s)
165166

166-
win = b5["a_window"]
167-
destroy(win)
167+
win = b5["a_window"]
168+
destroy(win)
169+
end
168170

169171
end
170172

test/list.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Gtk4.GLib
1+
using Gtk4.GLib, Test
22

33
@testset "glist" begin
44

0 commit comments

Comments
 (0)