Skip to content

Commit

Permalink
fix an issue with full transfer of GBoxed types
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand committed Nov 4, 2024
1 parent e643ea6 commit d39dee5
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Adwaita/src/gen/adw_consts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ $(Expr(:toplevel, quote
begin
const DURATION_INFINITE = 0xffffffff
const MAJOR_VERSION = 1
const MICRO_VERSION = 3
const MICRO_VERSION = 4
const MINOR_VERSION = 5
const VERSION_S = "1.5.3"
const VERSION_S = "1.5.4"
begin
@cenum AnimationState::Int32 AnimationState_IDLE = 0 AnimationState_PAUSED = 1 AnimationState_PLAYING = 2 AnimationState_FINISHED = 3
(GLib.g_type(::Type{T}) where T <: AnimationState) = begin
Expand Down
1 change: 1 addition & 0 deletions Adwaita/src/gen/adw_methods
Original file line number Diff line number Diff line change
Expand Up @@ -5435,6 +5435,7 @@ $(Expr(:toplevel, quote
get_buildable_id(GtkBuildable(instance))
end
function SpringAnimation_new(_widget::GtkWidget, _from::Real, _to::Real, _spring_params::AdwSpringParams, _target::AdwAnimationTarget)
_spring_params = GLib.glib_ref(_spring_params)
_target = GLib.glib_ref(_target)
ret = ccall(("adw_spring_animation_new", libadwaita), Ptr{GObject}, (Ptr{GObject}, Float64, Float64, Ptr{AdwSpringParams}, Ptr{GObject}), _widget, _from, _to, _spring_params, _target)
ret2 = AdwSpringAnimationLeaf(ret, false)
Expand Down
4 changes: 4 additions & 0 deletions GI/src/giimport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,10 @@ function convert_to_c(name::Symbol, arginfo::GIArgInfo, typeinfo::TypeDesc{T}) w
_convert_obj_to_c(name,arginfo,typeinfo)
end

function convert_to_c(name::Symbol, arginfo::GIArgInfo, typeinfo::TypeDesc{T}) where {T<:Type{GBoxed}}
_convert_obj_to_c(name,arginfo,typeinfo)
end

function convert_from_c(name::Symbol, arginfo::ArgInfo, typeinfo::TypeDesc{T}, isconstructor=false) where {T <: Type{GObject}}
owns = get_ownership_transfer(arginfo) != GITransfer.NOTHING
object = get_container(arginfo)
Expand Down
2 changes: 1 addition & 1 deletion examples/word_counter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using Gtk4
win = GtkWindow("Word counter")

b = GtkBox(:v)
tv = GtkTextView(; vexpand = true)
tv = GtkTextView(; vexpand = true, wrap_mode = Gtk4.WrapMode_WORD)
l = GtkLabel("0 characters, 0 words, 0 lines")
push!(b, tv)
Gtk4.gutter(tv, :bottom, l)
Expand Down
6 changes: 6 additions & 0 deletions src/GLib/gtype.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ function delboxed(x::GBoxed)
ccall((:g_boxed_free, libgobject), Nothing, (GType, Ptr{GBoxed},), gtype, x.handle)
end

function glib_ref(x::GBoxed)
T=typeof(x)
gtype = g_type(T)
ccall((:g_boxed_copy, libgobject), Ptr{GBoxed}, (GType, Ptr{GBoxed},), gtype, x.handle)
end

cconvert(::Type{Ptr{GObject}}, @nospecialize(x::GObject)) = x

# All GObjects are expected to have a 'handle' field
Expand Down
13 changes: 12 additions & 1 deletion src/Graphene.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,27 @@ module Graphene
using ..GLib
using Graphene_jll

import Base: convert, length, getindex, iterate, unsafe_convert

import CEnum: @cenum, CEnum

eval(include("gen/graphene_consts"))
eval(include("gen/graphene_structs"))

export _GrapheneRect, _GraphenePoint, _GrapheneMatrix, _GrapheneVec4, _GrapheneVec3, _GrapheneSize, _GraphenePoint3D

#eval(include("gen/graphene_methods"))
module G_

using Graphene_jll

using ..GLib
using ..Graphene

eval(include("gen/graphene_methods"))
#eval(include("gen/graphene_functions"))

end

_GrapheneRect(x::Number,y::Number,w::Number,h::Number) = _GrapheneRect(_GraphenePoint(x,y),_GrapheneSize(w,h))

function __init__()
Expand Down
43 changes: 37 additions & 6 deletions src/gen/gtk4_methods
Original file line number Diff line number Diff line change
Expand Up @@ -4428,7 +4428,12 @@ $(Expr(:toplevel, quote
end
function scroll_to(instance::GtkColumnView, _pos::Integer, _column::Maybe(GtkColumnViewColumn), _flags, _scroll::Maybe(GtkScrollInfo))
_column_maybe = nothing_to_null(_column)
_scroll_maybe = nothing_to_null(_scroll)
_scroll_maybe = begin
if _scroll !== nothing
GLib.glib_ref(_scroll)
end
nothing_to_null(_scroll)
end
ret = ccall(("gtk_column_view_scroll_to", libgtk4), Nothing, (Ptr{GObject}, UInt32, Ptr{GObject}, UInt32, Ptr{GtkScrollInfo}), instance, _pos, _column_maybe, _flags, _scroll_maybe)
nothing
end
Expand Down Expand Up @@ -5977,7 +5982,12 @@ $(Expr(:toplevel, quote
nothing
end
function DropTargetAsync_new(_formats::Maybe(GdkContentFormats), _actions)
_formats_maybe = nothing_to_null(_formats)
_formats_maybe = begin
if _formats !== nothing
GLib.glib_ref(_formats)
end
nothing_to_null(_formats)
end
ret = ccall(("gtk_drop_target_async_new", libgtk4), Ptr{GObject}, (Ptr{GdkContentFormats}, UInt32), _formats_maybe, _actions)
ret2 = GtkDropTargetAsyncLeaf(ret, true)
ret2
Expand Down Expand Up @@ -9845,7 +9855,12 @@ $(Expr(:toplevel, quote
ret2
end
function scroll_to(instance::GtkGridView, _pos::Integer, _flags, _scroll::Maybe(GtkScrollInfo))
_scroll_maybe = nothing_to_null(_scroll)
_scroll_maybe = begin
if _scroll !== nothing
GLib.glib_ref(_scroll)
end
nothing_to_null(_scroll)
end
ret = ccall(("gtk_grid_view_scroll_to", libgtk4), Nothing, (Ptr{GObject}, UInt32, UInt32, Ptr{GtkScrollInfo}), instance, _pos, _flags, _scroll_maybe)
nothing
end
Expand Down Expand Up @@ -12498,7 +12513,12 @@ $(Expr(:toplevel, quote
ret2
end
function scroll_to(instance::GtkListView, _pos::Integer, _flags, _scroll::Maybe(GtkScrollInfo))
_scroll_maybe = nothing_to_null(_scroll)
_scroll_maybe = begin
if _scroll !== nothing
GLib.glib_ref(_scroll)
end
nothing_to_null(_scroll)
end
ret = ccall(("gtk_list_view_scroll_to", libgtk4), Nothing, (Ptr{GObject}, UInt32, UInt32, Ptr{GtkScrollInfo}), instance, _pos, _flags, _scroll_maybe)
nothing
end
Expand Down Expand Up @@ -17467,6 +17487,7 @@ $(Expr(:toplevel, quote
nothing
end
function push_gl_shader(instance::GtkSnapshot, _shader::GskGLShader, _bounds::GrapheneRectLike, _take_args::GBytes)
_take_args = GLib.glib_ref(_take_args)
ret = ccall(("gtk_snapshot_push_gl_shader", libgtk4), Nothing, (Ptr{GObject}, Ptr{GObject}, Ptr{_GrapheneRect}, Ptr{GBytes}), instance, _shader, _bounds, _take_args)
nothing
end
Expand Down Expand Up @@ -21905,7 +21926,12 @@ $(Expr(:toplevel, quote
ret2
end
function scroll_to(instance::GtkViewport, _descendant::GtkWidget, _scroll::Maybe(GtkScrollInfo))
_scroll_maybe = nothing_to_null(_scroll)
_scroll_maybe = begin
if _scroll !== nothing
GLib.glib_ref(_scroll)
end
nothing_to_null(_scroll)
end
ret = ccall(("gtk_viewport_scroll_to", libgtk4), Nothing, (Ptr{GObject}, Ptr{GObject}, Ptr{GtkScrollInfo}), instance, _descendant, _scroll_maybe)
nothing
end
Expand Down Expand Up @@ -22100,7 +22126,12 @@ $(Expr(:toplevel, quote
nothing
end
function allocate(instance::GtkWidget, _width::Integer, _height::Integer, _baseline::Integer, _transform::Maybe(GskTransform))
_transform_maybe = nothing_to_null(_transform)
_transform_maybe = begin
if _transform !== nothing
GLib.glib_ref(_transform)
end
nothing_to_null(_transform)
end
ret = ccall(("gtk_widget_allocate", libgtk4), Nothing, (Ptr{GObject}, Int32, Int32, Int32, Ptr{GskTransform}), instance, _width, _height, _baseline, _transform_maybe)
nothing
end
Expand Down
3 changes: 3 additions & 0 deletions src/gen/pango_methods
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ $(Expr(:toplevel, quote
ret2
end
function change(instance::PangoAttrList, _attr::PangoAttributeLike)
_attr = GLib.glib_ref(_attr)
ret = ccall(("pango_attr_list_change", libpango), Nothing, (Ptr{PangoAttrList}, Ptr{_PangoAttribute}), instance, _attr)
nothing
end
Expand All @@ -72,10 +73,12 @@ $(Expr(:toplevel, quote
ret2
end
function insert(instance::PangoAttrList, _attr::PangoAttributeLike)
_attr = GLib.glib_ref(_attr)
ret = ccall(("pango_attr_list_insert", libpango), Nothing, (Ptr{PangoAttrList}, Ptr{_PangoAttribute}), instance, _attr)
nothing
end
function insert_before(instance::PangoAttrList, _attr::PangoAttributeLike)
_attr = GLib.glib_ref(_attr)
ret = ccall(("pango_attr_list_insert_before", libpango), Nothing, (Ptr{PangoAttrList}, Ptr{_PangoAttribute}), instance, _attr)
nothing
end
Expand Down

0 comments on commit d39dee5

Please sign in to comment.