topazproject / topaz

A high performance ruby, written in RPython
topazruby.com
BSD 3-Clause "New" or "Revised" License
1k stars 84 forks source link

[WIP] Use ruby/{rubyspec|mspec} instead of rubyspec/{rubyspec|mspec} #845

Closed kachick closed 7 years ago

kachick commented 9 years ago

Fault from below example.

  it "expects a block with no arguments" do
    lambda { "hola".instance_eval }.should raise_error(ArgumentError)
  end

https://github.com/topazproject/topaz/pull/847 fixes the problem. I'll check after #847.

kachick commented 9 years ago

And here :cry:

  describe "on a Float" do
    it "has no effect since it is already frozen" do
      1.2.frozen?.should be_true
      1.2.freeze
    end
  end
$ bin/topaz -e '0.1.frozen?'
[1]    22920 segmentation fault  bin/topaz -e '0.1.frozen?'
alex commented 9 years ago

Traceback:

Traceback (most recent call last):
  File "/Users/alex_gaynor/.pyenv/versions/2.7.10/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/Users/alex_gaynor/.pyenv/versions/2.7.10/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/Users/alex_gaynor/projects/topaz/topaz/__main__.py", line 14, in <module>
    sys.exit(entry_point(sys.argv))
  File "topaz/main.py", line 66, in entry_point
    return _entry_point(space, argv)
  File "topaz/main.py", line 313, in _entry_point
    space.execute(source, filepath=path)
  File "topaz/objspace.py", line 317, in execute
    return self.execute_frame(frame, bc)
  File "topaz/objspace.py", line 341, in execute_frame
    return Interpreter().interpret(self, frame, bc)
  File "topaz/interpreter.py", line 46, in interpret
    pc = self._interpret(space, pc, frame, bytecode)
  File "topaz/interpreter.py", line 63, in _interpret
    pc = self.handle_bytecode(space, pc, frame, bytecode)
  File "topaz/interpreter.py", line 88, in handle_bytecode
    pc = self.run_instr(space, consts.BYTECODE_NAMES[instr], consts.BYTECODE_NUM_ARGS[instr], bytecode, frame, pc)
  File "topaz/interpreter.py", line 111, in run_instr
    res = method(space, bytecode, frame, pc, *args)
  File "topaz/interpreter.py", line 526, in SEND
    w_res = space.send(w_receiver, space.symbol_w(bytecode.consts_w[meth_idx]), args_w)
  File "topaz/objspace.py", line 619, in send
    return self._send_raw(name, raw_method, w_receiver, w_cls, args_w, block)
  File "topaz/objspace.py", line 636, in _send_raw
    return raw_method.call(self, w_receiver, args_w, block)
  File "topaz/objects/functionobject.py", line 81, in call
    w_res = self.func(w_receiver, space, args_w, block)
  File "topaz/gateway.py", line 80, in wrapper
    w_res = func(*args)
  File "topaz/modules/kernel.py", line 413, in getter_method
    return self.get_flag(space, getter)
AttributeError: 'W_FloatObject' object has no attribute 'get_flag'
alex commented 9 years ago

(Same thing happens on Fixnum's, not sure what the correct behavior is there)

alex commented 9 years ago

(I think the answer is that frozen? always returns True and freeze is a noop)

kachick commented 9 years ago

(I think the answer is that frozen? always returns True and freeze is a noop)

:+1: your :thought_balloon:

kachick commented 9 years ago

Ah... Topaz is compatible with Ruby 1.9.3. Fixnum and Float were frozen since Ruby 2.0. In Ruby 1.9.3, freeze should affect.

ruby -e 'p 1.frozen?; 1.freeze; p 1.frozen?'

ruby-1.9.3p551

false
true

ruby-2.2.3p173

true
true
alex commented 9 years ago

Ah, indeed (I tested with 2.x). I guess it needs logic similar to instance variables with the out-of-object storage.

On Sat, Oct 17, 2015 at 10:56 AM, Kenichi Kamiya notifications@github.com wrote:

Ah... Topaz is compatible with Ruby 1.9.3. Fixnum and Float were frozen since Ruby 2.0. In Ruby 1.9.3, freeze should affect.

ruby -e 'p 1.frozen?; 1.freeze; p 1.frozen?'

  • ruby-1.9.3p551

false true

  • ruby-2.2.3p173

true true

— Reply to this email directly or view it on GitHub https://github.com/topazproject/topaz/pull/845#issuecomment-148921669.

"I disapprove of what you say, but I will defend to the death your right to say it." -- Evelyn Beatrice Hall (summarizing Voltaire) "The people's good is the highest law." -- Cicero GPG Key fingerprint: 125F 5C67 DFE9 4084

kachick commented 9 years ago

848 fixes frozen? segfault.

And below examples segfaults :crying_cat_face:

it "raises a TypeError when passed nil" do
  lambda { sleep(nil)   }.should raise_error(TypeError)
end

it "raises a TypeError when passed a String" do
  lambda { sleep('2')   }.should raise_error(TypeError)
end

849 fixes the sleep segfault

kachick commented 9 years ago

And below examples segfaults.

it "closes file descriptors >= 3 in the child process" do
  IO.pipe do |r, w|
    begin
      pid = @object.spawn(ruby_cmd(""), @options)
      w.close
      lambda { r.read_nonblock(1) }.should raise_error(EOFError)
    ensure
      Process.kill(:TERM, pid)
      Process.wait(pid)
    end
  end
end

it "closes file descriptors >= 3 in the child process because they are set close_on_exec by default" do
  IO.pipe do |r, w|
    begin
      pid = @object.spawn(ruby_cmd(""), @options)
      w.close
      lambda { r.read_nonblock(1) }.should raise_error(EOFError)
    ensure
      Process.kill(:TERM, pid)
      Process.wait(pid)
    end
  end
end

850 guards the Process.kill with nil PID

kachick commented 9 years ago

And this

it "raises a TypeError on an uninitialized Regexp" do
  lambda { Regexp.allocate.match('foo') }.should raise_error(TypeError)
end

851 guards Regexp#match on uninitialized regex from segfault.

kachick commented 9 years ago
describe "String#sub with pattern and without replacement and block" do
  it "raises a ArgumentError" do
    lambda { "abca".sub(/a/) }.should raise_error(ArgumentError)
  end
end

This raises Fatal RPython error: NotImplementedError.

852 will raise an ArgumentError instead.