Skip to content

Commit

Permalink
Fix fallout from std::libc separation
Browse files Browse the repository at this point in the history
  • Loading branch information
emberian authored and alexcrichton committed Apr 4, 2014
1 parent 06ad5eb commit 0459ee7
Show file tree
Hide file tree
Showing 121 changed files with 311 additions and 260 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 @@ -1472,11 +1472,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
74 changes: 29 additions & 45 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,43 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

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

/*!
* Bindings for the C standard library and other platform libraries
*
* This module contains bindings to the C standard library,
* organized into modules by their defining standard.
* Additionally, it contains some assorted platform-specific definitions.
* For convenience, most functions and types are reexported from `libc`,
* so `pub use std::*` will import the available
* C bindings as appropriate for the target platform. The exact
* set of functions available are platform specific.
* **NOTE:** These are *architecture and libc* specific. On Linux, these
* bindings are only correct for glibc.
*
* *Note* Because these definitions are platform-specific, some may not appear in
* the generated documentation.
* This module contains bindings to the C standard library, organized into
* modules by their defining standard. Additionally, it contains some assorted
* platform-specific definitions. For convenience, most functions and types
* are reexported, so `use libc::*` will import the available C bindings as
* appropriate for the target platform. The exact set of functions available
* are platform specific.
*
* We consider the following specs reasonably normative with respect
* to interoperating with the C standard library (libc/msvcrt):
* *Note:* Because these definitions are platform-specific, some may not appear
* in the generated documentation.
*
* We consider the following specs reasonably normative with respect to
* interoperating with the C standard library (libc/msvcrt):
*
* * ISO 9899:1990 ('C95', 'ANSI C', 'Standard C'), NA1, 1995.
* * ISO 9899:1999 ('C99' or 'C9x').
* * ISO 9945:1988 / IEEE 1003.1-1988 ('POSIX.1').
* * ISO 9945:2001 / IEEE 1003.1-2001 ('POSIX:2001', 'SUSv3').
* * ISO 9945:2008 / IEEE 1003.1-2008 ('POSIX:2008', 'SUSv4').
*
* Note that any reference to the 1996 revision of POSIX, or any revs
* between 1990 (when '88 was approved at ISO) and 2001 (when the next
* actual revision-revision happened), are merely additions of other
* chapters (1b and 1c) outside the core interfaces.
* Note that any reference to the 1996 revision of POSIX, or any revs between
* 1990 (when '88 was approved at ISO) and 2001 (when the next actual
* revision-revision happened), are merely additions of other chapters (1b and
* 1c) outside the core interfaces.
*
* Despite having several names each, these are *reasonably* coherent
* point-in-time, list-of-definition sorts of specs. You can get each under a
Expand All @@ -55,15 +61,13 @@
* sanity while editing, filling-in-details and eliminating duplication) into
* definitions common-to-all (held in modules named c95, c99, posix88, posix01
* and posix08) and definitions that appear only on *some* platforms (named
* 'extra'). This would be things like significant OSX foundation kit, or
* win32 library kernel32.dll, or various fancy glibc, linux or BSD
* extensions.
* 'extra'). This would be things like significant OSX foundation kit, or win32
* library kernel32.dll, or various fancy glibc, linux or BSD extensions.
*
* In addition to the per-platform 'extra' modules, we define a module of
* 'common BSD' libc routines that never quite made it into POSIX but show up
* in multiple derived systems. This is the 4.4BSD r2 / 1995 release, the
* final one from Berkeley after the lawsuits died down and the CSRG
* dissolved.
* in multiple derived systems. This is the 4.4BSD r2 / 1995 release, the final
* one from Berkeley after the lawsuits died down and the CSRG dissolved.
*/

#![allow(non_camel_case_types)]
Expand Down Expand Up @@ -997,7 +1001,6 @@ pub mod types {
pub mod bsd44 {
}
pub mod extra {
use ptr;
use consts::os::extra::{MAX_PROTOCOL_CHAIN,
WSAPROTOCOL_LEN};
use types::common::c95::c_void;
Expand Down Expand Up @@ -1102,24 +1105,6 @@ pub mod types {
}
pub type LPSYSTEM_INFO = *mut SYSTEM_INFO;

impl SYSTEM_INFO {
pub fn new() -> SYSTEM_INFO {
SYSTEM_INFO {
wProcessorArchitecture: 0,
wReserved: 0,
dwPageSize: 0,
lpMinimumApplicationAddress: ptr::mut_null(),
lpMaximumApplicationAddress: ptr::mut_null(),
dwActiveProcessorMask: 0,
dwNumberOfProcessors: 0,
dwProcessorType: 0,
dwAllocationGranularity: 0,
wProcessorLevel: 0,
wProcessorRevision: 0
}
}
}

pub struct MEMORY_BASIC_INFORMATION {
pub BaseAddress: LPVOID,
pub AllocationBase: LPVOID,
Expand Down Expand Up @@ -3901,12 +3886,11 @@ pub mod funcs {
pub mod glob {
use types::os::arch::c95::{c_char, c_int};
use types::os::common::posix01::{glob_t};
use Nullable;

extern {
pub fn glob(pattern: *c_char,
flags: c_int,
errfunc: Nullable<extern "C" fn(epath: *c_char, errno: int) -> int>,
errfunc: ::Nullable<extern "C" fn(epath: *c_char, errno: int) -> int>,
pglob: *mut glob_t);
pub fn globfree(pglob: *mut glob_t);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libnative/io/addrinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use ai = std::io::net::addrinfo;
use std::c_str::CString;
use std::cast;
use std::io::IoError;
use std::libc;
use std::libc::{c_char, c_int};
use libc;
use libc::{c_char, c_int};
use std::ptr::{null, mut_null};

use super::net::sockaddr_to_addr;
Expand Down
10 changes: 5 additions & 5 deletions src/libnative/io/file_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use std::sync::arc::UnsafeArc;
use std::c_str::CString;
use std::io::IoError;
use std::io;
use std::libc::{c_int, c_void};
use std::libc;
use libc::{c_int, c_void};
use libc;
use std::mem;
use std::rt::rtio;
use std::slice;
Expand Down Expand Up @@ -341,8 +341,8 @@ pub fn mkdir(p: &CString, mode: io::FilePermission) -> IoResult<()> {
}

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/libnative/io/file_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use std::c_str::CString;
use std::cast;
use std::io::IoError;
use std::io;
use std::libc::{c_int, c_void};
use std::libc;
use libc::{c_int, c_void};
use libc;
use std::mem;
use std::os::win32::{as_utf16_p, fill_utf16_buf_and_decode};
use std::ptr;
Expand Down
4 changes: 2 additions & 2 deletions src/libnative/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use std::io::IoError;
use std::io::net::ip::SocketAddr;
use std::io::process::ProcessConfig;
use std::io::signal::Signum;
use std::libc::c_int;
use std::libc;
use libc::c_int;
use libc;
use std::os;
use std::rt::rtio;
use std::rt::rtio::{RtioTcpStream, RtioTcpListener, RtioUdpSocket,
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::cast;
use std::io::net::ip;
use std::io;
use std::libc;
use libc;
use std::mem;
use std::rt::rtio;
use std::sync::arc::UnsafeArc;
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/io/pipe_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::c_str::CString;
use std::cast;
use std::io;
use std::libc;
use libc;
use std::mem;
use std::rt::rtio;
use std::sync::arc::UnsafeArc;
Expand Down
Loading

0 comments on commit 0459ee7

Please sign in to comment.