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

Add Value::from_type() to initialize an empty value from a Type #266

Merged
merged 3 commits into from Nov 28, 2017

Conversation

Projects
None yet
3 participants
@sdroege
Copy link
Member

sdroege commented Nov 28, 2017

This is only allowed for types that can be stored in GValues and
otherwise panics. The returned value contains the empty/default value of
the corresponding type.

As suggested by @EPashkin here: gtk-rs/gir#496 (comment)
This could be used by GIR for all the property getters to initialize the value

@GuillaumeGomez

This comment has been minimized.

Copy link
Member

GuillaumeGomez commented Nov 28, 2017

👍

@sdroege

This comment has been minimized.

Copy link
Member Author

sdroege commented Nov 28, 2017

We might also want to make Value::uninitialized() safe, I don't think there's anything unsafe about it or is there? The returned value is just empty and useless, but it can be filled with actual content by other code.

@sdroege

This comment has been minimized.

Copy link
Member Author

sdroege commented Nov 28, 2017

Also we might want to change Value::is() to consider subtyping (Type::is_a()) instead of just equality, like the G_VALUE_HOLDS(val, type) macro in C does.

@sdroege

This comment has been minimized.

Copy link
Member Author

sdroege commented Nov 28, 2017

Done that, but for making Value::uninitialized safe we have to do something about the Uninitialized trait. Is it used for anything at all other than Value?

Which reminded me that the InstanceType trait is completely unused currently and can be removed, done

@@ -627,9 +627,8 @@ impl<T: IsA<Object> + SetValue> ObjectExt for T {
};

unsafe {
let mut value = Value::uninitialized();
let mut value = Value::from_type(property_type);

This comment has been minimized.

@EPashkin

EPashkin Nov 28, 2017

Member

Empty line

@EPashkin

This comment has been minimized.

Copy link
Member

EPashkin commented Nov 28, 2017

IMHO Value::uninitialized() better be unsafe, as value must not used until it initialized

@EPashkin

This comment has been minimized.

Copy link
Member

EPashkin commented Nov 28, 2017

@sdroege Thanks

sdroege added some commits Nov 28, 2017

Add Value::from_type() to initialize an empty value from a Type
This is only allowed for types that can be stored in GValues and
otherwise panics. The returned value contains the empty/default value of
the corresponding type.

@sdroege sdroege force-pushed the sdroege:value-init branch from abd45fd to be2dec4 Nov 28, 2017

@sdroege

This comment has been minimized.

Copy link
Member Author

sdroege commented Nov 28, 2017

Removed the empty line, mergeable now I guess? Then gir can be updated

@GuillaumeGomez

This comment has been minimized.

Copy link
Member

GuillaumeGomez commented Nov 28, 2017

Yep, just waiting for CIs.

@GuillaumeGomez

This comment has been minimized.

Copy link
Member

GuillaumeGomez commented Nov 28, 2017

Thanks!

@GuillaumeGomez GuillaumeGomez merged commit d9961b3 into gtk-rs:master Nov 28, 2017

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
You can’t perform that action at this time.