Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

array::rb_ary_new() Segfaults. #5

Closed
wshatch opened this issue Jul 31, 2016 · 4 comments
Closed

array::rb_ary_new() Segfaults. #5

wshatch opened this issue Jul 31, 2016 · 4 comments
Labels

Comments

@wshatch
Copy link

wshatch commented Jul 31, 2016

Originally d-unsed/ruru#33.

Currently, creating a new ruby array segfaults.

extern crate ruby_sys;
use ruby_sys::array;

fn main() {
  unsafe {
    let foo = array::rb_ary_new();
  }
}

Here's the result of cargo run --verbose for anyone curious

       Fresh libc v0.2.14
       Fresh ruby-sys v0.2.6
   Compiling test_ruru v0.1.0 (file:///Users/william/code/test_ruru)
     Running `rustc src/main.rs --crate-name test_ruru --crate-type bin -g --out-dir /Users/william/code/test_ruru/target/debug --emit=dep-info,link -L dependency=/Users/william/code/test_ruru/target/debug -L dependency=/Users/william/code/test_ruru/target/debug/deps --extern ruby_sys=/Users/william/code/test_ruru/target/debug/deps/libruby_sys-6948a09fc5cf7b2c.rlib -L /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib`
src/main.rs:6:9: 6:12 warning: unused variable: `foo`, #[warn(unused_variables)] on by default
src/main.rs:6     let foo = array::rb_ary_new();
                      ^~~
     Running `target/debug/test_ruru`
error: Process didn't exit successfully: `target/debug/test_ruru` (signal: 11, SIGSEGV: invalid memory reference)
@steveklabnik
Copy link
Owner

Hm, it's not obvious to me what this would be off the top of my head; I'll have to dig in but it might take me a few days, sorry :/

@wshatch
Copy link
Author

wshatch commented Jul 31, 2016

No problem, thanks for looking into it! Also, I realized I was using an old version of ruby (compiled without proper chruby version). Not sure if it helps, but here's cargo run --verbose with ruby 2.3.0.

   Compiling libc v0.2.14
     Running `rustc /Users/william/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.14/src/lib.rs --crate-name libc --crate-type lib -g --cfg feature=\"use_std\" --cfg feature=\"default\" -C metadata=1f3392fe1afd1313 -C extra-filename=-1f3392fe1afd1313 --out-dir /Users/william/code/test_ruru/target/debug/deps --emit=dep-info,link -L dependency=/Users/william/code/test_ruru/target/debug/deps -L dependency=/Users/william/code/test_ruru/target/debug/deps --cap-lints allow`
   Compiling ruby-sys v0.2.6
     Running `rustc /Users/william/.cargo/registry/src/github.com-1ecc6299db9ec823/ruby-sys-0.2.6/build.rs --crate-name build_script_build --crate-type bin -g --cfg feature=\"default\" --out-dir /Users/william/code/test_ruru/target/debug/build/ruby-sys-63f7f6f801106a0a --emit=dep-info,link -L dependency=/Users/william/code/test_ruru/target/debug/deps -L dependency=/Users/william/code/test_ruru/target/debug/deps --cap-lints allow`
     Running `/Users/william/code/test_ruru/target/debug/build/ruby-sys-63f7f6f801106a0a/build-script-build`
     Running `rustc /Users/william/.cargo/registry/src/github.com-1ecc6299db9ec823/ruby-sys-0.2.6/src/lib.rs --crate-name ruby_sys --crate-type lib -g --cfg feature=\"default\" -C metadata=6948a09fc5cf7b2c -C extra-filename=-6948a09fc5cf7b2c --out-dir /Users/william/code/test_ruru/target/debug/deps --emit=dep-info,link -L dependency=/Users/william/code/test_ruru/target/debug/deps -L dependency=/Users/william/code/test_ruru/target/debug/deps --extern libc=/Users/william/code/test_ruru/target/debug/deps/liblibc-1f3392fe1afd1313.rlib --cap-lints allow -L /Users/william/.rubies/ruby-2.3.0/lib -l dylib=ruby.2.3.0`
   Compiling test_ruru v0.1.0 (file:///Users/william/code/test_ruru)
     Running `rustc src/main.rs --crate-name test_ruru --crate-type bin -g --out-dir /Users/william/code/test_ruru/target/debug --emit=dep-info,link -L dependency=/Users/william/code/test_ruru/target/debug -L dependency=/Users/william/code/test_ruru/target/debug/deps --extern ruby_sys=/Users/william/code/test_ruru/target/debug/deps/libruby_sys-6948a09fc5cf7b2c.rlib -L /Users/william/.rubies/ruby-2.3.0/lib`
src/main.rs:6:9: 6:12 warning: unused variable: `foo`, #[warn(unused_variables)] on by default
src/main.rs:6     let foo = array::rb_ary_new();
                      ^~~
     Running `target/debug/test_ruru`
error: Process didn't exit successfully: `target/debug/test_ruru` (signal: 11, SIGSEGV: invalid memory reference)

@Ryman
Copy link

Ryman commented Jul 31, 2016

Doesn't this require initializing the vm first?

@wshatch
Copy link
Author

wshatch commented Aug 1, 2016

Yep, changed the code to

extern crate ruby_sys;
use ruby_sys::vm;
use ruby_sys::array;

fn main() {
  unsafe{
    vm::ruby_init();
    let foo = array::rb_ary_new();
  }
}

@wshatch wshatch closed this as completed Aug 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants