forked from GitHub/bdwgc-rust
Compare commits
54 Commits
v0.6.3
...
feature/ru
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f52f6dcfaf | ||
|
|
3de34a77e9 | ||
|
|
81df12684f | ||
|
|
a3a13f061f | ||
|
|
085028a8e1 | ||
|
|
04f5f88b33 | ||
|
|
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
|
||||
updates:
|
||||
- package-ecosystem: github-actions
|
||||
directory: /
|
||||
schedule:
|
||||
interval: daily
|
||||
- package-ecosystem: cargo
|
||||
directory: /
|
||||
schedule:
|
||||
|
||||
6
.mergify.yml → .github/mergify.yml
vendored
6
.mergify.yml → .github/mergify.yml
vendored
@@ -3,5 +3,9 @@ pull_request_rules:
|
||||
conditions:
|
||||
- author=dependabot[bot]
|
||||
actions:
|
||||
merge:
|
||||
queue:
|
||||
name: default
|
||||
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
|
||||
on:
|
||||
- push
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
pull_request:
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo build
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
submodules: true
|
||||
- uses: actions-rs/toolchain@v1
|
||||
- uses: actions-rs/cargo@v1
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: cargo test
|
||||
examples:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
command: build
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: fmt
|
||||
args: -- --check
|
||||
- uses: actions-rs/cargo@v1
|
||||
with:
|
||||
command: clippy
|
||||
- uses: actions-rs/audit-check@v1
|
||||
with:
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
submodules: true
|
||||
- uses: Swatinem/rust-cache@v2
|
||||
- run: |
|
||||
cd examples
|
||||
./test.sh
|
||||
- run: |
|
||||
git clean -dfx
|
||||
cargo build --no-default-features --features cmake
|
||||
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,7 +1,7 @@
|
||||
[package]
|
||||
name = "bdwgc-alloc"
|
||||
description = "impl GlobalAlloc for bdwgc"
|
||||
version = "0.6.3"
|
||||
version = "0.6.5"
|
||||
authors = [
|
||||
"swgillespie <sean.william.g@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)]
|
||||
pub struct Error {
|
||||
description: &'static str,
|
||||
@@ -9,13 +14,13 @@ impl Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Error {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
impl Display for Error {
|
||||
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
|
||||
write!(formatter, "{}", self.description)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for Error {
|
||||
impl error::Error for Error {
|
||||
fn description(&self) -> &str {
|
||||
self.description
|
||||
}
|
||||
|
||||
42
src/lib.rs
42
src/lib.rs
@@ -1,9 +1,12 @@
|
||||
extern crate libc;
|
||||
#![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};
|
||||
use std::alloc::{GlobalAlloc, Layout};
|
||||
|
||||
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_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;
|
||||
@@ -45,9 +56,7 @@ impl Allocator {
|
||||
}
|
||||
|
||||
pub unsafe fn register_current_thread() -> Result<(), error::Error> {
|
||||
let mut base = GcStackBase {
|
||||
mem_base: std::ptr::null(),
|
||||
};
|
||||
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"));
|
||||
@@ -60,7 +69,7 @@ impl Allocator {
|
||||
|
||||
pub unsafe fn set_stack_bottom(bottom: *const u8) {
|
||||
GC_set_stackbottom(
|
||||
std::ptr::null(),
|
||||
null(),
|
||||
&GcStackBase {
|
||||
mem_base: bottom as *const libc::c_void,
|
||||
},
|
||||
@@ -70,6 +79,27 @@ impl Allocator {
|
||||
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 {
|
||||
|
||||
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