Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

record: Differentiate disguised vs pointer types #1530

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

ocrete
Copy link
Contributor

@ocrete ocrete commented Dec 13, 2023

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)

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.
@sdroege sdroege merged commit 20a5b17 into gtk-rs:master Dec 14, 2023
7 checks passed
@MarijnS95
Copy link
Contributor

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

@bilelmoussaoui
Copy link
Member

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
Copy link
Contributor Author

ocrete commented Jan 2, 2024

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
Copy link
Member

sdroege commented Jan 3, 2024

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

bilelmoussaoui added a commit to gtk-rs/gtk4-rs that referenced this pull request Jan 3, 2024
bilelmoussaoui added a commit to gtk-rs/gtk4-rs that referenced this pull request Jan 20, 2024
bilelmoussaoui added a commit to gtk-rs/gtk4-rs that referenced this pull request Jan 20, 2024
bilelmoussaoui added a commit to gtk-rs/gtk4-rs that referenced this pull request Jan 20, 2024
bilelmoussaoui added a commit to gtk-rs/gtk4-rs that referenced this pull request Jan 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants