gtk-rs / gir

Tool to generate rust bindings and user API for glib-based libraries
https://gtk-rs.org/gir/book/
MIT License
225 stars 99 forks source link

record: Differentiate disguised vs pointer types #1530

Closed ocrete closed 7 months ago

ocrete commented 7 months ago

Disguised types are not pointers, they're just typedefs to a private struct, while pointer types are typedef to a pointer to a private struct. Generate the right code for each.

In C, there are 2 types of "disguised" typdefs: typedef struct _Blob *Blob and typedef struct _Blob Blob

In Gir files, they're both called "disguised", but the first kind also has the "pointer" property set. The current generator only knows about the pointer type.

Currently, it generates pub type Blob = *mut _Blob;

But , it should do pub type Blob = _Blob for the non-pointer type.

The effect of this bug is that the rest of the code gen will think that the type is a pointer to a pointer.

So it will generate functions with a signature of fn func(*mut *mut blob) instead of fn func(*mut blob)

MarijnS95 commented 7 months ago

Thinking out loud, I'm curious if this would help out with mapping Vulkan types in gir.

bilelmoussaoui commented 6 months ago

Was this actually tested? it makes the gtk4-rs build fail with the following

error[E0277]: the trait bound `_GtkConstraintTargetInterface: std::marker::Copy` is not satisfied
   --> gtk4/src/subclass/constraint_target.rs:11:38
    |
11  | unsafe impl<T: ConstraintTargetImpl> IsImplementable<T> for ConstraintTarget {
    |                                      ^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `_GtkConstraintTargetInterface`
    |
note: required by a bound in `glib::subclass::types::IsImplementable`
   --> /home/bilalelmoussaoui/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/38f4ba1/glib/src/subclass/types.rs:287:42
    |
285 | pub unsafe trait IsImplementable<T: ObjectSubclass>: IsInterface
    |                  --------------- required by a bound in this trait
286 | where
287 |     <Self as ObjectType>::GlibClassType: Copy,
    |                                          ^^^^ required by this bound in `IsImplementable`

error[E0277]: the trait bound `_GtkNativeInterface: std::marker::Copy` is not satisfied
   --> gtk4/src/subclass/native.rs:10:28
    |
10  | unsafe impl<T: NativeImpl> IsImplementable<T> for Native {}
    |                            ^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `_GtkNativeInterface`
    |
note: required by a bound in `glib::subclass::types::IsImplementable`
   --> /home/bilalelmoussaoui/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/38f4ba1/glib/src/subclass/types.rs:287:42
    |
285 | pub unsafe trait IsImplementable<T: ObjectSubclass>: IsInterface
    |                  --------------- required by a bound in this trait
286 | where
287 |     <Self as ObjectType>::GlibClassType: Copy,
    |                                          ^^^^ required by this bound in `IsImplementable`

error[E0277]: the trait bound `_GtkRootInterface: std::marker::Copy` is not satisfied
   --> gtk4/src/subclass/root.rs:10:26
    |
10  | unsafe impl<T: RootImpl> IsImplementable<T> for Root {}
    |                          ^^^^^^^^^^^^^^^^^^ the trait `std::marker::Copy` is not implemented for `_GtkRootInterface`
    |
note: required by a bound in `glib::subclass::types::IsImplementable`
   --> /home/bilalelmoussaoui/.cargo/git/checkouts/gtk-rs-core-7be42ca38bd6361c/38f4ba1/glib/src/subclass/types.rs:287:42
    |
285 | pub unsafe trait IsImplementable<T: ObjectSubclass>: IsInterface
    |                  --------------- required by a bound in this trait
286 | where
287 |     <Self as ObjectType>::GlibClassType: Copy,
    |                                          ^^^^ required by this bound in `IsImplementable`
ocrete commented 6 months ago

I think the bindings were incorrect, in all of those cases, the interface struct is defined in private C headers, so I don't think they can be implemented outside of GTK+ itself,.

sdroege commented 6 months ago

Yes, the failures look correct. These are all interfaces that can't be implemented outside of GTK itself.