From c2e1262d31b4d04c7e825dc2cbcbaae83215f376 Mon Sep 17 00:00:00 2001 From: Jared Wahlstrand Date: Sat, 9 Nov 2024 09:07:40 -0500 Subject: [PATCH] properly handle transfer of instance type in methods --- GI/src/giimport.jl | 7 ++++++- GI/src/girepo.jl | 2 +- src/gen/gdk4_methods | 18 ++++++++++++------ src/gen/glib_methods | 21 ++++++++++++++------- src/gen/gsk4_methods | 36 ++++++++++++++++++++++++------------ src/gen/gtk4_methods | 9 ++++++--- 6 files changed, 63 insertions(+), 30 deletions(-) diff --git a/GI/src/giimport.jl b/GI/src/giimport.jl index d3136a7b..7fdc0a48 100644 --- a/GI/src/giimport.jl +++ b/GI/src/giimport.jl @@ -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 diff --git a/GI/src/girepo.jl b/GI/src/girepo.jl index 28ad398b..887fe88b 100644 --- a/GI/src/girepo.jl +++ b/GI/src/girepo.jl @@ -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), diff --git a/src/gen/gdk4_methods b/src/gen/gdk4_methods index c5d215bd..9c8c6571 100644 --- a/src/gen/gdk4_methods +++ b/src/gen/gdk4_methods @@ -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 @@ -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) diff --git a/src/gen/glib_methods b/src/gen/glib_methods index 0e20ddf9..05cd5ccb 100644 --- a/src/gen/glib_methods +++ b/src/gen/glib_methods @@ -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) @@ -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 @@ -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)) @@ -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}) diff --git a/src/gen/gsk4_methods b/src/gen/gsk4_methods index 4c0fad83..134a1403 100644 --- a/src/gen/gsk4_methods +++ b/src/gen/gsk4_methods @@ -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 @@ -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 @@ -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 @@ -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 @@ -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}) diff --git a/src/gen/gtk4_methods b/src/gen/gtk4_methods index 79a45261..cbba21f5 100644 --- a/src/gen/gtk4_methods +++ b/src/gen/gtk4_methods @@ -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) @@ -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 @@ -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)