Skip to content

Update for rust-master: specify mutability of bare pointers, and width of integer literals. #38

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

Merged
merged 5 commits into from
Jul 1, 2014

Conversation

drbawb
Copy link
Contributor

@drbawb drbawb commented Jun 30, 2014

This fixes two breaking changes from the rust nightlies.

These changes allow me to continue building rust-zmq on the following version of rustc:
rustc 0.11.0-pre (b569c77148e8e839b38b678c7c167efc643d2721 2014-06-29 11:21:39 +0000)
c5e2fe4 tested on rustc 0.11.0-pre (566b57f3de7de80599b052b1a042eef8c9091e7f 2014-06-30 12:16:30 +0000)

drbawb added 3 commits June 30, 2014 09:10
* `rust` master has replaced bare pointer (`*`) w/ `*mut` and `*const`
This code is equivalent to the original, specifying the `int` type.
This type is defined as being pointer-width.
@erickt
Copy link
Owner

erickt commented Jun 30, 2014

Thanks for this! I think you've gotten the pointer conversions incorrect though. According to @alexcrichton, C T* pointers should be converted into Rust *mut T, and const T* to *const T. So can you change:

fn zmq_version(major: *mut c_int, minor: *mut c_int, patch: *mut c_int);
type Context_ = *mut c_void;
type Socket_ = *mut c_void;
...

@drbawb
Copy link
Contributor Author

drbawb commented Jun 30, 2014

Doing that will have rustc complain about the call at lib.rs:257

Inside pub fn version() we're passing immutable references to zmq_version() in the unsafe block at 257.

So we would also have to change the let major; let minor; let patch; to be mutable, and then pass mutable references.

Is that OK?

The `rust` allocated memory for the version no. needs to be modified by FFI.

In light of recent changes: we mark the variables as mutable, and make sure
the FFI accepts mutable raw pointers.
@erickt
Copy link
Owner

erickt commented Jun 30, 2014

Oh geeze, that was bad of me. You're fix is the right thing to do.


fn zmq_socket(ctx: Context_, typ: c_int) -> Socket_;
fn zmq_close(socket: Socket_) -> c_int;

fn zmq_getsockopt(socket: Socket_, opt: c_int, optval: *mut c_void, size: *mut size_t) -> c_int;
fn zmq_setsockopt(socket: Socket_, opt: c_int, optval: *c_void, size: size_t) -> c_int;
fn zmq_setsockopt(socket: Socket_, opt: c_int, optval: *mut c_void, size: size_t) -> c_int;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optval should have a type *const c_void.

@erickt
Copy link
Owner

erickt commented Jun 30, 2014

other than that fix and cleaning up the later calls to zmq_setsockopt, it looks great. Once you fix it, i'll merge it in. thanks!

@bombela bombela mentioned this pull request Jul 1, 2014
erickt added a commit that referenced this pull request Jul 1, 2014
Update for rust-master: specify mutability of bare pointers, and width of integer literals.
@erickt erickt merged commit 82091be into erickt:master Jul 1, 2014
@erickt
Copy link
Owner

erickt commented Jul 1, 2014

Thanks!

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.

2 participants