]> git.lizzy.rs Git - rust.git/commitdiff
work around bug when calling c-stack-cdecl fns from outside crate
authorNiko Matsakis <niko@alum.mit.edu>
Fri, 21 Oct 2011 19:14:01 +0000 (12:14 -0700)
committerBrian Anderson <banderson@mozilla.com>
Mon, 24 Oct 2011 23:06:17 +0000 (16:06 -0700)
In the main test, I call the wrapper instead of the native fn, as intended.
I also added an xfail-test that exercises the broken code path.  Will
file a bug.

Description of the broken code path:

The code path is that when we look up the external identifier we go through
trans_external_path() ->  type_of_ty_param_kinds_and_ty() ->
type_of_fn_from_ty() -> type_of_fn(), and type_of_fn() adds a lot of external
parameters. Problem is, I guess, that we don't pass the native ABI (or even the
fact that it's a native function!), just the types and kinds of the parameters.

src/test/run-pass/invoke-external-native.rs [new file with mode: 0644]
src/test/stdtest/sys.rs

diff --git a/src/test/run-pass/invoke-external-native.rs b/src/test/run-pass/invoke-external-native.rs
new file mode 100644 (file)
index 0000000..6234685
--- /dev/null
@@ -0,0 +1,11 @@
+// xfail-test
+
+import std::sys;
+
+// The purpose of this test is to check that we can
+// successfully (and safely) invoke external, c-stack-cdecl
+// functions from outside the crate.
+
+fn main() {
+    let foo = sys::rustrt::last_os_error();
+}
\ No newline at end of file
index 547adba7bf56e9f34ab592087855a0b4fbd373a3..6f766e9ee6bb8f90da43f3a541a0693e3dacb119 100644 (file)
@@ -1,4 +1,6 @@
 import std::sys;
 
 #[test]
-fn last_os_error() unsafe { log sys::rustrt::last_os_error(); }
+fn last_os_error() {
+    log sys::last_os_error();
+}