Skip to content

Commit 39a7d3b

Browse files
committed
Update SYS_MIN_ALIGN
1 parent 0245d4c commit 39a7d3b

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

mlua-sys/src/lib.rs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,27 +40,34 @@ pub const LUA_MAX_UPVALUES: c_int = 200;
4040
#[doc(hidden)]
4141
pub const LUA_TRACEBACK_STACK: c_int = 11;
4242

43-
// Copied from https://github.com/rust-lang/rust/blob/master/library/std/src/sys/pal/common/alloc.rs
44-
// The minimum alignment guaranteed by the architecture. This value is used to
45-
// add fast paths for low alignment values.
46-
#[cfg(any(
43+
// The minimum alignment guaranteed by the architecture.
44+
// Copied from https://github.com/rust-lang/rust/blob/main/library/std/src/sys/alloc/mod.rs
45+
#[doc(hidden)]
46+
#[rustfmt::skip]
47+
pub const SYS_MIN_ALIGN: usize = if cfg!(any(
48+
all(target_arch = "riscv32", any(target_os = "espidf", target_os = "zkvm")),
49+
all(target_arch = "xtensa", target_os = "espidf"),
50+
)) {
51+
// The allocator on the esp-idf and zkvm platforms guarantees 4 byte alignment.
52+
4
53+
} else if cfg!(any(
4754
target_arch = "x86",
4855
target_arch = "arm",
4956
target_arch = "m68k",
5057
target_arch = "csky",
58+
target_arch = "loongarch32",
5159
target_arch = "mips",
5260
target_arch = "mips32r6",
5361
target_arch = "powerpc",
5462
target_arch = "powerpc64",
5563
target_arch = "sparc",
5664
target_arch = "wasm32",
5765
target_arch = "hexagon",
58-
all(target_arch = "riscv32", not(any(target_os = "espidf", target_os = "zkvm"))),
59-
all(target_arch = "xtensa", not(target_os = "espidf")),
60-
))]
61-
#[doc(hidden)]
62-
pub const SYS_MIN_ALIGN: usize = 8;
63-
#[cfg(any(
66+
target_arch = "riscv32",
67+
target_arch = "xtensa",
68+
)) {
69+
8
70+
} else if cfg!(any(
6471
target_arch = "x86_64",
6572
target_arch = "aarch64",
6673
target_arch = "arm64ec",
@@ -71,16 +78,11 @@ pub const SYS_MIN_ALIGN: usize = 8;
7178
target_arch = "sparc64",
7279
target_arch = "riscv64",
7380
target_arch = "wasm64",
74-
))]
75-
#[doc(hidden)]
76-
pub const SYS_MIN_ALIGN: usize = 16;
77-
// The allocator on the esp-idf and zkvm platforms guarantee 4 byte alignment.
78-
#[cfg(any(
79-
all(target_arch = "riscv32", any(target_os = "espidf", target_os = "zkvm")),
80-
all(target_arch = "xtensa", target_os = "espidf"),
81-
))]
82-
#[doc(hidden)]
83-
pub const SYS_MIN_ALIGN: usize = 4;
81+
)) {
82+
16
83+
} else {
84+
panic!("no value for SYS_MIN_ALIGN")
85+
};
8486

8587
#[macro_use]
8688
mod macros;

0 commit comments

Comments
 (0)