Skip to content

Instantly share code, notes, and snippets.

View olsonjeffery's full-sized avatar
💭
:3

Jeff Olson olsonjeffery

💭
:3
View GitHub Profile
unsafe fn get_list(p: &Path) -> ~[~str] {
use libc::{DIR, dirent_t};
use libc::{opendir, readdir, closedir};
extern mod rustrt {
unsafe fn rust_list_dir_val(ptr: *dirent_t)
-> *libc::c_char;
}
let input = p.to_str();
let mut strings = ~[];
let input_ptr = ::cast::transmute(&input[0]);
@olsonjeffery
olsonjeffery / gist:5145243
Created March 12, 2013 17:56
outstanding uses of ->malloc in src/rt
jeff@mbp:~/src/rust/build$ find ../src/rt/ -name '*.cpp' -exec grep '.->malloc' -H -n {} \;
../src/rt/rust_builtin.cpp:98: rust_rng *rng = (rust_rng *) task->malloc(sizeof(rust_rng),
../src/rt/rust_stack.cpp:61: stk_seg *stk = (stk_seg *)region->malloc(total_sz, "stack");
../src/rt/rust_stack.cpp:78: stk_seg *stk = (stk_seg *)exchange->malloc(total_sz);
../src/rt/rust_uv.cpp:40: void* ptr = rust_get_current_task()->kernel->malloc(size, tag);
../src/rt/boxed_region.cpp:22: (rust_opaque_box*)backing_region->malloc(total_size, "@");
@olsonjeffery
olsonjeffery / gist:5961159
Last active December 19, 2015 13:19
notes for newsched work
https://github.com/mozilla/rust/issues/6435
14:05 < ecr> olsonjeffery: it'd involve
- designing an RtioTimer interface in std::rt::rtio.rs,
- implementing Timer in std::rt::io on top of it,
- implementing RtioTimer for TimerWatcher in std::rt::uv::uvio.rs
14:09 < ecr> olsonjeffery: and you might want to look at the libuv timer interface as well to see if there's any additional functionality that still needs bindings (which would
give you the bottom layer of newsched I/O in std::rt::uv::uvll.rs).
14:12 <ecr> if I'm not responding in IRC, try email ([email protected]).
@olsonjeffery
olsonjeffery / newsched_timer.rs
Last active December 20, 2015 00:39
rustc spew
jeff@mbp:~/src/sandbox$ rustc newsched_timer.rs
newsched_timer.rs:4:4: 4:19 warning: unused import [-W unused-imports (default)]
newsched_timer.rs:4 use std::option::*;
^~~~~~~~~~~~~~~
error: linking with `cc` failed with code 1
note: cc arguments: -L/home/jeff/lib/rustc/x86_64-unknown-linux-gnu/lib -m64 -o newsched_timer newsched_timer.o -L/home/jeff/lib/rustc/x86_64-unknown-linux-gnu/lib -lstd-6c65cf4b443341b1-0.8-pre -lrustrt -lrt -lpthread -lrt -ldl -lm -lmorestack -lrustrt -Wl,-rpath,$ORIGIN/../../lib/rustc/x86_64-unknown-linux-gnu/lib -Wl,-rpath,/home/jeff/lib/rustc/x86_64-unknown-linux-gnu/lib
note: newsched_timer.o: In function `main::_b34d73d589378df4::_0$x2e0':
newsched_timer.rc:(.text+0x69): undefined reference to `rt::io::timer::__extensions__::meth_29117::init::_5139afb69d2758a::_0$x2e8$x2dpre'
collect2: error: ld returned 1 exit status
jeff@mbp:~/src/rust/build$ make check-stage1-extra
cfg: build triple x86_64-unknown-linux-gnu
cfg: host triples x86_64-unknown-linux-gnu
cfg: target triples x86_64-unknown-linux-gnu
cfg: host for x86_64-unknown-linux-gnu is x86_64
cfg: os for x86_64-unknown-linux-gnu is unknown-linux-gnu
cfg: using gcc
cfg: no pandoc found, omitting docs
cfg: no llnextgen found, omitting grammar-verification
cfg: no pandoc found, omitting library doc build
@olsonjeffery
olsonjeffery / gist:6135919
Last active December 20, 2015 13:08
~object issue?
/home/jeff/src/rust/src/libstd/rt/uv/uvio.rs:312:27: 312:77 error: failed to find an implementation of trait ~rt::rtaio::RtaioTcpStreamAsync:Send for rt::uv::uvaio::UvTcpStreamAsync
/home/jeff/src/rust/src/libstd/rt/uv/uvio.rs:312 Ok(_) => cb(Ok(~UvTcpStreamAsync(watcher) as ~RtaioTcpStreamAsync)),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
use std::io::println;
use std::result::{Result, Ok};
use std::task::{spawn};
pub struct Foo(int);
pub trait Bar {
fn baz(&self);
}
/// The Promise type. Can provide the value of a Future
pub struct Promise<A> (ChanOne<A>);
impl<A:Send> Promise<A> {
pub fn fulfill(&mut self, v: A) {
(*self).send(v);
}
}
pub fn connect(addr: IpAddr) -> Future<Option<TcpStreamAsync>> {
unsafe {
let (ret_future, ret_promise) = pair();
rtdebug!("borrowing io to connect");
let io = Local::unsafe_borrow::<IoFactoryObject>();
rtdebug!("about to connect");
let p_cell = Cell::new(ret_promise);
(*io).tcp_connect_async(addr,
|connect_result| {
let ret_promise = p_cell.take();
Program received signal SIGABRT, Aborted.
[Switching to Thread 0x7fffe4cc3700 (LWP 7875)]
0x00007ffff617e425 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0 0x00007ffff617e425 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1 0x00007ffff6181b8b in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2 0x00007ffff705d15c in upcall_call_shim_on_c_stack (args=0x7fffe4cc2008, fn_ptr=0x698010 <abort__c_stack_shim>) at /home/jeff/src/rust/src/rt/rust_upcall.cpp:78
#3 0x000000000055f581 in libc::funcs::c95::stdlib::abort::_3951cf1a412d1f90::_0$x2e8$x2dpre ()
#4 0x00000000005086c0 in rt::util::abort::_0cb6664c2aeff9f::_0$x2e8$x2dpre ()
#5 0x000000000078300c in rt::aio::net::tcp::__extensions__::connect::anon::expr_fn_62736 ()