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

ruby-changes:49998

From: normal <ko1@a...>
Date: Wed, 31 Jan 2018 08:55:56 +0900 (JST)
Subject: [ruby-changes:49998] normal:r62116 (trunk): ruby.h: relax rb_funcall check on extra args for clang

normal	2018-01-31 08:55:49 +0900 (Wed, 31 Jan 2018)

  New Revision: 62116

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

  Log:
    ruby.h: relax rb_funcall check on extra args for clang
    
    clang 5.+ (tested clang 7.0.0) seems to be attempting division-by-zero
    and giving a very large number for static args to rb_funcall.
    
    * include/ruby/ruby.h (rb_varargs_bad_length): relax check for clang
    * ext/-test-/funcall/funcall.c: renamed from passing_block.c
      define extra_args_name function
    * test/-ext-/funcall/test_funcall.rb: new test
      [ruby-core:85266] [Bug #14425]
    
    From: Eric Wong <e@8...>

  Added files:
    trunk/ext/-test-/funcall/funcall.c
    trunk/test/-ext-/funcall/test_funcall.rb
  Removed files:
    trunk/ext/-test-/funcall/passing_block.c
  Modified files:
    trunk/include/ruby/ruby.h
Index: ext/-test-/funcall/passing_block.c
===================================================================
--- ext/-test-/funcall/passing_block.c	(revision 62115)
+++ ext/-test-/funcall/passing_block.c	(nonexistent)
@@ -1,30 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/funcall/passing_block.c#L0
-#include "ruby.h"
-
-VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE*);
-
-static VALUE
-with_funcall2(int argc, VALUE *argv, VALUE self)
-{
-    return rb_funcallv(self, rb_intern("target"), argc, argv);
-}
-
-static VALUE
-with_funcall_passing_block(int argc, VALUE *argv, VALUE self)
-{
-    return rb_funcall_passing_block(self, rb_intern("target"), argc, argv);
-}
-
-void
-Init_funcall(void)
-{
-    VALUE cRelay = rb_path2class("TestFuncall::Relay");
-
-    rb_define_singleton_method(cRelay,
-			       "with_funcall2",
-			       with_funcall2,
-			       -1);
-    rb_define_singleton_method(cRelay,
-			       "with_funcall_passing_block",
-			       with_funcall_passing_block,
-			       -1);
-}

Property changes on: ext/-test-/funcall/passing_block.c
___________________________________________________________________
Deleted: svn:eol-style
## -1 +0,0 ##
-LF
\ No newline at end of property
Index: test/-ext-/funcall/test_funcall.rb
===================================================================
--- test/-ext-/funcall/test_funcall.rb	(nonexistent)
+++ test/-ext-/funcall/test_funcall.rb	(revision 62116)
@@ -0,0 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/funcall/test_funcall.rb#L1
+# frozen_string_literal: true
+require 'test/unit'
+
+class TestFuncall < Test::Unit::TestCase
+  require '-test-/funcall'
+
+  def test_funcall_extra_args
+    assert_equal 'TestFuncall', TestFuncall.extra_args_name,
+	 '[ruby-core:85266] [Bug #14425]'
+  end
+end
Index: ext/-test-/funcall/funcall.c
===================================================================
--- ext/-test-/funcall/funcall.c	(nonexistent)
+++ ext/-test-/funcall/funcall.c	(revision 62116)
@@ -0,0 +1,44 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/funcall/funcall.c#L1
+#include "ruby.h"
+
+VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE*);
+
+static VALUE
+with_funcall2(int argc, VALUE *argv, VALUE self)
+{
+    return rb_funcallv(self, rb_intern("target"), argc, argv);
+}
+
+static VALUE
+with_funcall_passing_block(int argc, VALUE *argv, VALUE self)
+{
+    return rb_funcall_passing_block(self, rb_intern("target"), argc, argv);
+}
+
+static VALUE
+extra_args_name(VALUE self)
+{
+    /*
+     * at least clang 5.x gets tripped by the extra 0 arg
+     * [ruby-core:85266] [Bug #14425]
+     */
+    return rb_funcall(self, rb_intern("name"), 0, 0);
+}
+
+void
+Init_funcall(void)
+{
+    VALUE cTestFuncall = rb_path2class("TestFuncall");
+    VALUE cRelay = rb_define_module_under(cTestFuncall, "Relay");
+
+    rb_define_singleton_method(cRelay,
+			       "with_funcall2",
+			       with_funcall2,
+			       -1);
+    rb_define_singleton_method(cRelay,
+			       "with_funcall_passing_block",
+			       with_funcall_passing_block,
+			       -1);
+    rb_define_singleton_method(cTestFuncall, "extra_args_name",
+                                extra_args_name,
+                                0);
+}

Property changes on: ext/-test-/funcall/funcall.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+LF
\ No newline at end of property
Index: include/ruby/ruby.h
===================================================================
--- include/ruby/ruby.h	(revision 62115)
+++ include/ruby/ruby.h	(revision 62116)
@@ -1783,6 +1783,8 @@ VALUE rb_check_symbol(volatile VALUE *na https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1783
 # if defined(HAVE_BUILTIN___BUILTIN_CHOOSE_EXPR_CONSTANT_P)
 #   if HAVE_ATTRIBUTE_ERRORFUNC
 ERRORFUNC((" argument length doesn't match"), int rb_varargs_bad_length(int,int));
+#   elif defined(__clang__) /* [ruby-core:85266] [Bug #14425] */
+#     define rb_varargs_bad_length(argc, vargc) ((argc)/((argc) <= (vargc)))
 #   else
 #     define rb_varargs_bad_length(argc, vargc) ((argc)/((argc) == (vargc)))
 #   endif

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

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