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

Lock objc to 0.1.7. Fix remaining libc pointer errors with casts. Fix warnings in cursor example. #655

Merged
merged 2 commits into from
Nov 9, 2015

Conversation

mitchmindtree
Copy link
Contributor

This fixes #654

@mitchmindtree
Copy link
Contributor Author

Build was successful on nightly osx, stable linux and two of the windows builds. Each of the others seem to have either timed out due to cargo hanging on an update or crashed in some unrelated process 🎉

@mitchmindtree
Copy link
Contributor Author

Ahhhh, despite this change working for glutin, users will likely still run into problems downstream as the cocoa crate also depends on objc, in turn creating an objc version conflict. For example, when I try to build conrod (with the local working glutin version) I get:

failed to select a version for `objc` (required by `glutin`):
all possible versions conflict with previously selected versions of `objc`
  version 0.1.8 in use by objc v0.1.8
  possible versions to select: 0.1.7, 0.1.6, 0.1.5, 0.1.4, 0.1.3, 0.1.2, 0.1.1, 0.1.0

Which doesn't seem to get fixed no matter how many times I cargo update or cargo clean.

😕

@SSheldon
Copy link
Contributor

SSheldon commented Nov 8, 2015

@mitchmindtree, sorry again that the objc update has contributed to this mess :/

It's not the most elegant, but one way to sidestep this issue would be to replace all uses of *mut libc::c_void with usize, like:

diff --git a/src/api/cocoa/mod.rs b/src/api/cocoa/mod.rs
index 2b4b5e5..1e5000b 100644
--- a/src/api/cocoa/mod.rs
+++ b/src/api/cocoa/mod.rs
@@ -81,7 +81,7 @@ impl WindowDelegate {

         extern fn window_should_close(this: &Object, _: Sel, _: id) -> BOOL {
             unsafe {
-                let state: *mut libc::c_void = *this.get_ivar("glutinState");
+                let state: usize = *this.get_ivar("glutinState");
                 let state = state as *mut DelegateState;
                 (*state).pending_events.lock().unwrap().push_back(Closed);
             }
@@ -90,7 +90,7 @@ impl WindowDelegate {

         extern fn window_did_resize(this: &Object, _: Sel, _: id) {
             unsafe {
-                let state: *mut libc::c_void = *this.get_ivar("glutinState");
+                let state: usize = *this.get_ivar("glutinState");
                 let state = &mut *(state as *mut DelegateState);

                 let _: () = msg_send![*state.context, update];
@@ -109,7 +109,7 @@ impl WindowDelegate {
                 // TODO: center the cursor if the window had mouse grab when it
                 // lost focus

-                let state: *mut libc::c_void = *this.get_ivar("glutinState");
+                let state: usize = *this.get_ivar("glutinState");
                 let state = state as *mut DelegateState;
                 (*state).pending_events.lock().unwrap().push_back(Focused(true));
             }
@@ -117,7 +117,7 @@ impl WindowDelegate {

         extern fn window_did_resign_key(this: &Object, _: Sel, _: id) {
             unsafe {
-                let state: *mut libc::c_void = *this.get_ivar("glutinState");
+                let state: usize = *this.get_ivar("glutinState");
                 let state = state as *mut DelegateState;
                 (*state).pending_events.lock().unwrap().push_back(Focused(false));
             }
@@ -143,7 +143,7 @@ impl WindowDelegate {
                 window_did_resign_key as extern fn(&Object, Sel, id));

             // Store internal state as user data
-            decl.add_ivar::<*mut libc::c_void>("glutinState");
+            decl.add_ivar::<usize>("glutinState");

             delegate_class = decl.register();
         });
@@ -160,7 +160,7 @@ impl WindowDelegate {
         unsafe {
             let delegate = IdRef::new(msg_send![WindowDelegate::class(), new]);

-            (&mut **delegate).set_ivar("glutinState", state_ptr as *mut libc::c_void);
+            (&mut **delegate).set_ivar("glutinState", state_ptr as usize);
             let _: () = msg_send![*state.window, setDelegate:*delegate];

             WindowDelegate { state: state, _this: delegate }

That way a mismatch between the libc versions in glutin and objc doesn't cause any errors.

@tomaka
Copy link
Contributor

tomaka commented Nov 8, 2015

Or just use *mut () instead of usize.

Rust allows writing as *mut _

EDIT: I just realized that glutin could be fixed right now by using as *mut _

@SSheldon
Copy link
Contributor

SSheldon commented Nov 8, 2015

I'm not sure *mut () will work, it needs to be a type for which an Objective-C type encoding is known.

*mut _ also doesn't seem to work, since then the type is unconstrained; these methods can take any type, not just *mut c_void.

@mitchmindtree
Copy link
Contributor Author

@SSheldon all good! It can be easy to overlook breakages sometimes especially when it's just in a version increment heh.

I tried building this again locally, however a wild #656 appeared. I don't have a windows system available to me atm so I'm unable to address this.

I did however try just updating kernel32-sys to 0.2 to appease the issue locally, however I was unable to see if this fixed anything as I'm now stuck behind rust-lang/cargo#2090, as is travis it seems. 😕

@tomaka
Copy link
Contributor

tomaka commented Nov 9, 2015

Ok, let's merge this.

tomaka added a commit that referenced this pull request Nov 9, 2015
Lock objc to 0.1.7. Fix remaining libc pointer errors with casts. Fix warnings in cursor example.
@tomaka tomaka merged commit 439d251 into rust-windowing:master Nov 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Compilation error on OS X 10.11.1 with rust 1.4
3 participants