Skip to content

FFI tutorial isn't being tested #4509

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

Closed
bstrie opened this issue Jan 16, 2013 · 3 comments
Closed

FFI tutorial isn't being tested #4509

bstrie opened this issue Jan 16, 2013 · 3 comments
Labels
A-FFI Area: Foreign function interface (FFI) A-testsuite Area: The testsuite used to check the correctness of rustc

Comments

@bstrie
Copy link
Contributor

bstrie commented Jan 16, 2013

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.

@bstrie
Copy link
Contributor Author

bstrie commented Jan 16, 2013

Even if it's not possible to run FFI tests for some reason, even a compile test would have caught these errors.

@thestinger
Copy link
Contributor

The samples in the tutorial are fixed now, but they're marked as xfail because they don't intentionally leave out all the boilerplate needed to compile. They get tested as part of the rust-snappy library though so I'll notice when they break.

@bblum
Copy link
Contributor

bblum commented Jul 3, 2013

uh, visiting for triage... good work everyone... move along

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-FFI Area: Foreign function interface (FFI) A-testsuite Area: The testsuite used to check the correctness of rustc
Projects
None yet
Development

No branches or pull requests

4 participants