Skip to content

Commit 7e1d891

Browse files
authored
Fix function pointer type. (#188)
1 parent 8e893af commit 7e1d891

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

mmtk/src/collection.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ use crate::{MutatorClosure, OpenJDK};
88

99
pub struct VMCollection {}
1010

11-
extern "C" fn report_mutator_stop<F>(mutator: *mut Mutator<OpenJDK>, callback: *mut F)
12-
where
11+
extern "C" fn report_mutator_stop<F>(
12+
mutator: *mut Mutator<OpenJDK>,
13+
callback_ptr: *mut libc::c_void,
14+
) where
1315
F: FnMut(&'static mut Mutator<OpenJDK>),
1416
{
15-
let callback: &mut F = unsafe { &mut *callback };
17+
let callback: &mut F = unsafe { &mut *(callback_ptr as *mut F) };
1618
callback(unsafe { &mut *mutator });
1719
}
1820

@@ -21,7 +23,7 @@ where
2123
F: FnMut(&'static mut Mutator<OpenJDK>),
2224
{
2325
MutatorClosure {
24-
func: report_mutator_stop::<F> as *const _,
26+
func: report_mutator_stop::<F>,
2527
data: callback as *mut F as *mut libc::c_void,
2628
}
2729
}

mmtk/src/lib.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ pub struct NewBuffer {
4040
/// A closure for reporting mutators. The C++ code should pass `data` back as the last argument.
4141
#[repr(C)]
4242
pub struct MutatorClosure {
43-
pub func: *const extern "C" fn(mutator: *mut Mutator<OpenJDK>, data: *mut libc::c_void),
43+
pub func: extern "C" fn(mutator: *mut Mutator<OpenJDK>, data: *mut libc::c_void),
4444
pub data: *mut libc::c_void,
4545
}
4646

4747
/// A closure for reporting root edges. The C++ code should pass `data` back as the last argument.
4848
#[repr(C)]
4949
pub struct EdgesClosure {
50-
pub func:
51-
*const extern "C" fn(buf: *mut Address, size: usize, cap: usize, data: *const libc::c_void),
50+
pub func: extern "C" fn(
51+
buf: *mut Address,
52+
size: usize,
53+
cap: usize,
54+
data: *mut libc::c_void,
55+
) -> NewBuffer,
5256
pub data: *const libc::c_void,
5357
}
5458

mmtk/src/scanning.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ extern "C" fn report_edges_and_renew_buffer<F: RootsWorkFactory<OpenJDKEdge>>(
1717
ptr: *mut Address,
1818
length: usize,
1919
capacity: usize,
20-
factory_ptr: *mut F,
20+
factory_ptr: *mut libc::c_void,
2121
) -> NewBuffer {
2222
if !ptr.is_null() {
2323
let buf = unsafe { Vec::<Address>::from_raw_parts(ptr, length, capacity) };
24-
let factory: &mut F = unsafe { &mut *factory_ptr };
24+
let factory: &mut F = unsafe { &mut *(factory_ptr as *mut F) };
2525
factory.create_process_edge_roots_work(buf);
2626
}
2727
let (ptr, _, capacity) = {
@@ -36,7 +36,7 @@ extern "C" fn report_edges_and_renew_buffer<F: RootsWorkFactory<OpenJDKEdge>>(
3636

3737
pub(crate) fn to_edges_closure<F: RootsWorkFactory<OpenJDKEdge>>(factory: &mut F) -> EdgesClosure {
3838
EdgesClosure {
39-
func: report_edges_and_renew_buffer::<F> as *const _,
39+
func: report_edges_and_renew_buffer::<F>,
4040
data: factory as *mut F as *mut libc::c_void,
4141
}
4242
}

0 commit comments

Comments
 (0)