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

ruby-changes:40797

From: nobu <ko1@a...>
Date: Fri, 4 Dec 2015 11:22:57 +0900 (JST)
Subject: [ruby-changes:40797] nobu:r52876 (trunk): thread.c: name must be ascii-compatible

nobu	2015-12-04 11:22:44 +0900 (Fri, 04 Dec 2015)

  New Revision: 52876

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

  Log:
    thread.c: name must be ascii-compatible
    
    * thread.c (rb_thread_setname): name must be ascii-compatible, as
      pthread APIs do not accept legacy wide char strings.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_thread.rb
    trunk/thread.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52875)
+++ ChangeLog	(revision 52876)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Dec  4 11:22:40 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* thread.c (rb_thread_setname): name must be ascii-compatible, as
+	  pthread APIs do not accept legacy wide char strings.
+
 Thu Dec  3 16:02:17 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* string.c (rb_obj_as_string): fstring should not be infected.
Index: thread.c
===================================================================
--- thread.c	(revision 52875)
+++ thread.c	(revision 52876)
@@ -2780,7 +2780,13 @@ rb_thread_setname(VALUE thread, VALUE na https://github.com/ruby/ruby/blob/trunk/thread.c#L2780
     rb_thread_t *th;
     GetThreadPtr(thread, th);
     if (!NIL_P(name)) {
+	rb_encoding *enc;
 	StringValueCStr(name);
+	enc = rb_enc_get(name);
+	if (!rb_enc_asciicompat(enc)) {
+	    rb_raise(rb_eArgError, "ASCII incompatible encoding (%s)",
+		     rb_enc_name(enc));
+	}
 	name = rb_str_new_frozen(name);
 #ifdef SET_ANOTHER_THREAD_NAME
 	s = RSTRING_PTR(name);
Index: test/ruby/test_thread.rb
===================================================================
--- test/ruby/test_thread.rb	(revision 52875)
+++ test/ruby/test_thread.rb	(revision 52876)
@@ -1067,6 +1067,7 @@ q.pop https://github.com/ruby/ruby/blob/trunk/test/ruby/test_thread.rb#L1067
     bug11756 = '[ruby-core:71774] [Bug #11756]'
     t = Thread.start {}
     assert_raise(ArgumentError, bug11756) {t.name = "foo\0bar"}
+    assert_raise(ArgumentError, bug11756) {t.name = "foo".encode(Encoding::UTF_32BE)}
   ensure
     t.kill
     t.join

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

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