From c495d08c5bd1233e2c6228133892730d5a78e535 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 12 Dec 2024 16:00:26 +0900 Subject: [PATCH 1/4] mruby-io (mrb_file__gethome): add casts to stop type warnings --- mrbgems/mruby-io/src/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/mruby-io/src/file.c b/mrbgems/mruby-io/src/file.c index 4759a401c..589f1be14 100644 --- a/mrbgems/mruby-io/src/file.c +++ b/mrbgems/mruby-io/src/file.c @@ -381,7 +381,7 @@ mrb_file__gethome(mrb_state *mrb, mrb_value klass) char *pathp = RSTRING_PTR(path); const char *const pathend = pathp + RSTRING_LEN(path); for (;;) { - pathp = memchr(pathp, '\\', pathend - pathp); + pathp = memchr((void*)pathp, '\\', (size_t)(pathend - pathp)); if (!pathp) break; *pathp++ = '/'; } From 29a2bc19a32c87fa4d20a0c67cd5f1aea36703fb Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 12 Dec 2024 17:12:08 +0900 Subject: [PATCH 2/4] mruby-bigint (mpz_get_str): use `UL` suffix for mp_limb table --- mrbgems/mruby-bigint/core/bigint.c | 60 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index 59c7bbe8d..a56c45e47 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -820,40 +820,40 @@ static const mp_limb base_limit[34*2] = { 42875, // 35^3 46656, // 36^3 #else - 3486784401, // 3^20 + 3486784401UL, // 3^20 0, // 4^16 (skip) - 1220703125, // 5^13 - 2176782336, // 6^12 - 1977326743, // 7^11 + 1220703125UL, // 5^13 + 2176782336UL, // 6^12 + 1977326743UL, // 7^11 0, // 8^10 (skip) - 3486784401, // 9^10 - 1000000000, // 10^9 - 2357947691, // 11^9 - 429981696, // 12^8 - 815730721, // 13^8 - 1475789056, // 14^8 - 2562890625, // 15^8 + 3486784401UL, // 9^10 + 1000000000UL, // 10^9 + 2357947691UL, // 11^9 + 429981696UL, // 12^8 + 815730721UL, // 13^8 + 1475789056UL, // 14^8 + 2562890625UL, // 15^8 0, // 16^8 (skip) - 410338673, // 17^7 - 612220032, // 18^7 - 893871739, // 19^7 - 1280000000, // 20^7 - 1801088541, // 21^7 - 2494357888, // 22^7 - 3404825447, // 23^7 - 191102976, // 24^6 - 244140625, // 25^6 - 308915776, // 26^6 - 387420489, // 27^6 - 481890304, // 28^6 - 594823321, // 29^6 - 729000000, // 30^6 - 887503681, // 31^6 + 410338673UL, // 17^7 + 612220032UL, // 18^7 + 893871739UL, // 19^7 + 1280000000UL, // 20^7 + 1801088541UL, // 21^7 + 2494357888UL, // 22^7 + 3404825447UL, // 23^7 + 191102976UL, // 24^6 + 244140625UL, // 25^6 + 308915776UL, // 26^6 + 387420489UL, // 27^6 + 481890304UL, // 28^6 + 594823321UL, // 29^6 + 729000000UL, // 30^6 + 887503681UL, // 31^6 0, // 32^6 (skip) - 1291467969, // 33^6 - 1544804416, // 34^6 - 1838265625, // 35^6 - 2176782336, // 36^6 + 1291467969UL, // 33^6 + 1544804416UL, // 34^6 + 1838265625UL, // 35^6 + 2176782336UL, // 36^6 #endif }; From ce1abfb2c9e41bb87e2001e36cb9761bb49b5a11 Mon Sep 17 00:00:00 2001 From: dearblue Date: Mon, 9 Dec 2024 22:17:28 +0900 Subject: [PATCH 3/4] Change `MRB_WITH_IO_PREAD_PWRITE` configuration name Change to `MRB_USE_IO_PREAD_PWRITE` for consistency with mruby configuration macros. Similarly, `MRB_WITHOUT_IO_PREAD_PWRITE` is changed to `MRB_NO_IO_PREAD_PWRITE`. The previous names are available for compatibility but are deprecated. --- build_config/i586-pc-msdosdjgpp.rb | 4 ++-- mrbgems/mruby-io/include/mruby/ext/io.h | 10 +++++----- mrbgems/mruby-io/src/io.c | 4 ++-- mrbgems/mruby-io/test/io.rb | 4 ++-- mrbgems/mruby-io/test/mruby_io_test.c | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/build_config/i586-pc-msdosdjgpp.rb b/build_config/i586-pc-msdosdjgpp.rb index 4275423cd..04cc2239f 100644 --- a/build_config/i586-pc-msdosdjgpp.rb +++ b/build_config/i586-pc-msdosdjgpp.rb @@ -15,13 +15,13 @@ MRuby::CrossBuild.new("i586-pc-msdosdjgpp") do |conf| conf.cc do |cc| cc.command = DJGPP_PATH ? File.join(DJGPP_PATH, GCC) : GCC - cc.defines << 'MRB_WITHOUT_IO_PREAD_PWRITE' + cc.defines << 'MRB_NO_IO_PREAD_PWRITE' cc.defines << 'MRB_UTF8_STRING' end conf.cxx do |cxx| cxx.command = DJGPP_PATH ? File.join(DJGPP_PATH, GXX) : GXX - cxx.defines << 'MRB_WITHOUT_IO_PREAD_PWRITE' + cxx.defines << 'MRB_NO_IO_PREAD_PWRITE' cxx.defines << 'MRB_UTF8_STRING' end diff --git a/mrbgems/mruby-io/include/mruby/ext/io.h b/mrbgems/mruby-io/include/mruby/ext/io.h index 537bf09c8..a12903f15 100644 --- a/mrbgems/mruby-io/include/mruby/ext/io.h +++ b/mrbgems/mruby-io/include/mruby/ext/io.h @@ -15,11 +15,11 @@ extern "C" { #endif -#if defined(MRB_WITHOUT_IO_PREAD_PWRITE) -# undef MRB_WITH_IO_PREAD_PWRITE -#elif !defined(MRB_WITH_IO_PREAD_PWRITE) -# if defined(__unix__) || defined(__MACH__) -# define MRB_WITH_IO_PREAD_PWRITE +#if defined(MRB_NO_IO_PREAD_PWRITE) || defined(MRB_WITHOUT_IO_PREAD_PWRITE) +# undef MRB_USE_IO_PREAD_PWRITE +#elif !defined(MRB_USE_IO_PREAD_PWRITE) +# if defined(__unix__) || defined(__MACH__) || defined(MRB_WITH_IO_PREAD_PWRITE) +# define MRB_USE_IO_PREAD_PWRITE # endif #endif diff --git a/mrbgems/mruby-io/src/io.c b/mrbgems/mruby-io/src/io.c index 5219183ad..534fcfef7 100644 --- a/mrbgems/mruby-io/src/io.c +++ b/mrbgems/mruby-io/src/io.c @@ -1502,7 +1502,7 @@ io_sync(mrb_state *mrb, mrb_value io) return mrb_bool_value(fptr->sync); } -#ifndef MRB_WITH_IO_PREAD_PWRITE +#ifndef MRB_USE_IO_PREAD_PWRITE # define io_pread mrb_notimplement_m # define io_pwrite mrb_notimplement_m #else @@ -1541,7 +1541,7 @@ io_pwrite(mrb_state *mrb, mrb_value io) return io_write_common(mrb, pwrite, io_get_write_fptr(mrb, io), RSTRING_PTR(buf), RSTRING_LEN(buf), value2off(mrb, off)); } -#endif /* MRB_WITH_IO_PREAD_PWRITE */ +#endif /* MRB_USE_IO_PREAD_PWRITE */ static mrb_value io_ungetc(mrb_state *mrb, mrb_value io) diff --git a/mrbgems/mruby-io/test/io.rb b/mrbgems/mruby-io/test/io.rb index 811038ff4..e87cbe8fb 100644 --- a/mrbgems/mruby-io/test/io.rb +++ b/mrbgems/mruby-io/test/io.rb @@ -589,7 +589,7 @@ assert('IO#sysseek') do end assert('IO#pread') do - skip "IO#pread is not implemented on this configuration" unless MRubyIOTestUtil::MRB_WITH_IO_PREAD_PWRITE + skip "IO#pread is not implemented on this configuration" unless MRubyIOTestUtil::MRB_USE_IO_PREAD_PWRITE IO.open(IO.sysopen($mrbtest_io_rfname, 'r'), 'r') do |io| assert_equal $mrbtest_io_msg.byteslice(5, 8), io.pread(8, 5) @@ -601,7 +601,7 @@ assert('IO#pread') do end assert('IO#pwrite') do - skip "IO#pwrite is not implemented on this configuration" unless MRubyIOTestUtil::MRB_WITH_IO_PREAD_PWRITE + skip "IO#pwrite is not implemented on this configuration" unless MRubyIOTestUtil::MRB_USE_IO_PREAD_PWRITE IO.open(IO.sysopen($mrbtest_io_wfname, 'w+'), 'w+') do |io| assert_equal 6, io.pwrite("Warld!", 7) diff --git a/mrbgems/mruby-io/test/mruby_io_test.c b/mrbgems/mruby-io/test/mruby_io_test.c index 18989a20c..d47e20cad 100644 --- a/mrbgems/mruby-io/test/mruby_io_test.c +++ b/mrbgems/mruby-io/test/mruby_io_test.c @@ -225,10 +225,10 @@ mrb_io_win_p(mrb_state *mrb, mrb_value klass) #endif } -#ifdef MRB_WITH_IO_PREAD_PWRITE -# define MRB_WITH_IO_PREAD_PWRITE_ENABLED TRUE +#ifdef MRB_USE_IO_PREAD_PWRITE +# define MRB_USE_IO_PREAD_PWRITE_ENABLED TRUE #else -# define MRB_WITH_IO_PREAD_PWRITE_ENABLED FALSE +# define MRB_USE_IO_PREAD_PWRITE_ENABLED FALSE #endif void @@ -242,7 +242,7 @@ mrb_mruby_io_gem_test(mrb_state* mrb) mrb_define_class_method(mrb, io_test, "rmdir", mrb_io_test_rmdir, MRB_ARGS_REQ(1)); mrb_define_class_method(mrb, io_test, "win?", mrb_io_win_p, MRB_ARGS_NONE()); - mrb_define_const(mrb, io_test, "MRB_WITH_IO_PREAD_PWRITE", mrb_bool_value(MRB_WITH_IO_PREAD_PWRITE_ENABLED)); + mrb_define_const(mrb, io_test, "MRB_USE_IO_PREAD_PWRITE", mrb_bool_value(MRB_USE_IO_PREAD_PWRITE_ENABLED)); const char *env_home = getenv("HOME"); #ifdef _WIN32 From 6fb93ce6f763e09cad75edbc0be097233a2b9136 Mon Sep 17 00:00:00 2001 From: Hoshiumi Arata Date: Fri, 13 Dec 2024 12:07:34 +0900 Subject: [PATCH 4/4] mruby-bigint: fix bug with division of a small number by a bigint; fix #6456 --- mrbgems/mruby-bigint/core/bigint.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index 59c7bbe8d..297ffa7a9 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -589,8 +589,12 @@ mpz_mdiv(mrb_state *mrb, mpz_t *q, mpz_t *x, mpz_t *y) if (uzero_p(q)) q->sn = 0; /* now if r != 0 and q < 0 we need to round q towards -inf */ - if (!uzero_p(&r) && qsign < 0) + if (!uzero_p(&r) && qsign < 0) { + /* add 1 to magnitude */ mpz_add_int(mrb, q, 1); + /* force negative sign in case the value of q was zero before rounding */ + q->sn = -1; + } mpz_clear(mrb, &r); } @@ -654,8 +658,12 @@ mpz_mdivmod(mrb_state *mrb, mpz_t *q, mpz_t *r, mpz_t *x, mpz_t *y) if (uzero_p(q)) q->sn = 0; /* now if r != 0 and q < 0 we need to round q towards -inf */ - if (!uzero_p(r) && qsign < 0) + if (!uzero_p(r) && qsign < 0) { + /* add 1 to magnitude */ mpz_add_int(mrb, q, 1); + /* force negative sign in case the value of q was zero before rounding */ + q->sn = -1; + } } static void