Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

Commit

Permalink
add stability attributes
Browse files Browse the repository at this point in the history
to make it easier to copy paste code from rust-lang/rust
  • Loading branch information
Jorge Aparicio committed Jan 14, 2017
1 parent 1d1c502 commit 550f572
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/fs.rs
@@ -1,13 +1,17 @@
#![unstable(feature = "steed", issue = "0")]

use ctypes::{c_int, c_uint};
use io::{Error, Read, Write};
use linux::types::umode_t;
use {linux, io};

#[unstable(feature = "steed", issue = "0")]
pub struct File {
fd: c_uint,
}

impl File {
#[unstable(feature = "steed", issue = "0")]
/// NOTE `path` must be null terminated
pub fn create(path: &[u8]) -> io::Result<File> {
OpenOptions::new()
Expand All @@ -18,17 +22,20 @@ impl File {
}

/// NOTE `path` must be null terminated
#[unstable(feature = "steed", issue = "0")]
pub fn open(path: &[u8]) -> io::Result<File> {
OpenOptions::new().read(true).open(path)
}
}

#[unstable(feature = "steed", issue = "0")]
impl Drop for File {
fn drop(&mut self) {
unsafe { linux::close(self.fd) };
}
}

#[unstable(feature = "steed", issue = "0")]
impl Read for File {
fn read(&mut self, buffer: &mut [u8]) -> io::Result<usize> {
match unsafe {
Expand All @@ -40,6 +47,7 @@ impl Read for File {
}
}

#[unstable(feature = "steed", issue = "0")]
impl Write for File {
fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
match unsafe {
Expand All @@ -51,6 +59,7 @@ impl Write for File {
}
}

#[unstable(feature = "steed", issue = "0")]
pub struct OpenOptions {
read: bool,
write: bool,
Expand All @@ -63,6 +72,7 @@ pub struct OpenOptions {
}

impl OpenOptions {
#[unstable(feature = "steed", issue = "0")]
pub fn new() -> Self {
OpenOptions {
read: false,
Expand All @@ -76,31 +86,37 @@ impl OpenOptions {
}
}

#[unstable(feature = "steed", issue = "0")]
pub fn read(&mut self, read: bool) -> &mut Self {
self.read = read;
self
}

#[unstable(feature = "steed", issue = "0")]
pub fn write(&mut self, write: bool) -> &mut Self {
self.write = write;
self
}

#[unstable(feature = "steed", issue = "0")]
pub fn append(&mut self, append: bool) -> &mut Self {
self.append = append;
self
}

#[unstable(feature = "steed", issue = "0")]
pub fn truncate(&mut self, truncate: bool) -> &mut Self {
self.truncate = truncate;
self
}

#[unstable(feature = "steed", issue = "0")]
pub fn create(&mut self, create: bool) -> &mut Self {
self.create = create;
self
}

#[unstable(feature = "steed", issue = "0")]
pub fn open(&self, path: &[u8]) -> io::Result<File> {
let flags = linux::O_CLOEXEC | self.get_access_mode()? |
self.get_creation_mode()? |
Expand Down
18 changes: 18 additions & 0 deletions src/io.rs
@@ -1,3 +1,5 @@
#![unstable(feature = "steed", issue = "0")]

use core::fmt;

use ctypes::c_uint;
Expand All @@ -7,23 +9,28 @@ const STDIN: c_uint = 0;
const STDOUT: c_uint = 1;
const STDERR: c_uint = 2;

#[unstable(feature = "steed", issue = "0")]
#[derive(Debug)]
pub struct Error {
code: i32,
}

impl Error {
#[unstable(feature = "steed", issue = "0")]
pub fn from_raw_os_error(code: i32) -> Error {
Error { code: code }
}
}

#[unstable(feature = "steed", issue = "0")]
pub type Result<T> = ::core::result::Result<T, Error>;

#[unstable(feature = "steed", issue = "0")]
pub trait Read {
fn read(&mut self, buffer: &mut [u8]) -> io::Result<usize>;
}

#[unstable(feature = "steed", issue = "0")]
pub trait Write {
fn write(&mut self, buffer: &[u8]) -> io::Result<usize>;

Expand All @@ -44,10 +51,12 @@ pub trait Write {
}
}

#[unstable(feature = "steed", issue = "0")]
pub struct Stderr {
_0: (),
}

#[unstable(feature = "steed", issue = "0")]
impl Write for Stderr {
fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
match unsafe {
Expand All @@ -59,16 +68,19 @@ impl Write for Stderr {
}
}

#[unstable(feature = "steed", issue = "0")]
impl fmt::Write for Stderr {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.write_all(s.as_bytes()).map_err(|_| fmt::Error)
}
}

#[unstable(feature = "steed", issue = "0")]
pub struct Stdin {
_0: (),
}

#[unstable(feature = "steed", issue = "0")]
impl Read for Stdin {
fn read(&mut self, buffer: &mut [u8]) -> io::Result<usize> {
match unsafe {
Expand All @@ -80,10 +92,12 @@ impl Read for Stdin {
}
}

#[unstable(feature = "steed", issue = "0")]
pub struct Stdout {
_0: (),
}

#[unstable(feature = "steed", issue = "0")]
impl Write for Stdout {
fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
match unsafe {
Expand All @@ -95,20 +109,24 @@ impl Write for Stdout {
}
}

#[unstable(feature = "steed", issue = "0")]
impl fmt::Write for Stdout {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.write_all(s.as_bytes()).map_err(|_| fmt::Error)
}
}

#[unstable(feature = "steed", issue = "0")]
pub fn stderr() -> Stderr {
Stderr { _0: () }
}

#[unstable(feature = "steed", issue = "0")]
pub fn stdin() -> Stdin {
Stdin { _0: () }
}

#[unstable(feature = "steed", issue = "0")]
pub fn stdout() -> Stdout {
Stdout { _0: () }
}
Expand Down
40 changes: 40 additions & 0 deletions src/lib.rs
Expand Up @@ -7,9 +7,12 @@
#![feature(macro_reexport)]
#![feature(naked_functions)]
#![feature(raw)]
#![feature(staged_api)]
#![feature(unicode)]
#![no_std]

#![stable(feature = "rust1", since = "1.0.0")]

extern crate alloc;
#[macro_reexport(vec)]
extern crate collections as core_collections;
Expand All @@ -20,40 +23,75 @@ extern crate sc;
extern crate std_unicode;

// Public module declarations and reexports
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::any;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::cell;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::clone;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::cmp;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::convert;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::default;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::hash;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::intrinsics;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::iter;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::marker;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::mem;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::ops;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::ptr;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::raw;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::result;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::option;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::isize;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::i8;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::i16;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::i32;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::i64;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::usize;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::u8;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::u16;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::u32;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::u64;
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc::boxed;
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc::rc;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core_collections::borrow;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core_collections::fmt;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core_collections::slice;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core_collections::str;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core_collections::string;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core_collections::vec;
#[stable(feature = "rust1", since = "1.0.0")]
pub use std_unicode::char;

#[macro_use]
Expand All @@ -72,12 +110,14 @@ mod panicking;

// NOTE These two are "undefined" symbols that LLVM emits but that, AFAIK, we
// never use
#[unstable(feature = "steed", issue = "0")]
#[doc(hidden)]
#[no_mangle]
pub unsafe extern "C" fn __aeabi_unwind_cpp_pr0() {
intrinsics::unreachable()
}

#[unstable(feature = "steed", issue = "0")]
#[doc(hidden)]
#[no_mangle]
pub unsafe extern "C" fn __aeabi_unwind_cpp_pr1() {
Expand Down
2 changes: 2 additions & 0 deletions src/macros.rs
@@ -1,8 +1,10 @@
#[unstable(feature = "steed", issue = "0")]
#[macro_export]
macro_rules! print {
($($arg:tt)*) => ($crate::io::_print(format_args!($($arg)*)));
}

#[unstable(feature = "steed", issue = "0")]
#[macro_export]
macro_rules! println {
() => (print!("\n"));
Expand Down
4 changes: 4 additions & 0 deletions src/rt.rs
@@ -1,8 +1,11 @@
//! Entry point

#![unstable(feature = "steed", issue = "0")]

use ctypes::c_int;
use linux;

#[unstable(feature = "steed", issue = "0")]
#[cfg_attr(any(target_arch = "mips",
target_arch = "mips64"), export_name = "__start")]
#[cfg_attr(any(target_arch = "aarch64",
Expand All @@ -20,6 +23,7 @@ pub extern "C" fn start() -> ! {
unsafe { linux::exit(main()) }
}

#[unstable(feature = "steed", issue = "0")]
// NOTE needed to get a 16 byte aligned stack. Without this, programs segfault
// when executing SSE instructions like `movaps` or `movdqa`
#[cfg(any(target_arch = "x86",
Expand Down

0 comments on commit 550f572

Please sign in to comment.