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

Add downcast_ref() and similar functions for all the casting machinery #356

Merged
merged 4 commits into from Jul 11, 2018

Conversation

Projects
None yet
3 participants
@sdroege
Member

sdroege commented Jul 11, 2018

See individual commits.

@sdroege

This comment has been minimized.

Show comment
Hide comment
@sdroege

sdroege Jul 11, 2018

Member

The object ones are preventing the obj.clone().downcast::<Foo>() calls I have in various places

Member

sdroege commented Jul 11, 2018

The object ones are preventing the obj.clone().downcast::<Foo>() calls I have in various places

where T: StaticType + UnsafeFrom<ObjectRef> + Wrapper,
Self: IsA<T> {
unsafe {
mem::transmute(self)

This comment has been minimized.

@sdroege

sdroege Jul 11, 2018

Member

The object casts are safe because all the types have the same memory representation apart from their name and the phantom data type, and IsA is an unsafe trait so must only be implemented if it's actually a proper GObject wrapper type

@sdroege

sdroege Jul 11, 2018

Member

The object casts are safe because all the types have the same memory representation apart from their name and the phantom data type, and IsA is an unsafe trait so must only be implemented if it's actually a proper GObject wrapper type

gobject_ffi::g_type_check_value_holds(mut_override(self.to_glib_none().0),
T::static_type().to_glib()));
if ok {
Some(mem::transmute(self))

This comment has been minimized.

@sdroege

sdroege Jul 11, 2018

Member

The value transmutes are safe because the only difference between Value and TypedValue is the zero-sized phantom data.

@sdroege

sdroege Jul 11, 2018

Member

The value transmutes are safe because the only difference between Value and TypedValue is the zero-sized phantom data.

This comment has been minimized.

@EPashkin

EPashkin Jul 11, 2018

Member

This comment not better be in code? ;)

@EPashkin

EPashkin Jul 11, 2018

Member

This comment not better be in code? ;)

@EPashkin

This comment has been minimized.

Show comment
Hide comment
@EPashkin

EPashkin Jul 11, 2018

Member

@sdroege Looks good

Member

EPashkin commented Jul 11, 2018

@sdroege Looks good

@GuillaumeGomez

This comment has been minimized.

Show comment
Hide comment
@GuillaumeGomez

GuillaumeGomez Jul 11, 2018

Member

I clearly don't know enough this part of GLib and the code looks good to me so I'll trust you and @EPashkin's opinion on this one. Thanks!

Member

GuillaumeGomez commented Jul 11, 2018

I clearly don't know enough this part of GLib and the code looks good to me so I'll trust you and @EPashkin's opinion on this one. Thanks!

@GuillaumeGomez GuillaumeGomez merged commit c5b00ed into gtk-rs:master Jul 11, 2018

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment