diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 1eed0e2b5fc96f..d7526120853318 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -14,6 +14,7 @@ d1474affa8e105bece209cc9d594bb0a989859e1 # Indentation 0e4bad888e605d424b9222ae0ca43f85c1634e5e +61aa46c41648c6d1e9b0daa1a292de551fde78df # Enable Style/StringLiterals cop for RubyGems/Bundler d7ffd3fea402239b16833cc434404a7af82d44f3 @@ -42,6 +43,8 @@ d4e24021d39e1f80f0055b55d91f8d5f22e15084 e90282be7ba1bc8e3119f6e1a2c80356ceb3f80a 26a9e0b4e31f7b5a9cbd755e0a15823a8fa51bae 2f53985da9ee593fe524d408256835667938c7d7 +bf01f6ae89a95d8f5572e050facfe311c8c28aaf +7480cd8d37fd71a41ce12b759090051c7e14fb5a # Win32: EOL code of batch files 23f9a0d655c4d405bb2397a147a1523436205486 diff --git a/.github/actions/setup/baseruby/action.yml b/.github/actions/setup/baseruby/action.yml new file mode 100644 index 00000000000000..76fe068897a163 --- /dev/null +++ b/.github/actions/setup/baseruby/action.yml @@ -0,0 +1,73 @@ +name: Setup directories etc. +description: >- + Build baseruby for cross-compiling + +inputs: + srcdir: + required: true + default: ${{ github.workspace }} + description: >- + Directory of source codes. + + builddir: + required: false + default: ${{ github.workspace }}/baseruby + description: >- + Where baseruby will be built. + + installdir: + required: false + default: install + description: >- + The path where the baseruby will be installed to. + This is relative from the workspace. + +outputs: + ruby: + value: ${{ steps.build.outputs.installdir }}/bin/ruby + description: >- + The path of the executable baseruby. + dump_ast: + value: ${{ steps.build.outputs.installdir }}/bin/dump_ast + description: >- + The path of the executable dump_ast. + +runs: + using: composite + + steps: + - name: Build baseruby + shell: bash + id: build + run: | + case "$installdir" in /*) ;; *) installdir="$PWD/$installdir";; esac + mkdir "$builddir" + ln -sr "$srcdir" "$builddir/.src" + pushd "$builddir" + .src/configure "--prefix=${installdir}" --disable-install-doc + CONFIGURE_ARGS=--with-out-ext=-test- make install + install dump_ast "${installdir}/bin" + { + echo "${installdir}/bin/dump_ast" + echo "${installdir}/.installed.list" + echo "${installdir}/" + } >> .installed.list + cp .installed.list "${installdir}/" + make distclean + rm .src + popd + rmdir "$builddir" + { + echo "installdir=${installdir}" + } | tee -a "$GITHUB_OUTPUT" + env: + srcdir: ${{ inputs.srcdir }} + builddir: ${{ inputs.builddir }} + installdir: ${{ inputs.installdir }} + + - name: clean + uses: gacts/run-and-post-run@598d7a875d5620e0457490555b5e18e46082aa47 # v1.4.4 + with: + working-directory: ${{ inputs.srcdir }} + post: | + ruby tool/rbuninstall.rb "${{ steps.build.outputs.installdir }}/.installed.list" > /dev/null diff --git a/.github/actions/setup/ubuntu/action.yml b/.github/actions/setup/ubuntu/action.yml index b4454d49c72c96..5209ccc03f19b1 100644 --- a/.github/actions/setup/ubuntu/action.yml +++ b/.github/actions/setup/ubuntu/action.yml @@ -24,18 +24,38 @@ runs: using: composite steps: + - id: uname + name: uname + shell: bash + env: + arch: ${{ inputs.arch }} + run: | + setarch="${arch:+setarch $arch --}" + # normalize `uname` + if uname=$(${setarch} uname -m 2> /dev/null); then + # `setarch` works, `$arch` is a valid architecture name. + echo "setarch=${setarch}" >> "$GITHUB_OUTPUT" + else + # if `setarch` failed, take the given `arch` as-is. + uname="${arch}" + setarch="" + fi + echo "uname=$uname" >> "$GITHUB_OUTPUT" + echo "dpkg=${uname/686/386}" >> "$GITHUB_OUTPUT" + - name: set SETARCH shell: bash run: echo "SETARCH=${setarch}" >> "$GITHUB_ENV" # zizmor: ignore[github-env] env: - setarch: ${{ inputs.arch && format('setarch {0} --', inputs.arch) }} + setarch: ${{ steps.uname.outputs.setarch }} # validated - - id: uname - name: uname + - name: dpkg setup shell: bash - run: | - echo uname=`${SETARCH} uname -m` >> "$GITHUB_OUTPUT" - echo dpkg=`${SETARCH} uname -m | sed s/686/386/` >> "$GITHUB_OUTPUT" + run: sudo dpkg --add-architecture "${dpkg}" + # `dpkg` is valid, also `uname`. + if: ${{ inputs.arch }} + env: + dpkg: ${{ steps.uname.outputs.dpkg }} - name: apt-get shell: bash @@ -43,7 +63,6 @@ runs: arch: ${{ inputs.arch && format(':{0}', steps.uname.outputs.dpkg) || '' }} run: | set -x - ${arch:+sudo dpkg --add-architecture ${arch#:}} sudo apt-get update -qq || : sudo apt-get install --no-install-recommends -qq -y -o=Dpkg::Use-Pty=0 \ ${arch:+cross}build-essential${arch/:/-} \ diff --git a/.github/workflows/crosscompile.yml b/.github/workflows/crosscompile.yml index 2b75a75df4078e..4c28516e25bd2c 100644 --- a/.github/workflows/crosscompile.yml +++ b/.github/workflows/crosscompile.yml @@ -64,9 +64,8 @@ jobs: builddir: build makeup: true - - name: Install cross-compilation toolchain + - name: Setup cross-compilation toolchain sources run: | - sudo dpkg --add-architecture ${{ matrix.arch }} native_arch=$(dpkg --print-architecture) # Restrict existing sources to native arch sudo sed -i '/^Architectures:/d' /etc/apt/sources.list.d/ubuntu.sources @@ -84,24 +83,15 @@ jobs: "Components: main universe" \ "Architectures: ${{ matrix.arch }}" \ | sudo tee /etc/apt/sources.list.d/cross-${{ matrix.arch }}.sources - sudo apt-get update -qq - sudo apt-get install --no-install-recommends -qq -y \ - crossbuild-essential-${{ matrix.arch }} \ - libssl-dev:${{ matrix.arch }} \ - libyaml-dev:${{ matrix.arch }} \ - zlib1g-dev:${{ matrix.arch }} \ - libffi-dev:${{ matrix.arch }} \ - libreadline-dev:${{ matrix.arch }} \ - libncurses-dev:${{ matrix.arch }} \ - autoconf ruby - - - name: Build baseruby - run: | - mkdir ../baseruby - cd ../baseruby - ../src/configure --prefix=$PWD/install --disable-install-doc - make - make install + + - uses: ./.github/actions/setup/ubuntu + with: + arch: ${{ matrix.arch }} + + - uses: ./.github/actions/setup/baseruby + id: baseruby + with: + srcdir: src - name: Run configure run: >- @@ -109,7 +99,9 @@ jobs: --prefix=/usr --build=${{ matrix.build }} --host=${{ matrix.host }} - --with-baseruby=$PWD/../baseruby/install/bin/ruby + --with-baseruby="$baseruby" + env: + baseruby: ${{ steps.baseruby.outputs.ruby }} - run: make diff --git a/.github/workflows/wasm.yml b/.github/workflows/wasm.yml index 0d1fb61cc376dc..1a428f4f1c5405 100644 --- a/.github/workflows/wasm.yml +++ b/.github/workflows/wasm.yml @@ -104,17 +104,10 @@ jobs: run: | echo "WASI_SDK_PATH=/opt/wasi-sdk" >> $GITHUB_ENV - - name: Build baseruby + - uses: ./.github/actions/setup/baseruby id: baseruby - run: | - set -ex - mkdir ../baseruby - pushd ../baseruby - echo "ruby=$PWD/install/bin/ruby" >> $GITHUB_OUTPUT - echo "dump_ast=$PWD/dump_ast" >> $GITHUB_OUTPUT - ../src/configure --prefix=$PWD/install - make - make install + with: + srcdir: src - name: Download config.guess with wasi version run: | diff --git a/gc/mmtk/mmtk.c b/gc/mmtk/mmtk.c index aa6ac39d7495ea..143999c6a19c76 100644 --- a/gc/mmtk/mmtk.c +++ b/gc/mmtk/mmtk.c @@ -813,19 +813,25 @@ rb_gc_impl_get_vm_context(void *objspace_ptr) // Object allocation static VALUE -rb_mmtk_alloc_fast_path(struct objspace *objspace, struct MMTk_ractor_cache *ractor_cache, size_t size) +rb_mmtk_alloc_fast_path(struct objspace *objspace, struct MMTk_ractor_cache *ractor_cache, size_t size, size_t align) { MMTk_BumpPointer *bump_pointer = ractor_cache->bump_pointer; if (bump_pointer == NULL) return 0; - uintptr_t new_cursor = bump_pointer->cursor + size; + uintptr_t cursor = bump_pointer->cursor; - if (new_cursor > bump_pointer->limit) { + // Ensure cursor is aligned + size_t mask = align - 1; + cursor = (cursor + mask) & ~mask; + + cursor += size; + + if (cursor > bump_pointer->limit) { return 0; } else { - VALUE obj = (VALUE)bump_pointer->cursor; - bump_pointer->cursor = new_cursor; + VALUE obj = cursor - size; + bump_pointer->cursor = cursor; return obj; } } @@ -910,7 +916,7 @@ rb_gc_impl_new_obj(void *objspace_ptr, void *cache_ptr, VALUE klass, VALUE flags // Layout: [hidden size header (sizeof(VALUE))][payload (alloc_size)][suffix (RVALUE_SUFFIX_SIZE)] alloc_size += sizeof(VALUE) + RVALUE_SUFFIX_SIZE; - VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size); + VALUE *alloc_obj = (VALUE *)rb_mmtk_alloc_fast_path(objspace, ractor_cache, alloc_size, MMTk_MIN_OBJ_ALIGN); if (!alloc_obj) { alloc_obj = mmtk_alloc(ractor_cache->mutator, alloc_size, MMTk_MIN_OBJ_ALIGN, 0, MMTK_ALLOCATION_SEMANTICS_DEFAULT); } diff --git a/string.c b/string.c index c72e2a8e36b17b..eb249662db74eb 100644 --- a/string.c +++ b/string.c @@ -11122,48 +11122,48 @@ rb_str_justify(int argc, VALUE *argv, VALUE str, char jflag) rlen = n - llen; cr = ENC_CODERANGE(str); if (flen > 1) { - llen2 = str_offset(f, f + flen, llen % fclen, enc, singlebyte); - rlen2 = str_offset(f, f + flen, rlen % fclen, enc, singlebyte); + llen2 = str_offset(f, f + flen, llen % fclen, enc, singlebyte); + rlen2 = str_offset(f, f + flen, rlen % fclen, enc, singlebyte); } size = RSTRING_LEN(str); if ((len = llen / fclen + rlen / fclen) >= LONG_MAX / flen || - (len *= flen) >= LONG_MAX - llen2 - rlen2 || - (len += llen2 + rlen2) >= LONG_MAX - size) { - rb_raise(rb_eArgError, "argument too big"); + (len *= flen) >= LONG_MAX - llen2 - rlen2 || + (len += llen2 + rlen2) >= LONG_MAX - size) { + rb_raise(rb_eArgError, "argument too big"); } len += size; res = str_enc_new(rb_cString, 0, len, enc); p = RSTRING_PTR(res); if (flen <= 1) { - memset(p, *f, llen); - p += llen; + memset(p, *f, llen); + p += llen; } else { - while (llen >= fclen) { + while (llen >= fclen) { memcpy(p,f,flen); p += flen; llen -= fclen; } - if (llen > 0) { - memcpy(p, f, llen2); - p += llen2; + if (llen > 0) { + memcpy(p, f, llen2); + p += llen2; } } memcpy(p, RSTRING_PTR(str), size); p += size; if (flen <= 1) { - memset(p, *f, rlen); - p += rlen; + memset(p, *f, rlen); + p += rlen; } else { - while (rlen >= fclen) { + while (rlen >= fclen) { memcpy(p,f,flen); p += flen; rlen -= fclen; } - if (rlen > 0) { - memcpy(p, f, rlen2); - p += rlen2; + if (rlen > 0) { + memcpy(p, f, rlen2); + p += rlen2; } } TERM_FILL(p, termlen);