about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-09-25 12:17:20 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-09-25 14:56:17 -0700
commitf41c53667e3464ab324d4484e8601968f9eb313f (patch)
tree43ff99f52e85598fc9bd46817cdbf9759d147feb /src/libcore
parent267ab11cca722c1c83dcb6df949961390af787c1 (diff)
rustc: Fix calls to the logging function when the must_cast flag is true; stop using shape code for logging
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/logging.rs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/libcore/logging.rs b/src/libcore/logging.rs
index 6086b2edd7e..a9f63b57fa5 100644
--- a/src/libcore/logging.rs
+++ b/src/libcore/logging.rs
@@ -4,13 +4,16 @@
 #[forbid(deprecated_mode)];
 #[forbid(deprecated_pattern)];
 
-export console_on, console_off;
+use cast::transmute;
+
+export console_on, console_off, log_type;
 
 #[nolink]
 extern mod rustrt {
     #[legacy_exports];
     fn rust_log_console_on();
     fn rust_log_console_off();
+    fn rust_log_str(level: u32, string: *libc::c_char, size: libc::size_t);
 }
 
 /// Turns on logging to stdout globally
@@ -27,4 +30,17 @@ fn console_on() {
  */
 fn console_off() {
     rustrt::rust_log_console_off();
-}
\ No newline at end of file
+}
+
+#[cfg(notest)]
+#[lang="log_type"]
+pub fn log_type<T>(level: u32, object: &T) {
+    let bytes = do io::with_bytes_writer() |writer| {
+        repr::write_repr(writer, object);
+    };
+    unsafe {
+        let len = bytes.len() as libc::size_t;
+        rustrt::rust_log_str(level, transmute(vec::raw::to_ptr(bytes)), len);
+    }
+}
+