implement #[nolink]; deprecate #[link_name = ""]; note in stdlib to remove empty link_name.

Can't remove them from stdlib until the snapshotted compiler supports #[nolink].
This commit is contained in:
Graham Fawcett 2011-12-15 15:25:29 -05:00 committed by Brian Anderson
parent 8dc5c445cc
commit 7ddd353ef6
16 changed files with 34 additions and 19 deletions

View File

@ -189,7 +189,7 @@ microsecond-resolution timer.
use std; use std;
type timeval = {mutable tv_sec: u32, type timeval = {mutable tv_sec: u32,
mutable tv_usec: u32}; mutable tv_usec: u32};
#[link_name = ""] #[nolink]
native mod libc { native mod libc {
fn gettimeofday(tv: *timeval, tz: *()) -> i32; fn gettimeofday(tv: *timeval, tz: *()) -> i32;
} }
@ -199,7 +199,7 @@ microsecond-resolution timer.
ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64); ret (x.tv_sec as u64) * 1000_000_u64 + (x.tv_usec as u64);
} }
The `#[link_name = ""]` sets the name of the native module to the The `#[nolink]` sets the name of the native module to the
empty string to prevent the rust compiler from trying to link it. empty string to prevent the rust compiler from trying to link it.
The standard C library is already linked with Rust programs. The standard C library is already linked with Rust programs.

View File

