forked from GitHub/bdwgc-rust
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3abd5dea37 | ||
|
|
ec67abe1ef | ||
|
|
8f73f3d63a | ||
|
|
ca51b73cf5 | ||
|
|
fbc2d363b8 | ||
|
|
7ff5ac5b21 |
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
|
||||
42
.github/workflows/test.yaml
vendored
42
.github/workflows/test.yaml
vendored
@@ -5,29 +5,37 @@ on:
|
||||
- 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.4"
|
||||
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
|
||||
}
|
||||
|
||||
27
src/lib.rs
27
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;
|
||||
|
||||
@@ -28,11 +31,11 @@ extern "C" {
|
||||
fn GC_unregister_my_thread();
|
||||
fn GC_gcollect();
|
||||
fn GC_register_finalizer(
|
||||
obj: *const c_void,
|
||||
f: extern "C" fn(*mut c_void, *mut c_void),
|
||||
ptr: *const c_void,
|
||||
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
||||
client_data: *const c_void,
|
||||
opt_old_f: *const c_void,
|
||||
opt_old_cd: *const c_void,
|
||||
opt_old_finalizer: *const c_void,
|
||||
opt_old_client_data: *const c_void,
|
||||
) -> *mut c_void;
|
||||
}
|
||||
|
||||
@@ -53,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"));
|
||||
@@ -68,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,
|
||||
},
|
||||
@@ -84,11 +85,11 @@ impl Allocator {
|
||||
}
|
||||
|
||||
pub unsafe fn register_finalizer(
|
||||
obj: *const c_void,
|
||||
f: extern "C" fn(*mut c_void, *mut c_void),
|
||||
ptr: *const c_void,
|
||||
finalizer: extern "C" fn(*mut c_void, *mut c_void),
|
||||
client_data: *const c_void,
|
||||
) {
|
||||
GC_register_finalizer(obj, f, client_data, std::ptr::null(), std::ptr::null());
|
||||
GC_register_finalizer(ptr, finalizer, client_data, null(), null());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
vendor/bdwgc
vendored
2
vendor/bdwgc
vendored
Submodule vendor/bdwgc updated: db76b2f831...71f838eb6e
Reference in New Issue
Block a user