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

ruby-changes:58160

From: Kenta <ko1@a...>
Date: Tue, 8 Oct 2019 09:06:47 +0900 (JST)
Subject: [ruby-changes:58160] dd0c75fdc2 (master): Import changes from ruby/bigdecimal (#2531)

https://git.ruby-lang.org/ruby.git/commit/?id=dd0c75fdc2

From dd0c75fdc2104a6ba38b68d4431a572504a3bbc2 Mon Sep 17 00:00:00 2001
From: Kenta Murata <mrkn@u...>
Date: Tue, 8 Oct 2019 09:06:28 +0900
Subject: Import changes from ruby/bigdecimal (#2531)

Sync to ruby/bigdecimal@92356ba71c6bd325b0ab618c634a7aecf8cdc767

diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c
index 6d50475..b235403 100644
--- a/ext/bigdecimal/bigdecimal.c
+++ b/ext/bigdecimal/bigdecimal.c
@@ -1756,12 +1756,15 @@ BigDecimal_fix(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L1756
  * round(n, mode)
  *
  * Round to the nearest integer (by default), returning the result as a
- * BigDecimal.
+ * BigDecimal if n is specified, or as an Integer if it isn't.
  *
  *	BigDecimal('3.14159').round #=> 3
  *	BigDecimal('8.7').round #=> 9
  *	BigDecimal('-9.9').round #=> -10
  *
+ *	BigDecimal('3.14159').round(2).class.name #=> "BigDecimal"
+ *	BigDecimal('3.14159').round.class.name #=> "Integer"
+ *
  * If n is specified and positive, the fractional part of the result has no
  * more than that many digits.
  *
@@ -2585,7 +2588,7 @@ opts_exception_p(VALUE opts) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2588
 #endif
 
 static Real *
-BigDecimal_new(int argc, VALUE *argv)
+VpNewVarArg(int argc, VALUE *argv)
 {
     size_t mf;
     VALUE  opts = Qnil;
@@ -2726,7 +2729,7 @@ f_BigDecimal(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2729
         if (argc == 1 || (argc == 2 && RB_TYPE_P(argv[1], T_HASH))) return argv[0];
     }
     obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, 0);
-    pv = BigDecimal_new(argc, argv);
+    pv = VpNewVarArg(argc, argv);
     if (pv == NULL) return Qnil;
     SAVE(pv);
     if (ToValue(pv)) pv = VpCopy(NULL, pv);
@@ -2735,6 +2738,20 @@ f_BigDecimal(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2738
     return pv->obj = obj;
 }
 
+static VALUE
+BigDecimal_s_interpret_loosely(VALUE klass, VALUE str)
+{
+    ENTER(1);
+    char const *c_str;
+    Real *pv;
+
+    c_str = StringValueCStr(str);
+    GUARD_OBJ(pv, VpAlloc(0, c_str, 0, 1));
+    pv->obj = TypedData_Wrap_Struct(klass, &BigDecimal_data_type, pv);
+    RB_OBJ_FREEZE(pv->obj);
+    return pv->obj;
+}
+
  /* call-seq:
   * BigDecimal.limit(digits)
   *
@@ -2954,6 +2971,10 @@ BigMath_s_exp(VALUE klass, VALUE x, VALUE vprec) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L2971
     n = prec + rmpd_double_figures();
     negative = BIGDECIMAL_NEGATIVE_P(vx);
     if (negative) {
+        VALUE x_zero = INT2NUM(1);
+        VALUE x_copy = f_BigDecimal(1, &x_zero, klass);
+        x = BigDecimal_initialize_copy(x_copy, x);
+        vx = DATA_PTR(x);
 	VpSetSign(vx, 1);
     }
 
@@ -3155,20 +3176,6 @@ get_vp_value: https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3176
     return y;
 }
 
-VALUE
-rmpd_util_str_to_d(VALUE str)
-{
-  ENTER(1);
-  char const *c_str;
-  Real *pv;
-
-  c_str = StringValueCStr(str);
-  GUARD_OBJ(pv, VpAlloc(0, c_str, 0, 1));
-  pv->obj = TypedData_Wrap_Struct(rb_cBigDecimal, &BigDecimal_data_type, pv);
-  RB_OBJ_FREEZE(pv->obj);
-  return pv->obj;
-}
-
 /* Document-class: BigDecimal
  * BigDecimal provides arbitrary-precision floating point decimal arithmetic.
  *
@@ -3315,6 +3322,7 @@ Init_bigdecimal(void) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L3322
     /* Class methods */
     rb_undef_method(CLASS_OF(rb_cBigDecimal), "allocate");
     rb_undef_method(CLASS_OF(rb_cBigDecimal), "new");
+    rb_define_singleton_method(rb_cBigDecimal, "interpret_loosely", BigDecimal_s_interpret_loosely, 1);
     rb_define_singleton_method(rb_cBigDecimal, "mode", BigDecimal_mode, -1);
     rb_define_singleton_method(rb_cBigDecimal, "limit", BigDecimal_limit, -1);
     rb_define_singleton_method(rb_cBigDecimal, "double_fig", BigDecimal_double_fig, 0);
@@ -4296,7 +4304,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc) https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L4304
 
     psz[i] = '\0';
 
-    if (((ni == 0 || dot_seen) && nf == 0) || (exp_seen && ne == 0)) {
+    if (strict_p && (((ni == 0 || dot_seen) && nf == 0) || (exp_seen && ne == 0))) {
         VALUE str;
       invalid_value:
         if (!strict_p) {
diff --git a/ext/bigdecimal/bigdecimal.def b/ext/bigdecimal/bigdecimal.def
deleted file mode 100644
index 615bf72..0000000
--- a/ext/bigdecimal/bigdecimal.def
+++ /dev/null
@@ -1,3 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.c#L0
-EXPORTS
-rmpd_util_str_to_d
-Init_bigdecimal
diff --git a/ext/bigdecimal/bigdecimal.gemspec b/ext/bigdecimal/bigdecimal.gemspec
index c483cfb..53dbe91 100644
--- a/ext/bigdecimal/bigdecimal.gemspec
+++ b/ext/bigdecimal/bigdecimal.gemspec
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.gemspec#L1
 # coding: utf-8
 
-bigdecimal_version = '1.4.2'
+bigdecimal_version = '2.0.0.dev'
 
 Gem::Specification.new do |s|
   s.name          = "bigdecimal"
@@ -14,16 +14,11 @@ Gem::Specification.new do |s| https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.gemspec#L14
   s.license       = "ruby"
 
   s.require_paths = %w[lib]
-  s.extensions    = %w[ext/bigdecimal/extconf.rb ext/bigdecimal/util/extconf.rb]
+  s.extensions    = %w[ext/bigdecimal/extconf.rb]
   s.files         = %w[
     bigdecimal.gemspec
     ext/bigdecimal/bigdecimal.c
-    ext/bigdecimal/bigdecimal.def
     ext/bigdecimal/bigdecimal.h
-    ext/bigdecimal/depend
-    ext/bigdecimal/extconf.rb
-    ext/bigdecimal/util/extconf.rb
-    ext/bigdecimal/util/util.c
     lib/bigdecimal.rb
     lib/bigdecimal/jacobian.rb
     lib/bigdecimal/ludcmp.rb
@@ -39,7 +34,6 @@ Gem::Specification.new do |s| https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/bigdecimal.gemspec#L34
 
   s.add_development_dependency "rake", "~> 10.0"
   s.add_development_dependency "rake-compiler", ">= 0.9"
-  s.add_development_dependency "rake-compiler-dock", ">= 0.6.1"
   s.add_development_dependency "minitest", "< 5.0.0"
   s.add_development_dependency "pry"
 end
diff --git a/ext/bigdecimal/extconf.rb b/ext/bigdecimal/extconf.rb
index 7a7af10..b4098fd 100644
--- a/ext/bigdecimal/extconf.rb
+++ b/ext/bigdecimal/extconf.rb
@@ -1,6 +1,21 @@ https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/extconf.rb#L1
 # frozen_string_literal: false
 require 'mkmf'
 
+def check_bigdecimal_version(gemspec_path)
+  message "checking RUBY_BIGDECIMAL_VERSION... "
+
+  bigdecimal_version =
+    IO.readlines(gemspec_path)
+      .grep(/\Abigdecimal_version\s+=\s+/)[0][/\'([^\']+)\'/, 1]
+
+  version_components = bigdecimal_version.split('.')
+  bigdecimal_version = version_components[0, 3].join('.')
+  bigdecimal_version << "-#{version_components[3]}" if version_components[3]
+  $defs << %Q[-DRUBY_BIGDECIMAL_VERSION=\\"#{bigdecimal_version}\\"]
+
+  message "#{bigdecimal_version}\n"
+end
+
 gemspec_name = gemspec_path = nil
 unless ['', '../../'].any? {|dir|
          gemspec_name = "#{dir}bigdecimal.gemspec"
@@ -11,11 +26,7 @@ unless ['', '../../'].any? {|dir| https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/extconf.rb#L26
   abort
 end
 
-bigdecimal_version =
-  IO.readlines(gemspec_path)
-    .grep(/\Abigdecimal_version\s+=\s+/)[0][/\'([\d\.]+)\'/, 1]
-
-$defs << %Q[-DRUBY_BIGDECIMAL_VERSION=\\"#{bigdecimal_version}\\"]
+check_bigdecimal_version(gemspec_path)
 
 have_func("labs", "stdlib.h")
 have_func("llabs", "stdlib.h")
diff --git a/ext/bigdecimal/lib/bigdecimal.rb b/ext/bigdecimal/lib/bigdecimal.rb
index 96995a3..8fd2587 100644
--- a/ext/bigdecimal/lib/bigdecimal.rb
+++ b/ext/bigdecimal/lib/bigdecimal.rb
@@ -1,6 +1 @@
 require 'bigdecimal.so'
-
-def BigDecimal.new(*args, **kwargs)
-  warn "BigDecimal.new is deprecated; use BigDecimal() method instead.", uplevel: 1
-  BigDecimal(*args, **kwargs)
-end
diff --git a/ext/bigdecimal/lib/bigdecimal/jacobian.rb b/ext/bigdecimal/lib/bigdecimal/jacobian.rb
index 84c5024..5e29304 100644
--- a/ext/bigdecimal/lib/bigdecimal/jacobian.rb
+++ b/ext/bigdecimal/lib/bigdecimal/jacobian.rb
@@ -1,5 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/jacobian.rb#L1
 # frozen_string_literal: false
-#
+
+require 'bigdecimal'
+
 # require 'bigdecimal/jacobian'
 #
 # Provides methods to compute the Jacobian matrix of a set of equations at a
@@ -21,9 +23,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/jacobian.rb#L23
 #
 # fx is f.values(x).
 #
-
-require 'bigdecimal'
-
 module Jacobian
   module_function
 
diff --git a/ext/bigdecimal/lib/bigdecimal/util.rb b/ext/bigdecimal/lib/bigdecimal/util.rb
index 88f490c..4ece834 100644
--- a/ext/bigdecimal/lib/bigdecimal/util.rb
+++ b/ext/bigdecimal/lib/bigdecimal/util.rb
@@ -6,7 +6,6 @@ https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L6
 #++
 
 require 'bigdecimal'
-require 'bigdecimal/util.so'
 
 class Integer < Numeric
   # call-seq:
@@ -66,6 +65,9 @@ class String https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L65
   #
   # See also BigDecimal::new.
   #
+  def to_d
+    BigDecimal.interpret_loosely(self)
+  end
 end
 
 
diff --git a/ext/bigdecimal/util/extconf.rb b/ext/bigdecimal/util/extconf.rb
deleted file mode 100644
index b0d5635..0000000
--- a/ext/bigdecimal/util/extconf.rb
+++ /dev/null
@@ -1,24 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/bigdecimal/lib/bigdecimal/util.rb#L0
-# frozen_string_literal: false
-require 'mkmf'
-
-checking_for(checking_message("Windows")) do
-  case RUBY_PLATFORM
-  when /cygwin|mingw/
-    if ARGV.include?('-rdevkit') # check `rake -rdevkit compile` case
-      base_dir = File.expand_path('../../../..', __FILE__)
-      build_dir = File.join(base_dir, "tmp", RUBY_PLATFORM, "bigdecimal", RUBY_VERSION, "")
-    else
-      build_dir (... truncated)

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

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