@ -57,12 +57,20 @@ fn visit_item(e: env, i: @ast::item) {
} }
either::left(msg) { e.sess.span_fatal(i.span, msg); } either::left(msg) { e.sess.span_fatal(i.span, msg); }
} }
let cstore = e.sess.get_cstore(); let cstore = e.sess.get_cstore();
let native_name = i.ident; let native_name = i.ident;
if vec::len(attr::find_attrs_by_name(i.attrs, "nolink")) > 0u {
ret;
}
alt attr::get_meta_item_value_str_by_name(i.attrs, "link_name") { alt attr::get_meta_item_value_str_by_name(i.attrs, "link_name") {
some(nn) { native_name = nn; } some(nn) { native_name = nn; }
none. { } none. { }
} }
if native_name == "" {
e.sess.span_fatal(i.span,
"empty #[link_name] not allowed; use #[nolink].");
}
if !cstore::add_used_library(cstore, native_name) { ret; } if !cstore::add_used_library(cstore, native_name) { ret; }
for a: ast::attribute in for a: ast::attribute in
attr::find_attrs_by_name(i.attrs, "link_args") { attr::find_attrs_by_name(i.attrs, "link_args") {

View File

@ -93,7 +93,6 @@ fn add_used_library(cstore: cstore, lib: str) -> bool {
if lib == "" { ret false; } if lib == "" { ret false; }
if vec::member(lib, p(cstore).used_libraries) { ret false; } if vec::member(lib, p(cstore).used_libraries) { ret false; }
p(cstore).used_libraries += [lib]; p(cstore).used_libraries += [lib];
ret true; ret true;
} }

View File

@ -24,7 +24,8 @@ export fsync_fd;
// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult // FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult
// by https://github.com/graydon/rust/issues#issue/268 // by https://github.com/graydon/rust/issues#issue/268
#[link_name = ""] #[link_name = ""] // FIXME remove after #[nolink] is snapshotted
#[nolink]
#[abi = "cdecl"] #[abi = "cdecl"]
native mod libc { native mod libc {
fn read(fd: fd_t, buf: *u8, count: size_t) -> ssize_t; fn read(fd: fd_t, buf: *u8, count: size_t) -> ssize_t;

View File

@ -18,7 +18,7 @@ export fsync_fd;
// FIXME Refactor into unix_os module or some such. Doesn't // FIXME Refactor into unix_os module or some such. Doesn't
// seem to work right now. // seem to work right now.
#[link_name = ""] #[nolink]
#[abi = "cdecl"] #[abi = "cdecl"]
native mod libc { native mod libc {
fn read(fd: fd_t, buf: *u8, count: size_t) -> ssize_t; fn read(fd: fd_t, buf: *u8, count: size_t) -> ssize_t;
@ -118,7 +118,8 @@ native mod rustrt {
fn getcwd() -> str { ret rustrt::rust_getcwd(); } fn getcwd() -> str { ret rustrt::rust_getcwd(); }
#[link_name = ""] #[link_name = ""] // FIXME remove after #[nolink] is snapshotted
#[nolink]
#[abi = "cdecl"] #[abi = "cdecl"]
native mod mac_libc { native mod mac_libc {
fn _NSGetExecutablePath(buf: str::sbuf, fn _NSGetExecutablePath(buf: str::sbuf,

View File

@ -2,7 +2,8 @@ import core::option;
import ctypes::*; import ctypes::*;
#[abi = "cdecl"] #[abi = "cdecl"]
#[link_name = ""] #[link_name = ""] // FIXME remove after #[nolink] is snapshotted
#[nolink]
native mod libc { native mod libc {
fn read(fd: fd_t, buf: *u8, count: size_t) -> ssize_t; fn read(fd: fd_t, buf: *u8, count: size_t) -> ssize_t;
fn write(fd: fd_t, buf: *u8, count: size_t) -> ssize_t; fn write(fd: fd_t, buf: *u8, count: size_t) -> ssize_t;

View File

@ -2,7 +2,7 @@
// http://shootout.alioth.debian.org/u32/benchmark.php?test=nbody&lang=java // http://shootout.alioth.debian.org/u32/benchmark.php?test=nbody&lang=java
#[abi = "cdecl"] #[abi = "cdecl"]
#[link_name = ""] #[nolink]
native mod llvm { native mod llvm {
fn sqrt(n: float) -> float; fn sqrt(n: float) -> float;
} }

View File

@ -0,0 +1,5 @@
// error-pattern:empty #[link_name] not allowed; use #[nolink].
#[link_name = ""]
native mod foo {
}

View File

@ -5,7 +5,7 @@ use std;
import str; import str;
import ctypes::*; import ctypes::*;
#[link_name = ""] #[nolink]
native mod libc { native mod libc {
fn write(fd: c_int, buf: *u8, nbyte: size_t); fn write(fd: c_int, buf: *u8, nbyte: size_t);
} }

View File

@ -118,7 +118,7 @@ fn test_fn() {
} }
#[abi = "cdecl"] #[abi = "cdecl"]
#[link_name = ""] #[nolink]
native mod test { native mod test {
fn do_gc(); fn do_gc();
fn unsupervise(); fn unsupervise();

View File

@ -2,7 +2,7 @@ use std;
import str; import str;
#[abi = "cdecl"] #[abi = "cdecl"]
#[link_name = ""] #[nolink]
native mod libc { native mod libc {
fn atol(x: str::sbuf) -> int; fn atol(x: str::sbuf) -> int;
fn atoll(x: str::sbuf) -> i64; fn atoll(x: str::sbuf) -> i64;

View File

@ -21,7 +21,7 @@ mod a1 {
mod a2 { mod a2 {
// | | | // | | |
#[abi = "cdecl"] #[abi = "cdecl"]
#[link_name = ""] #[nolink]
native mod b1 { native mod b1 {
// | | | // | | |
import a1::b2::*; import a1::b2::*;

View File

@ -3,7 +3,7 @@ use std;
import vec; import vec;
import str; import str;
#[link_name = ""] #[nolink]
#[abi = "cdecl"] #[abi = "cdecl"]
native mod libc { native mod libc {
#[link_name = "strlen"] #[link_name = "strlen"]

View File

@ -1,7 +1,7 @@
#[abi = "cdecl"] #[abi = "cdecl"]
#[link_name = ""] #[nolink]
native mod libc { native mod libc {
type file_handle; type file_handle;
} }

View File

@ -6,21 +6,21 @@ native mod rustrt {
} }
#[abi = "cdecl"] #[abi = "cdecl"]
#[link_name = ""] #[nolink]
native mod bar { } native mod bar { }
#[abi = "cdecl"] #[abi = "cdecl"]
#[link_name = ""] #[nolink]
native mod zed { } native mod zed { }
#[abi = "cdecl"] #[abi = "cdecl"]
#[link_name = ""] #[nolink]
native mod libc { native mod libc {
fn write(fd: int, buf: *u8, count: uint) -> int; fn write(fd: int, buf: *u8, count: uint) -> int;
} }
#[abi = "cdecl"] #[abi = "cdecl"]
#[link_name = ""] #[nolink]
native mod baz { } native mod baz { }
fn main(args: [str]) { } fn main(args: [str]) { }

View File

@ -5,7 +5,7 @@ use std;
import std::c_vec::*; import std::c_vec::*;
import ctypes::*; import ctypes::*;
#[link_name = ""] #[nolink]
#[abi = "cdecl"] #[abi = "cdecl"]
native mod libc { native mod libc {
fn malloc(n: size_t) -> *mutable u8; fn malloc(n: size_t) -> *mutable u8;