From 654f6fbf19c0ca2e01765a909b4d952b7f0f5baa Mon Sep 17 00:00:00 2001 From: Kenta Murata Date: Sat, 19 Dec 2020 11:55:46 +0900 Subject: [bigdecimal] Make BigDecimal#precs deprecated https://github.com/ruby/bigdecimal/commit/7e80e6e145 https://github.com/ruby/bigdecimal/commit/0ed7846e8c --- ext/bigdecimal/bigdecimal.c | 13 +++++++++---- ext/bigdecimal/bigdecimal.h | 4 ++++ ext/bigdecimal/extconf.rb | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'ext') diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index ef975a01e0..fa00395583 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -355,11 +355,12 @@ BigDecimal_double_fig(VALUE self) /* call-seq: * big_decimal.precs -> array * - * Returns an Array of two Integer values. + * Returns an Array of two Integer values that represent platform-dependent + * internal storage properties. * - * The first value is the current number of significant digits in the - * BigDecimal. The second value is the maximum number of significant digits - * for the BigDecimal. + * This method is deprecated and will be removed in the future. + * Instead, use BigDecimal#precision for obtaining the number of decimal + * digits. * * BigDecimal('5').precs #=> [9, 18] */ @@ -371,6 +372,10 @@ BigDecimal_prec(VALUE self) Real *p; VALUE obj; + rb_category_warn(RB_WARN_CATEGORY_DEPRECATED, + "BigDecimal#precs is deprecated and will be removed in the future; " + "use BigDecimal#precision instead."); + GUARD_OBJ(p, GetVpValue(self, 1)); obj = rb_assoc_new(SIZET2NUM(p->Prec*VpBaseFig()), SIZET2NUM(p->MaxPrec*VpBaseFig())); diff --git a/ext/bigdecimal/bigdecimal.h b/ext/bigdecimal/bigdecimal.h index e3eae06e67..28f3363b3c 100644 --- a/ext/bigdecimal/bigdecimal.h +++ b/ext/bigdecimal/bigdecimal.h @@ -159,6 +159,10 @@ rb_sym2str(VALUE sym) # define vabs llabs #endif +#if !defined(HAVE_RB_CATEGORY_WARN) || !defined(HAVE_CONST_RB_WARN_CATEGORY_DEPRECATED) +# define rb_category_warn(category, ...) rb_warn(__VA_ARGS__) +#endif + extern VALUE rb_cBigDecimal; #if 0 || SIZEOF_BDIGITS >= 16 diff --git a/ext/bigdecimal/extconf.rb b/ext/bigdecimal/extconf.rb index fc448ed380..63123e2892 100644 --- a/ext/bigdecimal/extconf.rb +++ b/ext/bigdecimal/extconf.rb @@ -42,6 +42,8 @@ have_func("rb_complex_imag", "ruby.h") have_func("rb_array_const_ptr", "ruby.h") have_func("rb_sym2str", "ruby.h") have_func("rb_opts_exception_p", "ruby.h") +have_func("rb_category_warn", "ruby.h") +have_const("RB_WARN_CATEGORY_DEPRECATED", "ruby.h") if File.file?(File.expand_path('../lib/bigdecimal.rb', __FILE__)) bigdecimal_rb = "$(srcdir)/lib/bigdecimal.rb" -- cgit v1.2.3