Skip to content
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

docs: tutorial ffi: the example compilation fails #5871

Closed
mdesantis opened this issue Apr 13, 2013 · 2 comments
Closed

docs: tutorial ffi: the example compilation fails #5871

mdesantis opened this issue Apr 13, 2013 · 2 comments
Labels
A-FFI Area: Foreign function interface (FFI)

Comments

@mdesantis
Copy link

The compilation of the first example of Rust Foreign Function Interface Tutorial fails:

extern mod std;
use core::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() {
    io::println(sha1(core::os::args()[1]));
}

with this error:

$ rustc main.rs && ./main asd
main.rs:25:21: 25:39 error: moving out of immutable vec content
main.rs:25     io::println(sha1(core::os::args()[1]));
                                ^~~~~~~~~~~~~~~~~~
error: aborting due to previous error

since the program argument, which is of ~str type, must be clone()'d:

fn main() {
    io::println(sha1(core::os::args()[1].clone()));
}
$ rustc main.rs && ./main asd
f10e2821bbbea527ea02200352313bc059445190
@thestinger
Copy link
Contributor

I actually rewrote the FFI tutorial, but the doc bot hasn't regenerated it because incoming hasn't been merged to master for a while.

Until then you can look at a less pretty version on GitHub: https://github.com/mozilla/rust/blob/incoming/doc/tutorial-ffi.md

@mdesantis
Copy link
Author

I'll look at it, thank you
Il giorno 14/apr/2013 00:07, "Daniel Micay" notifications@github.com ha
scritto:

I actually rewrote the FFI tutorial, the doc bot just hasn't regenerated
it because incoming hasn't been merged to master for a while.

Until then you can look at a less pretty version on GitHub:
https://github.com/mozilla/rust/blob/master/doc/tutorial-ffi.md


Reply to this email directly or view it on GitHubhttps://github.com//issues/5871#issuecomment-16341826
.

flip1995 added a commit to flip1995/rust that referenced this issue Aug 11, 2020
…flip1995

Lint .min(x).max(y) with x < y

Fixes  rust-lang#5854

changelog: Also lint `ord.min(a).max(b)`, where `a < b` in [`min_max`] lint
flip1995 pushed a commit to flip1995/rust that referenced this issue Aug 11, 2020
Rollup of 5 pull requests

Successful merges:

 - rust-lang#5825 (Add the new lint `same_item_push`)
 - rust-lang#5869 (New lint against `Self` as an arbitrary self type)
 - rust-lang#5870 (enable #[allow(clippy::unsafe_derive_deserialize)])
 - rust-lang#5871 (Lint .min(x).max(y) with x < y)
 - rust-lang#5874 (Make the docs clearer for new contributors)

Failed merges:

r? @ghost

changelog: rollup
calebcartwright added a commit to calebcartwright/rust that referenced this issue Oct 23, 2023
* Fix rust-lang#5871

* Only idempotence test is necessary

* Update src/expr.rs

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>

---------

Co-authored-by: Caleb Cartwright <calebcartwright@users.noreply.github.com>
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)
Projects
None yet
Development

No branches or pull requests

2 participants