Skip to content

Commit f1f5056

Browse files
committed
auto merge of #13315 : alexcrichton/rust/libc, r=alexcrichton,me
Rebasing of #12526 with a very obscure bug fixed on windows.
2 parents 667f82a + 38f7a1b commit f1f5056

File tree

124 files changed

+626
-525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+626
-525
lines changed

mk/crates.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@
4949
# automatically generated for all stage/host/target combinations.
5050
################################################################################
5151

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

59-
DEPS_std := native:rustrt native:compiler-rt native:backtrace
59+
DEPS_std := libc native:rustrt native:compiler-rt native:backtrace
6060
DEPS_green := std rand native:context_switch
6161
DEPS_rustuv := std native:uv native:uv_support
6262
DEPS_native := std

src/doc/guide-ffi.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ The following is a minimal example of calling a foreign function which will
1212
compile if snappy is installed:
1313

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

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

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

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

446448
~~~~
449+
extern crate libc;
450+
447451
#[cfg(target_os = "win32", target_arch = "x86")]
448452
#[link(name = "kernel32")]
449453
extern "stdcall" {
450-
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> std::libc::c_int;
454+
fn SetEnvironmentVariableA(n: *u8, v: *u8) -> libc::c_int;
451455
}
456+
457+
# fn main() { }
452458
~~~~
453459

454460
This applies to the entire `extern` block. The list of supported ABI constraints

src/doc/guide-unsafe.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ As an example, we give a reimplementation of owned boxes by wrapping
192192
reimplementation is as safe as the built-in `~` type.
193193

194194
```
195-
use std::libc::{c_void, size_t, malloc, free};
195+
extern crate libc;
196+
use libc::{c_void, size_t, malloc, free};
196197
use std::mem;
197198
use std::ptr;
198199

src/doc/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ li {list-style-type: none; }
3636
* [The `glob` file path matching library](glob/index.html)
3737
* [The `green` M:N runtime library](green/index.html)
3838
* [The `hexfloat` library for hexadecimal floating-point literals](hexfloat/index.html)
39+
* [The `libc` bindings](libc/index.html)
3940
* [The `native` 1:1 threading runtime](native/index.html)
4041
* [The `num` arbitrary precision numerics library](num/index.html)
4142
* [The `rand` library for random numbers and distributions](rand/index.html)

src/doc/rust.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1471,11 +1471,13 @@ with the exception that they may not have a body
14711471
and are instead terminated by a semicolon.
14721472

14731473
~~~~
1474-
# use std::libc::{c_char, FILE};
1474+
extern crate libc;
1475+
use libc::{c_char, FILE};
14751476
14761477
extern {
14771478
fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
14781479
}
1480+
# fn main() {}
14791481
~~~~
14801482

14811483
Functions within external blocks may be called by Rust code,

src/etc/zsh/_rust

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ _rustc_opts_switches=(
4040
)
4141
_rustc_opts_lint=(
4242
'attribute-usage[detects bad use of attributes]'
43-
'ctypes[proper use of std::libc types in foreign modules]'
43+
'ctypes[proper use of libc types in foreign modules]'
4444
'dead-assignment[detect assignments that will never be read]'
4545
'dead-code[detect piece of code that will never be used]'
4646
'default-type-param-usage[prevents explicitly setting a type parameter with a default]'

src/libcollections/hashmap.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ use std::result::{Ok, Err};
3030
use std::slice::ImmutableVector;
3131

3232
mod table {
33+
extern crate libc;
34+
3335
use std::clone::Clone;
3436
use std::cmp::Eq;
3537
use std::hash::{Hash, Hasher};
3638
use std::kinds::marker;
37-
use std::libc;
3839
use std::num::CheckedMul;
3940
use std::option::{Option, Some, None};
4041
use std::prelude::Drop;

src/libflate/lib.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ Simple compression
2626

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

29-
use std::libc::{c_void, size_t, c_int};
30-
use std::libc;
29+
extern crate libc;
30+
3131
use std::c_vec::CVec;
32+
use libc::{c_void, size_t, c_int};
3233

33-
pub mod rustrt {
34-
use std::libc::{c_int, c_void, size_t};
3534

35+
pub mod rustrt {
36+
use libc::{c_void, size_t, c_int};
3637
#[link(name = "miniz", kind = "static")]
3738
extern {
3839
pub fn tdefl_compress_mem_to_heap(psrc_buf: *c_void,

src/libgreen/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
#[cfg(test)] #[phase(syntax, link)] extern crate log;
200200
#[cfg(test)] extern crate rustuv;
201201
extern crate rand;
202+
extern crate libc;
202203

203204
use std::mem::replace;
204205
use std::os;

src/libgreen/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ macro_rules! rtabort (
5252

5353
pub fn dumb_println(args: &fmt::Arguments) {
5454
use std::io;
55-
use std::libc;
55+
use libc;
5656

5757
struct Stderr;
5858
impl io::Writer for Stderr {

src/libgreen/sched.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ fn new_sched_rng() -> XorShiftRng {
976976
}
977977
#[cfg(unix)]
978978
fn new_sched_rng() -> XorShiftRng {
979-
use std::libc;
979+
use libc;
980980
use std::mem;
981981
use rand::SeedableRng;
982982

src/libgreen/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::rt::env::max_cached_stacks;
1212
use std::os::{errno, page_size, MemoryMap, MapReadable, MapWritable,
1313
MapNonStandardFlags, MapVirtual};
14-
use std::libc;
14+
use libc;
1515

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

0 commit comments

Comments
 (0)