Skip to content

Commit

Permalink
fix methods with certain non-opaque structs as arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand committed Oct 1, 2023
1 parent b61e49c commit 48f086d
Show file tree
Hide file tree
Showing 20 changed files with 666 additions and 547 deletions.
19 changes: 15 additions & 4 deletions GI/src/giimport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,24 @@ function typename(info::GIStructInfo)
Symbol(GLib.g_type_name(g_type))
end
end
function extract_type(typeinfo::TypeInfo, info::GIStructInfo)
function extract_type(typeinfo::GITypeInfo, info::GIStructInfo)
name = typename(info)
sname = get_struct_name(info)
if is_pointer(typeinfo)
#TypeDesc(info,:(Ptr{$name}),:(Ptr{$name})) # use this for plain old structs?
TypeDesc(info,typename(info),typename(info),:(Ptr{$sname}))
#TypeDesc(info,:Any,:(Ptr{Nothing}))
fname = get_full_name(info)
tname = isopaque(info) ? fname : :(Union{$fname,Ref{$sname}})
TypeDesc(info,tname,typename(info),:(Ptr{$sname}))
else
TypeDesc(info,sname,sname,sname)
end
end
function extract_type(typeinfo::Type{InstanceType}, info::GIStructInfo)
name = typename(info)
sname = get_struct_name(info)
if is_pointer(typeinfo)
fname = get_full_name(info)
tname = isopaque(info) ? fname : :(Union{$fname,Ref{$sname}})
TypeDesc(info,tname,typename(info),:(Ptr{$sname}))
else
TypeDesc(info,sname,sname,sname)
end
Expand Down
3 changes: 1 addition & 2 deletions GI/src/girepo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -397,8 +397,7 @@ function get_base_type(info::GITypeInfo)
if GLib.g_isa(gtyp,boxed_gtype)
return GBoxed
else
# we don't have a type defined so return the name
return get_struct_name(interf_info)
return interf_info
end
elseif typ === :GIEnumInfo
return CEnum.Cenum
Expand Down
2 changes: 1 addition & 1 deletion gen/gen_gio.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ toplevel, exprs, exports = GI.output_exprs()
skiplist=[:bus_own_name_on_connection,:bus_own_name,:bus_watch_name_on_connection,:bus_watch_name,:dbus_annotation_info_lookup,:dbus_error_encode_gerror,:dbus_error_get_remote_error,:dbus_error_is_remote_error,:dbus_error_new_for_dbus_error,
:dbus_error_strip_remote_error,:dbus_error_register_error_domain,:io_modules_load_all_in_directory_with_scope,:io_modules_scan_all_in_directory_with_scope,:dbus_gvariant_to_gvalue,:unix_mount_at,:unix_mount_copy,:unix_mount_compare,:unix_mount_for,:unix_mount_free,
:unix_mount_get_device_path,:unix_mount_get_fs_type,:unix_mount_get_mount_path,:unix_mount_get_options,:unix_mount_get_root_path,:unix_mount_guess_can_eject,:unix_mount_guess_icon,:unix_mount_guess_name,:unix_mount_guess_should_display,:unix_mount_guess_symbolic_icon,
:unix_mount_is_readonly,:unix_mount_is_system_internal,:unix_mount_point_at,:unix_mount_points_changed_since,:unix_mount_points_get,:unix_mounts_get,:file_new_build_filenamev]
:unix_mount_is_readonly,:unix_mount_is_system_internal,:unix_mount_point_at,:unix_mount_points_changed_since,:unix_mount_points_get,:unix_mounts_get,:file_new_build_filenamev,:io_extension_point_implement,:io_extension_point_lookup,:io_extension_point_register]

GI.all_functions!(exprs,ns,skiplist=skiplist)

Expand Down
2 changes: 1 addition & 1 deletion gen/gen_glib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ GI.write_to_file(path,"glib_methods",toplevel)
toplevel, exprs, exports = GI.output_exprs()

