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

ruby-changes:34592

From: nagachika <ko1@a...>
Date: Fri, 4 Jul 2014 00:37:58 +0900 (JST)
Subject: [ruby-changes:34592] nagachika:r46673 (ruby_2_1): merge revision(s) r45462, r45463, r45466: [Backport #9684]

nagachika	2014-07-04 00:37:51 +0900 (Fri, 04 Jul 2014)

  New Revision: 46673

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

  Log:
    merge revision(s) r45462,r45463,r45466: [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_1/ext/-test-/struct/
    branches/ruby_2_1/test/-ext-/struct/
  Modified directories:
    branches/ruby_2_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/struct.c
    branches/ruby_2_1/test/-ext-/struct/test_member.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 46672)
+++ ruby_2_1/ChangeLog	(revision 46673)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Fri Jul  4 00:25:16 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]
+
 Thu Jul  3 01:19:50 2014  CHIKANAGA Tomoyuki  <nagachika@r...>
 
 	* numeric.c (num_step_scan_args): table argument of rb_get_kwargs() is
Index: ruby_2_1/struct.c
===================================================================
--- ruby_2_1/struct.c	(revision 46672)
+++ ruby_2_1/struct.c	(revision 46673)
@@ -86,6 +86,13 @@ rb_struct_members_m(VALUE obj) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/struct.c#L86
     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)
 {
@@ -100,7 +107,7 @@ rb_struct_getmember(VALUE obj, ID id) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/struct.c#L107
 	    return RSTRUCT_GET(obj, i);
 	}
     }
-    rb_name_error(id, "%s is not struct member", rb_id2name(id));
+    not_a_member(id);
 
     UNREACHABLE;
 }
@@ -149,19 +156,19 @@ rb_struct_set(VALUE obj, VALUE val) https://github.com/ruby/ruby/blob/trunk/ruby_2_1/struct.c#L156
 {
     VALUE members, slot;
     long i, len;
+    ID fid = rb_frame_this_func();
 
     members = rb_struct_members(obj);
     len = RARRAY_LEN(members);
     rb_struct_modify(obj);
     for (i=0; i<len; i++) {
 	slot = RARRAY_AREF(members, i);
-	if (rb_id_attrset(SYM2ID(slot)) == rb_frame_this_func()) {
+	if (rb_id_attrset(SYM2ID(slot)) == fid) {
 	    RSTRUCT_SET(obj, i, val);
 	    return 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_1/ext/-test-/struct/init.c
===================================================================
--- ruby_2_1/ext/-test-/struct/init.c	(revision 0)
+++ ruby_2_1/ext/-test-/struct/init.c	(revision 46673)
@@ -0,0 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/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_1/ext/-test-/struct/init.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_1/ext/-test-/struct/extconf.rb
===================================================================
--- ruby_2_1/ext/-test-/struct/extconf.rb	(revision 0)
+++ ruby_2_1/ext/-test-/struct/extconf.rb	(revision 46673)
@@ -0,0 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/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_1/ext/-test-/struct/extconf.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_1/ext/-test-/struct/member.c
===================================================================
--- ruby_2_1/ext/-test-/struct/member.c	(revision 0)
+++ ruby_2_1/ext/-test-/struct/member.c	(revision 46673)
@@ -0,0 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/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_1/ext/-test-/struct/member.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 46672)
+++ ruby_2_1/version.h	(revision 46673)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.2"
-#define RUBY_RELEASE_DATE "2014-07-03"
-#define RUBY_PATCHLEVEL 161
+#define RUBY_RELEASE_DATE "2014-07-04"
+#define RUBY_PATCHLEVEL 162
 
 #define RUBY_RELEASE_YEAR 2014
 #define RUBY_RELEASE_MONTH 7
-#define RUBY_RELEASE_DAY 3
+#define RUBY_RELEASE_DAY 4
 
 #include "ruby/version.h"
 
Index: ruby_2_1/test/-ext-/struct/test_member.rb
===================================================================
--- ruby_2_1/test/-ext-/struct/test_member.rb	(revision 0)
+++ ruby_2_1/test/-ext-/struct/test_member.rb	(revision 46673)
@@ -0,0 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/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_1/test/-ext-/struct/test_member.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


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


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

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