mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-09-26 12:13:39 -06:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f52f6dcfaf | ||
|
|
3de34a77e9 | ||
|
|
81df12684f | ||
|
|
a3a13f061f | ||
|
|
085028a8e1 | ||
|
|
04f5f88b33 |
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"words": [
|
||||||
|
"dealloc",
|
||||||
|
"finalizer",
|
||||||
|
"gcollect",
|
||||||
|
"libc",
|
||||||
|
"realloc",
|
||||||
|
"repr",
|
||||||
|
"stackbottom"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
name: setup
|
|
||||||
description: Sets up a build environment
|
|
||||||
inputs: {}
|
|
||||||
outputs: {}
|
|
||||||
runs:
|
|
||||||
using: composite
|
|
||||||
steps:
|
|
||||||
- uses: swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
|
|
||||||
- uses: homebrew/actions/setup-homebrew@e99025eb970cfa124b8284a35463d87426917478 # main
|
|
||||||
- run: brew install autoconf automake libtool
|
|
||||||
shell: sh
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
pull_request_rules:
|
||||||
|
- name: dependabot
|
||||||
|
conditions:
|
||||||
|
- author=dependabot[bot]
|
||||||
|
actions:
|
||||||
|
queue:
|
||||||
|
name: default
|
||||||
|
method: squash
|
||||||
|
queue_rules:
|
||||||
|
- name: default
|
||||||
|
conditions: []
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
name: dependabot
|
|
||||||
on: pull_request
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
jobs:
|
|
||||||
merge:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: github.actor == 'dependabot[bot]'
|
|
||||||
steps:
|
|
||||||
- run: gh pr merge --auto --squash ${{ github.event.pull_request.html_url }}
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
name: document
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
pages: write
|
|
||||||
id-token: write
|
|
||||||
jobs:
|
|
||||||
document:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
|
|
||||||
- uses: swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
|
|
||||||
- run: cargo doc --no-deps
|
|
||||||
- run: rm target/doc/.lock
|
|
||||||
- uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
|
|
||||||
with:
|
|
||||||
path: target/doc
|
|
||||||
- uses: actions/deploy-pages@368f82528645a54fb793d4d04e342629a3f51346 # v5.0.1
|
|
||||||
if: github.ref == 'refs/heads/main'
|
|
||||||
+11
-19
@@ -5,38 +5,30 @@ on:
|
|||||||
- main
|
- main
|
||||||
pull_request:
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
clippy:
|
lint:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- uses: swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
|
- uses: Swatinem/rust-cache@v2
|
||||||
- run: cargo clippy -- -D warnings
|
- run: cargo clippy -- -D warnings
|
||||||
format:
|
format:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@v3
|
||||||
- run: cargo fmt --all -- --check
|
- run: cargo fmt -- --check
|
||||||
spell-check:
|
spell-check:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@v3
|
||||||
- uses: streetsidesoftware/cspell-action@6f3c77c1406bc930f944ba97e9801a22e42caf58 # v9.1.0
|
- uses: streetsidesoftware/cspell-action@main
|
||||||
with:
|
with:
|
||||||
files: "**/*.{md,rs}"
|
files: "**/*.{md,rs}"
|
||||||
readme:
|
readme:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
- uses: actions/checkout@v3
|
||||||
- uses: lycheeverse/lychee-action@e7477775783ea5526144ba13e8db5eec57747ce8 # v2.9.0
|
- uses: lycheeverse/lychee-action@v1
|
||||||
lint:
|
with:
|
||||||
needs:
|
fail: true
|
||||||
- clippy
|
|
||||||
- format
|
|
||||||
- spell-check
|
|
||||||
- readme
|
|
||||||
if: always()
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- run: for result in ${{ join(needs.*.result, ' ') }}; do [ $result = success ]; done
|
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
name: release
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- main
|
|
||||||
pull_request:
|
|
||||||
concurrency:
|
|
||||||
group: release-${{ github.ref }}
|
|
||||||
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
|
|
||||||
jobs:
|
|
||||||
release:
|
|
||||||
permissions:
|
|
||||||
id-token: write
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
environment: ${{ github.ref == 'refs/heads/main' && 'release' || '' }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- uses: swatinem/rust-cache@6323deb102c322ba6fcbdcafc7e3dddab59af2b6 # v2.9.2
|
|
||||||
- run: cargo install cargo-workspaces
|
|
||||||
- uses: rust-lang/crates-io-auth-action@c6f97d42243bad5fab37ca0427f495c86d5b1a18 # v1.0.5
|
|
||||||
id: auth
|
|
||||||
if: github.ref == 'refs/heads/main'
|
|
||||||
- run: >
|
|
||||||
cargo workspaces publish -y --from-git --no-verify
|
|
||||||
${{ github.ref != 'refs/heads/main' && '--dry-run' || '' }}
|
|
||||||
env:
|
|
||||||
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
|
|
||||||
+31
-54
@@ -6,59 +6,36 @@ on:
|
|||||||
pull_request:
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- ubuntu-26.04-arm
|
|
||||||
- macos-latest
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- uses: ./.github/actions/setup
|
|
||||||
- run: cargo build
|
|
||||||
unit_test:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- ubuntu-26.04-arm
|
|
||||||
- macos-latest
|
|
||||||
options:
|
|
||||||
-
|
|
||||||
- --no-default-features --features cmake
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- uses: ./.github/actions/setup
|
|
||||||
- run: cargo test ${{ matrix.options }}
|
|
||||||
examples:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
os:
|
|
||||||
- ubuntu-latest
|
|
||||||
- ubuntu-26.04-arm
|
|
||||||
- macos-latest
|
|
||||||
runs-on: ${{ matrix.os }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
||||||
with:
|
|
||||||
submodules: true
|
|
||||||
- uses: ./.github/actions/setup
|
|
||||||
- run: tools/example_test.sh
|
|
||||||
test:
|
|
||||||
needs:
|
|
||||||
- build
|
|
||||||
- unit_test
|
|
||||||
- examples
|
|
||||||
if: always()
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- run: for result in ${{ join(needs.*.result, ' ') }}; do [ $result = success ]; done
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: cargo build
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: cargo test
|
||||||
|
examples:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: |
|
||||||
|
cd examples
|
||||||
|
./test.sh
|
||||||
|
cmake:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: cargo build --no-default-features --features cmake
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
.cargo_cache
|
*.lock
|
||||||
target
|
target
|
||||||
|
|||||||
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
[submodule "vendor/bdwgc"]
|
[submodule "vendor/bdwgc"]
|
||||||
path = bdwgc-alloc-sys/vendor/bdwgc
|
path = vendor/bdwgc
|
||||||
url = https://github.com/bdwgc/bdwgc
|
url = https://github.com/ivmai/bdwgc
|
||||||
[submodule "vendor/libatomic_ops"]
|
[submodule "vendor/libatomic_ops"]
|
||||||
path = bdwgc-alloc-sys/vendor/libatomic_ops
|
path = vendor/libatomic_ops
|
||||||
url = https://github.com/bdwgc/libatomic_ops
|
url = https://github.com/ivmai/libatomic_ops
|
||||||
|
|||||||
Generated
-289
@@ -1,289 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
version = 4
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aho-corasick"
|
|
||||||
version = "1.1.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "autotools"
|
|
||||||
version = "0.2.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ef941527c41b0fc0dd48511a8154cd5fc7e29200a0ff8b7203c5d777dbc795cf"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bdwgc-alloc"
|
|
||||||
version = "0.6.15"
|
|
||||||
dependencies = [
|
|
||||||
"bdwgc-alloc-sys",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bdwgc-alloc-sys"
|
|
||||||
version = "0.6.15"
|
|
||||||
dependencies = [
|
|
||||||
"autotools",
|
|
||||||
"bindgen",
|
|
||||||
"cmake",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bindgen"
|
|
||||||
version = "0.73.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "787ef8ef523575546b106a58213d6e6b06198a05c2f757258c68a74273670cfa"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"cexpr",
|
|
||||||
"clang-sys",
|
|
||||||
"log",
|
|
||||||
"prettyplease",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"regex",
|
|
||||||
"rustc-hash",
|
|
||||||
"shlex 2.0.1",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bitflags"
|
|
||||||
version = "2.13.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cc"
|
|
||||||
version = "1.2.49"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "90583009037521a116abf44494efecd645ba48b6622457080f080b85544e2215"
|
|
||||||
dependencies = [
|
|
||||||
"find-msvc-tools",
|
|
||||||
"shlex 1.3.0",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cexpr"
|
|
||||||
version = "0.6.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
|
||||||
dependencies = [
|
|
||||||
"nom",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cfg-if"
|
|
||||||
version = "1.0.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "clang-sys"
|
|
||||||
version = "1.9.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a"
|
|
||||||
dependencies = [
|
|
||||||
"glob",
|
|
||||||
"libc",
|
|
||||||
"libloading",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cmake"
|
|
||||||
version = "0.1.58"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "c0f78a02292a74a88ac736019ab962ece0bc380e3f977bf72e376c5d78ff0678"
|
|
||||||
dependencies = [
|
|
||||||
"cc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dynamic_threads"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"bdwgc-alloc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "find-msvc-tools"
|
|
||||||
version = "0.1.5"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "free_by_borrow"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"bdwgc-alloc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "free_by_gc"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"bdwgc-alloc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "glob"
|
|
||||||
version = "0.3.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libc"
|
|
||||||
version = "0.2.189"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "libloading"
|
|
||||||
version = "0.8.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
|
|
||||||
dependencies = [
|
|
||||||
"cfg-if",
|
|
||||||
"windows-link",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "log"
|
|
||||||
version = "0.4.34"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f9f8bd3e56ce4dfc153cf470fffbfa98c7620958b312ca5c3a4b8d5181fd13c6"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "memchr"
|
|
||||||
version = "2.8.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "minimal-lexical"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "nom"
|
|
||||||
version = "7.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
"minimal-lexical",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "prettyplease"
|
|
||||||
version = "0.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2bfe0f4c752e450fc2faf62654f1c134747922825d5b04ca717b8874f41a40c0"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"syn",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "proc-macro2"
|
|
||||||
version = "1.0.107"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
||||||
dependencies = [
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "quote"
|
|
||||||
version = "1.0.47"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex"
|
|
||||||
version = "1.13.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
|
|
||||||
dependencies = [
|
|
||||||
"aho-corasick",
|
|
||||||
"memchr",
|
|
||||||
"regex-automata",
|
|
||||||
"regex-syntax",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex-automata"
|
|
||||||
version = "0.4.18"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ad8553b9b26413251cbf30e620595c7a41b3887f03da04579c0e6b0d6a06b4b2"
|
|
||||||
dependencies = [
|
|
||||||
"aho-corasick",
|
|
||||||
"memchr",
|
|
||||||
"regex-syntax",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "regex-syntax"
|
|
||||||
version = "0.8.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustc-hash"
|
|
||||||
version = "2.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shlex"
|
|
||||||
version = "1.3.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "shlex"
|
|
||||||
version = "2.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "static_threads"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"bdwgc-alloc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "syn"
|
|
||||||
version = "3.0.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee"
|
|
||||||
dependencies = [
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"unicode-ident",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unicode-ident"
|
|
||||||
version = "1.0.26"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "windows-link"
|
|
||||||
version = "0.2.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
|
||||||
+19
-18
@@ -1,21 +1,22 @@
|
|||||||
[workspace]
|
[package]
|
||||||
resolver = "3"
|
name = "bdwgc-alloc"
|
||||||
members = ["bdwgc-alloc", "bdwgc-alloc-sys", "examples/*"]
|
description = "impl GlobalAlloc for bdwgc"
|
||||||
default-members = ["bdwgc-alloc", "bdwgc-alloc-sys"]
|
version = "0.6.5"
|
||||||
|
authors = [
|
||||||
[workspace.package]
|
"swgillespie <sean.william.g@gmail.com>",
|
||||||
version = "0.6.15"
|
"Yota Toyama <raviqqe@gmail.com>",
|
||||||
edition = "2024"
|
]
|
||||||
repository = "https://github.com/bdwgc/bdwgc-rust"
|
repository = "https://github.com/raviqqe/bdwgc-alloc"
|
||||||
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
build = "build.rs"
|
||||||
|
|
||||||
[workspace.lints.clippy]
|
[features]
|
||||||
alloc_instead_of_core = "deny"
|
default = ["autotools"]
|
||||||
dbg_macro = "deny"
|
|
||||||
missing_const_for_fn = "deny"
|
|
||||||
std_instead_of_alloc = "deny"
|
|
||||||
std_instead_of_core = "deny"
|
|
||||||
|
|
||||||
[workspace.lints.rust]
|
[dependencies]
|
||||||
missing_docs = "deny"
|
libc = "0.2"
|
||||||
warnings = "deny"
|
|
||||||
|
[build-dependencies]
|
||||||
|
autotools = { version = "0.2", optional = true }
|
||||||
|
cmake = { version = "0.1", optional = true }
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
# bdwgc-rust
|
# bdwgc-alloc
|
||||||
|
|
||||||
[](https://github.com/bdwgc/bdwgc-rust/actions)
|
[](https://github.com/raviqqe/bdwgc-alloc/actions)
|
||||||
[](https://crates.io/crates/bdwgc-alloc)
|
[](https://crates.io/crates/bdwgc-alloc)
|
||||||
[](https://github.com/bdwgc/bdwgc-rust/blob/main/LICENSE)
|
[](LICENSE)
|
||||||
|
|
||||||
[`GlobalAlloc`](https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html) implementation for [`bdwgc`][bdwgc], the conservative garbage collector.
|
[`GlobalAlloc`](https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html) implementation for [`bdwgc`][bdwgc], the conservative garbage collector.
|
||||||
|
|
||||||
This crate is for use cases in which developers need to integrate [`bdwgc`][bdwgc] into their programs written in Rust (e.g. writing a runtime library in Rust for their own programming language whose GC is done by [`bdwgc`][bdwgc].)
|
This crate is for use cases in which developers need to integrate [`bdwgc`][bdwgc] into their programs written in Rust (e.g. writing a runtime library in Rust for their own programming language whose GC is done by [`bdwgc`][bdwgc].)
|
||||||
|
|
||||||
The raw bindings to the C API of [`bdwgc`][bdwgc] that this crate is built on are available as the `bdwgc-alloc-sys` crate.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
See [`examples`](https://github.com/bdwgc/bdwgc-rust/tree/main/examples) directory.
|
See [`examples`](examples) directory.
|
||||||
|
|
||||||
By default [`bdwgc`][bdwgc] is built with autotools. To build with cmake, enable the `cmake` feature:
|
By default [`bdwgc`][bdwgc] is built with autotools. To build with cmake, enable the `cmake` feature:
|
||||||
|
|
||||||
@@ -22,6 +20,6 @@ cargo build --no-default-features --features cmake
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
[MIT](https://github.com/bdwgc/bdwgc-rust/blob/main/LICENSE)
|
[MIT](LICENSE)
|
||||||
|
|
||||||
[bdwgc]: https://github.com/bdwgc/bdwgc
|
[bdwgc]: https://github.com/ivmai/bdwgc
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "bdwgc-alloc-sys"
|
|
||||||
version.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
description = "Rust bindings to the bdwgc C API"
|
|
||||||
documentation = "https://bdwgc.github.io/bdwgc-rust/bdwgc_alloc_sys/"
|
|
||||||
repository.workspace = true
|
|
||||||
license.workspace = true
|
|
||||||
categories = ["external-ffi-bindings", "memory-management", "no-std", "no-std::no-alloc"]
|
|
||||||
links = "gc"
|
|
||||||
|
|
||||||
[build-dependencies]
|
|
||||||
autotools = { version = "0.2.7", optional = true }
|
|
||||||
bindgen = "0.73.2"
|
|
||||||
cmake = { version = "0.1.58", optional = true }
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["autotools"]
|
|
||||||
|
|
||||||
[lints]
|
|
||||||
workspace = true
|
|
||||||
|
|
||||||
[[test]]
|
|
||||||
name = "collector"
|
|
||||||
harness = false
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
# bdwgc-alloc-sys
|
|
||||||
|
|
||||||
[](https://github.com/bdwgc/bdwgc-rust/actions)
|
|
||||||
[](https://github.com/bdwgc/bdwgc-rust/blob/main/LICENSE)
|
|
||||||
|
|
||||||
Rust bindings to the C API of [`bdwgc`][bdwgc], the conservative garbage collector.
|
|
||||||
|
|
||||||
This crate builds [`bdwgc`][bdwgc] from its vendored source and links it statically. The bindings are generated from its headers at build time by [`bindgen`](https://github.com/rust-lang/rust-bindgen), which requires `libclang`.
|
|
||||||
|
|
||||||
See the [`bdwgc-alloc`](https://crates.io/crates/bdwgc-alloc) crate for a [`GlobalAlloc`](https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html) implementation on top of these bindings.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
```sh
|
|
||||||
cargo add bdwgc-alloc-sys
|
|
||||||
```
|
|
||||||
|
|
||||||
By default [`bdwgc`][bdwgc] is built with autotools. To build with cmake, enable the `cmake` feature:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
cargo add bdwgc-alloc-sys --no-default-features --features cmake
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
|
||||||
|
|
||||||
[MIT](https://github.com/bdwgc/bdwgc-rust/blob/main/LICENSE)
|
|
||||||
|
|
||||||
[bdwgc]: https://github.com/bdwgc/bdwgc
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
//! A build script.
|
|
||||||
|
|
||||||
use core::error::Error;
|
|
||||||
use std::{env, path::PathBuf};
|
|
||||||
|
|
||||||
// cspell: ignore reconf
|
|
||||||
|
|
||||||
const LIB_ATOMIC_OPS_DIR: &str = "vendor/libatomic_ops";
|
|
||||||
const LIB_GC_DIR: &str = "vendor/bdwgc";
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn Error>> {
|
|
||||||
build_library()?;
|
|
||||||
|
|
||||||
bindgen::builder()
|
|
||||||
.header(format!("{LIB_GC_DIR}/include/gc.h"))
|
|
||||||
.clang_arg(format!("-I{LIB_GC_DIR}/include"))
|
|
||||||
.clang_arg("-DGC_THREADS")
|
|
||||||
.use_core()
|
|
||||||
.allowlist_item("GC_.*")
|
|
||||||
.default_macro_constant_type(bindgen::MacroTypeVariation::Signed)
|
|
||||||
.generate()?
|
|
||||||
.write_to_file(PathBuf::from(env::var("OUT_DIR")?).join("bindings.rs"))?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg_select! {
|
|
||||||
feature = "cmake" => {
|
|
||||||
fn build_library() -> Result<(), Box<dyn Error>> {
|
|
||||||
use cmake::Config;
|
|
||||||
use std::path::Path;
|
|
||||||
|
|
||||||
let libatomic_include_path = Path::new(LIB_ATOMIC_OPS_DIR)
|
|
||||||
.join("src")
|
|
||||||
.canonicalize()?
|
|
||||||
.display()
|
|
||||||
.to_string()
|
|
||||||
.replace(r"\\?\", "");
|
|
||||||
|
|
||||||
let dst = Config::new(LIB_GC_DIR)
|
|
||||||
.profile("Release")
|
|
||||||
.define("GC_BUILD_SHARED_LIBS", "FALSE")
|
|
||||||
.cflag(format!("-I{}", libatomic_include_path))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search=native={}",
|
|
||||||
dst.join("lib").display()
|
|
||||||
);
|
|
||||||
println!("cargo:rustc-link-lib=static=gc");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
feature = "autotools" => {
|
|
||||||
fn build_library() -> Result<(), Box<dyn Error>> {
|
|
||||||
let dst = autotools::Config::new(LIB_ATOMIC_OPS_DIR)
|
|
||||||
.reconf("-i")
|
|
||||||
.cflag("-fPIC")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search=native={}",
|
|
||||||
dst.join("lib").display()
|
|
||||||
);
|
|
||||||
println!("cargo:rustc-link-lib=static=atomic_ops");
|
|
||||||
|
|
||||||
let dst = autotools::Config::new(LIB_GC_DIR)
|
|
||||||
.reconf("-i")
|
|
||||||
.cflag(format!(
|
|
||||||
// spell-checker: disable-next-line
|
|
||||||
"-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC",
|
|
||||||
dst.join("include").display()
|
|
||||||
))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
println!(
|
|
||||||
"cargo:rustc-link-search=native={}",
|
|
||||||
dst.join("lib").display()
|
|
||||||
);
|
|
||||||
println!("cargo:rustc-link-lib=static=gc");
|
|
||||||
|
|
||||||
for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] {
|
|
||||||
std::process::Command::new("sh")
|
|
||||||
.arg("-c")
|
|
||||||
.arg(format!("cd {dir} && git clean -dfx"))
|
|
||||||
.output()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
#![doc = include_str!("../README.md")]
|
|
||||||
#![no_std]
|
|
||||||
#![allow(missing_docs)]
|
|
||||||
#![allow(non_camel_case_types)]
|
|
||||||
#![allow(non_snake_case)]
|
|
||||||
#![allow(non_upper_case_globals)]
|
|
||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
//! A smoke test of the bindings.
|
|
||||||
|
|
||||||
use bdwgc_alloc_sys::{
|
|
||||||
GC_SUCCESS, GC_allow_register_threads, GC_free, GC_gcollect, GC_get_stack_base, GC_init,
|
|
||||||
GC_malloc, GC_realloc, GC_register_finalizer, GC_register_my_thread, GC_stack_base,
|
|
||||||
GC_unregister_my_thread,
|
|
||||||
};
|
|
||||||
use core::{
|
|
||||||
ffi::c_void,
|
|
||||||
ptr::null_mut,
|
|
||||||
sync::atomic::{AtomicUsize, Ordering},
|
|
||||||
};
|
|
||||||
use std::thread::spawn;
|
|
||||||
|
|
||||||
const TOTAL_COUNT: usize = 1 << 10;
|
|
||||||
|
|
||||||
static FINALIZED_COUNT: AtomicUsize = AtomicUsize::new(0);
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
unsafe {
|
|
||||||
GC_init();
|
|
||||||
GC_allow_register_threads();
|
|
||||||
}
|
|
||||||
|
|
||||||
allocate();
|
|
||||||
finalize();
|
|
||||||
register_thread();
|
|
||||||
}
|
|
||||||
|
|
||||||
fn allocate() {
|
|
||||||
let ptr = unsafe { GC_malloc(42) };
|
|
||||||
assert!(!ptr.is_null());
|
|
||||||
|
|
||||||
let ptr = unsafe { GC_realloc(ptr, 84) };
|
|
||||||
assert!(!ptr.is_null());
|
|
||||||
|
|
||||||
unsafe { GC_free(ptr) };
|
|
||||||
}
|
|
||||||
|
|
||||||
fn finalize() {
|
|
||||||
extern "C" fn count(_object: *mut c_void, _client_data: *mut c_void) {
|
|
||||||
FINALIZED_COUNT.fetch_add(1, Ordering::Relaxed);
|
|
||||||
}
|
|
||||||
|
|
||||||
for _ in 0..TOTAL_COUNT {
|
|
||||||
unsafe {
|
|
||||||
GC_register_finalizer(
|
|
||||||
GC_malloc(42),
|
|
||||||
Some(count),
|
|
||||||
null_mut(),
|
|
||||||
null_mut(),
|
|
||||||
null_mut(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe { GC_gcollect() };
|
|
||||||
|
|
||||||
// TODO Is there any way to collect all?
|
|
||||||
assert!(FINALIZED_COUNT.load(Ordering::Relaxed) > TOTAL_COUNT / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn register_thread() {
|
|
||||||
spawn(|| {
|
|
||||||
let mut base = GC_stack_base {
|
|
||||||
mem_base: null_mut(),
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(unsafe { GC_get_stack_base(&mut base) }, GC_SUCCESS);
|
|
||||||
assert_eq!(unsafe { GC_register_my_thread(&base) }, GC_SUCCESS);
|
|
||||||
assert!(!unsafe { GC_malloc(42) }.is_null());
|
|
||||||
assert_eq!(unsafe { GC_unregister_my_thread() }, GC_SUCCESS);
|
|
||||||
})
|
|
||||||
.join()
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
||||||
Vendored
-1
Submodule bdwgc-alloc-sys/vendor/bdwgc deleted from 2547e33aa8
Vendored
-1
Submodule bdwgc-alloc-sys/vendor/libatomic_ops deleted from d007246aa7
@@ -1,20 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "bdwgc-alloc"
|
|
||||||
version.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
description = "impl GlobalAlloc for bdwgc"
|
|
||||||
documentation = "https://bdwgc.github.io/bdwgc-rust/bdwgc_alloc/"
|
|
||||||
repository.workspace = true
|
|
||||||
license.workspace = true
|
|
||||||
categories = ["api-bindings", "memory-management", "no-std", "no-std::no-alloc"]
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
bdwgc-alloc-sys = { version = "0.6.15", path = "../bdwgc-alloc-sys", default-features = false }
|
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["autotools"]
|
|
||||||
autotools = ["bdwgc-alloc-sys/autotools"]
|
|
||||||
cmake = ["bdwgc-alloc-sys/cmake"]
|
|
||||||
|
|
||||||
[lints]
|
|
||||||
workspace = true
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../README.md
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
#![doc = include_str!("../README.md")]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
mod error;
|
|
||||||
|
|
||||||
use bdwgc_alloc_sys::{
|
|
||||||
GC_SUCCESS, GC_alloc_lock, GC_alloc_unlock, GC_allow_register_threads, GC_free, GC_gcollect,
|
|
||||||
GC_get_stack_base, GC_init, GC_malloc, GC_realloc, GC_register_finalizer,
|
|
||||||
GC_register_my_thread, GC_set_stackbottom, GC_stack_base, GC_unregister_my_thread,
|
|
||||||
};
|
|
||||||
use core::{
|
|
||||||
alloc::{GlobalAlloc, Layout},
|
|
||||||
ffi::c_void,
|
|
||||||
ptr::null_mut,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// An allocator.
|
|
||||||
pub struct Allocator;
|
|
||||||
|
|
||||||
impl Allocator {
|
|
||||||
/// Locks a collector.
|
|
||||||
pub fn lock() {
|
|
||||||
unsafe { GC_alloc_lock() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unlocks a collector.
|
|
||||||
pub fn unlock() {
|
|
||||||
unsafe { GC_alloc_unlock() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Initializes a collector.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// This function must be called in a main thread.
|
|
||||||
pub unsafe fn initialize() {
|
|
||||||
unsafe {
|
|
||||||
GC_init();
|
|
||||||
GC_allow_register_threads();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Registers a current thread to a collector.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// This function must not be called in a main thread.
|
|
||||||
pub unsafe fn register_current_thread() -> Result<(), error::Error> {
|
|
||||||
let mut base = GC_stack_base {
|
|
||||||
mem_base: null_mut(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if unsafe { GC_get_stack_base(&mut base) } != GC_SUCCESS {
|
|
||||||
return Err(error::Error::new("failed to get stack base"));
|
|
||||||
} else if unsafe { GC_register_my_thread(&base) } != GC_SUCCESS {
|
|
||||||
return Err(error::Error::new("failed to register a thread for GC"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets a bottom of a stack.
|
|
||||||
///
|
|
||||||
/// You do not have to call this function in most cases.
|
|
||||||
/// A collector detects the bottom on initialization automatically.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// The bottom address must be valid.
|
|
||||||
pub unsafe fn set_stack_bottom(bottom: *const u8) {
|
|
||||||
unsafe {
|
|
||||||
GC_set_stackbottom(
|
|
||||||
null_mut(),
|
|
||||||
&GC_stack_base {
|
|
||||||
mem_base: bottom.cast_mut().cast(),
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unregisters a current thread from a collector.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// The thread must be registered already.
|
|
||||||
pub unsafe fn unregister_current_thread() {
|
|
||||||
unsafe { GC_unregister_my_thread() };
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Runs a garbage collection forcibly.
|
|
||||||
pub fn force_collect() {
|
|
||||||
unsafe { GC_gcollect() }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Registers a finalizer of an object.
|
|
||||||
///
|
|
||||||
/// # Safety
|
|
||||||
///
|
|
||||||
/// The given finalizer must not be null and handle pointers properly.
|
|
||||||
pub unsafe fn register_finalizer(
|
|
||||||
ptr: *const c_void,
|
|
||||||
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
|
||||||
client_data: *const c_void,
|
|
||||||
) {
|
|
||||||
unsafe {
|
|
||||||
GC_register_finalizer(
|
|
||||||
ptr.cast_mut(),
|
|
||||||
Some(finalizer),
|
|
||||||
client_data.cast_mut(),
|
|
||||||
null_mut(),
|
|
||||||
null_mut(),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl GlobalAlloc for Allocator {
|
|
||||||
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
|
||||||
(unsafe { GC_malloc(layout.size()) }) as *mut u8
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
|
||||||
unsafe { GC_free(ptr as *mut c_void) }
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, size: usize) -> *mut u8 {
|
|
||||||
(unsafe { GC_realloc(ptr as *mut c_void, size) }) as *mut u8
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
const LIB_ATOMIC_OPS_DIR: &str = "vendor/libatomic_ops";
|
||||||
|
const LIB_GC_DIR: &str = "vendor/bdwgc";
|
||||||
|
|
||||||
|
#[cfg(feature = "autotools")]
|
||||||
|
fn main() {
|
||||||
|
for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] {
|
||||||
|
std::process::Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(format!("cd {} && ./autogen.sh", dir))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let dst = autotools::Config::new(LIB_ATOMIC_OPS_DIR)
|
||||||
|
.cflag("-fPIC")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-search=native={}",
|
||||||
|
dst.join("lib").display()
|
||||||
|
);
|
||||||
|
println!("cargo:rustc-link-lib=static=atomic_ops");
|
||||||
|
|
||||||
|
let dst = autotools::Config::new(LIB_GC_DIR)
|
||||||
|
.cflag(format!(
|
||||||
|
"-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC",
|
||||||
|
dst.join("include").display()
|
||||||
|
))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-search=native={}",
|
||||||
|
dst.join("lib").display()
|
||||||
|
);
|
||||||
|
println!("cargo:rustc-link-lib=static=gc");
|
||||||
|
|
||||||
|
for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] {
|
||||||
|
std::process::Command::new("sh")
|
||||||
|
.arg("-c")
|
||||||
|
.arg(format!("cd {} && git clean -dfx", dir))
|
||||||
|
.output()
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "cmake")]
|
||||||
|
fn main() {
|
||||||
|
use cmake::Config;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
let libatomic_include_path = Path::new(LIB_ATOMIC_OPS_DIR)
|
||||||
|
.join("src")
|
||||||
|
.canonicalize()
|
||||||
|
.unwrap()
|
||||||
|
.display()
|
||||||
|
.to_string()
|
||||||
|
.replace(r"\\?\", "");
|
||||||
|
|
||||||
|
let dst = Config::new(LIB_GC_DIR)
|
||||||
|
.profile("Release")
|
||||||
|
.define("BUILD_SHARED_LIBS", "FALSE")
|
||||||
|
.cflag(format!("-I{}", libatomic_include_path))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"cargo:rustc-link-search=native={}",
|
||||||
|
dst.join("lib").display()
|
||||||
|
);
|
||||||
|
println!("cargo:rustc-link-lib=static=gc");
|
||||||
|
}
|
||||||
-24
@@ -1,24 +0,0 @@
|
|||||||
{
|
|
||||||
"words": [
|
|
||||||
"autogen",
|
|
||||||
"autotools",
|
|
||||||
"bdwgc",
|
|
||||||
"bindgen",
|
|
||||||
"canonicalize",
|
|
||||||
"cflag",
|
|
||||||
"clippy",
|
|
||||||
"dealloc",
|
|
||||||
"finalizer",
|
|
||||||
"gcollect",
|
|
||||||
"gitsubmodule",
|
|
||||||
"libatomic",
|
|
||||||
"libc",
|
|
||||||
"libclang",
|
|
||||||
"realloc",
|
|
||||||
"repr",
|
|
||||||
"rustc",
|
|
||||||
"stackbottom",
|
|
||||||
"swatinem",
|
|
||||||
"unregisters"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"dynamic_threads",
|
||||||
|
"free_by_borrow",
|
||||||
|
"free_by_gc",
|
||||||
|
"static_threads",
|
||||||
|
]
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dynamic_threads"
|
name = "dynamic_threads"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bdwgc-alloc = { path = "../../bdwgc-alloc" }
|
bdwgc-alloc = { path = "../.." }
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
extern crate bdwgc_alloc;
|
||||||
|
|
||||||
use bdwgc_alloc::Allocator;
|
use bdwgc_alloc::Allocator;
|
||||||
use std::alloc::Layout;
|
use std::alloc::Layout;
|
||||||
|
|
||||||
@@ -12,7 +14,7 @@ fn main() {
|
|||||||
unsafe { Allocator::register_current_thread().unwrap() }
|
unsafe { Allocator::register_current_thread().unwrap() }
|
||||||
|
|
||||||
for _ in 0..100 {
|
for _ in 0..100 {
|
||||||
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe { Allocator::unregister_current_thread() }
|
unsafe { Allocator::unregister_current_thread() }
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "free_by_borrow"
|
name = "free_by_borrow"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bdwgc-alloc = { path = "../../bdwgc-alloc" }
|
bdwgc-alloc = { path = "../.." }
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
extern crate bdwgc_alloc;
|
||||||
|
|
||||||
use bdwgc_alloc::Allocator;
|
use bdwgc_alloc::Allocator;
|
||||||
|
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "free_by_gc"
|
name = "free_by_gc"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bdwgc-alloc = { path = "../../bdwgc-alloc" }
|
bdwgc-alloc = { path = "../.." }
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
extern crate bdwgc_alloc;
|
||||||
|
|
||||||
use bdwgc_alloc::Allocator;
|
use bdwgc_alloc::Allocator;
|
||||||
use std::alloc::Layout;
|
use std::alloc::Layout;
|
||||||
|
|
||||||
@@ -8,6 +10,6 @@ fn main() {
|
|||||||
unsafe { Allocator::initialize() }
|
unsafe { Allocator::initialize() }
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "static_threads"
|
name = "static_threads"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||||
|
edition = "2018"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bdwgc-alloc = { path = "../../bdwgc-alloc" }
|
bdwgc-alloc = { path = "../.." }
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
extern crate bdwgc_alloc;
|
||||||
|
|
||||||
use bdwgc_alloc::Allocator;
|
use bdwgc_alloc::Allocator;
|
||||||
use std::alloc::Layout;
|
use std::alloc::Layout;
|
||||||
|
|
||||||
@@ -11,7 +13,7 @@ fn main() {
|
|||||||
unsafe { Allocator::register_current_thread().unwrap() }
|
unsafe { Allocator::register_current_thread().unwrap() }
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let _ = unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
unsafe { std::alloc::alloc(Layout::from_size_align(2 ^ 8, 8).unwrap()) };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Executable
+13
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
for cargo_file in */Cargo.toml
|
||||||
|
do
|
||||||
|
target/debug/$(dirname $cargo_file) &
|
||||||
|
pid=$!
|
||||||
|
sleep 10
|
||||||
|
kill $pid
|
||||||
|
done
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
stable
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
[toolchain]
|
|
||||||
channel = "stable"
|
|
||||||
components = ["clippy", "rustfmt", "rust-analyzer", "rust-src"]
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
use core::{
|
use std::{
|
||||||
error,
|
error,
|
||||||
fmt::{self, Display, Formatter},
|
fmt::{self, Display, Formatter},
|
||||||
};
|
};
|
||||||
@@ -9,7 +9,7 @@ pub struct Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
pub const fn new(description: &'static str) -> Error {
|
pub fn new(description: &'static str) -> Error {
|
||||||
Error { description }
|
Error { description }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+117
@@ -0,0 +1,117 @@
|
|||||||
|
#![doc = include_str!("../README.md")]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
|
mod error;
|
||||||
|
|
||||||
|
use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
|
use core::ptr::null;
|
||||||
|
use libc::{c_int, c_void, size_t};
|
||||||
|
|
||||||
|
const GC_SUCCESS: c_int = 0;
|
||||||
|
|
||||||
|
#[repr(C)]
|
||||||
|
struct GcStackBase {
|
||||||
|
mem_base: *const c_void,
|
||||||
|
// TODO: Add reg_base field to support IA64.
|
||||||
|
}
|
||||||
|
|
||||||
|
#[link(name = "gc", kind = "static")]
|
||||||
|
extern "C" {
|
||||||
|
fn GC_allow_register_threads();
|
||||||
|
fn GC_alloc_lock();
|
||||||
|
fn GC_alloc_unlock();
|
||||||
|
fn GC_free(ptr: *mut c_void);
|
||||||
|
fn GC_get_stack_base(stack_base: *mut GcStackBase) -> c_int;
|
||||||
|
fn GC_init();
|
||||||
|
fn GC_malloc(size: size_t) -> *mut c_void;
|
||||||
|
fn GC_realloc(ptr: *mut c_void, size: size_t) -> *mut c_void;
|
||||||
|
fn GC_register_my_thread(stack_base: *const GcStackBase) -> c_int;
|
||||||
|
fn GC_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase);
|
||||||
|
fn GC_unregister_my_thread();
|
||||||
|
fn GC_gcollect();
|
||||||
|
fn GC_register_finalizer(
|
||||||
|
ptr: *const c_void,
|
||||||
|
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
||||||
|
client_data: *const c_void,
|
||||||
|
opt_old_finalizer: *const c_void,
|
||||||
|
opt_old_client_data: *const c_void,
|
||||||
|
) -> *mut c_void;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Allocator;
|
||||||
|
|
||||||
|
impl Allocator {
|
||||||
|
pub fn lock() {
|
||||||
|
unsafe { GC_alloc_lock() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn unlock() {
|
||||||
|
unsafe { GC_alloc_unlock() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn initialize() {
|
||||||
|
GC_init();
|
||||||
|
GC_allow_register_threads();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn register_current_thread() -> Result<(), error::Error> {
|
||||||
|
let mut base = GcStackBase { mem_base: null() };
|
||||||
|
|
||||||
|
if GC_get_stack_base(&mut base) != GC_SUCCESS {
|
||||||
|
return Err(error::Error::new("failed to get stack base"));
|
||||||
|
} else if GC_register_my_thread(&base) != GC_SUCCESS {
|
||||||
|
return Err(error::Error::new("failed to register a thread for GC"));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn set_stack_bottom(bottom: *const u8) {
|
||||||
|
GC_set_stackbottom(
|
||||||
|
null(),
|
||||||
|
&GcStackBase {
|
||||||
|
mem_base: bottom as *const libc::c_void,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn unregister_current_thread() {
|
||||||
|
GC_unregister_my_thread()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn force_collect() {
|
||||||
|
unsafe { GC_gcollect() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn register_finalizer<F: FnOnce(*mut c_void) + 'static>(
|
||||||
|
ptr: *const c_void,
|
||||||
|
finalizer: F,
|
||||||
|
) {
|
||||||
|
extern "C" fn finalize<F: FnOnce(*mut c_void)>(ptr: *mut c_void, data: *mut c_void) {
|
||||||
|
(unsafe { Box::from_raw(data as *mut F) })(ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
GC_register_finalizer(
|
||||||
|
ptr,
|
||||||
|
finalize::<F>,
|
||||||
|
Box::into_raw(Box::new(finalizer)) as *const _,
|
||||||
|
null(),
|
||||||
|
null(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe impl GlobalAlloc for Allocator {
|
||||||
|
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
|
||||||
|
GC_malloc(layout.size()) as *mut u8
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
||||||
|
GC_free(ptr as *mut c_void)
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn realloc(&self, ptr: *mut u8, _layout: Layout, size: usize) -> *mut u8 {
|
||||||
|
GC_realloc(ptr as *mut c_void, size) as *mut u8
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
duration=20
|
|
||||||
|
|
||||||
cd $(dirname $0)/..
|
|
||||||
|
|
||||||
for directory in $(ls examples); do
|
|
||||||
(
|
|
||||||
cd examples/$directory
|
|
||||||
|
|
||||||
cargo build
|
|
||||||
cargo run &
|
|
||||||
|
|
||||||
pid=$!
|
|
||||||
sleep $duration
|
|
||||||
kill $pid
|
|
||||||
)
|
|
||||||
done
|
|
||||||
+1
Submodule vendor/bdwgc added at 71f838eb6e
+1
Submodule vendor/libatomic_ops added at e06dc9549f
Reference in New Issue
Block a user