# many of these are skipped because they involve callbacks
skiplist=[:convert,:atomic_rc_box_release_full,:child_watch_add,:datalist_foreach,:dataset_foreach,:io_add_watch,:io_create_watch,:log_set_handler,:log_set_writer_func,:rc_box_release_full,:spawn_async,:spawn_async_with_fds,:spawn_async_with_pipes,:spawn_async_with_pipes_and_fds,:spawn_sync,:test_add_data_func,:test_add_data_func_full,:test_add_func,:test_queue_destroy,:thread_self, :unix_fd_add_full,:unix_signal_add, :datalist_get_data, :datalist_get_flags, :datalist_id_get_data, :datalist_set_flags, :datalist_unset_flags,:hook_destroy,:hook_destroy_link,:hook_free,:hook_insert_before, :hook_prepend,:hook_unref,:poll, :sequence_get,:sequence_move,:sequence_move_range,:sequence_remove,:sequence_remove_range,:sequence_set,:sequence_swap,:shell_parse_argv,:source_remove_by_funcs_user_data,:test_run_suite, :assertion_message_error,:uri_parse_params, :pattern_match,:pattern_match_string,:log_structured_array,:log_writer_default,:log_writer_format_fields,:log_writer_journald,:log_writer_standard_streams,:parse_debug_string,:child_watch_source_new,:date_strftime,:idle_source_new,:main_current_source,:timeout_source_new,:timeout_source_new_seconds,:unix_fd_source_new,:unix_signal_source_new,:datalist_id_remove_multiple,:base64_encode_close,:base64_encode_step]
skiplist=[:convert,:atomic_rc_box_release_full,:child_watch_add,:datalist_foreach,:dataset_foreach,:io_add_watch,:io_create_watch,:log_set_handler,:log_set_writer_func,:rc_box_release_full,:spawn_async,:spawn_async_with_fds,:spawn_async_with_pipes,:spawn_async_with_pipes_and_fds,:spawn_sync,:test_add_data_func,:test_add_data_func_full,:test_add_func,:test_queue_destroy,:thread_self, :unix_fd_add_full,:unix_signal_add, :datalist_get_data, :datalist_get_flags, :datalist_id_get_data, :datalist_set_flags, :datalist_unset_flags,:hook_destroy,:hook_destroy_link,:hook_free,:hook_insert_before, :hook_prepend,:hook_unref,:poll, :sequence_get,:sequence_move,:sequence_move_range,:sequence_remove,:sequence_remove_range,:sequence_set,:sequence_swap,:shell_parse_argv,:source_remove_by_funcs_user_data,:test_run_suite, :assertion_message_error,:uri_parse_params, :pattern_match,:pattern_match_string,:log_structured_array,:log_writer_default,:log_writer_format_fields,:log_writer_journald,:log_writer_standard_streams,:parse_debug_string,:child_watch_source_new,:date_strftime,:idle_source_new,:main_current_source,:timeout_source_new,:timeout_source_new_seconds,:unix_fd_source_new,:unix_signal_source_new,:datalist_id_remove_multiple,:base64_encode_close,:base64_encode_step,:sequence_insert_before,:sequence_range_get_midpoint]

GI.all_functions!(exprs,ns,skiplist=skiplist,symbol_skiplist=symbols_handled, liboverride=:libglib)

Expand Down
4 changes: 3 additions & 1 deletion src/GLib/GLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,22 @@ function _extract_instance_type(m)
# type unfortunately has a namespace attached
p=split(decls[2][2],".")
length(p)==0 && error("Empty instance type in accessor generation for $m: maybe skip this one?")
length(p)>3 && error("Too many namespaces in accessor generation for $m.")
length(p)>3 && return nothing
p
end

# for an instance method in `G_`, generate a getter method
function gen_getter(func,v,m)
p=_extract_instance_type(m)
isnothing(p) && return nothing
t=Symbol(p[end]) # the type name
return :($v(x::$t)=G_.$func(x))
end

