From 69674e8c0f0bb8abab4da481f2545d2fad48e1af Mon Sep 17 00:00:00 2001 From: Andrew Konchin Date: Tue, 26 Mar 2024 13:00:11 +0200 Subject: [PATCH 1/9] Restore TruffleRuby on CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cd6f20b..4744eb2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: ruby-versions: uses: ruby/actions/.github/workflows/ruby_versions.yml@master with: - engine: cruby + engine: cruby-truffleruby min_version: 2.5 versions: '["debug"]' From ccdd8d2b6ae339af786638ac7a33d7c26ca1996f Mon Sep 17 00:00:00 2001 From: Kenta Murata <3959+mrkn@users.noreply.github.com> Date: Sun, 5 May 2024 00:14:56 +0900 Subject: [PATCH 2/9] CI: Remove macos-latest 2.5 Because it's unavailable. --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4744eb2..5bee326 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,7 @@ jobs: - { os: windows-latest , ruby: mingw } - { os: windows-latest , ruby: mswin } exclude: + - { os: macos-latest , ruby: "2.5" } - { os: macos-arm-oss , ruby: "2.5" } - { os: windows-latest , ruby: debug } - { os: windows-latest , ruby: truffleruby } From be80c3fdbff961be5b86f06f497b275204c9cf0f Mon Sep 17 00:00:00 2001 From: Kenta Murata <3959+mrkn@users.noreply.github.com> Date: Mon, 6 May 2024 11:53:18 +0900 Subject: [PATCH 3/9] Fix memory leak in VpAlloc by exception (#294) --- ext/bigdecimal/bigdecimal.c | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 3e14364..e4068a5 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -5203,6 +5203,48 @@ bigdecimal_parse_special_string(const char *str) return NULL; } +struct VpCtoV_args { + Real *a; + const char *int_chr; + size_t ni; + const char *frac; + size_t nf; + const char *exp_chr; + size_t ne; +}; + +static VALUE +call_VpCtoV(VALUE arg) +{ + struct VpCtoV_args *x = (struct VpCtoV_args *)arg; + return (VALUE)VpCtoV(x->a, x->int_chr, x->ni, x->frac, x->nf, x->exp_chr, x->ne); +} + +static int +protected_VpCtoV(Real *a, const char *int_chr, size_t ni, const char *frac, size_t nf, const char *exp_chr, size_t ne, int free_on_error) +{ + struct VpCtoV_args args; + int state = 0; + + args.a = a; + args.int_chr = int_chr; + args.ni = ni; + args.frac = frac; + args.nf = nf; + args.exp_chr = exp_chr; + args.ne = ne; + + VALUE result = rb_protect(call_VpCtoV, (VALUE)&args, &state); + if (state) { + if (free_on_error) { + rbd_free_struct(a); + } + rb_jump_tag(state); + } + + return (int)result; +} + /* * Allocates variable. * [Input] @@ -5422,7 +5464,7 @@ VpAlloc(size_t mx, const char *szVal, int strict_p, int exc) vp = rbd_allocate_struct(len); vp->MaxPrec = len; /* set max precision */ VpSetZero(vp, sign); - VpCtoV(vp, psz, ni, psz + ipf, nf, psz + ipe, ne); + protected_VpCtoV(vp, psz, ni, psz + ipf, nf, psz + ipe, ne, true); rb_str_resize(buf, 0); return vp; } From 381340ad7d001a106dcfdb60680e3c579fb2515c Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 7 May 2024 10:11:17 +0900 Subject: [PATCH 4/9] Add missing documents (#277) * [DOC] Make constants documented * [DOC] Add missing documents * [DOC] Link Infinity and NaN --- ext/bigdecimal/bigdecimal.c | 62 +++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index e4068a5..e011b4a 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -1780,6 +1780,17 @@ BigDecimal_neg(VALUE self) return VpCheckGetValue(c); } +/* + * call-seq: + * a * b -> bigdecimal + * + * Multiply by the specified value. + * + * The result precision will be the precision of the sum of each precision. + * + * See BigDecimal#mult. + */ + static VALUE BigDecimal_mult(VALUE self, VALUE r) { @@ -3257,10 +3268,11 @@ BigDecimal_initialize_copy(VALUE self, VALUE other) return self; } +/* :nodoc: */ static VALUE BigDecimal_clone(VALUE self) { - return self; + return self; } #ifdef HAVE_RB_OPTS_EXCEPTION_P @@ -3758,6 +3770,12 @@ f_BigDecimal(int argc, VALUE *argv, VALUE self) return rb_convert_to_BigDecimal(val, digs, exception); } +/* call-seq: + * BigDecimal.interpret_loosely(string) -> bigdecimal + * + * Returns the +BigDecimal+ converted loosely from +string+. + */ + static VALUE BigDecimal_s_interpret_loosely(VALUE klass, VALUE str) { @@ -4238,6 +4256,17 @@ BigDecimal_negative_zero(void) return BIGDECIMAL_NEGATIVE_ZERO; } +static inline VALUE +BigDecimal_literal(const char *str) +{ + VALUE arg = rb_str_new_cstr(str); + VALUE val = f_BigDecimal(1, &arg, rb_cBigDecimal); + rb_gc_register_mark_object(val); + return val; +} + +#define BIGDECIMAL_LITERAL(var, val) (BIGDECIMAL_ ## var = BigDecimal_literal(#val)) + /* Document-class: BigDecimal * BigDecimal provides arbitrary-precision floating point decimal arithmetic. * @@ -4394,7 +4423,6 @@ Init_bigdecimal(void) #ifdef HAVE_RB_EXT_RACTOR_SAFE rb_ext_ractor_safe(true); #endif - VALUE arg; id_BigDecimal_exception_mode = rb_intern_const("BigDecimal.exception_mode"); id_BigDecimal_rounding_mode = rb_intern_const("BigDecimal.rounding_mode"); @@ -4532,33 +4560,19 @@ Init_bigdecimal(void) rb_define_const(rb_cBigDecimal, "SIGN_NEGATIVE_INFINITE", INT2FIX(VP_SIGN_NEGATIVE_INFINITE)); /* Positive zero value. */ - arg = rb_str_new2("+0"); - BIGDECIMAL_POSITIVE_ZERO = f_BigDecimal(1, &arg, rb_cBigDecimal); - rb_gc_register_mark_object(BIGDECIMAL_POSITIVE_ZERO); + BIGDECIMAL_LITERAL(POSITIVE_ZERO, +0); /* Negative zero value. */ - arg = rb_str_new2("-0"); - BIGDECIMAL_NEGATIVE_ZERO = f_BigDecimal(1, &arg, rb_cBigDecimal); - rb_gc_register_mark_object(BIGDECIMAL_NEGATIVE_ZERO); + BIGDECIMAL_LITERAL(NEGATIVE_ZERO, -0); - /* Positive infinity value. */ - arg = rb_str_new2("+Infinity"); - BIGDECIMAL_POSITIVE_INFINITY = f_BigDecimal(1, &arg, rb_cBigDecimal); - rb_gc_register_mark_object(BIGDECIMAL_POSITIVE_INFINITY); + /* Positive infinity[rdoc-ref:BigDecimal@Infinity] value. */ + rb_define_const(rb_cBigDecimal, "INFINITY", BIGDECIMAL_LITERAL(POSITIVE_INFINITY, +Infinity)); /* Negative infinity value. */ - arg = rb_str_new2("-Infinity"); - BIGDECIMAL_NEGATIVE_INFINITY = f_BigDecimal(1, &arg, rb_cBigDecimal); - rb_gc_register_mark_object(BIGDECIMAL_NEGATIVE_INFINITY); - - /* 'Not a Number' value. */ - arg = rb_str_new2("NaN"); - BIGDECIMAL_NAN = f_BigDecimal(1, &arg, rb_cBigDecimal); - rb_gc_register_mark_object(BIGDECIMAL_NAN); - - /* Special value constants */ - rb_define_const(rb_cBigDecimal, "INFINITY", BIGDECIMAL_POSITIVE_INFINITY); - rb_define_const(rb_cBigDecimal, "NAN", BIGDECIMAL_NAN); + BIGDECIMAL_LITERAL(NEGATIVE_INFINITY, -Infinity); + + /* '{Not a Number}[rdoc-ref:BigDecimal@Not+a+Number]' value. */ + rb_define_const(rb_cBigDecimal, "NAN", BIGDECIMAL_LITERAL(NAN, NaN)); /* instance methods */ rb_define_method(rb_cBigDecimal, "precs", BigDecimal_prec, 0); From 4b54be557f685af71d3c66dfe9cde683711a4388 Mon Sep 17 00:00:00 2001 From: mark-young-atg <113439900+mark-young-atg@users.noreply.github.com> Date: Tue, 7 May 2024 02:17:35 +0100 Subject: [PATCH 5/9] Provide a 'Changelog' link on rubygems.org/gems/bigdecimal (#281) By providing a 'changelog_uri' in the metadata of the gemspec a 'Changelog' link will be shown on https://rubygems.org/gems/bigdecimal which makes it quick and easy for someone to check on the changes introduced with a new version. Details of this functionality can be found on https://guides.rubygems.org/specification-reference/ --- bigdecimal.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bigdecimal.gemspec b/bigdecimal.gemspec index 6942383..b6ef8fd 100644 --- a/bigdecimal.gemspec +++ b/bigdecimal.gemspec @@ -52,4 +52,6 @@ Gem::Specification.new do |s| end s.required_ruby_version = Gem::Requirement.new(">= 2.5.0") + + s.metadata["changelog_uri"] = s.homepage + "/blob/master/CHANGES.md" end From a564961e9cc9c1ac70da51b32e991cf522555efa Mon Sep 17 00:00:00 2001 From: Kenta Murata <3959+mrkn@users.noreply.github.com> Date: Tue, 7 May 2024 10:27:23 +0900 Subject: [PATCH 6/9] CHANGES: Add 3.1.7 entry --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 2123976..ae81e83 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # CHANGES +## 3.1.7 + +* Only consists of CI settings and test changes. + ## 3.1.6 * Add LICENSE file to gem files [GH-282] From 9e16b26682fc83c453e6f37e03bcb42e26f484b9 Mon Sep 17 00:00:00 2001 From: Kenta Murata <3959+mrkn@users.noreply.github.com> Date: Tue, 7 May 2024 10:29:54 +0900 Subject: [PATCH 7/9] CHANGES: Add 3.1.8 entry --- CHANGES.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ae81e83..8d805bd 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,15 @@ # CHANGES +## 3.1.8 + +* Add missing documents [GH-277] + + **@nobu** + +* Fix memory leak in VpAlloc [GH-294] [GH-290] + + Reoprted by **@MaxLap** + ## 3.1.7 * Only consists of CI settings and test changes. From bd49f16d21673bba8eac8db39c803a6366d49e78 Mon Sep 17 00:00:00 2001 From: Kenta Murata <3959+mrkn@users.noreply.github.com> Date: Tue, 7 May 2024 10:31:52 +0900 Subject: [PATCH 8/9] CHANGES: Add note for 3.1.7 --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 8d805bd..299819c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -13,6 +13,7 @@ ## 3.1.7 * Only consists of CI settings and test changes. + This release is needed for developing Ruby to run `make test-bundled-gems` with the released version of bigdecimal. ## 3.1.6 From ae3915ba8831cb0bbed2bc60a1345b320f2eafb4 Mon Sep 17 00:00:00 2001 From: Kenta Murata Date: Tue, 7 May 2024 10:34:08 +0900 Subject: [PATCH 9/9] Bump up to 3.1.8 --- ext/bigdecimal/bigdecimal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index e011b4a..aa2bf21 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -31,7 +31,7 @@ #include "bits.h" #include "static_assert.h" -#define BIGDECIMAL_VERSION "3.1.7" +#define BIGDECIMAL_VERSION "3.1.8" /* #define ENABLE_NUMERIC_STRING */