mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Machine types are different from int/uint, etc (Issue #2187)
This commit is contained in:
parent
5f904d278f
commit
1e8f501343
@ -25,6 +25,7 @@ io::println(comm::recv(p));
|
||||
"];
|
||||
|
||||
import either::either;
|
||||
import libc::size_t;
|
||||
|
||||
export port::{};
|
||||
export chan::{};
|
||||
@ -66,7 +67,7 @@ enum chan<T: send> {
|
||||
|
||||
#[doc = "Constructs a port"]
|
||||
fn port<T: send>() -> port<T> {
|
||||
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>())))
|
||||
port_t(@port_ptr(rustrt::new_port(sys::size_of::<T>() as size_t)))
|
||||
}
|
||||
|
||||
impl methods<T: send> for port<T> {
|
||||
@ -109,7 +110,7 @@ resource port_ptr<T: send>(po: *rust_port) unsafe {
|
||||
rustrt::rust_port_end_detach(po);
|
||||
|
||||
// Drain the port so that all the still-enqueued items get dropped
|
||||
while rustrt::rust_port_size(po) > 0u {
|
||||
while rustrt::rust_port_size(po) > 0u as size_t {
|
||||
recv_::<T>(po);
|
||||
}
|
||||
rustrt::del_port(po);
|
||||
|
@ -76,6 +76,10 @@ pure fn ge(x: f64, y: f64) -> bool { ret x >= y; }
|
||||
|
||||
pure fn gt(x: f64, y: f64) -> bool { ret x > y; }
|
||||
|
||||
pure fn sqrt(x: f64) -> f64 {
|
||||
cmath::c_double::sqrt(x as libc::c_double) as f64
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
Returns true if `x` is a positive number, including +0.0f640 and +Infinity.
|
||||
"]
|
||||
|
@ -27,6 +27,57 @@ export j0, j1, jn, y0, y1, yn;
|
||||
import m_float = f64;
|
||||
import f64::*;
|
||||
|
||||
const NaN: float = 0.0/0.0;
|
||||
|
||||
const infinity: float = 1.0/0.0;
|
||||
|
||||
const neg_infinity: float = -1.0/0.0;
|
||||
|
||||
/* Module: consts */
|
||||
mod consts {
|
||||
|
||||
// FIXME replace with mathematical constants from cmath
|
||||
// (requires Issue #1433 to fix)
|
||||
#[doc = "Archimedes' constant"]
|
||||
const pi: float = 3.14159265358979323846264338327950288;
|
||||
|
||||
#[doc = "pi/2.0"]
|
||||
const frac_pi_2: float = 1.57079632679489661923132169163975144;
|
||||
|
||||
#[doc = "pi/4.0"]
|
||||
const frac_pi_4: float = 0.785398163397448309615660845819875721;
|
||||
|
||||
#[doc = "1.0/pi"]
|
||||
const frac_1_pi: float = 0.318309886183790671537767526745028724;
|
||||
|
||||
#[doc = "2.0/pi"]
|
||||
const frac_2_pi: float = 0.636619772367581343075535053490057448;
|
||||
|
||||
#[doc = "2.0/sqrt(pi)"]
|
||||
const frac_2_sqrtpi: float = 1.12837916709551257389615890312154517;
|
||||
|
||||
#[doc = "sqrt(2.0)"]
|
||||
const sqrt2: float = 1.41421356237309504880168872420969808;
|
||||
|
||||
#[doc = "1.0/sqrt(2.0)"]
|
||||
const frac_1_sqrt2: float = 0.707106781186547524400844362104849039;
|
||||
|
||||
#[doc = "Euler's number"]
|
||||
const e: float = 2.71828182845904523536028747135266250;
|
||||
|
||||
#[doc = "log2(e)"]
|
||||
const log2_e: float = 1.44269504088896340735992468100189214;
|
||||
|
||||
#[doc = "log10(e)"]
|
||||
const log10_e: float = 0.434294481903251827651128918916605082;
|
||||
|
||||
#[doc = "ln(2.0)"]
|
||||
const ln_2: float = 0.693147180559945309417232121458176568;
|
||||
|
||||
#[doc = "ln(10.0)"]
|
||||
const ln_10: float = 2.30258509299404568401799145468436421;
|
||||
}
|
||||
|
||||
/**
|
||||
* Section: String Conversions
|
||||
*/
|
||||
@ -178,11 +229,11 @@ where `n` is the floating-point number represented by `[num]`.
|
||||
"]
|
||||
fn from_str(num: str) -> option<float> {
|
||||
if num == "inf" {
|
||||
ret some(infinity);
|
||||
ret some(infinity as float);
|
||||
} else if num == "-inf" {
|
||||
ret some(neg_infinity);
|
||||
ret some(neg_infinity as float);
|
||||
} else if num == "NaN" {
|
||||
ret some(NaN);
|
||||
ret some(NaN as float);
|
||||
}
|
||||
|
||||
let mut pos = 0u; //Current byte position in the string.
|
||||
@ -322,25 +373,40 @@ Compute the exponentiation of an integer by another integer as a float
|
||||
`NaN` if both `x` and `pow` are `0u`, otherwise `x^pow`
|
||||
"]
|
||||
fn pow_with_uint(base: uint, pow: uint) -> float {
|
||||
if base == 0u {
|
||||
if pow == 0u {
|
||||
ret NaN;
|
||||
}
|
||||
ret 0.;
|
||||
}
|
||||
let mut my_pow = pow;
|
||||
let mut total = 1f;
|
||||
let mut multiplier = base as float;
|
||||
while (my_pow > 0u) {
|
||||
if my_pow % 2u == 1u {
|
||||
total = total * multiplier;
|
||||
}
|
||||
my_pow /= 2u;
|
||||
multiplier *= multiplier;
|
||||
}
|
||||
ret total;
|
||||
if base == 0u {
|
||||
if pow == 0u {
|
||||
ret NaN as float;
|
||||
}
|
||||
ret 0.;
|
||||
}
|
||||
let mut my_pow = pow;
|
||||
let mut total = 1f;
|
||||
let mut multiplier = base as float;
|
||||
while (my_pow > 0u) {
|
||||
if my_pow % 2u == 1u {
|
||||
total = total * multiplier;
|
||||
}
|
||||
my_pow /= 2u;
|
||||
multiplier *= multiplier;
|
||||
}
|
||||
ret total;
|
||||
}
|
||||
|
||||
fn is_positive(x: float) -> bool { f64::is_positive(x as f64) }
|
||||
fn is_negative(x: float) -> bool { f64::is_negative(x as f64) }
|
||||
fn is_nonpositive(x: float) -> bool { f64::is_nonpositive(x as f64) }
|
||||
fn is_nonnegative(x: float) -> bool { f64::is_nonnegative(x as f64) }
|
||||
fn is_zero(x: float) -> bool { f64::is_zero(x as f64) }
|
||||
fn is_infinite(x: float) -> bool { f64::is_infinite(x as f64) }
|
||||
fn is_finite(x: float) -> bool { f64::is_finite(x as f64) }
|
||||
fn is_NaN(x: float) -> bool { f64::is_NaN(x as f64) }
|
||||
|
||||
fn abs(x: float) -> float { f64::abs(x as f64) as float }
|
||||
fn sqrt(x: float) -> float { f64::sqrt(x as f64) as float }
|
||||
fn atan(x: float) -> float { f64::atan(x as f64) as float }
|
||||
fn sin(x: float) -> float { f64::sin(x as f64) as float }
|
||||
fn cos(x: float) -> float { f64::cos(x as f64) as float }
|
||||
fn tan(x: float) -> float { f64::tan(x as f64) as float }
|
||||
|
||||
#[test]
|
||||
fn test_from_str() {
|
||||
|
@ -7,7 +7,7 @@ Basic input/output
|
||||
import result::result;
|
||||
|
||||
import dvec::{dvec, extensions};
|
||||
import libc::{c_int, c_uint, c_void, size_t, ssize_t};
|
||||
import libc::{c_int, c_long, c_uint, c_void, size_t, ssize_t};
|
||||
import libc::consts::os::posix88::*;
|
||||
import libc::consts::os::extra::*;
|
||||
|
||||
@ -196,9 +196,9 @@ impl of reader for *libc::FILE {
|
||||
let mut buf : [mut u8] = [mut];
|
||||
vec::reserve(buf, len);
|
||||
vec::as_mut_buf(buf) {|b|
|
||||
let read = libc::fread(b as *mut c_void, 1u,
|
||||
len, self);
|
||||
vec::unsafe::set_len(buf, read);
|
||||
let read = libc::fread(b as *mut c_void, 1u as size_t,
|
||||
len as size_t, self);
|
||||
vec::unsafe::set_len(buf, read as uint);
|
||||
}
|
||||
ret vec::from_mut(buf);
|
||||
}
|
||||
@ -206,7 +206,7 @@ impl of reader for *libc::FILE {
|
||||
fn unread_byte(byte: int) { libc::ungetc(byte as c_int, self); }
|
||||
fn eof() -> bool { ret libc::feof(self) != 0 as c_int; }
|
||||
fn seek(offset: int, whence: seek_style) {
|
||||
assert libc::fseek(self, offset, convert_whence(whence))
|
||||
assert libc::fseek(self, offset as c_long, convert_whence(whence))
|
||||
== 0 as c_int;
|
||||
}
|
||||
fn tell() -> uint { ret libc::ftell(self) as uint; }
|
||||
@ -332,7 +332,8 @@ impl <T: writer, C> of writer for {base: T, cleanup: C} {
|
||||
impl of writer for *libc::FILE {
|
||||
fn write(v: [const u8]/&) unsafe {
|
||||
vec::unpack_const_slice(v) {|vbuf, len|
|
||||
let nout = libc::fwrite(vbuf as *c_void, len, 1u, self);
|
||||
let nout = libc::fwrite(vbuf as *c_void, len as size_t,
|
||||
1u as size_t, self);
|
||||
if nout < 1 as size_t {
|
||||
#error("error writing buffer");
|
||||
log(error, os::last_os_error());
|
||||
@ -341,7 +342,7 @@ impl of writer for *libc::FILE {
|
||||
}
|
||||
}
|
||||
fn seek(offset: int, whence: seek_style) {
|
||||
assert libc::fseek(self, offset, convert_whence(whence))
|
||||
assert libc::fseek(self, offset as c_long, convert_whence(whence))
|
||||
== 0 as c_int;
|
||||
}
|
||||
fn tell() -> uint { libc::ftell(self) as uint }
|
||||
@ -362,7 +363,7 @@ impl of writer for fd_t {
|
||||
vec::unpack_const_slice(v) {|vbuf, len|
|
||||
while count < len {
|
||||
let vb = ptr::const_offset(vbuf, count) as *c_void;
|
||||
let nout = libc::write(self, vb, len);
|
||||
let nout = libc::write(self, vb, len as size_t);
|
||||
if nout < 0 as ssize_t {
|
||||
#error("error writing buffer");
|
||||
log(error, os::last_os_error());
|
||||
|
@ -185,8 +185,8 @@ mod types {
|
||||
mod c99 {
|
||||
type c_longlong = i64;
|
||||
type c_ulonglong = u64;
|
||||
type intptr_t = i32;
|
||||
type uintptr_t = u32;
|
||||
type intptr_t = int;
|
||||
type uintptr_t = uint;
|
||||
}
|
||||
mod posix88 {
|
||||
type off_t = i32;
|
||||
@ -229,8 +229,8 @@ mod types {
|
||||
mod c99 {
|
||||
type c_longlong = i64;
|
||||
type c_ulonglong = u64;
|
||||
type intptr_t = i64;
|
||||
type uintptr_t = u64;
|
||||
type intptr_t = int;
|
||||
type uintptr_t = uint;
|
||||
}
|
||||
mod posix88 {
|
||||
type off_t = i64;
|
||||
@ -276,8 +276,8 @@ mod types {
|
||||
mod c99 {
|
||||
type c_longlong = i64;
|
||||
type c_ulonglong = u64;
|
||||
type intptr_t = i64;
|
||||
type uintptr_t = u64;
|
||||
type intptr_t = int;
|
||||
type uintptr_t = uint;
|
||||
}
|
||||
mod posix88 {
|
||||
type off_t = i64;
|
||||
@ -323,8 +323,8 @@ mod types {
|
||||
mod c99 {
|
||||
type c_longlong = i64;
|
||||
type c_ulonglong = u64;
|
||||
type intptr_t = i32;
|
||||
type uintptr_t = u32;
|
||||
type intptr_t = int;
|
||||
type uintptr_t = uint;
|
||||
}
|
||||
mod posix88 {
|
||||
type off_t = i32;
|
||||
@ -397,8 +397,8 @@ mod types {
|
||||
mod c99 {
|
||||
type c_longlong = i64;
|
||||
type c_ulonglong = u64;
|
||||
type intptr_t = i32;
|
||||
type uintptr_t = u32;
|
||||
type intptr_t = int;
|
||||
type uintptr_t = uint;
|
||||
}
|
||||
mod posix88 {
|
||||
type off_t = i64;
|
||||
@ -441,8 +441,8 @@ mod types {
|
||||
mod c99 {
|
||||
type c_longlong = i64;
|
||||
type c_ulonglong = u64;
|
||||
type intptr_t = i64;
|
||||
type uintptr_t = u64;
|
||||
type intptr_t = int;
|
||||
type uintptr_t = uint;
|
||||
}
|
||||
mod posix88 {
|
||||
type off_t = i64;
|
||||
|
@ -90,11 +90,11 @@ mod win32 {
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
import libc::consts::os::extra::*;
|
||||
|
||||
let mut n = tmpbuf_sz;
|
||||
let mut n = tmpbuf_sz as dword;
|
||||
let mut res = none;
|
||||
let mut done = false;
|
||||
while !done {
|
||||
let buf = vec::to_mut(vec::from_elem(n, 0u16));
|
||||
let buf = vec::to_mut(vec::from_elem(n as uint, 0u16));
|
||||
vec::as_mut_buf(buf) {|b|
|
||||
let k : dword = f(b, tmpbuf_sz as dword);
|
||||
if k == (0 as dword) {
|
||||
@ -412,7 +412,7 @@ fn self_exe_path() -> option<path> {
|
||||
import libc::funcs::extra::kernel32::*;
|
||||
import win32::*;
|
||||
fill_utf16_buf_and_decode() {|buf, sz|
|
||||
GetModuleFileNameW(0u, buf, sz)
|
||||
GetModuleFileNameW(0u as dword, buf, sz)
|
||||
}
|
||||
}
|
||||
|
||||
@ -692,16 +692,19 @@ fn copy_file(from: path, to: path) -> bool {
|
||||
let mut ok = true;
|
||||
while !done {
|
||||
vec::as_mut_buf(buf) {|b|
|
||||
let nread = libc::fread(b as *mut c_void, 1u, bufsize, istream);
|
||||
let nread = libc::fread(b as *mut c_void, 1u as size_t,
|
||||
bufsize as size_t,
|
||||
istream);
|
||||
if nread > 0 as size_t {
|
||||
if libc::fwrite(b as *c_void, 1u, nread, ostream) != nread {
|
||||
ok = false;
|
||||
done = true;
|
||||
}
|
||||
if libc::fwrite(b as *c_void, 1u as size_t, nread,
|
||||
ostream) != nread {
|
||||
ok = false;
|
||||
done = true;
|
||||
}
|
||||
} else {
|
||||
done = true;
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(istream);
|
||||
fclose(ostream);
|
||||
@ -988,8 +991,9 @@ mod tests {
|
||||
let s = "hello";
|
||||
let mut buf = vec::to_mut(str::bytes(s) + [0 as u8]);
|
||||
vec::as_mut_buf(buf) {|b|
|
||||
assert (libc::fwrite(b as *c_void, 1u, str::len(s) + 1u, ostream) ==
|
||||
buf.len())};
|
||||
assert (libc::fwrite(b as *c_void, 1u as size_t,
|
||||
(str::len(s) + 1u) as size_t, ostream)
|
||||
== buf.len() as size_t)};
|
||||
assert (libc::fclose(ostream) == (0u as c_int));
|
||||
let rs = os::copy_file(in, out);
|
||||
if (!os::path_exists(in)) {
|
||||
|
@ -14,7 +14,7 @@ export buf_len;
|
||||
export position;
|
||||
export extensions;
|
||||
|
||||
import libc::c_void;
|
||||
import libc::{c_void, size_t};
|
||||
|
||||
#[nolink]
|
||||
#[abi = "cdecl"]
|
||||
@ -93,7 +93,7 @@ and destination may not overlap.
|
||||
#[inline(always)]
|
||||
unsafe fn memcpy<T>(dst: *T, src: *T, count: uint) {
|
||||
let n = count * sys::size_of::<T>();
|
||||
libc_::memcpy(dst as *c_void, src as *c_void, n);
|
||||
libc_::memcpy(dst as *c_void, src as *c_void, n as size_t);
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
@ -105,7 +105,7 @@ and destination may overlap.
|
||||
#[inline(always)]
|
||||
unsafe fn memmove<T>(dst: *T, src: *T, count: uint) {
|
||||
let n = count * sys::size_of::<T>();
|
||||
libc_::memmove(dst as *c_void, src as *c_void, n);
|
||||
libc_::memmove(dst as *c_void, src as *c_void, n as size_t);
|
||||
}
|
||||
|
||||
#[doc = "Extension methods for pointers"]
|
||||
|
@ -7,6 +7,8 @@ for efficiency, but UTF-8 unsafe operations should be avoided. For
|
||||
some heavy-duty uses, try std::rope.
|
||||
"];
|
||||
|
||||
import libc::size_t;
|
||||
|
||||
export
|
||||
// Creating a string
|
||||
from_bytes,
|
||||
@ -1596,7 +1598,7 @@ capacity, then no action is taken.
|
||||
"]
|
||||
fn reserve(&s: str, n: uint) {
|
||||
if capacity(s) < n {
|
||||
rustrt::str_reserve_shared(s, n);
|
||||
rustrt::str_reserve_shared(s, n as size_t);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,8 @@
|
||||
iface to_str { fn to_str() -> str; }
|
||||
|
||||
impl of to_str for int {
|
||||
fn to_str() -> str { int::str(self) }
|
||||
}
|
||||
impl of to_str for i8 {
|
||||
fn to_str() -> str { i8::str(self) }
|
||||
}
|
||||
@ -12,6 +15,9 @@ impl of to_str for i32 {
|
||||
impl of to_str for i64 {
|
||||
fn to_str() -> str { i64::str(self) }
|
||||
}
|
||||
impl of to_str for uint {
|
||||
fn to_str() -> str { uint::str(self) }
|
||||
}
|
||||
impl of to_str for u8 {
|
||||
fn to_str() -> str { u8::str(self) }
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
import option::{some, none};
|
||||
import ptr::addr_of;
|
||||
import libc::size_t;
|
||||
|
||||
export init_op;
|
||||
export is_empty;
|
||||
@ -123,7 +124,8 @@ fn reserve<T>(&v: [const T], n: uint) {
|
||||
// Only make the (slow) call into the runtime if we have to
|
||||
if capacity(v) < n {
|
||||
let ptr = ptr::addr_of(v) as **unsafe::vec_repr;
|
||||
rustrt::vec_reserve_shared(sys::get_type_desc::<T>(), ptr, n);
|
||||
rustrt::vec_reserve_shared(sys::get_type_desc::<T>(),
|
||||
ptr, n as size_t);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1213,7 +1215,7 @@ mod unsafe {
|
||||
ret ::unsafe::reinterpret_cast(
|
||||
rustrt::vec_from_buf_shared(sys::get_type_desc::<T>(),
|
||||
ptr as *(),
|
||||
elts));
|
||||
elts as size_t));
|
||||
}
|
||||
|
||||
#[doc = "
|
||||
|
@ -135,13 +135,13 @@ mod tests {
|
||||
|
||||
assert mem as int != 0;
|
||||
|
||||
ret unsafe { c_vec_with_dtor(mem as *mut u8, n,
|
||||
ret unsafe { c_vec_with_dtor(mem as *mut u8, n as uint,
|
||||
bind free(mem)) };
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_basic() {
|
||||
let cv = malloc(16u);
|
||||
let cv = malloc(16u as size_t);
|
||||
|
||||
set(cv, 3u, 8u8);
|
||||
set(cv, 4u, 9u8);
|
||||
@ -154,7 +154,7 @@ mod tests {
|
||||
#[should_fail]
|
||||
#[ignore(cfg(target_os = "win32"))]
|
||||
fn test_overrun_get() {
|
||||
let cv = malloc(16u);
|
||||
let cv = malloc(16u as size_t);
|
||||
|
||||
get(cv, 17u);
|
||||
}
|
||||
@ -163,14 +163,14 @@ mod tests {
|
||||
#[should_fail]
|
||||
#[ignore(cfg(target_os = "win32"))]
|
||||
fn test_overrun_set() {
|
||||
let cv = malloc(16u);
|
||||
let cv = malloc(16u as size_t);
|
||||
|
||||
set(cv, 17u, 0u8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_and_I_mean_it() {
|
||||
let cv = malloc(16u);
|
||||
let cv = malloc(16u as size_t);
|
||||
let p = unsafe { ptr(cv) };
|
||||
|
||||
set(cv, 0u, 32u8);
|
||||
|
@ -10,6 +10,7 @@ import comm::*;
|
||||
import result::*;
|
||||
import str::*;
|
||||
import future::*;
|
||||
import libc::size_t;
|
||||
|
||||
// data
|
||||
export tcp_socket, tcp_conn_port, tcp_err_data;
|
||||
@ -1136,7 +1137,7 @@ crust fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t,
|
||||
let loop_ptr = uv::ll::get_loop_for_uv_handle(stream);
|
||||
let socket_data_ptr = uv::ll::get_data_for_uv_handle(stream)
|
||||
as *tcp_socket_data;
|
||||
alt nread {
|
||||
alt nread as int {
|
||||
// incoming err.. probably eof
|
||||
-1 {
|
||||
let err_data = uv::ll::get_last_err_data(loop_ptr).to_tcp_err();
|
||||
@ -1150,11 +1151,11 @@ crust fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t,
|
||||
// have data
|
||||
_ {
|
||||
// we have data
|
||||
log(debug, #fmt("tcp on_read_cb nread: %d", nread));
|
||||
log(debug, #fmt("tcp on_read_cb nread: %d", nread as int));
|
||||
let reader_ch = (*socket_data_ptr).reader_ch;
|
||||
let buf_base = uv::ll::get_base_from_buf(buf);
|
||||
let buf_len = uv::ll::get_len_from_buf(buf);
|
||||
let new_bytes = vec::unsafe::from_buf(buf_base, buf_len);
|
||||
let new_bytes = vec::unsafe::from_buf(buf_base, buf_len as uint);
|
||||
comm::send(reader_ch, result::ok(new_bytes));
|
||||
}
|
||||
}
|
||||
@ -1171,7 +1172,7 @@ crust fn on_alloc_cb(handle: *libc::c_void,
|
||||
handle,
|
||||
char_ptr as uint,
|
||||
suggested_size as uint));
|
||||
uv::ll::buf_init(char_ptr, suggested_size)
|
||||
uv::ll::buf_init(char_ptr, suggested_size as uint)
|
||||
}
|
||||
|
||||
type tcp_socket_close_data = {
|
||||
|
@ -8,6 +8,7 @@
|
||||
import either::either;
|
||||
import result::{ok, err};
|
||||
import io::writer_util;
|
||||
import libc::size_t;
|
||||
|
||||
export test_name;
|
||||
export test_fn;
|
||||
@ -322,7 +323,7 @@ const sched_overcommit : uint = 1u;
|
||||
const sched_overcommit : uint = 4u;
|
||||
|
||||
fn get_concurrency() -> uint {
|
||||
let threads = rustrt::sched_threads();
|
||||
let threads = rustrt::sched_threads() as uint;
|
||||
if threads == 1u { 1u }
|
||||
else { threads * sched_overcommit }
|
||||
}
|
||||
|
@ -20,6 +20,8 @@ This module's implementation will hopefully be, eventually, replaced
|
||||
with per-platform, generated source files from rust-bindgen.
|
||||
"];
|
||||
|
||||
import libc::size_t;
|
||||
|
||||
// libuv struct mappings
|
||||
type uv_ip4_addr = {
|
||||
ip: [u8],
|
||||
@ -695,8 +697,8 @@ unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t {
|
||||
len as uint,
|
||||
out_buf_ptr as uint));
|
||||
// yuck :/
|
||||
rustrt::rust_uv_buf_init(out_buf_ptr, input, len);
|
||||
//let result = rustrt::rust_uv_buf_init_2(input, len);
|
||||
rustrt::rust_uv_buf_init(out_buf_ptr, input, len as size_t);
|
||||
//let result = rustrt::rust_uv_buf_init_2(input, len as size_t);
|
||||
log(debug, "after rust_uv_buf_init");
|
||||
let res_base = get_base_from_buf(out_buf);
|
||||
let res_len = get_len_from_buf(out_buf);
|
||||
@ -851,13 +853,15 @@ mod test {
|
||||
handle,
|
||||
char_ptr as uint,
|
||||
suggested_size as uint));
|
||||
ret buf_init(char_ptr, suggested_size);
|
||||
ret buf_init(char_ptr, suggested_size as uint);
|
||||
}
|
||||
|
||||
crust fn on_read_cb(stream: *uv_stream_t,
|
||||
nread: libc::ssize_t,
|
||||
++buf: uv_buf_t) unsafe {
|
||||
log(debug, #fmt("CLIENT entering on_read_cb nred: %d", nread));
|
||||
let nread = nread as int;
|
||||
log(debug, #fmt("CLIENT entering on_read_cb nred: %d",
|
||||
nread));
|
||||
if (nread > 0) {
|
||||
// we have data
|
||||
log(debug, #fmt("CLIENT read: data! nread: %d", nread));
|
||||
@ -867,7 +871,7 @@ mod test {
|
||||
as *request_wrapper;
|
||||
let buf_base = get_base_from_buf(buf);
|
||||
let buf_len = get_len_from_buf(buf);
|
||||
let bytes = vec::unsafe::from_buf(buf_base, buf_len);
|
||||
let bytes = vec::unsafe::from_buf(buf_base, buf_len as uint);
|
||||
let read_chan = *((*client_data).read_chan);
|
||||
let msg_from_server = str::from_bytes(bytes);
|
||||
comm::send(read_chan, msg_from_server);
|
||||
@ -1029,17 +1033,18 @@ mod test {
|
||||
crust fn on_server_read_cb(client_stream_ptr: *uv_stream_t,
|
||||
nread: libc::ssize_t,
|
||||
++buf: uv_buf_t) unsafe {
|
||||
let nread = nread as int;
|
||||
if (nread > 0) {
|
||||
// we have data
|
||||
log(debug, #fmt("SERVER read: data! nread: %d", nread));
|
||||
|
||||
// pull out the contents of the write from the client
|
||||
let buf_base = get_base_from_buf(buf);
|
||||
let buf_len = get_len_from_buf(buf);
|
||||
let buf_len = get_len_from_buf(buf) as uint;
|
||||
log(debug, #fmt("SERVER buf base: %u, len: %u, nread: %d",
|
||||
buf_base as uint,
|
||||
buf_len as uint,
|
||||
nread));
|
||||
buf_base as uint,
|
||||
buf_len as uint,
|
||||
nread));
|
||||
let bytes = vec::unsafe::from_buf(buf_base, buf_len);
|
||||
let request_str = str::from_bytes(bytes);
|
||||
|
||||
|
@ -3,7 +3,7 @@ import syntax::ast::*;
|
||||
// FIXME this doesn't handle big integer/float literals correctly (nor does
|
||||
// the rest of our literal handling)
|
||||
enum const_val {
|
||||
const_float(float),
|
||||
const_float(f64),
|
||||
const_int(i64),
|
||||
const_uint(u64),
|
||||
const_str(str),
|
||||
@ -111,7 +111,7 @@ fn lit_to_const(lit: @lit) -> const_val {
|
||||
lit_str(s) { const_str(s) }
|
||||
lit_int(n, _) { const_int(n) }
|
||||
lit_uint(n, _) { const_uint(n) }
|
||||
lit_float(n, _) { const_float(option::get(float::from_str(n))) }
|
||||
lit_float(n, _) { const_float(option::get(float::from_str(n)) as f64) }
|
||||
lit_nil { const_int(0i64) }
|
||||
lit_bool(b) { const_int(b as i64) }
|
||||
}
|
||||
|
@ -1406,11 +1406,20 @@ fn super_tys<C:combine>(
|
||||
b.to_str(self.infcx())]);
|
||||
}
|
||||
|
||||
(ty::ty_nil, _) |
|
||||
(ty::ty_bool, _) |
|
||||
(ty::ty_int(_), _) |
|
||||
(ty::ty_uint(_), _) |
|
||||
(ty::ty_float(_), _) |
|
||||
(ty::ty_float(_), _) {
|
||||
let as = ty::get(a).struct;
|
||||
let bs = ty::get(b).struct;
|
||||
if as == bs {
|
||||
ok(a)
|
||||
} else {
|
||||
err(ty::terr_sorts(b, a))
|
||||
}
|
||||
}
|
||||
|
||||
(ty::ty_nil, _) |
|
||||
(ty::ty_bool, _) |
|
||||
(ty::ty_str, _) {
|
||||
let cfg = tcx.sess.targ_cfg;
|
||||
if ty::mach_sty(cfg, a) == ty::mach_sty(cfg, b) {
|
||||
|
@ -36,12 +36,12 @@ pure fn cabs(x: cmplx) -> f64
|
||||
|
||||
fn mb(x: cmplx) -> bool
|
||||
{
|
||||
let mut z = {re: 0., im: 0.};
|
||||
let mut z = {re: 0f64, im: 0f64};
|
||||
let mut i = 0;
|
||||
let mut in = true;
|
||||
while i < 50 {
|
||||
z = z*z + x;
|
||||
if cabs(z) >= 4. {
|
||||
if cabs(z) >= 4f64 {
|
||||
in = false;
|
||||
break;
|
||||
}
|
||||
@ -66,12 +66,12 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
|
||||
fn chanmb(i: uint, size: uint, ch: comm::chan<line>) -> ()
|
||||
{
|
||||
let mut crv = [];
|
||||
let incr = 2./(size as f64);
|
||||
let y = incr*(i as f64) - 1.;
|
||||
let xincr = 8.*incr;
|
||||
let incr = 2f64/(size as f64);
|
||||
let y = incr*(i as f64) - 1f64;
|
||||
let xincr = 8f64*incr;
|
||||
for uint::range(0_u, size/8_u) {
|
||||
|j|
|
||||
let x = {re: xincr*(j as f64) - 1.5, im: y};
|
||||
let x = {re: xincr*(j as f64) - 1.5f64, im: y};
|
||||
crv += [fillbyte(x, incr)];
|
||||
};
|
||||
comm::send(ch, {i:i, b:crv});
|
||||
|
@ -13,7 +13,7 @@ native mod libc {
|
||||
fn main() {
|
||||
let s = "hello world\n";
|
||||
let b = str::bytes(s);
|
||||
let l = str::len(s);
|
||||
let l = str::len(s) as core::libc::size_t;
|
||||
let b8 = unsafe { vec::unsafe::to_ptr(b) };
|
||||
libc::write(0i32, b8, l);
|
||||
let a = bind libc::write(0i32, _, _);
|
||||
|
@ -6,5 +6,5 @@ fn main() {
|
||||
|
||||
let digits: uint = 10 as uint;
|
||||
|
||||
println( float::to_str( f64::sqrt(42.0), digits) );
|
||||
println(float::to_str(f64::sqrt(42.0f64) as float, digits));
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
// The two functions returning `result` should by type compatibile
|
||||
// even though they use different int types. This will probably
|
||||
// not be true after #2187
|
||||
|
||||
#[no_core];
|
||||
|
||||
enum result<T, U> {
|
||||
ok(T),
|
||||
err(U)
|
||||
}
|
||||
|
||||
type error = int;
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn get_fd() -> result<int, error> {
|
||||
getsockopt_i64()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
fn getsockopt_i64() -> result<i64, error> {
|
||||
fail
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
fn get_fd() -> result<int, error> {
|
||||
getsockopt_i32()
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
fn getsockopt_i32() -> result<i32, error> {
|
||||
fail
|
||||
}
|
||||
|
||||
fn main() { }
|
@ -5,7 +5,7 @@ enum malloc_pool = ();
|
||||
impl methods for malloc_pool {
|
||||
fn alloc(sz: uint, align: uint) -> *() {
|
||||
unsafe {
|
||||
unsafe::reinterpret_cast(libc::malloc(sz))
|
||||
unsafe::reinterpret_cast(libc::malloc(sz as libc::size_t))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ type ccx = {
|
||||
|
||||
impl arena for arena {
|
||||
fn alloc(sz: uint, _align: uint) -> *() unsafe {
|
||||
ret unsafe::reinterpret_cast(libc::malloc(sz));
|
||||
ret unsafe::reinterpret_cast(libc::malloc(sz as libc::size_t));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,8 @@ type ccx = {
|
||||
};
|
||||
|
||||
fn alloc(_bcx : &a.arena) -> &a.bcx unsafe {
|
||||
ret unsafe::reinterpret_cast(libc::malloc(sys::size_of::<bcx/&blk>()));
|
||||
ret unsafe::reinterpret_cast(
|
||||
libc::malloc(sys::size_of::<bcx/&blk>() as libc::size_t));
|
||||
}
|
||||
|
||||
fn h(bcx : &a.bcx) -> &a.bcx {
|
||||
|
@ -32,9 +32,9 @@ fn test2() {
|
||||
#error("a: %f", ff.a as float);
|
||||
#error("b: %u", ff.b as uint);
|
||||
#error("c: %f", ff.c as float);
|
||||
assert ff.a == f.c + 1.0;
|
||||
assert ff.a == f.c + 1.0f64;
|
||||
assert ff.b == 0xff_u8;
|
||||
assert ff.c == f.a - 1.0;
|
||||
assert ff.c == f.a - 1.0f64;
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86")]
|
||||
|
Loading…
Reference in New Issue
Block a user