# for an instance method in `G_`, generate a setter method
function gen_setter(func,v,m)
p=_extract_instance_type(m)
isnothing(p) && return nothing
t=Symbol(p[end]) # the type name
return :($v(x::$t,y)=G_.$func(x,y))
end
Expand Down
24 changes: 12 additions & 12 deletions src/gen/gdk4_methods
Original file line number Diff line number Diff line change
Expand Up @@ -170,62 +170,62 @@ $(Expr(:toplevel, quote
ret = ccall(("gdk_popup_layout_unref", libgtk4), Nothing, (Ptr{GdkPopupLayout},), instance)
nothing
end
function copy(instance::GdkRGBA)
function copy(instance::Union{GdkRGBA, Ref{_GdkRGBA}})
ret = ccall(("gdk_rgba_copy", libgtk4), Ptr{_GdkRGBA}, (Ptr{_GdkRGBA},), instance)
ret2 = convert(Union{GdkRGBA, Ref{_GdkRGBA}}, ret, true)
ret2
end
function equal(instance::GdkRGBA, _p2::Union{GdkRGBA, Ref{_GdkRGBA}})
function equal(instance::Union{GdkRGBA, Ref{_GdkRGBA}}, _p2::Union{GdkRGBA, Ref{_GdkRGBA}})
ret = ccall(("gdk_rgba_equal", libgtk4), Cint, (Ptr{_GdkRGBA}, Ptr{_GdkRGBA}), instance, _p2)
ret2 = convert(Bool, ret)
ret2
end
function free(instance::GdkRGBA)
function free(instance::Union{GdkRGBA, Ref{_GdkRGBA}})
ret = ccall(("gdk_rgba_free", libgtk4), Nothing, (Ptr{_GdkRGBA},), instance)
nothing
end
function hash(instance::GdkRGBA)
function hash(instance::Union{GdkRGBA, Ref{_GdkRGBA}})
ret = ccall(("gdk_rgba_hash", libgtk4), UInt32, (Ptr{_GdkRGBA},), instance)
ret
end
function is_clear(instance::GdkRGBA)
function is_clear(instance::Union{GdkRGBA, Ref{_GdkRGBA}})
ret = ccall(("gdk_rgba_is_clear", libgtk4), Cint, (Ptr{_GdkRGBA},), instance)
ret2 = convert(Bool, ret)
ret2
end
function is_opaque(instance::GdkRGBA)
function is_opaque(instance::Union{GdkRGBA, Ref{_GdkRGBA}})
ret = ccall(("gdk_rgba_is_opaque", libgtk4), Cint, (Ptr{_GdkRGBA},), instance)
ret2 = convert(Bool, ret)
ret2
end
function parse(instance::GdkRGBA, _spec::Union{AbstractString, Symbol})
function parse(instance::Union{GdkRGBA, Ref{_GdkRGBA}}, _spec::Union{AbstractString, Symbol})
ret = ccall(("gdk_rgba_parse", libgtk4), Cint, (Ptr{_GdkRGBA}, Cstring), instance, _spec)
ret2 = convert(Bool, ret)
ret2
end
function to_string(instance::GdkRGBA)
function to_string(instance::Union{GdkRGBA, Ref{_GdkRGBA}})
ret = ccall(("gdk_rgba_to_string", libgtk4), Cstring, (Ptr{_GdkRGBA},), instance)
ret2 = string_or_nothing(ret, true)
ret2
end
function contains_point(instance::GdkRectangle, _x::Integer, _y::Integer)
function contains_point(instance::Union{GdkRectangle, Ref{_GdkRectangle}}, _x::Integer, _y::Integer)
ret = ccall(("gdk_rectangle_contains_point", libgtk4), Cint, (Ptr{_GdkRectangle}, Int32, Int32), instance, _x, _y)
ret2 = convert(Bool, ret)
ret2
end
function equal(instance::GdkRectangle, _rect2::Union{GdkRectangle, Ref{_GdkRectangle}})
function equal(instance::Union{GdkRectangle, Ref{_GdkRectangle}}, _rect2::Union{GdkRectangle, Ref{_GdkRectangle}})
ret = ccall(("gdk_rectangle_equal", libgtk4), Cint, (Ptr{_GdkRectangle}, Ptr{_GdkRectangle}), instance, _rect2)
ret2 = convert(Bool, ret)
ret2
end
function intersect(instance::GdkRectangle, _src2::Union{GdkRectangle, Ref{_GdkRectangle}})
function intersect(instance::Union{GdkRectangle, Ref{_GdkRectangle}}, _src2::Union{GdkRectangle, Ref{_GdkRectangle}})
m_dest = Ref{_GdkRectangle}()
ret = ccall(("gdk_rectangle_intersect", libgtk4), Cint, (Ptr{_GdkRectangle}, Ptr{_GdkRectangle}, Ptr{_GdkRectangle}), instance, _src2, m_dest)
ret2 = convert(Bool, ret)
_dest = m_dest[]
(ret2, _dest)
end
function union(instance::GdkRectangle, _src2::Union{GdkRectangle, Ref{_GdkRectangle}})
function union(instance::Union{GdkRectangle, Ref{_GdkRectangle}}, _src2::Union{GdkRectangle, Ref{_GdkRectangle}})
m_dest = Ref{_GdkRectangle}()
ret = ccall(("gdk_rectangle_union", libgtk4), Nothing, (Ptr{_GdkRectangle}, Ptr{_GdkRectangle}, Ptr{_GdkRectangle}), instance, _src2, m_dest)
_dest = m_dest[]
Expand Down
24 changes: 12 additions & 12 deletions src/gen/gdkpixbuf_methods
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
quote
$(Expr(:toplevel, quote
function copy(instance::GdkPixbufFormat)
function copy(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}})
ret = ccall(("gdk_pixbuf_format_copy", libgdkpixbuf), Ptr{_GdkPixbufFormat}, (Ptr{_GdkPixbufFormat},), instance)
ret2 = convert(Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}}, ret, true)
ret2
end
function free(instance::GdkPixbufFormat)
function free(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}})
ret = ccall(("gdk_pixbuf_format_free", libgdkpixbuf), Nothing, (Ptr{_GdkPixbufFormat},), instance)
nothing
end
function get_description(instance::GdkPixbufFormat)
function get_description(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}})
ret = ccall(("gdk_pixbuf_format_get_description", libgdkpixbuf), Cstring, (Ptr{_GdkPixbufFormat},), instance)
ret2 = string_or_nothing(ret, true)
ret2
end
function get_extensions(instance::GdkPixbufFormat)
function get_extensions(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}})
ret = ccall(("gdk_pixbuf_format_get_extensions", libgdkpixbuf), Ptr{Cstring}, (Ptr{_GdkPixbufFormat},), instance)
ret2 = begin
_len = length_zt(ret)
Expand All @@ -24,12 +24,12 @@ $(Expr(:toplevel, quote
end
ret2
end
function get_license(instance::GdkPixbufFormat)
function get_license(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}})
ret = ccall(("gdk_pixbuf_format_get_license", libgdkpixbuf), Cstring, (Ptr{_GdkPixbufFormat},), instance)
ret2 = string_or_nothing(ret, true)
ret2
end
function get_mime_types(instance::GdkPixbufFormat)
function get_mime_types(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}})
ret = ccall(("gdk_pixbuf_format_get_mime_types", libgdkpixbuf), Ptr{Cstring}, (Ptr{_GdkPixbufFormat},), instance)
ret2 = begin
_len = length_zt(ret)
Expand All @@ -39,32 +39,32 @@ $(Expr(:toplevel, quote
end
ret2
end
function get_name(instance::GdkPixbufFormat)
function get_name(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}})
ret = ccall(("gdk_pixbuf_format_get_name", libgdkpixbuf), Cstring, (Ptr{_GdkPixbufFormat},), instance)
ret2 = string_or_nothing(ret, true)
ret2
end
function is_disabled(instance::GdkPixbufFormat)
function is_disabled(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}})
ret = ccall(("gdk_pixbuf_format_is_disabled", libgdkpixbuf), Cint, (Ptr{_GdkPixbufFormat},), instance)
ret2 = convert(Bool, ret)
ret2
end
function is_save_option_supported(instance::GdkPixbufFormat, _option_key::Union{AbstractString, Symbol})
function is_save_option_supported(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}}, _option_key::Union{AbstractString, Symbol})
ret = ccall(("gdk_pixbuf_format_is_save_option_supported", libgdkpixbuf), Cint, (Ptr{_GdkPixbufFormat}, Cstring), instance, _option_key)
ret2 = convert(Bool, ret)
ret2
end
function is_scalable(instance::GdkPixbufFormat)
function is_scalable(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}})
ret = ccall(("gdk_pixbuf_format_is_scalable", libgdkpixbuf), Cint, (Ptr{_GdkPixbufFormat},), instance)
ret2 = convert(Bool, ret)
ret2
end
function is_writable(instance::GdkPixbufFormat)
function is_writable(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}})
ret = ccall(("gdk_pixbuf_format_is_writable", libgdkpixbuf), Cint, (Ptr{_GdkPixbufFormat},), instance)
ret2 = convert(Bool, ret)
ret2
end
function set_disabled(instance::GdkPixbufFormat, _disabled::Bool)
function set_disabled(instance::Union{GdkPixbufFormat, Ref{_GdkPixbufFormat}}, _disabled::Bool)
ret = ccall(("gdk_pixbuf_format_set_disabled", libgdkpixbuf), Nothing, (Ptr{_GdkPixbufFormat}, Cint), instance, _disabled)
nothing
end
Expand Down
5 changes: 5 additions & 0 deletions src/gen/gio_functions
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ $(Expr(:toplevel, quote
ret2 = string_or_nothing(ret, true)
ret2
end
function dbus_gvalue_to_gvariant(_gvalue::Union{GValue, Ref{_GValue}}, _type::GVariantType)
ret = ccall(("g_dbus_gvalue_to_gvariant", libgio), Ptr{GVariant}, (Ptr{_GValue}, Ptr{GVariantType}), _gvalue, _type)
ret2 = convert(GVariant, ret)
ret2
end
function dbus_is_address(_string::Union{AbstractString, Symbol})
ret = ccall(("g_dbus_is_address", libgio), Cint, (Cstring,), _string)
ret2 = convert(Bool, ret)
Expand Down
12 changes: 6 additions & 6 deletions src/gen/gio_methods
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ $(Expr(:toplevel, quote
ret2 = convert(Union{GFileAttributeInfoList, Ref{_GFileAttributeInfoList}}, ret, true)
ret2
end
function add(instance::GFileAttributeInfoList, _name::Union{AbstractString, Symbol}, _type, _flags)
function add(instance::Union{GFileAttributeInfoList, Ref{_GFileAttributeInfoList}}, _name::Union{AbstractString, Symbol}, _type, _flags)
ret = ccall(("g_file_attribute_info_list_add", libgio), Nothing, (Ptr{_GFileAttributeInfoList}, Cstring, UInt32, UInt32), instance, _name, _type, _flags)
nothing
end
function dup(instance::GFileAttributeInfoList)
function dup(instance::Union{GFileAttributeInfoList, Ref{_GFileAttributeInfoList}})
ret = ccall(("g_file_attribute_info_list_dup", libgio), Ptr{_GFileAttributeInfoList}, (Ptr{_GFileAttributeInfoList},), instance)
ret2 = convert(Union{GFileAttributeInfoList, Ref{_GFileAttributeInfoList}}, ret, true)
ret2
end
function lookup(instance::GFileAttributeInfoList, _name::Union{AbstractString, Symbol})
function lookup(instance::Union{GFileAttributeInfoList, Ref{_GFileAttributeInfoList}}, _name::Union{AbstractString, Symbol})
ret = ccall(("g_file_attribute_info_list_lookup", libgio), Ptr{_GFileAttributeInfo}, (Ptr{_GFileAttributeInfoList}, Cstring), instance, _name)
ret2 = convert(_GFileAttributeInfo, ret)
ret2 = convert(Union{GFileAttributeInfo, Ref{_GFileAttributeInfo}}, ret)
ret2
end
function ref(instance::GFileAttributeInfoList)
function ref(instance::Union{GFileAttributeInfoList, Ref{_GFileAttributeInfoList}})
ret = ccall(("g_file_attribute_info_list_ref", libgio), Ptr{_GFileAttributeInfoList}, (Ptr{_GFileAttributeInfoList},), instance)
ret2 = convert(Union{GFileAttributeInfoList, Ref{_GFileAttributeInfoList}}, ret, true)
ret2
end
function unref(instance::GFileAttributeInfoList)
function unref(instance::Union{GFileAttributeInfoList, Ref{_GFileAttributeInfoList}})
ret = ccall(("g_file_attribute_info_list_unref", libgio), Nothing, (Ptr{_GFileAttributeInfoList},), instance)
nothing
end
Expand Down
10 changes: 10 additions & 0 deletions src/gen/glib_functions
Original file line number Diff line number Diff line change
Expand Up @@ -2664,6 +2664,16 @@ $(Expr(:toplevel, quote
ret2 = convert(Bool, ret)
ret2
end
function variant_parse(_type::Maybe(GVariantType), _text::Union{AbstractString, Symbol}, _limit::Maybe(Union{AbstractString, Symbol}), _endptr::Maybe(Union{AbstractString, Symbol}))
_type_maybe = nothing_to_null(_type)
_limit_maybe = nothing_to_null(_limit)
_endptr_maybe = nothing_to_null(_endptr)
err = err_buf()
ret = ccall(("g_variant_parse", libglib), Ptr{GVariant}, (Ptr{GVariantType}, Cstring, Cstring, Cstring, Ptr{Ptr{GError}}), _type_maybe, _text, _limit_maybe, _endptr_maybe, err)
check_err(err)
ret2 = convert(GVariant, ret)
ret2
end
function variant_parse_error_print_context(_error, _source_str::Union{AbstractString, Symbol})
ret = ccall(("g_variant_parse_error_print_context", libglib), Cstring, (Ptr{GError}, Cstring), _error, _source_str)
ret2 = string_or_nothing(ret, true)
Expand Down
Loading

0 comments on commit 48f086d

Please sign in to comment.