[前][次][番号順一覧][スレッド一覧]

ruby-changes:34658

From: usa <ko1@a...>
Date: Mon, 7 Jul 2014 12:47:38 +0900 (JST)
Subject: [ruby-changes:34658] usa:r46741 (ruby_2_0_0): merge revision(s) 45462, 45463, 45466: [Backport #9684]

usa	2014-07-07 12:47:31 +0900 (Mon, 07 Jul 2014)

  New Revision: 46741

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46741

  Log:
    merge revision(s) 45462,45463,45466: [Backport #9684]
    
    * struct.c (not_a_member): extract name error and use same error
      messages.  based on the patch by Marcus Stollsteimer <sto.mar AT
      web.de> at [ruby-core:61721].  [Bug #9684]

  Added directories:
    branches/ruby_2_0_0/ext/-test-/struct/
    branches/ruby_2_0_0/test/-ext-/struct/
  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/struct.c
    branches/ruby_2_0_0/test/-ext-/struct/test_member.rb
    branches/ruby_2_0_0/version.h
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 46740)
+++ ruby_2_0_0/ChangeLog	(revision 46741)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Mon Jul  7 12:46:28 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* struct.c (not_a_member): extract name error and use same error
+	  messages.  based on the patch by Marcus Stollsteimer <sto.mar AT
+	  web.de> at [ruby-core:61721].  [Bug #9684]
+
 Mon Jul  7 12:39:34 2014  Nobuyoshi Nakada  <nobu@r...>
 
 	* io.c (read_all): truncate the buffer before appending read data,
Index: ruby_2_0_0/struct.c
===================================================================
--- ruby_2_0_0/struct.c	(revision 46740)
+++ ruby_2_0_0/struct.c	(revision 46741)
@@ -87,6 +87,13 @@ rb_struct_members_m(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/struct.c#L87
     return rb_struct_s_members_m(rb_obj_class(obj));
 }
 
+NORETURN(static void not_a_member(ID id));
+static void
+not_a_member(ID id)
+{
+    rb_name_error(id, "`%"PRIsVALUE"' is not a struct member", QUOTE_ID(id));
+}
+
 VALUE
 rb_struct_getmember(VALUE obj, ID id)
 {
@@ -103,7 +110,7 @@ rb_struct_getmember(VALUE obj, ID id) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/struct.c#L110
 	    return ptr[i];
 	}
     }
-    rb_name_error(id, "%s is not struct member", rb_id2name(id));
+    not_a_member(id);
 
     UNREACHABLE;
 }
@@ -153,6 +160,7 @@ rb_struct_set(VALUE obj, VALUE val) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/struct.c#L160
 {
     VALUE members, slot, *ptr, *ptr_members;
     long i, len;
+    ID fid = rb_frame_this_func();
 
     members = rb_struct_members(obj);
     ptr_members = RARRAY_PTR(members);
@@ -161,12 +169,11 @@ rb_struct_set(VALUE obj, VALUE val) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/struct.c#L169
     ptr = RSTRUCT_PTR(obj);
     for (i=0; i<len; i++) {
 	slot = ptr_members[i];
-	if (rb_id_attrset(SYM2ID(slot)) == rb_frame_this_func()) {
+	if (rb_id_attrset(SYM2ID(slot)) == fid) {
 	    return ptr[i] = val;
 	}
     }
-    rb_name_error(rb_frame_this_func(), "`%s' is not a struct member",
-		  rb_id2name(rb_frame_this_func()));
+    not_a_member(fid);
 
     UNREACHABLE;
 }
Index: ruby_2_0_0/ext/-test-/struct/init.c
===================================================================
--- ruby_2_0_0/ext/-test-/struct/init.c	(revision 0)
+++ ruby_2_0_0/ext/-test-/struct/init.c	(revision 46741)
@@ -0,0 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/-test-/struct/init.c#L1
+#include "ruby.h"
+
+#define init(n) {void Init_##n(VALUE klass); Init_##n(klass);}
+
+void
+Init_struct(void)
+{
+    VALUE mBug = rb_define_module("Bug");
+    VALUE klass = rb_define_class_under(mBug, "Struct", rb_cStruct);
+    TEST_INIT_FUNCS(init);
+}

Property changes on: ruby_2_0_0/ext/-test-/struct/init.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_0_0/ext/-test-/struct/extconf.rb
===================================================================
--- ruby_2_0_0/ext/-test-/struct/extconf.rb	(revision 0)
+++ ruby_2_0_0/ext/-test-/struct/extconf.rb	(revision 46741)
@@ -0,0 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/-test-/struct/extconf.rb#L1
+$INCFLAGS << " -I$(topdir) -I$(top_srcdir)"
+$srcs = Dir[File.join($srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
+inits = $srcs.map {|s| File.basename(s, ".*")}
+inits.delete("init")
+inits.map! {|s|"X(#{s})"}
+$defs << "-DTEST_INIT_FUNCS(X)=\"#{inits.join(' ')}\""
+create_makefile("-test-/struct")

Property changes on: ruby_2_0_0/ext/-test-/struct/extconf.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_0_0/ext/-test-/struct/member.c
===================================================================
--- ruby_2_0_0/ext/-test-/struct/member.c	(revision 0)
+++ ruby_2_0_0/ext/-test-/struct/member.c	(revision 46741)
@@ -0,0 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ext/-test-/struct/member.c#L1
+#include "ruby.h"
+
+static VALUE
+bug_struct_get(VALUE obj, VALUE name)
+{
+    ID id = rb_check_id(&name);
+
+    if (!id) {
+	rb_name_error_str(name, "`%"PRIsVALUE"' is not a struct member", name);
+    }
+    return rb_struct_getmember(obj, id);
+}
+
+void
+Init_member(VALUE klass)
+{
+    rb_define_method(klass, "get", bug_struct_get, 1);
+}

Property changes on: ruby_2_0_0/ext/-test-/struct/member.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 46740)
+++ ruby_2_0_0/version.h	(revision 46741)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2014-07-07"
-#define RUBY_PATCHLEVEL 523
+#define RUBY_PATCHLEVEL 524
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 7
Index: ruby_2_0_0/test/-ext-/struct/test_member.rb
===================================================================
--- ruby_2_0_0/test/-ext-/struct/test_member.rb	(revision 0)
+++ ruby_2_0_0/test/-ext-/struct/test_member.rb	(revision 46741)
@@ -0,0 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/-ext-/struct/test_member.rb#L1
+require 'test/unit'
+require "-test-/struct"
+require_relative '../../ruby/envutil'
+
+class  Bug::Struct::Test_Member < Test::Unit::TestCase
+  S = Bug::Struct.new(:a)
+
+  def test_member_get
+    s = S.new(1)
+    assert_equal(1, s.get(:a))
+    assert_raise_with_message(NameError, /is not a struct member/) {s.get(:b)}
+    EnvUtil.with_default_external(Encoding::UTF_8) do
+      assert_raise_with_message(NameError, /\u{3042}/) {s.get(:"\u{3042}")}
+    end
+  end
+end

Property changes on: ruby_2_0_0/test/-ext-/struct/test_member.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r45462-45463,45466


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]