mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-30 02:18:57 -06:00
Compare commits
6 Commits
main
...
feature/ru
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f52f6dcfaf | ||
|
|
3de34a77e9 | ||
|
|
81df12684f | ||
|
|
a3a13f061f | ||
|
|
085028a8e1 | ||
|
|
04f5f88b33 |
11
.cspell.json
Normal file
11
.cspell.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"words": [
|
||||
"dealloc",
|
||||
"finalizer",
|
||||
"gcollect",
|
||||
"libc",
|
||||
"realloc",
|
||||
"repr",
|
||||
"stackbottom"
|
||||
]
|
||||
}
|
||||
11
.github/mergify.yml
vendored
Normal file
11
.github/mergify.yml
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
pull_request_rules:
|
||||
- name: dependabot
|
||||
conditions:
|
||||
- author=dependabot[bot]
|
||||
actions:
|
||||
queue:
|
||||
name: default
|
||||
method: squash
|
||||
queue_rules:
|
||||
- name: default
|
||||
conditions: []
|
||||
13
.github/workflows/dependabot.yaml
vendored
13
.github/workflows/dependabot.yaml
vendored
@@ -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 }}
|
||||
14
.github/workflows/lint.yaml
vendored
14
.github/workflows/lint.yaml
vendored
@@ -8,25 +8,27 @@ jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- uses: swatinem/rust-cache@v2
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo clippy -- -D warnings
|
||||
format:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v3
|
||||
- run: cargo fmt -- --check
|
||||
spell-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v3
|
||||
- uses: streetsidesoftware/cspell-action@main
|
||||
with:
|
||||
files: "**/*.{md,rs}"
|
||||
readme:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: lycheeverse/lychee-action@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: lycheeverse/lychee-action@v1
|
||||
with:
|
||||
fail: true
|
||||
|
||||
29
.github/workflows/release.yaml
vendored
29
.github/workflows/release.yaml
vendored
@@ -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@v6
|
||||
with:
|
||||
submodules: true
|
||||
- uses: swatinem/rust-cache@v2
|
||||
- run: cargo install cargo-workspaces
|
||||
- uses: rust-lang/crates-io-auth-action@v1
|
||||
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 }}
|
||||
20
.github/workflows/test.yaml
vendored
20
.github/workflows/test.yaml
vendored
@@ -8,32 +8,34 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- uses: swatinem/rust-cache@v2
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo build
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- uses: swatinem/rust-cache@v2
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo test
|
||||
examples:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- uses: swatinem/rust-cache@v2
|
||||
- run: tools/example_test.sh
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: |
|
||||
cd examples
|
||||
./test.sh
|
||||
cmake:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- uses: swatinem/rust-cache@v2
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo build --no-default-features --features cmake
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
.cargo_cache
|
||||
*.lock
|
||||
target
|
||||
|
||||
4
.gitmodules
vendored
4
.gitmodules
vendored
@@ -1,6 +1,6 @@
|
||||
[submodule "vendor/bdwgc"]
|
||||
path = vendor/bdwgc
|
||||
url = https://github.com/bdwgc/bdwgc
|
||||
url = https://github.com/ivmai/bdwgc
|
||||
[submodule "vendor/libatomic_ops"]
|
||||
path = vendor/libatomic_ops
|
||||
url = https://github.com/bdwgc/libatomic_ops
|
||||
url = https://github.com/ivmai/libatomic_ops
|
||||
|
||||
86
Cargo.lock
generated
86
Cargo.lock
generated
@@ -1,86 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[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.13"
|
||||
dependencies = [
|
||||
"autotools",
|
||||
"cmake",
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.49"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "90583009037521a116abf44494efecd645ba48b6622457080f080b85544e2215"
|
||||
dependencies = [
|
||||
"find-msvc-tools",
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[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 = "libc"
|
||||
version = "0.2.186"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "static_threads"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bdwgc-alloc",
|
||||
]
|
||||
33
Cargo.toml
33
Cargo.toml
@@ -1,29 +1,22 @@
|
||||
[package]
|
||||
name = "bdwgc-alloc"
|
||||
version = "0.6.13"
|
||||
edition = "2024"
|
||||
description = "impl GlobalAlloc for bdwgc"
|
||||
version = "0.6.5"
|
||||
authors = [
|
||||
"swgillespie <sean.william.g@gmail.com>",
|
||||
"Yota Toyama <raviqqe@gmail.com>",
|
||||
]
|
||||
repository = "https://github.com/raviqqe/bdwgc-alloc"
|
||||
edition = "2021"
|
||||
license = "MIT"
|
||||
categories = ["api-bindings", "memory-management", "no-std", "no-std::no-alloc"]
|
||||
|
||||
[workspace]
|
||||
resolver = "3"
|
||||
members = ["examples/*"]
|
||||
|
||||
[dependencies]
|
||||
libc = "0.2.186"
|
||||
|
||||
[build-dependencies]
|
||||
autotools = { version = "0.2.7", optional = true }
|
||||
cmake = { version = "0.1.58", optional = true }
|
||||
build = "build.rs"
|
||||
|
||||
[features]
|
||||
default = ["autotools"]
|
||||
|
||||
[lints.clippy]
|
||||
alloc_instead_of_core = "deny"
|
||||
dbg_macro = "deny"
|
||||
missing_const_for_fn = "deny"
|
||||
std_instead_of_alloc = "deny"
|
||||
std_instead_of_core = "deny"
|
||||
[dependencies]
|
||||
libc = "0.2"
|
||||
|
||||
[build-dependencies]
|
||||
autotools = { version = "0.2", optional = true }
|
||||
cmake = { version = "0.1", optional = true }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# bdwgc-rust
|
||||
# bdwgc-alloc
|
||||
|
||||
[](https://github.com/bdwgc/bdwgc-rust/actions)
|
||||
[](https://github.com/raviqqe/bdwgc-alloc/actions)
|
||||
[](https://crates.io/crates/bdwgc-alloc)
|
||||
[](LICENSE)
|
||||
[](LICENSE)
|
||||
|
||||
[`GlobalAlloc`](https://doc.rust-lang.org/std/alloc/trait.GlobalAlloc.html) implementation for [`bdwgc`][bdwgc], the conservative garbage collector.
|
||||
|
||||
@@ -22,4 +22,4 @@ cargo build --no-default-features --features cmake
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
[bdwgc]: https://github.com/bdwgc/bdwgc
|
||||
[bdwgc]: https://github.com/ivmai/bdwgc
|
||||
|
||||
7
build.rs
7
build.rs
@@ -6,7 +6,7 @@ fn main() {
|
||||
for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] {
|
||||
std::process::Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(format!("cd {dir} && ./autogen.sh"))
|
||||
.arg(format!("cd {} && ./autogen.sh", dir))
|
||||
.output()
|
||||
.unwrap();
|
||||
}
|
||||
@@ -23,7 +23,6 @@ fn main() {
|
||||
|
||||
let dst = autotools::Config::new(LIB_GC_DIR)
|
||||
.cflag(format!(
|
||||
// spell-checker: disable-next-line
|
||||
"-I{} -L/lib/x86_64-linux-gnu -lpthread -fPIC",
|
||||
dst.join("include").display()
|
||||
))
|
||||
@@ -38,7 +37,7 @@ fn main() {
|
||||
for dir in &[LIB_ATOMIC_OPS_DIR, LIB_GC_DIR] {
|
||||
std::process::Command::new("sh")
|
||||
.arg("-c")
|
||||
.arg(format!("cd {dir} && git clean -dfx"))
|
||||
.arg(format!("cd {} && git clean -dfx", dir))
|
||||
.output()
|
||||
.unwrap();
|
||||
}
|
||||
@@ -59,7 +58,7 @@ fn main() {
|
||||
|
||||
let dst = Config::new(LIB_GC_DIR)
|
||||
.profile("Release")
|
||||
.define("GC_BUILD_SHARED_LIBS", "FALSE")
|
||||
.define("BUILD_SHARED_LIBS", "FALSE")
|
||||
.cflag(format!("-I{}", libatomic_include_path))
|
||||
.build();
|
||||
|
||||
|
||||
21
cspell.json
21
cspell.json
@@ -1,21 +0,0 @@
|
||||
{
|
||||
"words": [
|
||||
"autogen",
|
||||
"autotools",
|
||||
"bdwgc",
|
||||
"canonicalize",
|
||||
"cflag",
|
||||
"clippy",
|
||||
"dealloc",
|
||||
"finalizer",
|
||||
"gcollect",
|
||||
"libatomic",
|
||||
"libc",
|
||||
"realloc",
|
||||
"repr",
|
||||
"rustc",
|
||||
"stackbottom",
|
||||
"swatinem",
|
||||
"unregisters"
|
||||
]
|
||||
}
|
||||
7
examples/Cargo.toml
Normal file
7
examples/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
||||
[workspace]
|
||||
members = [
|
||||
"dynamic_threads",
|
||||
"free_by_borrow",
|
||||
"free_by_gc",
|
||||
"static_threads",
|
||||
]
|
||||
@@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "dynamic_threads"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
extern crate bdwgc_alloc;
|
||||
|
||||
use bdwgc_alloc::Allocator;
|
||||
use std::alloc::Layout;
|
||||
|
||||
@@ -12,7 +14,7 @@ fn main() {
|
||||
unsafe { Allocator::register_current_thread().unwrap() }
|
||||
|
||||
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() }
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "free_by_borrow"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
extern crate bdwgc_alloc;
|
||||
|
||||
use bdwgc_alloc::Allocator;
|
||||
|
||||
#[global_allocator]
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
[package]
|
||||
name = "free_by_gc"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
extern crate bdwgc_alloc;
|
||||
|
||||
use bdwgc_alloc::Allocator;
|
||||
use std::alloc::Layout;
|
||||
|
||||
@@ -8,6 +10,6 @@ fn main() {
|
||||
unsafe { Allocator::initialize() }
|
||||
|
||||
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,7 +1,8 @@
|
||||
[package]
|
||||
name = "static_threads"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
authors = ["Yota Toyama <raviqqe@gmail.com>"]
|
||||
edition = "2018"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
extern crate bdwgc_alloc;
|
||||
|
||||
use bdwgc_alloc::Allocator;
|
||||
use std::alloc::Layout;
|
||||
|
||||
@@ -11,7 +13,7 @@ fn main() {
|
||||
unsafe { Allocator::register_current_thread().unwrap() }
|
||||
|
||||
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()) };
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
13
examples/test.sh
Executable file
13
examples/test.sh
Executable file
@@ -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
|
||||
1
rust-toolchain
Normal file
1
rust-toolchain
Normal file
@@ -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,
|
||||
fmt::{self, Display, Formatter},
|
||||
};
|
||||
@@ -9,7 +9,7 @@ pub struct Error {
|
||||
}
|
||||
|
||||
impl Error {
|
||||
pub const fn new(description: &'static str) -> Error {
|
||||
pub fn new(description: &'static str) -> Error {
|
||||
Error { description }
|
||||
}
|
||||
}
|
||||
|
||||
71
src/lib.rs
71
src/lib.rs
@@ -1,9 +1,10 @@
|
||||
#![doc = include_str!("../README.md")]
|
||||
#![no_std]
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
mod error;
|
||||
|
||||
use core::alloc::{GlobalAlloc, Layout};
|
||||
use alloc::alloc::{GlobalAlloc, Layout};
|
||||
use core::ptr::null;
|
||||
use libc::{c_int, c_void, size_t};
|
||||
|
||||
@@ -16,7 +17,7 @@ struct GcStackBase {
|
||||
}
|
||||
|
||||
#[link(name = "gc", kind = "static")]
|
||||
unsafe extern "C" {
|
||||
extern "C" {
|
||||
fn GC_allow_register_threads();
|
||||
fn GC_alloc_lock();
|
||||
fn GC_alloc_unlock();
|
||||
@@ -41,55 +42,32 @@ unsafe extern "C" {
|
||||
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 = GcStackBase { mem_base: null() };
|
||||
|
||||
if unsafe { GC_get_stack_base(&mut base) } != GC_SUCCESS {
|
||||
if 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 {
|
||||
} else if 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(),
|
||||
&GcStackBase {
|
||||
@@ -97,46 +75,43 @@ impl Allocator {
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// 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() }
|
||||
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(
|
||||
pub unsafe fn register_finalizer<F: FnOnce(*mut c_void) + 'static>(
|
||||
ptr: *const c_void,
|
||||
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
||||
client_data: *const c_void,
|
||||
finalizer: F,
|
||||
) {
|
||||
unsafe { GC_register_finalizer(ptr, finalizer, client_data, null(), null()) };
|
||||
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 {
|
||||
(unsafe { GC_malloc(layout.size()) }) as *mut u8
|
||||
GC_malloc(layout.size()) as *mut u8
|
||||
}
|
||||
|
||||
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
|
||||
unsafe { GC_free(ptr as *mut c_void) }
|
||||
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
|
||||
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
|
||||
2
vendor/bdwgc
vendored
2
vendor/bdwgc
vendored
Submodule vendor/bdwgc updated: fc2990b5ec...71f838eb6e
2
vendor/libatomic_ops
vendored
2
vendor/libatomic_ops
vendored
Submodule vendor/libatomic_ops updated: d007246aa7...e06dc9549f
Reference in New Issue
Block a user