Skip to content

Commit

Permalink
type stability fixes, hopfully fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jwahlstrand committed Aug 26, 2023
1 parent ebbc846 commit b01276a
Show file tree
Hide file tree
Showing 13 changed files with 252 additions and 115 deletions.
6 changes: 3 additions & 3 deletions GI/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ In function definitions, it uses [annotations](https://gi.readthedocs.io/en/late
should be freed, whether pointer arguments can be optionally NULL, whether list
outputs are NULL-terminated, which argument corresponds to the length of array
inputs, which arguments are outputs and which are inputs, and more.
The primary advantage over writing `ccall`'s (as is done in Gtk.jl) is that it can rapidly cover an entire library, saving a lot of tedious work.
The primary advantage over manually writing `ccall`'s (as is done in Gtk.jl) is that it can rapidly cover an entire library, saving a lot of tedious work.
As new functionality is added to libraries, you just have to run GI.jl again and new code is generated.
Disadvantages include: the current implementation only extracts GI information on Linux, leading to potential bugs on other platforms, and annotations are inaccurate in some libraries.

This package is currently unregistered, and it only works on Linux because it uses gobject_introspection_jll, which is currently only available for Linux. However, most generated code works on other platforms.
This package is currently unregistered, and it only works on Linux because it uses [gobject_introspection_jll](https://github.com/JuliaPackaging/Yggdrasil/tree/master/G/gobject_introspection), which is currently only available for Linux. However, most generated code works on other platforms.

## Status

Expand Down Expand Up @@ -81,4 +81,4 @@ inputs can optionally be NULL, the Julia methods accept nothing as the argument.
When outputs are NULL, the Julia methods output nothing.

Object and struct methods are typically exported in a file "lib_methods" in a "src/gen" directory and packages typically include them in a "G_" submodule.
Functions not associated with objects or structs are typically exported in a file "lib_functions".
Functions not associated with objects or structs are typically exported in a file "lib_functions".
2 changes: 1 addition & 1 deletion GI/src/giimport.jl
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ function convert_from_c(name::Symbol, arginfo::ArgInfo, typeinfo::TypeDesc{T}, i
object = get_container(arginfo)
if may_be_null(arginfo)
:(convert_if_not_null($(typeinfo.jtype), $name, $owns))
elseif isconstructor && !get_abstract(object) && !owns
elseif isconstructor && !get_abstract(object)
# For a constructor, we know this is a never-before-seen object, so use the known concrete type to allow type inference
# Many of these have an abstract type as the return type in GI, but we need the
# concrete one. Since this is a constructor we can look up the name.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ Most of the code for GLib support (`GType`, `GValue`, `GObject`, etc.) was copie
Documentation for the master branch version of this package can be found [here](https://juliagtk.github.io/Gtk4.jl/dev/). Complete GTK documentation is available at [https://www.gtk.org/docs](https://www.gtk.org/docs).

## Current status
Based on limited data, Gtk4.jl works about as well as Gtk.jl. Notably, it does not cause REPL lag on Windows the way that Gtk.jl does.

For auto-generated code, Gtk4.jl relies on GObject introspection data generated on a Linux x86_64 machine, which may result in code that crashes on 32 bit computers. This seems to affect mostly obscure parts of GLib that are unlikely to be useful to Julia users, but 32 bit users should be aware of this.

Note that this package uses binaries for the GTK library and its dependencies that are built and packaged using [BinaryBuilder.jl](https://github.com/JuliaPackaging/BinaryBuilder.jl). On Linux it does **not** use the binaries that are packaged with your distribution. The build scripts for these binaries, including the library versions currently being used, can be found by perusing [Yggdrasil.jl](https://github.com/JuliaPackaging/Yggdrasil.jl).

## Enabling GTK4's EGL backend (Linux)
On Wayland, a Cairo-based fallback backend will be used unless you tell `libglvnd_jll` where to find libEGL. This can be done by setting the environment variable __EGL_VENDOR_LIBRARY_DIRS. See [here](https://gitlab.freedesktop.org/glvnd/libglvnd/-/blob/master/src/EGL/icd_enumeration.md) for details.

Expand All @@ -28,4 +28,4 @@ using Gtk4
Gtk4.set_EGL_vendorlib_dirs("/usr/share/glvnd/egl_vendor.d")
[ Info: Setting will take effect after restarting Julia.
```
where "/usr/share/glvnd/egl_vendor.d" is a typical location for Mesa's libEGL (this should be modified if it's somewhere else on your distribution). Other vendor-provided libraries may be in other locations, and a colon-separated list of directories can be used for that situation. **Note that this has only been tested for the Mesa-provided libEGL on Fedora and Ubuntu.**
where "/usr/share/glvnd/egl_vendor.d" is a typical location for Mesa's libEGL (this should be modified if it's somewhere else on your distribution). Other vendor-provided libraries may be in other locations, and a colon-separated list of directories can be used for that situation. **Note that this has only been tested for the Mesa-provided libEGL on Fedora and Ubuntu.**
1 change: 1 addition & 0 deletions examples/listbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ end

sw[] = listBox
listBox.vexpand = true

2 changes: 1 addition & 1 deletion gen/gen_gsk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ GI.append_struc_docs!(exprs, "gsk4", d, c, ns)

## objects

c = GI.all_objects!(exprs,exports,ns,,output_cache_define=false,output_cache_init=false)
c = GI.all_objects!(exprs,exports,ns,output_cache_define=false,output_cache_init=false)
GI.append_object_docs!(exprs, "gsk4", d, c, ns)
GI.all_interfaces!(exprs,exports,ns)

Expand Down
10 changes: 5 additions & 5 deletions src/gen/gdk4_methods
Original file line number Diff line number Diff line change
Expand Up @@ -502,19 +502,19 @@ $(Expr(:toplevel, quote
end
function ContentProvider_new_for_bytes(_mime_type::Union{AbstractString, Symbol}, _bytes::GBytes)
ret = ccall(("gdk_content_provider_new_for_bytes", libgtk4), Ptr{GObject}, (Cstring, Ptr{GBytes}), _mime_type, _bytes)
ret2 = convert(GdkContentProvider, ret, true)
ret2 = GdkContentProviderLeaf(ret, true)
ret2
end
function ContentProvider_new_for_value(_value::Union{GValue, Ref{_GValue}})
ret = ccall(("gdk_content_provider_new_for_value", libgtk4), Ptr{GObject}, (Ptr{_GValue},), _value)
ret2 = convert(GdkContentProvider, ret, true)
ret2 = GdkContentProviderLeaf(ret, true)
ret2
end
function ContentProvider_new_union(_providers)
_providers_arr = convert(Vector{Ptr{GObject}}, _providers)
_n_providers = length(_providers)
ret = ccall(("gdk_content_provider_new_union", libgtk4), Ptr{GObject}, (Ptr{Ptr{GObject}}, UInt64), _providers_arr, _n_providers)
ret2 = convert(GdkContentProvider, ret, true)
ret2 = GdkContentProviderLeaf(ret, true)
ret2
end
function content_changed(instance::GdkContentProvider)
Expand Down Expand Up @@ -629,7 +629,7 @@ $(Expr(:toplevel, quote
function Cursor_new_from_texture(_texture::GdkTexture, _hotspot_x::Integer, _hotspot_y::Integer, _fallback::Maybe(GdkCursor))
_fallback_maybe = nothing_to_null(_fallback)
ret = ccall(("gdk_cursor_new_from_texture", libgtk4), Ptr{GObject}, (Ptr{GObject}, Int32, Int32, Ptr{GObject}), _texture, _hotspot_x, _hotspot_y, _fallback_maybe)
ret2 = convert(GdkCursor, ret, true)
ret2 = GdkCursorLeaf(ret, true)
ret2
end
function get_fallback(instance::GdkCursor)
Expand Down Expand Up @@ -1449,7 +1449,7 @@ $(Expr(:toplevel, quote
end
function MemoryTexture_new(_width::Integer, _height::Integer, _format, _bytes::GBytes, _stride::Integer)
ret = ccall(("gdk_memory_texture_new", libgtk4), Ptr{GObject}, (Int32, Int32, UInt32, Ptr{GBytes}, UInt64), _width, _height, _format, _bytes, _stride)
ret2 = convert(GdkMemoryTexture, ret, true)
ret2 = GdkMemoryTextureLeaf(ret, true)
ret2
end
function get_connector(instance::GdkMonitor)
Expand Down
16 changes: 8 additions & 8 deletions src/gen/gdkpixbuf_methods
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ $(Expr(:toplevel, quote
end
function Pixbuf_new_from_bytes(_data::GBytes, _colorspace, _has_alpha::Bool, _bits_per_sample::Integer, _width::Integer, _height::Integer, _rowstride::Integer)
ret = ccall(("gdk_pixbuf_new_from_bytes", libgdkpixbuf), Ptr{GObject}, (Ptr{GBytes}, UInt32, Cint, Int32, Int32, Int32, Int32), _data, _colorspace, _has_alpha, _bits_per_sample, _width, _height, _rowstride)
ret2 = convert(GdkPixbuf, ret, true)
ret2 = GdkPixbufLeaf(ret, true)
ret2
end
function Pixbuf_new_from_data(_data, _colorspace, _has_alpha::Bool, _bits_per_sample::Integer, _width::Integer, _height::Integer, _rowstride::Integer, _destroy_fn::Maybe(Function))
Expand All @@ -88,7 +88,7 @@ $(Expr(:toplevel, quote
_destroy_fn_closure = GLib.gc_ref(_destroy_fn)
end
ret = ccall(("gdk_pixbuf_new_from_data", libgdkpixbuf), Ptr{GObject}, (Ptr{UInt8}, UInt32, Cint, Int32, Int32, Int32, Int32, Ptr{Cvoid}, Ptr{Nothing}), _data_arr, _colorspace, _has_alpha, _bits_per_sample, _width, _height, _rowstride, _destroy_fn_cfunc, _destroy_fn_closure)
ret2 = convert(GdkPixbuf, ret, true)
ret2 = GdkPixbufLeaf(ret, true)
ret2
end
function Pixbuf_new_from_file(_filename::Union{AbstractString, Symbol})
Expand Down Expand Up @@ -151,7 +151,7 @@ $(Expr(:toplevel, quote
end
function Pixbuf_new_from_xpm_data(_data)
ret = ccall(("gdk_pixbuf_new_from_xpm_data", libgdkpixbuf), Ptr{GObject}, (Ptr{Cstring},), _data)
ret2 = convert(GdkPixbuf, ret, true)
ret2 = GdkPixbufLeaf(ret, true)
ret2
end
function calculate_rowstride(_colorspace, _has_alpha::Bool, _bits_per_sample::Integer, _width::Integer, _height::Integer)
Expand Down Expand Up @@ -479,21 +479,21 @@ $(Expr(:toplevel, quote
end
function PixbufLoader_new()
ret = ccall(("gdk_pixbuf_loader_new", libgdkpixbuf), Ptr{GObject}, ())
ret2 = convert(GdkPixbufLoader, ret, true)
ret2 = GdkPixbufLoaderLeaf(ret, true)
ret2
end
function PixbufLoader_new_with_mime_type(_mime_type::Union{AbstractString, Symbol})
err = err_buf()
ret = ccall(("gdk_pixbuf_loader_new_with_mime_type", libgdkpixbuf), Ptr{GObject}, (Cstring, Ptr{Ptr{GError}}), _mime_type, err)
check_err(err)
ret2 = convert(GdkPixbufLoader, ret, true)
ret2 = GdkPixbufLoaderLeaf(ret, true)
ret2
end
function PixbufLoader_new_with_type(_image_type::Union{AbstractString, Symbol})
err = err_buf()
ret = ccall(("gdk_pixbuf_loader_new_with_type", libgdkpixbuf), Ptr{GObject}, (Cstring, Ptr{Ptr{GError}}), _image_type, err)
check_err(err)
ret2 = convert(GdkPixbufLoader, ret, true)
ret2 = GdkPixbufLoaderLeaf(ret, true)
ret2
end
function close(instance::GdkPixbufLoader)
Expand Down Expand Up @@ -540,12 +540,12 @@ $(Expr(:toplevel, quote
end
function PixbufNonAnim_new(_pixbuf::GdkPixbuf)
ret = ccall(("gdk_pixbuf_non_anim_new", libgdkpixbuf), Ptr{GObject}, (Ptr{GObject},), _pixbuf)
ret2 = convert(GdkPixbufAnimation, ret, true)
ret2 = GdkPixbufNonAnimLeaf(ret, true)
ret2
end
function PixbufSimpleAnim_new(_width::Integer, _height::Integer, _rate::Real)
ret = ccall(("gdk_pixbuf_simple_anim_new", libgdkpixbuf), Ptr{GObject}, (Int32, Int32, Float32), _width, _height, _rate)
ret2 = convert(GdkPixbufSimpleAnim, ret, true)
ret2 = GdkPixbufSimpleAnimLeaf(ret, true)
ret2
end
function add_frame(instance::GdkPixbufSimpleAnim, _pixbuf::GdkPixbuf)
Expand Down
Loading

0 comments on commit b01276a

Please sign in to comment.