From 427baea8bee17f5de93202d308649dcda122f1e0 Mon Sep 17 00:00:00 2001 From: Robert Straw Date: Mon, 30 Jun 2014 09:10:39 -0500 Subject: [PATCH 1/5] Update bare pointers to incl. their mutability. * `rust` master has replaced bare pointer (`*`) w/ `*mut` and `*const` --- src/zmq/lib.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/zmq/lib.rs b/src/zmq/lib.rs index 7b0b53491..ffae1ce4a 100644 --- a/src/zmq/lib.rs +++ b/src/zmq/lib.rs @@ -18,10 +18,10 @@ use std::{mem, ptr, str, slice}; use std::fmt; /// The ZMQ container that manages all the sockets -type Context_ = *c_void; +type Context_ = *const c_void; /// A ZMQ socket -type Socket_ = *c_void; +type Socket_ = *const c_void; static MsgSize_: uint = 48; @@ -30,26 +30,26 @@ type Msg_ = [c_char, ..MsgSize_]; #[link(name = "zmq")] extern { - fn zmq_version(major: *c_int, minor: *c_int, patch: *c_int); + fn zmq_version(major: *const c_int, minor: *const c_int, patch: *const c_int); fn zmq_ctx_new() -> Context_; fn zmq_ctx_destroy(ctx: Context_) -> c_int; fn zmq_errno() -> c_int; - fn zmq_strerror(errnum: c_int) -> *c_char; + fn zmq_strerror(errnum: c_int) -> *const c_char; 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; - fn zmq_bind(socket: Socket_, endpoint: *c_char) -> c_int; - fn zmq_connect(socket: Socket_, endpoint: *c_char) -> c_int; + fn zmq_bind(socket: Socket_, endpoint: *const c_char) -> c_int; + fn zmq_connect(socket: Socket_, endpoint: *const c_char) -> c_int; fn zmq_msg_init(msg: &Msg_) -> c_int; fn zmq_msg_init_size(msg: &Msg_, size: size_t) -> c_int; - fn zmq_msg_data(msg: &Msg_) -> *u8; + fn zmq_msg_data(msg: &Msg_) -> *const u8; fn zmq_msg_size(msg: &Msg_) -> size_t; fn zmq_msg_close(msg: &Msg_) -> c_int; @@ -727,7 +727,7 @@ macro_rules! setsockopt_num( unsafe { let size = mem::size_of::<$ty>() as size_t; - if -1 == zmq_setsockopt(sock, opt, (&value as *$ty) as *c_void, size) { + if -1 == zmq_setsockopt(sock, opt, (&value as *const $ty) as *mut c_void, size) { Err(errno_to_error()) } else { Ok(()) @@ -746,7 +746,7 @@ fn setsockopt_bytes(sock: Socket_, opt: c_int, value: &[u8]) -> Result<(), Error let r = zmq_setsockopt( sock, opt, - value.as_ptr() as *c_void, + value.as_ptr() as *mut c_void, value.len() as size_t ); From 2639093adcc488540c1b1e5c0f9b35e0a7dcb9dc Mon Sep 17 00:00:00 2001 From: Robert Straw Date: Mon, 30 Jun 2014 09:11:58 -0500 Subject: [PATCH 2/5] Integer literals no longer assume a width. This code is equivalent to the original, specifying the `int` type. This type is defined as being pointer-width. --- src/examples/zguide/helloworld-client/main.rs | 2 +- src/examples/zguide/weather-client/main.rs | 2 +- src/examples/zguide/weather-server/main.rs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/examples/zguide/helloworld-client/main.rs b/src/examples/zguide/helloworld-client/main.rs index 087a5a660..8e90a0f8b 100644 --- a/src/examples/zguide/helloworld-client/main.rs +++ b/src/examples/zguide/helloworld-client/main.rs @@ -14,7 +14,7 @@ fn main() { let mut msg = zmq::Message::new(); - for x in range(0, 10) { + for x in range(0i, 10i) { println!("Sending Hello {}", x); requester.send(b"Hello", 0).unwrap(); diff --git a/src/examples/zguide/weather-client/main.rs b/src/examples/zguide/weather-client/main.rs index 70bb7b2fd..0eca5e780 100644 --- a/src/examples/zguide/weather-client/main.rs +++ b/src/examples/zguide/weather-client/main.rs @@ -25,7 +25,7 @@ fn main() { let mut total_temp = 0; - for _ in range(0, 100) { + for _ in range(0i, 100i) { let string = subscriber.recv_str(0).unwrap(); let chks: Vec = string.as_slice().split(' ').map(|x| atoi(x)).collect(); let (_zipcode, temperature, _relhumidity) = (chks.get(0), chks.get(1), chks.get(2)); diff --git a/src/examples/zguide/weather-server/main.rs b/src/examples/zguide/weather-server/main.rs index 299278eaf..c1a9adae6 100644 --- a/src/examples/zguide/weather-server/main.rs +++ b/src/examples/zguide/weather-server/main.rs @@ -18,9 +18,9 @@ fn main() { let mut rng = std::rand::weak_rng(); loop { - let zipcode = rng.gen_range(0, 100000); - let temperature = rng.gen_range(-80, 135); - let relhumidity = rng.gen_range(10, 60); + let zipcode = rng.gen_range(0i, 100000i); + let temperature = rng.gen_range(-80i, 135i); + let relhumidity = rng.gen_range(10i, 60i); // this is slower than C because the current format! implementation is // very, very slow. Several orders of magnitude slower than glibc's From c5e2fe4005bdd19f6e892a8ebeb621e862fa2a2f Mon Sep 17 00:00:00 2001 From: Robert Straw Date: Mon, 30 Jun 2014 13:52:10 -0500 Subject: [PATCH 3/5] Enums expect `int` but the `posix88` constants are `c_int` (aka `i32`s) --- src/zmq/lib.rs | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/zmq/lib.rs b/src/zmq/lib.rs index ffae1ce4a..9411eb5b5 100644 --- a/src/zmq/lib.rs +++ b/src/zmq/lib.rs @@ -163,25 +163,25 @@ impl Constants { #[deriving(Clone, Eq, PartialEq)] pub enum Error { - EACCES = posix88::EACCES, - EADDRINUSE = posix88::EADDRINUSE, - EAGAIN = posix88::EAGAIN, - EBUSY = posix88::EBUSY, - ECONNREFUSED = posix88::ECONNREFUSED, - EFAULT = posix88::EFAULT, - EHOSTUNREACH = posix88::EHOSTUNREACH, - EINPROGRESS = posix88::EINPROGRESS, - EINVAL = posix88::EINVAL, - EMFILE = posix88::EMFILE, - EMSGSIZE = posix88::EMSGSIZE, - ENAMETOOLONG = posix88::ENAMETOOLONG, - ENODEV = posix88::ENODEV, - ENOENT = posix88::ENOENT, - ENOMEM = posix88::ENOMEM, - ENOTCONN = posix88::ENOTCONN, - ENOTSOCK = posix88::ENOTSOCK, - EPROTO = posix88::EPROTO, - EPROTONOSUPPORT = posix88::EPROTONOSUPPORT, + EACCES = posix88::EACCES as int, + EADDRINUSE = posix88::EADDRINUSE as int, + EAGAIN = posix88::EAGAIN as int, + EBUSY = posix88::EBUSY as int, + ECONNREFUSED = posix88::ECONNREFUSED as int, + EFAULT = posix88::EFAULT as int, + EHOSTUNREACH = posix88::EHOSTUNREACH as int, + EINPROGRESS = posix88::EINPROGRESS as int, + EINVAL = posix88::EINVAL as int, + EMFILE = posix88::EMFILE as int, + EMSGSIZE = posix88::EMSGSIZE as int, + ENAMETOOLONG = posix88::ENAMETOOLONG as int, + ENODEV = posix88::ENODEV as int, + ENOENT = posix88::ENOENT as int, + ENOMEM = posix88::ENOMEM as int, + ENOTCONN = posix88::ENOTCONN as int, + ENOTSOCK = posix88::ENOTSOCK as int, + EPROTO = posix88::EPROTO as int, + EPROTONOSUPPORT = posix88::EPROTONOSUPPORT as int, // magic number is EHAUSNUMERO + num ENOTSUP = 156384713, ENOBUFS = 156384715, From cb083b7cfbb5222184b89c79b206ea9c1aff2d2f Mon Sep 17 00:00:00 2001 From: Robert Straw Date: Mon, 30 Jun 2014 14:07:21 -0500 Subject: [PATCH 4/5] Allow `fn version()` to mutate version numbers in place. 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. --- src/zmq/lib.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/zmq/lib.rs b/src/zmq/lib.rs index 9411eb5b5..b5b164af4 100644 --- a/src/zmq/lib.rs +++ b/src/zmq/lib.rs @@ -18,10 +18,10 @@ use std::{mem, ptr, str, slice}; use std::fmt; /// The ZMQ container that manages all the sockets -type Context_ = *const c_void; +type Context_ = *mut c_void; /// A ZMQ socket -type Socket_ = *const c_void; +type Socket_ = *mut c_void; static MsgSize_: uint = 48; @@ -30,7 +30,7 @@ type Msg_ = [c_char, ..MsgSize_]; #[link(name = "zmq")] extern { - fn zmq_version(major: *const c_int, minor: *const c_int, patch: *const c_int); + fn zmq_version(major: *mut c_int, minor: *mut c_int, patch: *mut c_int); fn zmq_ctx_new() -> Context_; fn zmq_ctx_destroy(ctx: Context_) -> c_int; @@ -249,12 +249,12 @@ impl Error { // Return the current zeromq version. pub fn version() -> (int, int, int) { - let major = 0; - let minor = 0; - let patch = 0; + let mut major = 0; + let mut minor = 0; + let mut patch = 0; unsafe { - zmq_version(&major, &minor, &patch); + zmq_version(&mut major, &mut minor, &mut patch); } (major as int, minor as int, patch as int) From 3b1a653c1b2d5168e561ab29971a7bee6ec4fd01 Mon Sep 17 00:00:00 2001 From: Robert Straw Date: Mon, 30 Jun 2014 15:33:45 -0500 Subject: [PATCH 5/5] setsockopt value does not have to be mutable --- src/zmq/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/zmq/lib.rs b/src/zmq/lib.rs index b5b164af4..494bbed2c 100644 --- a/src/zmq/lib.rs +++ b/src/zmq/lib.rs @@ -42,7 +42,7 @@ extern { 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: *mut c_void, size: size_t) -> c_int; + fn zmq_setsockopt(socket: Socket_, opt: c_int, optval: *const c_void, size: size_t) -> c_int; fn zmq_bind(socket: Socket_, endpoint: *const c_char) -> c_int; fn zmq_connect(socket: Socket_, endpoint: *const c_char) -> c_int; @@ -727,7 +727,7 @@ macro_rules! setsockopt_num( unsafe { let size = mem::size_of::<$ty>() as size_t; - if -1 == zmq_setsockopt(sock, opt, (&value as *const $ty) as *mut c_void, size) { + if -1 == zmq_setsockopt(sock, opt, (&value as *const $ty) as *const c_void, size) { Err(errno_to_error()) } else { Ok(()) @@ -746,7 +746,7 @@ fn setsockopt_bytes(sock: Socket_, opt: c_int, value: &[u8]) -> Result<(), Error let r = zmq_setsockopt( sock, opt, - value.as_ptr() as *mut c_void, + value.as_ptr() as *const c_void, value.len() as size_t );