Skip to content

Commit fb48ee5

Browse files
committed
[WIP] Try to fix proc_macro abi incompatibility
1 parent 4a4c949 commit fb48ee5

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

src/libproc_macro/bridge/buffer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::slice;
99
struct Slice<'a, T> {
1010
data: &'a [T; 0],
1111
len: usize,
12+
_a: u8, // Force ByRef passing of this struct
1213
}
1314

1415
unsafe impl<'a, T: Sync> Sync for Slice<'a, T> {}
@@ -23,7 +24,7 @@ impl<T> Clone for Slice<'a, T> {
2324

2425
impl<T> From<&'a [T]> for Slice<'a, T> {
2526
fn from(xs: &'a [T]) -> Self {
26-
Slice { data: unsafe { &*(xs.as_ptr() as *const [T; 0]) }, len: xs.len() }
27+
Slice { data: unsafe { &*(xs.as_ptr() as *const [T; 0]) }, len: xs.len(), _a: 0 }
2728
}
2829
}
2930

src/libproc_macro/bridge/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ macro_rules! define_handles {
4444
}
4545

4646
$(
47-
#[repr(C)]
47+
#[repr(transparent)]
4848
pub(crate) struct $oty(handle::Handle);
4949
impl !Send for $oty {}
5050
impl !Sync for $oty {}
@@ -119,7 +119,7 @@ macro_rules! define_handles {
119119
)*
120120

121121
$(
122-
#[repr(C)]
122+
#[repr(transparent)]
123123
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
124124
pub(crate) struct $ity(handle::Handle);
125125
impl !Send for $ity {}

src/libproc_macro/bridge/closure.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
pub struct Closure<'a, A, R> {
55
call: unsafe extern "C" fn(&mut Env, A) -> R,
66
env: &'a mut Env,
7+
_a: u8, // Force ByRef abi
78
}
89

910
extern "C" {
@@ -18,7 +19,7 @@ impl<'a, A, R, F: FnMut(A) -> R> From<&'a mut F> for Closure<'a, A, R> {
1819
unsafe extern "C" fn call<A, R, F: FnMut(A) -> R>(env: &mut Env, arg: A) -> R {
1920
(*(env as *mut _ as *mut F))(arg)
2021
}
21-
Closure { call: call::<A, R, F>, env: unsafe { &mut *(f as *mut _ as *mut Env) } }
22+
Closure { call: call::<A, R, F>, env: unsafe { &mut *(f as *mut _ as *mut Env) }, _a: 0 }
2223
}
2324
}
2425

src/libproc_macro/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub fn is_available() -> bool {
7272
/// and `#[proc_macro_derive]` definitions.
7373
#[stable(feature = "proc_macro_lib", since = "1.15.0")]
7474
#[derive(Clone)]
75+
#[repr(transparent)]
7576
pub struct TokenStream(bridge::client::TokenStream);
7677

7778
#[stable(feature = "proc_macro_lib", since = "1.15.0")]

0 commit comments

Comments
 (0)