Feature #6724
closedwaaaaaaant! (ISeq.load)
Description
GIMME GIMME GIMME! waaaaaant... We don't need a verifier. User responsibility... etc etc.
Can I commit this??? PLEEEEEEASE???
Index: iseq.c¶
--- iseq.c (revision 36369)
+++ iseq.c (working copy)
@@ -1585,9 +1585,7 @@
rb_define_method(rb_cISeq, "marshal_load", iseq_marshal_load, 1);
#endif
- /* disable this feature because there is no verifier. */
- /* rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1); */
- (void)iseq_s_load;
-
rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1);
rb_define_singleton_method(rb_cISeq, "compile", iseq_s_compile, -1);
rb_define_singleton_method(rb_cISeq, "new", iseq_s_compile, -1);
Files
Updated by shyouhei (Shyouhei Urabe) over 12 years ago
I really like this feature. I have this exact patch applied to my local ruby binary.
But having used it a while, I found that ISeq loading is not what an application programmer would try. It is rather a tool that a library author thirst for. So I doubt a user is really the one who should be pushed the responsibility.
Updated by ko1 (Koichi Sasada) over 12 years ago
(2012/07/12 8:58), zenspider (Ryan Davis) wrote:
GIMME GIMME GIMME! waaaaaant... We don't need a verifier. User responsibility... etc etc.
Without a verifier, it is easy to cause SEGV or critical trouble. Matz
prohibits such feature.
You can use it from C ext.
VALUE rb_iseq_load(VALUE data, VALUE parent, VALUE opt);
... ah, the signature of this function is not exposed by GCC's
visibility control. I'll make it public (unofficial).
Toward 2.0, I'll make verifier if I have a spare time (but not high
priority).
--
// SASADA Koichi at atdot dot net
Updated by ko1 (Koichi Sasada) over 12 years ago
(2012/07/12 12:20), SASADA Koichi wrote:
... ah, the signature of this function is not exposed by GCC's
visibility control. I'll make it public (unofficial).
nobu pointed out that this function is already public. I misunderstood.
Thanks,
Koichi
--
// SASADA Koichi at atdot dot net
Updated by nobu (Nobuyoshi Nakada) over 12 years ago
- Tracker changed from Bug to Feature
Updated by nobu (Nobuyoshi Nakada) over 12 years ago
- Tracker changed from Feature to Bug
- Subject changed from waaaaaaant! ( to waaaaaaant! (ISeq.load)
Updated by nobu (Nobuyoshi Nakada) over 12 years ago
- Tracker changed from Bug to Feature
Updated by mame (Yusuke Endoh) over 12 years ago
- Status changed from Open to Assigned
Updated by Anonymous over 12 years ago
On Thu, Jul 12, 2012 at 08:58:36AM +0900, zenspider (Ryan Davis) wrote:
Issue #6724 has been reported by zenspider (Ryan Davis).
Bug #6724: waaaaaaant! (
https://bugs.ruby-lang.org/issues/6724Author: zenspider (Ryan Davis)
Status: Open
Priority: Normal
Assignee: ko1 (Koichi Sasada)
Category:
Target version:
ruby -v: 2.xGIMME GIMME GIMME! waaaaaant... We don't need a verifier. User responsibility... etc etc.
Can I commit this??? PLEEEEEEASE???
Index: iseq.c¶
--- iseq.c (revision 36369)
+++ iseq.c (working copy)
@@ -1585,9 +1585,7 @@
rb_define_method(rb_cISeq, "marshal_load", iseq_marshal_load, 1);
#endif
- /* disable this feature because there is no verifier. */
- /* rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1); */
- (void)iseq_s_load;
rb_define_singleton_method(rb_cISeq, "load", iseq_s_load, -1);
rb_define_singleton_method(rb_cISeq, "compile", iseq_s_compile, -1);
rb_define_singleton_method(rb_cISeq, "new", iseq_s_compile, -1);
require 'dl'
require 'fiddle'
require 'minitest/autorun'
class RubyVM
class InstructionSequence
address = DL::Handle::DEFAULT['rb_iseq_load']
func = Fiddle::Function.new(address, [DL::TYPE_VOIDP] * 3, DL::TYPE_VOIDP)
define_singleton_method(:load) do |data, parent = nil, opt = nil|
func.call(DL.dlwrap(data), parent, opt).to_value
end
end
end
class TestISeq < MiniTest::Unit::TestCase
def test_load
ins = RubyVM::InstructionSequence.new '5 + 10'
other = RubyVM::InstructionSequence.load ins.to_a
assert_equal ins.eval, other.eval
end
end
<3<3<3<3
--
Aaron Patterson
http://tenderlovemaking.com/
Updated by luislavena (Luis Lavena) over 12 years ago
On Tue, Jul 17, 2012 at 6:27 PM, Aaron Patterson
tenderlove@ruby-lang.org wrote:
class RubyVM class InstructionSequence address = DL::Handle::DEFAULT['rb_iseq_load'] func = Fiddle::Function.new(address, [DL::TYPE_VOIDP] * 3, DL::TYPE_VOIDP) define_singleton_method(:load) do |data, parent = nil, opt = nil| func.call(DL.dlwrap(data), parent, opt).to_value end end end
For some reason ::DEFAULT doesn't work on windows, so a bit of tweak:
require 'rbconfig'
require 'dl'
require 'fiddle'
require 'minitest/autorun'
class RubyVM
class InstructionSequence
handle = DL::Handle.new(RbConfig::CONFIG["RUBY_SO_NAME"])
address = handle['rb_iseq_load']
func = Fiddle::Function.new(address, [DL::TYPE_VOIDP] * 3,
DL::TYPE_VOIDP)
define_singleton_method(:load) do |data, parent = nil, opt = nil|
func.call(DL.dlwrap(data), parent, opt).to_value
end
end
end
class TestISeq < MiniTest::Unit::TestCase
def test_load
ins = RubyVM::InstructionSequence.new '5 + 10'
other = RubyVM::InstructionSequence.load ins.to_a
assert_equal ins.eval, other.eval
end
end
That or simply: DL::Handle.new (no argument) which will resolve to libruby DLL.
--
Luis Lavena
AREA 17
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry
Updated by Anonymous over 12 years ago
On Wed, Jul 18, 2012 at 09:13:45AM +0900, Luis Lavena wrote:
On Tue, Jul 17, 2012 at 6:27 PM, Aaron Patterson
tenderlove@ruby-lang.org wrote:class RubyVM class InstructionSequence address = DL::Handle::DEFAULT['rb_iseq_load'] func = Fiddle::Function.new(address, [DL::TYPE_VOIDP] * 3, DL::TYPE_VOIDP) define_singleton_method(:load) do |data, parent = nil, opt = nil| func.call(DL.dlwrap(data), parent, opt).to_value end end end
For some reason ::DEFAULT doesn't work on windows, so a bit of tweak:
require 'rbconfig' require 'dl' require 'fiddle' require 'minitest/autorun' class RubyVM class InstructionSequence handle = DL::Handle.new(RbConfig::CONFIG["RUBY_SO_NAME"]) address = handle['rb_iseq_load'] func = Fiddle::Function.new(address, [DL::TYPE_VOIDP] * 3,
DL::TYPE_VOIDP)
define_singleton_method(:load) do |data, parent = nil, opt = nil| func.call(DL.dlwrap(data), parent, opt).to_value end end end class TestISeq < MiniTest::Unit::TestCase def test_load ins = RubyVM::InstructionSequence.new '5 + 10' other = RubyVM::InstructionSequence.load ins.to_a assert_equal ins.eval, other.eval end end
That or simply: DL::Handle.new (no argument) which will resolve to libruby DLL.
Glad we could get this working on windows! ;-)
As a side note, maybe we should fix DEFAULT? Any ideas what's wrong on
windows?
--
Aaron Patterson
http://tenderlovemaking.com/
Updated by luislavena (Luis Lavena) over 12 years ago
On Wed, Jul 18, 2012 at 3:45 PM, Aaron Patterson
tenderlove@ruby-lang.org wrote:
Glad we could get this working on windows! ;-)
:-)
As a side note, maybe we should fix DEFAULT? Any ideas what's wrong on
windows?
I need to investigate it, there is no test that exercises DEFAULT or
NEXT behaviors as far I can see. But I think that is a separate
discussion ;-)
--
Luis Lavena
AREA 17
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry
Updated by ko1 (Koichi Sasada) over 12 years ago
- Status changed from Assigned to Closed