mirror of
https://github.com/bdwgc/bdwgc-rust.git
synced 2026-05-29 09:58:55 -06:00
Compare commits
48 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3abd5dea37 | ||
|
|
ec67abe1ef | ||
|
|
8f73f3d63a | ||
|
|
ca51b73cf5 | ||
|
|
fbc2d363b8 | ||
|
|
7ff5ac5b21 | ||
|
|
2d329a6e65 | ||
|
|
59fe9dfa47 | ||
|
|
d7521be32f | ||
|
|
0779f60a82 | ||
|
|
8d12fa613e | ||
|
|
7578318bc1 | ||
|
|
974afa310e | ||
|
|
12a68b35e5 | ||
|
|
a03985d3ea | ||
|
|
22ddca7811 | ||
|
|
833abbcecb | ||
|
|
450257b73e | ||
|
|
bddf66861e | ||
|
|
658f8f7b5b | ||
|
|
273291836d | ||
|
|
186123157f | ||
|
|
6e3107ab80 | ||
|
|
e0cb8aca15 | ||
|
|
6d9ce150cd | ||
|
|
3563d4e213 | ||
|
|
cbb3bd39d4 | ||
|
|
85701b18c8 | ||
|
|
82e7664a74 | ||
|
|
82c6516d29 | ||
|
|
bd9137b1f6 | ||
|
|
f590a7c7ed | ||
|
|
b31a5cff06 | ||
|
|
c35a6a9212 | ||
|
|
a74ccfc19c | ||
|
|
d60cf964d0 | ||
|
|
b824c776f6 | ||
|
|
f41ade234c | ||
|
|
e3d427aaf8 | ||
|
|
362bbd4ac4 | ||
|
|
40fae8cfc5 | ||
|
|
fa50cd76d1 | ||
|
|
e3162293df | ||
|
|
20fbf8e1e9 | ||
|
|
4dc952a872 | ||
|
|
fb4e72bcdd | ||
|
|
444ee0ecc1 | ||
|
|
b01f884f5d |
11
.cspell.json
Normal file
11
.cspell.json
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"words": [
|
||||||
|
"dealloc",
|
||||||
|
"finalizer",
|
||||||
|
"gcollect",
|
||||||
|
"libc",
|
||||||
|
"realloc",
|
||||||
|
"repr",
|
||||||
|
"stackbottom"
|
||||||
|
]
|
||||||
|
}
|
||||||
4
.github/dependabot.yml
vendored
4
.github/dependabot.yml
vendored
@@ -1,5 +1,9 @@
|
|||||||
version: 2
|
version: 2
|
||||||
updates:
|
updates:
|
||||||
|
- package-ecosystem: github-actions
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: daily
|
||||||
- package-ecosystem: cargo
|
- package-ecosystem: cargo
|
||||||
directory: /
|
directory: /
|
||||||
schedule:
|
schedule:
|
||||||
|
|||||||
6
.mergify.yml → .github/mergify.yml
vendored
6
.mergify.yml → .github/mergify.yml
vendored
@@ -3,5 +3,9 @@ pull_request_rules:
|
|||||||
conditions:
|
conditions:
|
||||||
- author=dependabot[bot]
|
- author=dependabot[bot]
|
||||||
actions:
|
actions:
|
||||||
merge:
|
queue:
|
||||||
|
name: default
|
||||||
method: squash
|
method: squash
|
||||||
|
queue_rules:
|
||||||
|
- name: default
|
||||||
|
conditions: []
|
||||||
34
.github/workflows/lint.yaml
vendored
Normal file
34
.github/workflows/lint.yaml
vendored
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
name: lint
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
lint:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: cargo clippy -- -D warnings
|
||||||
|
format:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- run: cargo fmt -- --check
|
||||||
|
spell-check:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: streetsidesoftware/cspell-action@main
|
||||||
|
with:
|
||||||
|
files: "**/*.{md,rs}"
|
||||||
|
readme:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: lycheeverse/lychee-action@v1
|
||||||
|
with:
|
||||||
|
fail: true
|
||||||
47
.github/workflows/test.yaml
vendored
47
.github/workflows/test.yaml
vendored
@@ -1,30 +1,41 @@
|
|||||||
name: test
|
name: test
|
||||||
on:
|
on:
|
||||||
- push
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
jobs:
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: cargo build
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: true
|
submodules: true
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: Swatinem/rust-cache@v2
|
||||||
- uses: actions-rs/cargo@v1
|
- run: cargo test
|
||||||
|
examples:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
command: build
|
submodules: true
|
||||||
- uses: actions-rs/cargo@v1
|
- uses: Swatinem/rust-cache@v2
|
||||||
with:
|
|
||||||
command: fmt
|
|
||||||
args: -- --check
|
|
||||||
- uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: clippy
|
|
||||||
- uses: actions-rs/audit-check@v1
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
- run: |
|
- run: |
|
||||||
cd examples
|
cd examples
|
||||||
./test.sh
|
./test.sh
|
||||||
- run: |
|
cmake:
|
||||||
git clean -dfx
|
runs-on: ubuntu-latest
|
||||||
cargo build --no-default-features --features cmake
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
with:
|
||||||
|
submodules: true
|
||||||
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
- run: cargo build --no-default-features --features cmake
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bdwgc-alloc"
|
name = "bdwgc-alloc"
|
||||||
description = "impl GlobalAlloc for bdwgc"
|
description = "impl GlobalAlloc for bdwgc"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
authors = [
|
authors = [
|
||||||
"swgillespie <sean.william.g@gmail.com>",
|
"swgillespie <sean.william.g@gmail.com>",
|
||||||
"Yota Toyama <raviqqe@gmail.com>",
|
"Yota Toyama <raviqqe@gmail.com>",
|
||||||
|
|||||||
11
src/error.rs
11
src/error.rs
@@ -1,3 +1,8 @@
|
|||||||
|
use std::{
|
||||||
|
error,
|
||||||
|
fmt::{self, Display, Formatter},
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Error {
|
pub struct Error {
|
||||||
description: &'static str,
|
description: &'static str,
|
||||||
@@ -9,13 +14,13 @@ impl Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Error {
|
impl Display for Error {
|
||||||
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
|
||||||
write!(formatter, "{}", self.description)
|
write!(formatter, "{}", self.description)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for Error {
|
impl error::Error for Error {
|
||||||
fn description(&self) -> &str {
|
fn description(&self) -> &str {
|
||||||
self.description
|
self.description
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/lib.rs
33
src/lib.rs
@@ -1,9 +1,12 @@
|
|||||||
extern crate libc;
|
#![doc = include_str!("../README.md")]
|
||||||
|
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
mod error;
|
mod error;
|
||||||
|
|
||||||
|
use alloc::alloc::{GlobalAlloc, Layout};
|
||||||
|
use core::ptr::null;
|
||||||
use libc::{c_int, c_void, size_t};
|
use libc::{c_int, c_void, size_t};
|
||||||
use std::alloc::{GlobalAlloc, Layout};
|
|
||||||
|
|
||||||
const GC_SUCCESS: c_int = 0;
|
const GC_SUCCESS: c_int = 0;
|
||||||
|
|
||||||
@@ -26,6 +29,14 @@ extern "C" {
|
|||||||
fn GC_register_my_thread(stack_base: *const GcStackBase) -> c_int;
|
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_set_stackbottom(thread: *const c_void, stack_bottom: *const GcStackBase);
|
||||||
fn GC_unregister_my_thread();
|
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;
|
pub struct Allocator;
|
||||||
@@ -45,9 +56,7 @@ impl Allocator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn register_current_thread() -> Result<(), error::Error> {
|
pub unsafe fn register_current_thread() -> Result<(), error::Error> {
|
||||||
let mut base = GcStackBase {
|
let mut base = GcStackBase { mem_base: null() };
|
||||||
mem_base: std::ptr::null(),
|
|
||||||
};
|
|
||||||
|
|
||||||
if 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"));
|
return Err(error::Error::new("failed to get stack base"));
|
||||||
@@ -60,7 +69,7 @@ impl Allocator {
|
|||||||
|
|
||||||
pub unsafe fn set_stack_bottom(bottom: *const u8) {
|
pub unsafe fn set_stack_bottom(bottom: *const u8) {
|
||||||
GC_set_stackbottom(
|
GC_set_stackbottom(
|
||||||
std::ptr::null(),
|
null(),
|
||||||
&GcStackBase {
|
&GcStackBase {
|
||||||
mem_base: bottom as *const libc::c_void,
|
mem_base: bottom as *const libc::c_void,
|
||||||
},
|
},
|
||||||
@@ -70,6 +79,18 @@ impl Allocator {
|
|||||||
pub unsafe fn unregister_current_thread() {
|
pub unsafe fn unregister_current_thread() {
|
||||||
GC_unregister_my_thread()
|
GC_unregister_my_thread()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn force_collect() {
|
||||||
|
unsafe { GC_gcollect() }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub unsafe fn register_finalizer(
|
||||||
|
ptr: *const c_void,
|
||||||
|
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
||||||
|
client_data: *const c_void,
|
||||||
|
) {
|
||||||
|
GC_register_finalizer(ptr, finalizer, client_data, null(), null());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl GlobalAlloc for Allocator {
|
unsafe impl GlobalAlloc for Allocator {
|
||||||
|
|||||||
2
vendor/bdwgc
vendored
2
vendor/bdwgc
vendored
Submodule vendor/bdwgc updated: 0a1667bee7...71f838eb6e
2
vendor/libatomic_ops
vendored
2
vendor/libatomic_ops
vendored
Submodule vendor/libatomic_ops updated: 0445739035...e06dc9549f
Reference in New Issue
Block a user