about summary refs log tree commit diff
path: root/src/rt/rust_builtin.cpp
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-03-08 20:44:37 -0500
committerNiko Matsakis <niko@alum.mit.edu>2013-03-13 16:59:37 -0400
commitefc7f82bc44926c864c52caca8764816ab9150dd (patch)
treec2d0cb8d8e8260c58e5b12d51218d935a83462d9 /src/rt/rust_builtin.cpp
parent4d8ddff52a60d3785052f1e0a231cb95c98fdc24 (diff)
downloadrust-efc7f82bc44926c864c52caca8764816ab9150dd.tar.gz
rust-efc7f82bc44926c864c52caca8764816ab9150dd.zip
Revamp foreign code not to consider the Rust modes. This requires
adjusting a few foreign functions that were declared with by-ref
mode.  This also allows us to remove by-val mode in the near future.

With copy mode, though, we have to be careful because Rust will implicitly pass
somethings by pointer but this may not be the C ABI rules.  For example, rust
will pass a struct Foo as a Foo*.  So I added some code into the adapters to
fix this (though the C ABI rules may put the pointer back, oh well).

This patch also includes a lint mode for the use of by-ref mode
in foreign functions as the semantics of this have changed.
Diffstat (limited to 'src/rt/rust_builtin.cpp')
-rw-r--r--src/rt/rust_builtin.cpp44
1 files changed, 38 insertions, 6 deletions
diff --git a/src/rt/rust_builtin.cpp b/src/rt/rust_builtin.cpp
index 8d83e2036b9..5a9de9735ba 100644
--- a/src/rt/rust_builtin.cpp
+++ b/src/rt/rust_builtin.cpp
@@ -434,18 +434,18 @@ rust_tzset() {
 }
 
 extern "C" CDECL void
-rust_gmtime(int64_t *sec, int32_t *nsec, rust_tm *timeptr) {
+rust_gmtime(int64_t sec, int32_t nsec, rust_tm *timeptr) {
     tm tm;
-    time_t s = *sec;
+    time_t s = sec;
     GMTIME(&s, &tm);
 
-    tm_to_rust_tm(&tm, timeptr, 0, "UTC", *nsec);
+    tm_to_rust_tm(&tm, timeptr, 0, "UTC", nsec);
 }
 
 extern "C" CDECL void
-rust_localtime(int64_t *sec, int32_t *nsec, rust_tm *timeptr) {
+rust_localtime(int64_t sec, int32_t nsec, rust_tm *timeptr) {
     tm tm;
-    time_t s = *sec;
+    time_t s = sec;
     LOCALTIME(&s, &tm);
 
 #if defined(__WIN32__)
@@ -457,7 +457,7 @@ rust_localtime(int64_t *sec, int32_t *nsec, rust_tm *timeptr) {
     const char *zone = tm.tm_zone;
 #endif
 
-    tm_to_rust_tm(&tm, timeptr, gmtoff, zone, *nsec);
+    tm_to_rust_tm(&tm, timeptr, gmtoff, zone, nsec);
 }
 
 extern "C" CDECL void
@@ -844,6 +844,38 @@ rust_readdir() {
 
 #endif
 
+// These functions are used in the unit tests for C ABI calls.
+
+extern "C" CDECL uint32_t
+rust_dbg_extern_identity_u32(uint32_t u) {
+    return u;
+}
+
+extern "C" CDECL uint64_t
+rust_dbg_extern_identity_u64(uint64_t u) {
+    return u;
+}
+
+struct TwoU64s {
+    uint64_t one;
+    uint64_t two;
+};
+
+extern "C" CDECL TwoU64s
+rust_dbg_extern_identity_TwoU64s(TwoU64s u) {
+    return u;
+}
+
+extern "C" CDECL double
+rust_dbg_extern_identity_double(double u) {
+    return u;
+}
+
+extern "C" CDECL char
+rust_dbg_extern_identity_u8(char u) {
+    return u;
+}
+
 
 //
 // Local Variables: