Revision: 785 http://trac.macosforge.org/projects/ruby/changeset/785 Author: eloy.de.enige@gmail.com Date: 2009-01-13 05:22:19 -0800 (Tue, 13 Jan 2009) Log Message: ----------- Reverted speed improvements to syck (YAML) around rb_str_split2 which causes seg faults. Isolated bug in known_bugs_in_c.c Modified Paths: -------------- MacRuby/trunk/ext/syck/rubyext.c MacRuby/trunk/test-macruby/known_bugs.rb Added Paths: ----------- MacRuby/trunk/test-macruby/extconf.rb MacRuby/trunk/test-macruby/known_bugs_in_c.c Modified: MacRuby/trunk/ext/syck/rubyext.c =================================================================== --- MacRuby/trunk/ext/syck/rubyext.c 2009-01-10 05:24:32 UTC (rev 784) +++ MacRuby/trunk/ext/syck/rubyext.c 2009-01-13 13:22:19 UTC (rev 785) @@ -1028,7 +1028,10 @@ syck_const_find(VALUE const_name) { VALUE tclass = rb_cObject; - VALUE tparts = rb_str_split2( const_name, oDoubleColon ); + // This speed improvement currently leads to a SEGV, + // See known_bugs: test_accessing_an_array_created_via_rb_str_split2 + // VALUE tparts = rb_str_split2( const_name, oDoubleColon ); + VALUE tparts = rb_str_split( const_name, "::" ); int i = 0, count; for ( i = 0, count = RARRAY_LEN(tparts); i < count; i++ ) { VALUE tpart = rb_to_id( rb_ary_entry( tparts, i ) ); @@ -1063,7 +1066,10 @@ if ( NIL_P( target_class ) ) { VALUE subclass_parts = rb_ary_new(); - VALUE parts = rb_str_split2( type, oColon ); + // This speed improvement currently leads to a SEGV, + // See known_bugs: test_accessing_an_array_created_via_rb_str_split2 + //VALUE parts = rb_str_split2( type, oColon ); + VALUE parts = rb_str_split( type, ":" ); while ( RARRAY_LEN(parts) > 1 ) { Added: MacRuby/trunk/test-macruby/extconf.rb =================================================================== --- MacRuby/trunk/test-macruby/extconf.rb (rev 0) +++ MacRuby/trunk/test-macruby/extconf.rb 2009-01-13 13:22:19 UTC (rev 785) @@ -0,0 +1,2 @@ +require "mkmf" +create_makefile("known_bugs_in_c") \ No newline at end of file Modified: MacRuby/trunk/test-macruby/known_bugs.rb =================================================================== --- MacRuby/trunk/test-macruby/known_bugs.rb 2009-01-10 05:24:32 UTC (rev 784) +++ MacRuby/trunk/test-macruby/known_bugs.rb 2009-01-13 13:22:19 UTC (rev 785) @@ -1,51 +1,53 @@ #!/usr/local/bin/macruby require "test/unit" -framework 'Cocoa' +#framework 'Cocoa' module KnownBugs - class TestYaml < Test::Unit::TestCase - require "yaml" - class IDontWantToCrash; end - - def test_load_non_native_classes - data = YAML.dump(IDontWantToCrash.new) - assert_nothing_raised { YAML.load(data) } + class TestBugsInC < Test::Unit::TestCase + def setup + dir = File.expand_path('../', __FILE__) + exit(1) unless system("cd #{dir} && macruby extconf.rb && make") + require File.join(dir, 'known_bugs_in_c') end + + def test_accessing_an_array_created_via_rb_str_split2 + KnownBugsInC.test_rb_str_split2("foo:bar", ":") + end end - + class TestKernel < Test::Unit::TestCase module ::Kernel private def is_callable?; true end end - + module ::Kernel def should_be_callable?; true end private :should_be_callable? end - + def test_kernel_methods_made_private_with_keyword assert is_callable? # works end - + def test_kernel_methods_made_private_with_class_method assert should_be_callable? # causes endless loop end end - + class TestDuplicatingInstances < Test::Unit::TestCase # Works - + class Foo; end - + def test_dup_on_an_instance_of_a_pure_ruby_class obj = Foo.new assert_not_equal obj, obj.dup.object_id end - + # Fails - + def test_dup_on_an_instance_of_Object obj = Object.new assert_nothing_raised(NSException) do @@ -53,75 +55,75 @@ assert_not_equal obj.object_id, obj.dup.object_id end end - + def test_dup_on_a_class_instance assert_not_equal Foo.object_id, Foo.dup.object_id end end - + class TestStringFormatting < Test::Unit::TestCase def test_formatting_with_a_Bignum assert_nothing_raised(RangeError) { "%d" % 68727360256 } end end - + class TestIncludingModuleInClass < Test::Unit::TestCase module ClassInstanceMethod def a_class_instance_method; end end - + class ::Class include ClassInstanceMethod end - + def test_class_should_respond_to_methods_included_in_Class assert Class.new.respond_to?(:a_class_instance_method) end end - + class TestIncludingModuleInModule < Test::Unit::TestCase module ModuleInstanceMethod def a_module_instance_method; end end - + class ::Module include ModuleInstanceMethod end - + def test_module_should_respond_to_methods_included_in_Module assert Module.new.respond_to?(:a_module_instance_method) end end - + class TestConstantLookup < Test::Unit::TestCase module Namespace NamespacedConstant = nil class NamespacedClass; end end - + def test_should_not_find_namespaced_constants # works assert_raise(NameError) { NamespacedConstant } end - + def test_should_not_find_namespaced_classes # fails assert_raise(NameError) { NamespacedClass } end end - + class TestRespondTo < Test::Unit::TestCase class RespondTo def respond_to?(method, hidden = false) super end end - + def test_super_implementation assert_nothing_raised(SystemStackError) do RespondTo.new.respond_to?(:object_id) end end end - + class TestBooleanComparison < Test::Unit::TestCase def test_NSCFBoolean_comparison_to_Ruby_bool assert_equal true, NSNumber.numberWithBool(true) Added: MacRuby/trunk/test-macruby/known_bugs_in_c.c =================================================================== --- MacRuby/trunk/test-macruby/known_bugs_in_c.c (rev 0) +++ MacRuby/trunk/test-macruby/known_bugs_in_c.c 2009-01-13 13:22:19 UTC (rev 785) @@ -0,0 +1,17 @@ +#include "ruby/ruby.h" + +static VALUE +known_bug_rb_str_split2(VALUE recv, VALUE str, VALUE sep) +{ + VALUE parts = rb_str_split2(str, sep); + // Accessing the array goes wrong, has it been collected? + // Because at the end of rb_str_split_m the `result' _is_ the array as expected… + return rb_ary_entry(parts, 0); +} + +void Init_known_bugs_in_c() { + VALUE cKnownBugsInC; + + cKnownBugsInC = rb_define_module("KnownBugsInC"); + rb_define_module_function(cKnownBugsInC, "test_rb_str_split2", known_bug_rb_str_split2, 2); +} \ No newline at end of file