~tim/scheme-vm

c41f0ae39fca3ab59b794143dadd7facb0fb091c — Tim Morgan 4 years ago e071223
Deep dup AST until I can figure out the bug

There is a use-after-free error I believe.
3 files changed, 16 insertions(+), 4 deletions(-)

M parser.rb
M spec/parser_spec.rb
M src/lib.rs
M parser.rb => parser.rb +13 -1
@@ 20,7 20,19 @@ class Parser
  end

  def parse
    raise 'This method is implemented in Rust.'
    # FIXME: there is a use-after-free error somewhere in my Rust code.
    # I'm deep duping the AST until I can learn how to valgrind. :-)
    deep_dup(parse_native)
  end

  private

  def deep_dup(ary)
    if ary.respond_to?(:map)
      ary.map { |i| deep_dup(i) }
    else
      ary.dup
    end
  end
end


M spec/parser_spec.rb => spec/parser_spec.rb +1 -1
@@ 1,6 1,6 @@
require_relative './spec_helper'

fdescribe Parser do
describe Parser do
  describe '#parse' do
    subject do
      described_class.new(<<-END)

M src/lib.rs => src/lib.rs +2 -2
@@ 13,7 13,7 @@ mod lisp {
    include!(concat!(env!("OUT_DIR"), "/lisp.rs"));
}

fn parse(rself: Value) -> Value {
fn parse_native(rself: Value) -> Value {
    let program_str = rbstr2str!(&rb::ivar_get(&rself, "@code"));
    match lisp::program(&program_str) {
        Ok(ast) => ast,


@@ 36,5 36,5 @@ fn parse(rself: Value) -> Value {
#[no_mangle]
pub extern fn init_parser() {
    let c_parser = rb::const_get("Parser", &RB_NIL);
    rb::define_method(&c_parser, "parse", parse as CallbackPtr, 0);
    rb::define_method(&c_parser, "parse_native", parse_native as CallbackPtr, 0);
}