Skip to content

Commit

Permalink
properly handle transfer of instance type in methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand committed Nov 9, 2024
1 parent a065121 commit c2e1262
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 30 deletions.
7 changes: 6 additions & 1 deletion GI/src/giimport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,12 @@ function create_method(info::GIFunctionInfo, liboverride = nothing)
object = get_container(info)
if object !== nothing
typeinfo = extract_type(InstanceType,object)
push!(cargs, Arg(:instance, typeinfo.ctype))
if get_instance_ownership_transfer(info) == GITransfer.EVERYTHING
push!(prologue, :(reffed_instance = GLib.glib_ref(instance)))
push!(cargs, Arg(:reffed_instance, typeinfo.ctype))
else
push!(cargs, Arg(:instance, typeinfo.ctype))
end
end
end
if flags & GIFunction.IS_CONSTRUCTOR != 0
Expand Down
2 changes: 1 addition & 1 deletion GI/src/girepo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ ctypes = Dict(GIInfo=>Ptr{GIBaseInfo},
for (owner,property,typ) in [
(:base, :name, Symbol), (:base, :namespace, Symbol), (:base, :type, Int),
(:base, :container, MaybeGIInfo), (:registered_type, :g_type, GType), (:registered_type, :type_name, Symbol), (:object, :parent, MaybeGIInfo), (:object, :type_init, Symbol),
(:callable, :return_type, GIInfo), (:callable, :caller_owns, EnumGI), (:registered_type, :type_init, Symbol),
(:callable, :return_type, GIInfo), (:callable, :caller_owns, EnumGI), (:callable, :instance_ownership_transfer, EnumGI), (:registered_type, :type_init, Symbol),
(:function, :flags, EnumGI), (:function, :symbol, Symbol), (:property, :type, GIInfo), (:property, :ownership_transfer, EnumGI), (:property, :flags, EnumGI),
(:arg, :type, GIInfo), (:arg, :direction, EnumGI), (:arg, :ownership_transfer, EnumGI), #(:function, :property, MaybeGIInfo),
(:arg, :closure, Cint), (:arg, :destroy, Cint), (:arg, :scope, EnumGI),
Expand Down
18 changes: 12 additions & 6 deletions src/gen/gdk4_methods
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,32 @@ $(Expr(:toplevel, quote
ret2
end
function union(instance::GdkContentFormats, _second::GdkContentFormats)
ret = ccall(("gdk_content_formats_union", libgtk4), Ptr{GdkContentFormats}, (Ptr{GdkContentFormats}, Ptr{GdkContentFormats}), instance, _second)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gdk_content_formats_union", libgtk4), Ptr{GdkContentFormats}, (Ptr{GdkContentFormats}, Ptr{GdkContentFormats}), reffed_instance, _second)
ret2 = convert(GdkContentFormats, ret, true)
ret2
end
function union_deserialize_gtypes(instance::GdkContentFormats)
ret = ccall(("gdk_content_formats_union_deserialize_gtypes", libgtk4), Ptr{GdkContentFormats}, (Ptr{GdkContentFormats},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gdk_content_formats_union_deserialize_gtypes", libgtk4), Ptr{GdkContentFormats}, (Ptr{GdkContentFormats},), reffed_instance)
ret2 = convert(GdkContentFormats, ret, true)
ret2
end
function union_deserialize_mime_types(instance::GdkContentFormats)
ret = ccall(("gdk_content_formats_union_deserialize_mime_types", libgtk4), Ptr{GdkContentFormats}, (Ptr{GdkContentFormats},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gdk_content_formats_union_deserialize_mime_types", libgtk4), Ptr{GdkContentFormats}, (Ptr{GdkContentFormats},), reffed_instance)
ret2 = convert(GdkContentFormats, ret, true)
ret2
end
function union_serialize_gtypes(instance::GdkContentFormats)
ret = ccall(("gdk_content_formats_union_serialize_gtypes", libgtk4), Ptr{GdkContentFormats}, (Ptr{GdkContentFormats},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gdk_content_formats_union_serialize_gtypes", libgtk4), Ptr{GdkContentFormats}, (Ptr{GdkContentFormats},), reffed_instance)
ret2 = convert(GdkContentFormats, ret, true)
ret2
end
function union_serialize_mime_types(instance::GdkContentFormats)
ret = ccall(("gdk_content_formats_union_serialize_mime_types", libgtk4), Ptr{GdkContentFormats}, (Ptr{GdkContentFormats},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gdk_content_formats_union_serialize_mime_types", libgtk4), Ptr{GdkContentFormats}, (Ptr{GdkContentFormats},), reffed_instance)
ret2 = convert(GdkContentFormats, ret, true)
ret2
end
Expand Down Expand Up @@ -1584,7 +1589,8 @@ $(Expr(:toplevel, quote
ret2
end
function unref(instance::GdkEvent)
ret = ccall(("gdk_event_unref", libgtk4), Nothing, (Ptr{GdkEvent},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gdk_event_unref", libgtk4), Nothing, (Ptr{GdkEvent},), reffed_instance)
nothing
end
function get_in(instance::GdkFocusEvent)
Expand Down
21 changes: 14 additions & 7 deletions src/gen/glib_methods
Original file line number Diff line number Diff line change
Expand Up @@ -339,13 +339,15 @@ $(Expr(:toplevel, quote
nothing
end
function unref_to_array(instance::GBytes)
ret = ccall(("g_bytes_unref_to_array", libglib), Ptr{GByteArray}, (Ptr{GBytes},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("g_bytes_unref_to_array", libglib), Ptr{GByteArray}, (Ptr{GBytes},), reffed_instance)
ret2 = convert(GByteArray, ret, true)
ret2
end
function unref_to_data(instance::GBytes)
reffed_instance = GLib.glib_ref(instance)
m_size = Ref{UInt64}()
ret = ccall(("g_bytes_unref_to_data", libglib), Ptr{UInt8}, (Ptr{GBytes}, Ptr{UInt64}), instance, m_size)
ret = ccall(("g_bytes_unref_to_data", libglib), Ptr{UInt8}, (Ptr{GBytes}, Ptr{UInt64}), reffed_instance, m_size)
ret2 = begin
arrtemp = copy(unsafe_wrap(Vector{UInt8}, ret, m_size[]))
GLib.g_free(ret)
Expand Down Expand Up @@ -1550,17 +1552,20 @@ $(Expr(:toplevel, quote
ret2
end
function free(instance::GStringLike, _free_segment::Bool)
ret = ccall(("g_string_free", libglib), Cstring, (Ptr{_GString}, Cint), instance, _free_segment)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("g_string_free", libglib), Cstring, (Ptr{_GString}, Cint), reffed_instance, _free_segment)
ret2 = string_or_nothing(ret, true)
ret2
end
function free_and_steal(instance::GStringLike)
ret = ccall(("g_string_free_and_steal", libglib), Cstring, (Ptr{_GString},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("g_string_free_and_steal", libglib), Cstring, (Ptr{_GString},), reffed_instance)
ret2 = string_or_nothing(ret, true)
ret2
end
function free_to_bytes(instance::GStringLike)
ret = ccall(("g_string_free_to_bytes", libglib), Ptr{GBytes}, (Ptr{_GString},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("g_string_free_to_bytes", libglib), Ptr{GBytes}, (Ptr{_GString},), reffed_instance)
ret2 = convert(GBytes, ret, true)
ret2
end
Expand Down Expand Up @@ -2171,7 +2176,8 @@ $(Expr(:toplevel, quote
ret2
end
function unref(instance::GVariantBuilder)
ret = ccall(("g_variant_builder_unref", libglib), Nothing, (Ptr{GVariantBuilder},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("g_variant_builder_unref", libglib), Nothing, (Ptr{GVariantBuilder},), reffed_instance)
nothing
end
function VariantDict_new(_from_asv::Maybe(GVariant))
Expand Down Expand Up @@ -2210,7 +2216,8 @@ $(Expr(:toplevel, quote
ret2
end
function unref(instance::GVariantDict)
ret = ccall(("g_variant_dict_unref", libglib), Nothing, (Ptr{GVariantDict},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("g_variant_dict_unref", libglib), Nothing, (Ptr{GVariantDict},), reffed_instance)
nothing
end
function VariantType_new(_type_string::Union{AbstractString, Symbol})
Expand Down
36 changes: 24 additions & 12 deletions src/gen/gsk4_methods
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,20 @@ $(Expr(:toplevel, quote
ret2
end
function invert(instance::GskTransform)
ret = ccall(("gsk_transform_invert", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_transform_invert", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform},), reffed_instance)
ret2 = convert_if_not_null(GskTransform, ret, true)
ret2
end
function matrix(instance::GskTransform, _matrix::GrapheneMatrixLike)
ret = ccall(("gsk_transform_matrix", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Ptr{_GrapheneMatrix}), instance, _matrix)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_transform_matrix", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Ptr{_GrapheneMatrix}), reffed_instance, _matrix)
ret2 = convert(GskTransform, ret, true)
ret2
end
function perspective(instance::GskTransform, _depth::Real)
ret = ccall(("gsk_transform_perspective", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32), instance, _depth)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_transform_perspective", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32), reffed_instance, _depth)
ret2 = convert(GskTransform, ret, true)
ret2
end
Expand All @@ -139,27 +142,32 @@ $(Expr(:toplevel, quote
ret2
end
function rotate(instance::GskTransform, _angle::Real)
ret = ccall(("gsk_transform_rotate", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32), instance, _angle)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_transform_rotate", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32), reffed_instance, _angle)
ret2 = convert_if_not_null(GskTransform, ret, true)
ret2
end
function rotate_3d(instance::GskTransform, _angle::Real, _axis::GrapheneVec3Like)
ret = ccall(("gsk_transform_rotate_3d", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32, Ptr{_GrapheneVec3}), instance, _angle, _axis)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_transform_rotate_3d", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32, Ptr{_GrapheneVec3}), reffed_instance, _angle, _axis)
ret2 = convert_if_not_null(GskTransform, ret, true)
ret2
end
function scale(instance::GskTransform, _factor_x::Real, _factor_y::Real)
ret = ccall(("gsk_transform_scale", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32, Float32), instance, _factor_x, _factor_y)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_transform_scale", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32, Float32), reffed_instance, _factor_x, _factor_y)
ret2 = convert_if_not_null(GskTransform, ret, true)
ret2
end
function scale_3d(instance::GskTransform, _factor_x::Real, _factor_y::Real, _factor_z::Real)
ret = ccall(("gsk_transform_scale_3d", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32, Float32, Float32), instance, _factor_x, _factor_y, _factor_z)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_transform_scale_3d", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32, Float32, Float32), reffed_instance, _factor_x, _factor_y, _factor_z)
ret2 = convert_if_not_null(GskTransform, ret, true)
ret2
end
function skew(instance::GskTransform, _skew_x::Real, _skew_y::Real)
ret = ccall(("gsk_transform_skew", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32, Float32), instance, _skew_x, _skew_y)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_transform_skew", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Float32, Float32), reffed_instance, _skew_x, _skew_y)
ret2 = convert_if_not_null(GskTransform, ret, true)
ret2
end
Expand Down Expand Up @@ -229,8 +237,9 @@ $(Expr(:toplevel, quote
(_out_dx, _out_dy)
end
function transform(instance::GskTransform, _other::Maybe(GskTransform))
reffed_instance = GLib.glib_ref(instance)
_other_maybe = nothing_to_null(_other)
ret = ccall(("gsk_transform_transform", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Ptr{GskTransform}), instance, _other_maybe)
ret = ccall(("gsk_transform_transform", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Ptr{GskTransform}), reffed_instance, _other_maybe)
ret2 = convert_if_not_null(GskTransform, ret, true)
ret2
end
Expand All @@ -247,12 +256,14 @@ $(Expr(:toplevel, quote
_out_point
end
function translate(instance::GskTransform, _point::GraphenePointLike)
ret = ccall(("gsk_transform_translate", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Ptr{_GraphenePoint}), instance, _point)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_transform_translate", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Ptr{_GraphenePoint}), reffed_instance, _point)
ret2 = convert_if_not_null(GskTransform, ret, true)
ret2
end
function translate_3d(instance::GskTransform, _point::GraphenePoint3DLike)
ret = ccall(("gsk_transform_translate_3d", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Ptr{_GraphenePoint3D}), instance, _point)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_transform_translate_3d", libgtk4), Ptr{GskTransform}, (Ptr{GskTransform}, Ptr{_GraphenePoint3D}), reffed_instance, _point)
ret2 = convert_if_not_null(GskTransform, ret, true)
ret2
end
Expand Down Expand Up @@ -777,7 +788,8 @@ $(Expr(:toplevel, quote
ret2
end
function unref(instance::GskRenderNode)
ret = ccall(("gsk_render_node_unref", libgtk4), Nothing, (Ptr{GskRenderNode},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gsk_render_node_unref", libgtk4), Nothing, (Ptr{GskRenderNode},), reffed_instance)
nothing
end
function write_to_file(instance::GskRenderNode, _filename::Union{AbstractString, Symbol})
Expand Down
9 changes: 6 additions & 3 deletions src/gen/gtk4_methods
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ $(Expr(:toplevel, quote
ret2
end
function unref(instance::GtkExpressionWatch)
ret = ccall(("gtk_expression_watch_unref", libgtk4), Nothing, (Ptr{GtkExpressionWatch},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gtk_expression_watch_unref", libgtk4), Nothing, (Ptr{GtkExpressionWatch},), reffed_instance)
nothing
end
function unwatch(instance::GtkExpressionWatch)
Expand Down Expand Up @@ -7088,8 +7089,9 @@ $(Expr(:toplevel, quote
get_buildable_id(GtkBuildable(instance))
end
function bind(instance::GtkExpression, _target::GObject, _property::Union{AbstractString, Symbol}, _this_::Maybe(GObject))
reffed_instance = GLib.glib_ref(instance)
_this__maybe = nothing_to_null(_this_)
ret = ccall(("gtk_expression_bind", libgtk4), Ptr{GtkExpressionWatch}, (Ptr{GtkExpression}, Ptr{GObject}, Cstring, Ptr{GObject}), instance, _target, _property, _this__maybe)
ret = ccall(("gtk_expression_bind", libgtk4), Ptr{GtkExpressionWatch}, (Ptr{GtkExpression}, Ptr{GObject}, Cstring, Ptr{GObject}), reffed_instance, _target, _property, _this__maybe)
ret2 = convert(GtkExpressionWatch, ret, false)
ret2
end
Expand All @@ -7114,7 +7116,8 @@ $(Expr(:toplevel, quote
ret2
end
function unref(instance::GtkExpression)
ret = ccall(("gtk_expression_unref", libgtk4), Nothing, (Ptr{GtkExpression},), instance)
reffed_instance = GLib.glib_ref(instance)
ret = ccall(("gtk_expression_unref", libgtk4), Nothing, (Ptr{GtkExpression},), reffed_instance)
nothing
end
function announce(instance::GtkFileChooserDialog, _message::Union{AbstractString, Symbol}, _priority)
Expand Down

0 comments on commit c2e1262

Please sign in to comment.