Skip to content

Commit

Permalink
auto merge of #13315 : alexcrichton/rust/libc, r=alexcrichton,me
Browse files Browse the repository at this point in the history
Rebasing of #12526 with a very obscure bug fixed on windows.
  • Loading branch information
bors committed Apr 6, 2014
2 parents 667f82a + 38f7a1b commit f1f5056
Show file tree
Hide file tree
Showing 124 changed files with 626 additions and 525 deletions.
4 changes: 2 additions & 2 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
# automatically generated for all stage/host/target combinations.
################################################################################

TARGET_CRATES := std green rustuv native flate arena glob term semver \
TARGET_CRATES := libc std green rustuv native flate arena glob term semver \
uuid serialize sync getopts collections num test time rand \
workcache url log
HOST_CRATES := syntax rustc rustdoc fourcc hexfloat
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc

DEPS_std := native:rustrt native:compiler-rt native:backtrace
DEPS_std := libc native:rustrt native:compiler-rt native:backtrace
DEPS_green := std rand native:context_switch
DEPS_rustuv := std native:uv native:uv_support
DEPS_native := std
Expand Down
16 changes: 11 additions & 5 deletions src/doc/guide-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ The following is a minimal example of calling a foreign function which will
compile if snappy is installed:

~~~~ {.ignore}
use std::libc::size_t;
extern crate libc;
use libc::size_t;
#[link(name = "snappy")]
extern {
Expand Down Expand Up @@ -44,7 +45,8 @@ keeping the binding correct at runtime.
The `extern` block can be extended to cover the entire snappy API:

~~~~ {.ignore}
use std::libc::{c_int, size_t};
extern crate libc;
use libc::{c_int, size_t};
#[link(name = "snappy")]
extern {
Expand Down Expand Up @@ -402,7 +404,7 @@ global state. In order to access these variables, you declare them in `extern`
blocks with the `static` keyword:

~~~{.ignore}
use std::libc;
extern crate libc;
#[link(name = "readline")]
extern {
Expand All @@ -420,7 +422,7 @@ interface. To do this, statics can be declared with `mut` so rust can mutate
them.

~~~{.ignore}
use std::libc;
extern crate libc;
use std::ptr;
#[link(name = "readline")]
Expand All @@ -444,11 +446,15 @@ calling foreign functions. Some foreign functions, most notably the Windows API,
conventions. Rust provides a way to tell the compiler which convention to use:

~~~~
extern crate libc;
#[cfg(target_os = "win32", target_arch = "x86")]
#[link(name = "kernel32")]
extern "stdcall" {
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> std::libc::c_int;
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> libc::c_int;
}
# fn main() { }
~~~~

This applies to the entire `extern` block. The list of supported ABI constraints
Expand Down
3 changes: 2 additions & 1 deletion src/doc/guide-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ As an example, we give a reimplementation of owned boxes by wrapping
reimplementation is as safe as the built-in `~` type.

```
use std::libc::{c_void, size_t, malloc, free};
extern crate libc;
use libc::{c_void, size_t, malloc, free};
use std::mem;
use std::ptr;
Expand Down
1 change: 1 addition & 0 deletions src/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ li {list-style-type: none; }
* [The `glob` file path matching library](glob/index.html)
* [The `green` M:N runtime library](green/index.html)
* [The `hexfloat` library for hexadecimal floating-point literals](hexfloat/index.html)
* [The `libc` bindings](libc/index.html)
* [The `native` 1:1 threading runtime](native/index.html)
* [The `num` arbitrary precision numerics library](num/index.html)
* [The `rand` library for random numbers and distributions](rand/index.html)
Expand Down
4 changes: 3 additions & 1 deletion src/doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -1471,11 +1471,13 @@ with the exception that they may not have a body
and are instead terminated by a semicolon.

~~~~
# use std::libc::{c_char, FILE};
extern crate libc;
use libc::{c_char, FILE};
extern {
fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
}
# fn main() {}
~~~~

Functions within external blocks may be called by Rust code,
Expand Down
2 changes: 1 addition & 1 deletion src/etc/zsh/_rust
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ _rustc_opts_switches=(
)
_rustc_opts_lint=(
'attribute-usage[detects bad use of attributes]'
'ctypes[proper use of std::libc types in foreign modules]'
'ctypes[proper use of libc types in foreign modules]'
'dead-assignment[detect assignments that will never be read]'
'dead-code[detect piece of code that will never be used]'
'default-type-param-usage[prevents explicitly setting a type parameter with a default]'
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ use std::result::{Ok, Err};
use std::slice::ImmutableVector;

mod table {
extern crate libc;

use std::clone::Clone;
use std::cmp::Eq;
use std::hash::{Hash, Hasher};
use std::kinds::marker;
use std::libc;
use std::num::CheckedMul;
use std::option::{Option, Some, None};
use std::prelude::Drop;
Expand Down
9 changes: 5 additions & 4 deletions src/libflate/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ Simple compression

#[cfg(test)] #[phase(syntax, link)] extern crate log;

use std::libc::{c_void, size_t, c_int};
use std::libc;
extern crate libc;

use std::c_vec::CVec;
use libc::{c_void, size_t, c_int};

pub mod rustrt {
use std::libc::{c_int, c_void, size_t};

pub mod rustrt {
use libc::{c_void, size_t, c_int};
#[link(name = "miniz", kind = "static")]
extern {
pub fn tdefl_compress_mem_to_heap(psrc_buf: *c_void,
Expand Down
1 change: 1 addition & 0 deletions src/libgreen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@
#[cfg(test)] #[phase(syntax, link)] extern crate log;
#[cfg(test)] extern crate rustuv;
extern crate rand;
extern crate libc;

use std::mem::replace;
use std::os;
Expand Down
2 changes: 1 addition & 1 deletion src/libgreen/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ macro_rules! rtabort (

pub fn dumb_println(args: &fmt::Arguments) {
use std::io;
use std::libc;
use libc;

struct Stderr;
impl io::Writer for Stderr {
Expand Down
2 changes: 1 addition & 1 deletion src/libgreen/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ fn new_sched_rng() -> XorShiftRng {
}
#[cfg(unix)]
fn new_sched_rng() -> XorShiftRng {
use std::libc;
use libc;
use std::mem;
use rand::SeedableRng;

Expand Down
2 changes: 1 addition & 1 deletion src/libgreen/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::rt::env::max_cached_stacks;
use std::os::{errno, page_size, MemoryMap, MapReadable, MapWritable,
MapNonStandardFlags, MapVirtual};
use std::libc;
use libc;

/// A task's stack. The name "Stack" is a vestige of segmented stacks.
pub struct Stack {
Expand Down
Loading

0 comments on commit f1f5056

Please sign in to comment.