Skip to content

Commit 0459ee7

Browse files
emberianalexcrichton
authored andcommitted
Fix fallout from std::libc separation
1 parent 06ad5eb commit 0459ee7

File tree

121 files changed

+311
-260
lines changed

Some content is hidden

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

121 files changed

+311
-260
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
@@ -1472,11 +1472,13 @@ with the exception that they may not have a body
14721472
and are instead terminated by a semicolon.
14731473

14741474
~~~~
1475-
# use std::libc::{c_char, FILE};
1475+
extern crate libc;
1476+
use libc::{c_char, FILE};
14761477
14771478
extern {
14781479
fn fopen(filename: *c_char, mode: *c_char) -> *FILE;
14791480
}
1481+
# fn main() {}
14801482
~~~~
14811483

14821484
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 {

src/liblibc/lib.rs

+29-45
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,43 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[feature(globs)];
12-
#[crate_id = "libc#0.10-pre"];
13-
#[experimental];
11+
#![feature(globs)]
12+
#![crate_id = "libc#0.10-pre"]
13+
#![experimental]
14+
#![no_std] // we don't need std, and we can't have std, since it doesn't exist
15+
// yet. std depends on us.
16+
#![crate_type = "rlib"]
17+
#![crate_type = "dylib"]
1418

1519
/*!
1620
* Bindings for the C standard library and other platform libraries
1721
*
18-
* This module contains bindings to the C standard library,
19-
* organized into modules by their defining standard.
20-
* Additionally, it contains some assorted platform-specific definitions.
21-
* For convenience, most functions and types are reexported from `libc`,
22-
* so `pub use std::*` will import the available
23-
* C bindings as appropriate for the target platform. The exact
24-
* set of functions available are platform specific.
22+
* **NOTE:** These are *architecture and libc* specific. On Linux, these
23+
* bindings are only correct for glibc.
2524
*
26-
* *Note* Because these definitions are platform-specific, some may not appear in
27-
* the generated documentation.
25+
* This module contains bindings to the C standard library, organized into
26+
* modules by their defining standard. Additionally, it contains some assorted
27+
* platform-specific definitions. For convenience, most functions and types
28+
* are reexported, so `use libc::*` will import the available C bindings as
29+
* appropriate for the target platform. The exact set of functions available
30+
* are platform specific.
2831
*
29-
* We consider the following specs reasonably normative with respect
30-
* to interoperating with the C standard library (libc/msvcrt):
32+
* *Note:* Because these definitions are platform-specific, some may not appear
33+
* in the generated documentation.
34+
*
35+
* We consider the following specs reasonably normative with respect to
36+
* interoperating with the C standard library (libc/msvcrt):
3137
*
3238
* * ISO 9899:1990 ('C95', 'ANSI C', 'Standard C'), NA1, 1995.
3339
* * ISO 9899:1999 ('C99' or 'C9x').
3440
* * ISO 9945:1988 / IEEE 1003.1-1988 ('POSIX.1').
3541
* * ISO 9945:2001 / IEEE 1003.1-2001 ('POSIX:2001', 'SUSv3').
3642
* * ISO 9945:2008 / IEEE 1003.1-2008 ('POSIX:2008', 'SUSv4').
3743
*
38-
* Note that any reference to the 1996 revision of POSIX, or any revs
39-
* between 1990 (when '88 was approved at ISO) and 2001 (when the next
40-
* actual revision-revision happened), are merely additions of other
41-
* chapters (1b and 1c) outside the core interfaces.
44+
* Note that any reference to the 1996 revision of POSIX, or any revs between
45+
* 1990 (when '88 was approved at ISO) and 2001 (when the next actual
46+
* revision-revision happened), are merely additions of other chapters (1b and
47+
* 1c) outside the core interfaces.
4248
*
4349
* Despite having several names each, these are *reasonably* coherent
4450
* point-in-time, list-of-definition sorts of specs. You can get each under a
@@ -55,15 +61,13 @@
5561
* sanity while editing, filling-in-details and eliminating duplication) into
5662
* definitions common-to-all (held in modules named c95, c99, posix88, posix01
5763
* and posix08) and definitions that appear only on *some* platforms (named
58-
* 'extra'). This would be things like significant OSX foundation kit, or
59-
* win32 library kernel32.dll, or various fancy glibc, linux or BSD
60-
* extensions.
64+
* 'extra'). This would be things like significant OSX foundation kit, or win32
65+
* library kernel32.dll, or various fancy glibc, linux or BSD extensions.
6166
*
6267
* In addition to the per-platform 'extra' modules, we define a module of
6368
* 'common BSD' libc routines that never quite made it into POSIX but show up
64-
* in multiple derived systems. This is the 4.4BSD r2 / 1995 release, the
65-
* final one from Berkeley after the lawsuits died down and the CSRG
66-
* dissolved.
69+
* in multiple derived systems. This is the 4.4BSD r2 / 1995 release, the final
70+
* one from Berkeley after the lawsuits died down and the CSRG dissolved.
6771
*/
6872

6973
#![allow(non_camel_case_types)]
@@ -997,7 +1001,6 @@ pub mod types {
9971001
pub mod bsd44 {
9981002
}
9991003
pub mod extra {
1000-
use ptr;
10011004
use consts::os::extra::{MAX_PROTOCOL_CHAIN,
10021005
WSAPROTOCOL_LEN};
10031006
use types::common::c95::c_void;
@@ -1102,24 +1105,6 @@ pub mod types {
11021105
}
11031106
pub type LPSYSTEM_INFO = *mut SYSTEM_INFO;
11041107

1105-
impl SYSTEM_INFO {
1106-
pub fn new() -> SYSTEM_INFO {
1107-
SYSTEM_INFO {
1108-
wProcessorArchitecture: 0,
1109-
wReserved: 0,
1110-
dwPageSize: 0,
1111-
lpMinimumApplicationAddress: ptr::mut_null(),
1112-
lpMaximumApplicationAddress: ptr::mut_null(),
1113-
dwActiveProcessorMask: 0,
1114-
dwNumberOfProcessors: 0,
1115-
dwProcessorType: 0,
1116-
dwAllocationGranularity: 0,
1117-
wProcessorLevel: 0,
1118-
wProcessorRevision: 0
1119-
}
1120-
}
1121-
}
1122-
11231108
pub struct MEMORY_BASIC_INFORMATION {
11241109
pub BaseAddress: LPVOID,
11251110
pub AllocationBase: LPVOID,
@@ -3901,12 +3886,11 @@ pub mod funcs {
39013886
pub mod glob {
39023887
use types::os::arch::c95::{c_char, c_int};
39033888
use types::os::common::posix01::{glob_t};
3904-
use Nullable;
39053889

39063890
extern {
39073891
pub fn glob(pattern: *c_char,
39083892
flags: c_int,
3909-
errfunc: Nullable<extern "C" fn(epath: *c_char, errno: int) -> int>,
3893+
errfunc: ::Nullable<extern "C" fn(epath: *c_char, errno: int) -> int>,
39103894
pglob: *mut glob_t);
39113895
pub fn globfree(pglob: *mut glob_t);
39123896
}

src/libnative/io/addrinfo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use ai = std::io::net::addrinfo;
1212
use std::c_str::CString;
1313
use std::cast;
1414
use std::io::IoError;
15-
use std::libc;
16-
use std::libc::{c_char, c_int};
15+
use libc;
16+
use libc::{c_char, c_int};
1717
use std::ptr::{null, mut_null};
1818

1919
use super::net::sockaddr_to_addr;

src/libnative/io/file_unix.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use std::sync::arc::UnsafeArc;
1414
use std::c_str::CString;
1515
use std::io::IoError;
1616
use std::io;
17-
use std::libc::{c_int, c_void};
18-
use std::libc;
17+
use libc::{c_int, c_void};
18+
use libc;
1919
use std::mem;
2020
use std::rt::rtio;
2121
use std::slice;
@@ -341,8 +341,8 @@ pub fn mkdir(p: &CString, mode: io::FilePermission) -> IoResult<()> {
341341
}
342342

343343
pub fn readdir(p: &CString) -> IoResult<~[Path]> {
344-
use std::libc::{dirent_t};
345-
use std::libc::{opendir, readdir_r, closedir};
344+
use libc::{dirent_t};
345+
use libc::{opendir, readdir_r, closedir};
346346

347347
fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
348348
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
@@ -520,7 +520,7 @@ pub fn utime(p: &CString, atime: u64, mtime: u64) -> IoResult<()> {
520520
mod tests {
521521
use super::{CFile, FileDesc};
522522
use std::io;
523-
use std::libc;
523+
use libc;
524524
use std::os;
525525
use std::rt::rtio::RtioFileStream;
526526

src/libnative/io/file_win32.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ use std::c_str::CString;
1414
use std::cast;
1515
use std::io::IoError;
1616
use std::io;
17-
use std::libc::{c_int, c_void};
18-
use std::libc;
17+
use libc::{c_int, c_void};
18+
use libc;
1919
use std::mem;
2020
use std::os::win32::{as_utf16_p, fill_utf16_buf_and_decode};
2121
use std::ptr;

src/libnative/io/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ use std::io::IoError;
2727
use std::io::net::ip::SocketAddr;
2828
use std::io::process::ProcessConfig;
2929
use std::io::signal::Signum;
30-
use std::libc::c_int;
31-
use std::libc;
30+
use libc::c_int;
31+
use libc;
3232
use std::os;
3333
use std::rt::rtio;
3434
use std::rt::rtio::{RtioTcpStream, RtioTcpListener, RtioUdpSocket,

src/libnative/io/net.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::cast;
1212
use std::io::net::ip;
1313
use std::io;
14-
use std::libc;
14+
use libc;
1515
use std::mem;
1616
use std::rt::rtio;
1717
use std::sync::arc::UnsafeArc;

src/libnative/io/pipe_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::c_str::CString;
1212
use std::cast;
1313
use std::io;
14-
use std::libc;
14+
use libc;
1515
use std::mem;
1616
use std::rt::rtio;
1717
use std::sync::arc::UnsafeArc;

0 commit comments

Comments
 (0)