Skip to content

FFI tutorial isn't being tested #4509

Description

@bstrie

The FFI tutorial for 0.5 (http://static.rust-lang.org/doc/0.5/tutorial-ffi.html) contains this code, busted in two places:

extern mod std;
use libc::c_uint;

extern mod crypto {
    fn SHA1(src: *u8, sz: c_uint, out: *u8) -> *u8;
}

fn as_hex(data: ~[u8]) -> ~str {
    let mut acc = ~"";
    for data.each |byte| { acc += fmt!("%02x", byte as uint); }
    return acc;
}

fn sha1(data: ~str) -> ~str unsafe {
    let bytes = str::to_bytes(data);
    let hash = crypto::SHA1(vec::raw::to_ptr(bytes),
                            vec::len(bytes) as c_uint, ptr::null());
    return as_hex(vec::from_buf(hash, 20));
}

fn main(args: ~[~str]) {
    io::println(sha1(args[1]));
}

(See for data.each |byte| and fn main(args ~[~str]).)

I thus conclude that it isn't being tested automatically like the other docs are.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-FFIArea: Foreign function interface (FFI)A-testsuiteArea: The testsuite used to check the correctness of rustc

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions