Skip to content

Commit 86d63ef

Browse files
committed
Fix missing BUFSIZ for wasm32 in libc
1 parent e33bcf7 commit 86d63ef

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

mlua-sys/src/lua51/lauxlib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,14 @@ pub unsafe fn luaL_opt<T>(
154154
// Generic Buffer Manipulation
155155
//
156156

157+
#[cfg(target_arch = "wasm32")]
158+
const BUFSIZ: usize = 1024; // WASI libc's BUFSIZ is 1024
159+
#[cfg(not(target_arch = "wasm32"))]
160+
const BUFSIZ: usize = libc::BUFSIZ as usize;
161+
157162
// The buffer size used by the lauxlib buffer system.
158163
// The "16384" workaround is taken from the LuaJIT source code.
159-
#[rustfmt::skip]
160-
pub const LUAL_BUFFERSIZE: usize = if libc::BUFSIZ > 16384 { 8192 } else { libc::BUFSIZ as usize };
164+
pub const LUAL_BUFFERSIZE: usize = if BUFSIZ > 16384 { 8192 } else { BUFSIZ };
161165

162166
#[repr(C)]
163167
pub struct luaL_Buffer {

mlua-sys/src/lua52/lauxlib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,14 @@ pub unsafe fn luaL_opt<T>(
189189
// Generic Buffer Manipulation
190190
//
191191

192+
#[cfg(target_arch = "wasm32")]
193+
const BUFSIZ: usize = 1024; // WASI libc's BUFSIZ is 1024
194+
#[cfg(not(target_arch = "wasm32"))]
195+
const BUFSIZ: usize = libc::BUFSIZ as usize;
196+
192197
// The buffer size used by the lauxlib buffer system.
193198
// The "16384" workaround is taken from the LuaJIT source code.
194-
#[rustfmt::skip]
195-
pub const LUAL_BUFFERSIZE: usize = if libc::BUFSIZ > 16384 { 8192 } else { libc::BUFSIZ as usize };
199+
pub const LUAL_BUFFERSIZE: usize = if BUFSIZ > 16384 { 8192 } else { BUFSIZ };
196200

197201
#[repr(C)]
198202
pub struct luaL_Buffer {

0 commit comments

Comments
 (0)