Skip to content

Instantly share code, notes, and snippets.

The Rust compiler 0.1 is unleashed
Today Mozilla and the Rust community are releasing version 0.1 of the Rust compiler
and associated tools.
Rust is a strongly-typed systems programming language in the C family with a focus
on memory safety and concurrency. This is the initial release of the compiler after
a multi-year development cycle focusing on self-hosting, implementation of the major
features, and solidifying the syntax.
The Rust compiler 0.1 is unleashed
Today Mozilla and the Rust community are releasing version 0.1 of the Rust compiler
and associated tools.
Rust is a strongly-typed systems programming language with a focus on memory safety
and concurrency. This is the initial release of the compiler after a multi-year
development cycle focusing on self-hosting, implementation of major features, and
solidifying the syntax.
connect ("host", port) -> fileno
notify_on _read (channel, fileno)
read (fileno) -> "data"
notify_on _write (channel, fileno)
write (fileno, "data") -> bytes_written
close (fileno)
notify_on _timeout (channel, millis)
@brson
brson / gist:1679583
Created January 25, 2012 23:14 — forked from nikomatsakis/gist:1679581
etags-select
;;; etags-select.el --- Select from multiple tags
;;; From http://www.emacswiki.org/emacs/download/etags-select.el
;; Copyright (C) 2007 Scott Frazer
;; Author: Scott Frazer <[email protected]>
;; Maintainer: Scott Frazer <[email protected]>
;; Created: 07 Jun 2007
;; Version: 1.13
;; Keywords: etags tags tag select
Analysis:
https://github.com/mozilla/rust/issues/1702
https://github.com/mozilla/rust/issues/1634
https://github.com/mozilla/rust/issues/1630
https://github.com/mozilla/rust/issues/1570
Frontend:
https://github.com/mozilla/rust/issues/1633
https://github.com/mozilla/rust/issues/1655
https://github.com/mozilla/rust/issues/1654
==20081== Thread 4:
==20081== Conditional jump or move depends on uninitialised value(s)
==20081== at 0x659B3AF: js::GlobalObject::initFunctionAndObjectClasses(JSContext*) (jsval.h:803)
==20081== by 0x659BB82: js::GlobalObject::initStandardClasses(JSContext*) (GlobalObject.cpp:304)
==20081== by 0x643952C: JS_InitStandardClasses (jsapi.cpp:1738)
==20081== by 0x53479B8: JS_InitStandardClasses__c_stack_shim (in /home/brian/dev/rust-spidermonkey/libspidermonkey-abc7bdbd9528371c-0.1.so)
==20081== by 0x558A4C8: ??? (in /home/brian/dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so)
==20081== by 0x708A40F: ???
==20081== by 0x7196E4F: ???
==20081== by 0x57BE807: ??? (in /home/brian/dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustc/x86_64-unknown-linux-gnu/lib/librustrt.so)
Rust functions that can be called from C
We have a lot of scenarios now where people creating bindings want to be able to provide a callback that a C function can call. The current solution is to write a native C function that uses some unspecified internal APIs to send a message back to Rust code. The ideal solution involves writing no C code.
Here is a minimal solution for creating functions in Rust that can be called from C code. The gist is: 1) we have yet another kind of function declaration, 2) this function cannot be called from Rust code, 3) it's value can be taken as an opaque unsafe pointer, 4) it bakes in the stack switching magic and adapts from the C ABI to the Rust ABI.
Declarations of C-to-Rust (crust) functions:
```
crust fn callback(a: *whatever) {
brian@axis:~/dev/rust2/build$ RUST_LOG=rustc=0,::rt::backtrace x86_64-unknown-linux-gnu/stage1/bin/rustc ../src/test/run-pass/test.rs
rust: "parse_buf(): buf is empty"
rust: upcall fail 'explicit failure', ../src/libcore/u64.rs:118
/home/brian/dev/rust2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustrt.so(_ZN9rust_task4failEv+0x25)[0x7f101d828545]
/home/brian/dev/rust2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustrt.so(+0x2b5a9)[0x7f101d83c5a9]
/home/brian/dev/rust2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustrt.so(upcall_fail+0x39)[0x7f101d82af39]
/home/brian/dev/rust2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/libcore-14bd852465126fe7-0.1.so(_ZN3u648from_str17_2c4beb2ad58728b6E+0x291)[0x7f101e755241]
/home/brian/dev/rust2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc-4171d83aef249987-0.1.so(_ZN6syntax5parse5lexer11scan_number17_5b1df691a4585079E+0x131f)[0x7f101dd7ceff]
/home/brian/dev/rust2/build/x86_64-unknown-linux-gnu/stage1/bin/../lib/librustc-4171d83aef
use std;
import std::dbg::refcount;
type foo<T> = {
mutable f: option<@T>
fn from_cstrs(cstrs: *str::sbuf, n: uint) -> [str] unsafe {
let curr = cstrs;
let result = [];
let i = 0u;
while i < n {
result += [str::from_cstr(*curr)];
curr = ptr::offset(cstrs, i);
i += 1u;
}
ret result;