diff --git a/Cargo.toml b/Cargo.toml index cb131f5..7d7466e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,6 @@ members = [ ] [dependencies] -libc = { version = "0.2" } num-traits = { version = "0.2.6" } bstr = { version = "0.2", features = ["std"], default_features = false } diff --git a/src/ffi/glue/glue.c b/src/ffi/glue/glue.c index fd74614..65249d6 100644 --- a/src/ffi/glue/glue.c +++ b/src/ffi/glue/glue.c @@ -200,7 +200,7 @@ int main(int argc, const char **argv) { const rs_item glue_entries[] = { RS_COMMENT("this file was generated by glue.c; do not modify it by hand"), - RS_RAW("use libc::*;\n"), + RS_RAW("use std::os::raw::*;\n"), // == luaconf.h ========================================================== @@ -212,7 +212,7 @@ int main(int argc, const char **argv) { RS_INT("LUA_EXTRASPACE", LUA_EXTRASPACE), RS_INT("LUA_IDSIZE", LUA_IDSIZE), // RS_INT("LUAI_MAXSHORTLEN", LUAI_MAXSHORTLEN), - RS_TYPE("LUA_KCONTEXT", xstr(LUA_KCONTEXT)), + // RS_TYPE("LUA_KCONTEXT", xstr(LUA_KCONTEXT)), RS_INT("LUAI_BITSINT", LUAI_BITSINT), // LUA_INT32? LUAI_UMEM? LUAI_MEM? RS_INT("LUAI_MAXSTACK", LUAI_MAXSTACK), diff --git a/src/ffi/lauxlib.rs b/src/ffi/lauxlib.rs index 258b741..5a9c5c8 100644 --- a/src/ffi/lauxlib.rs +++ b/src/ffi/lauxlib.rs @@ -22,7 +22,7 @@ //! Contains definitions from `lauxlib.h`. -use libc::{c_char, c_int, c_long, c_void, size_t}; +use std::os::raw::{c_char, c_int, c_long, c_void}; use std::ptr; use super::lua::{self, lua_CFunction, lua_Integer, lua_Number, lua_State}; @@ -45,23 +45,23 @@ pub unsafe fn luaL_checkversion(L: *mut lua_State) { luaL_checkversion_( L, lua::LUA_VERSION_NUM as lua_Number, - LUAL_NUMSIZES as size_t, + LUAL_NUMSIZES as usize, ) } extern "C" { - pub fn luaL_checkversion_(L: *mut lua_State, ver: lua_Number, sz: size_t); + pub fn luaL_checkversion_(L: *mut lua_State, ver: lua_Number, sz: usize); pub fn luaL_getmetafield(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int; pub fn luaL_callmeta(L: *mut lua_State, obj: c_int, e: *const c_char) -> c_int; - pub fn luaL_tolstring(L: *mut lua_State, idx: c_int, len: *mut size_t) -> *const c_char; + pub fn luaL_tolstring(L: *mut lua_State, idx: c_int, len: *mut usize) -> *const c_char; pub fn luaL_argerror(L: *mut lua_State, arg: c_int, l: *const c_char) -> c_int; - pub fn luaL_checklstring(L: *mut lua_State, arg: c_int, l: *mut size_t) -> *const c_char; + pub fn luaL_checklstring(L: *mut lua_State, arg: c_int, l: *mut usize) -> *const c_char; pub fn luaL_optlstring( L: *mut lua_State, arg: c_int, def: *const c_char, - l: *mut size_t, + l: *mut usize, ) -> *const c_char; pub fn luaL_checknumber(L: *mut lua_State, arg: c_int) -> lua_Number; pub fn luaL_optnumber(L: *mut lua_State, arg: c_int, def: lua_Number) -> lua_Number; @@ -113,7 +113,7 @@ extern "C" { pub fn luaL_loadbufferx( L: *mut lua_State, buff: *const c_char, - sz: size_t, + sz: usize, name: *const c_char, mode: *const c_char, ) -> c_int; @@ -242,7 +242,7 @@ pub unsafe fn luaL_getmetatable(L: *mut lua_State, n: *const c_char) { pub unsafe fn luaL_loadbuffer( L: *mut lua_State, s: *const c_char, - sz: size_t, + sz: usize, n: *const c_char, ) -> c_int { luaL_loadbufferx(L, s, sz, n, ptr::null()) @@ -251,8 +251,8 @@ pub unsafe fn luaL_loadbuffer( #[repr(C)] pub struct luaL_Buffer { pub b: *mut c_char, - pub size: size_t, - pub n: size_t, + pub size: usize, + pub n: usize, pub L: *mut lua_State, pub initb: [c_char; LUAL_BUFFERSIZE as usize], } @@ -271,29 +271,23 @@ pub unsafe fn luaL_addchar(B: *mut luaL_Buffer, c: c_char) { } #[inline(always)] -pub unsafe fn luaL_addsize(B: *mut luaL_Buffer, s: size_t) { +pub unsafe fn luaL_addsize(B: *mut luaL_Buffer, s: usize) { (*B).n += s; } extern "C" { pub fn luaL_buffinit(L: *mut lua_State, B: *mut luaL_Buffer); - pub fn luaL_prepbuffsize(B: *mut luaL_Buffer, sz: size_t) -> *mut c_char; - pub fn luaL_addlstring(B: *mut luaL_Buffer, s: *const c_char, l: size_t); + pub fn luaL_prepbuffsize(B: *mut luaL_Buffer, sz: usize) -> *mut c_char; + pub fn luaL_addlstring(B: *mut luaL_Buffer, s: *const c_char, l: usize); pub fn luaL_addstring(B: *mut luaL_Buffer, s: *const c_char); pub fn luaL_addvalue(B: *mut luaL_Buffer); pub fn luaL_pushresult(B: *mut luaL_Buffer); - pub fn luaL_pushresultsize(B: *mut luaL_Buffer, sz: size_t); - pub fn luaL_buffinitsize(L: *mut lua_State, B: *mut luaL_Buffer, sz: size_t) -> *mut c_char; + pub fn luaL_pushresultsize(B: *mut luaL_Buffer, sz: usize); + pub fn luaL_buffinitsize(L: *mut lua_State, B: *mut luaL_Buffer, sz: usize) -> *mut c_char; } pub unsafe fn luaL_prepbuffer(B: *mut luaL_Buffer) -> *mut c_char { - luaL_prepbuffsize(B, LUAL_BUFFERSIZE as size_t) -} - -#[repr(C)] -pub struct luaL_Stream { - pub f: *mut ::libc::FILE, - pub closef: lua_CFunction, + luaL_prepbuffsize(B, LUAL_BUFFERSIZE as usize) } // omitted: old module system compatibility diff --git a/src/ffi/lua.rs b/src/ffi/lua.rs index cb0d1f5..3c29a04 100644 --- a/src/ffi/lua.rs +++ b/src/ffi/lua.rs @@ -22,7 +22,7 @@ //! Contains definitions from `lua.h`. -use libc::{c_char, c_int, c_uchar, c_void, size_t}; +use std::os::raw::{c_char, c_int, c_uchar, c_void}; use std::ptr; use super::luaconf; @@ -96,16 +96,16 @@ pub type lua_KFunction = // Type for functions that read/write blocks when loading/dumping Lua chunks pub type lua_Reader = - unsafe extern "C" fn(L: *mut lua_State, ud: *mut c_void, sz: *mut size_t) -> *const c_char; + unsafe extern "C" fn(L: *mut lua_State, ud: *mut c_void, sz: *mut usize) -> *const c_char; pub type lua_Writer = - unsafe extern "C" fn(L: *mut lua_State, p: *const c_void, sz: size_t, ud: *mut c_void) -> c_int; + unsafe extern "C" fn(L: *mut lua_State, p: *const c_void, sz: usize, ud: *mut c_void) -> c_int; /// Type for memory-allocation functions. pub type lua_Alloc = unsafe extern "C" fn( ud: *mut c_void, ptr: *mut c_void, - osize: size_t, - nsize: size_t, + osize: usize, + nsize: usize, ) -> *mut c_void; extern "C" { @@ -141,8 +141,8 @@ extern "C" { pub fn lua_tonumberx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Number; pub fn lua_tointegerx(L: *mut lua_State, idx: c_int, isnum: *mut c_int) -> lua_Integer; pub fn lua_toboolean(L: *mut lua_State, idx: c_int) -> c_int; - pub fn lua_tolstring(L: *mut lua_State, idx: c_int, len: *mut size_t) -> *const c_char; - pub fn lua_rawlen(L: *mut lua_State, idx: c_int) -> size_t; + pub fn lua_tolstring(L: *mut lua_State, idx: c_int, len: *mut usize) -> *const c_char; + pub fn lua_rawlen(L: *mut lua_State, idx: c_int) -> usize; pub fn lua_tocfunction(L: *mut lua_State, idx: c_int) -> lua_CFunction; pub fn lua_touserdata(L: *mut lua_State, idx: c_int) -> *mut c_void; pub fn lua_tothread(L: *mut lua_State, idx: c_int) -> *mut lua_State; @@ -183,7 +183,7 @@ extern "C" { pub fn lua_pushnil(L: *mut lua_State); pub fn lua_pushnumber(L: *mut lua_State, n: lua_Number); pub fn lua_pushinteger(L: *mut lua_State, n: lua_Integer); - pub fn lua_pushlstring(L: *mut lua_State, s: *const c_char, l: size_t) -> *const c_char; + pub fn lua_pushlstring(L: *mut lua_State, s: *const c_char, l: usize) -> *const c_char; pub fn lua_pushstring(L: *mut lua_State, s: *const c_char) -> *const c_char; // TODO: omitted: // lua_pushvfstring @@ -205,7 +205,7 @@ extern "C" { pub fn lua_rawgetp(L: *mut lua_State, idx: c_int, p: *const c_void) -> c_int; pub fn lua_createtable(L: *mut lua_State, narr: c_int, nrec: c_int); - pub fn lua_newuserdata(L: *mut lua_State, sz: size_t) -> *mut c_void; + pub fn lua_newuserdata(L: *mut lua_State, sz: usize) -> *mut c_void; pub fn lua_getmetatable(L: *mut lua_State, objindex: c_int) -> c_int; pub fn lua_getuservalue(L: *mut lua_State, idx: c_int) -> c_int; } @@ -304,7 +304,7 @@ extern "C" { pub fn lua_next(L: *mut lua_State, idx: c_int) -> c_int; pub fn lua_concat(L: *mut lua_State, n: c_int); pub fn lua_len(L: *mut lua_State, idx: c_int); - pub fn lua_stringtonumber(L: *mut lua_State, s: *const c_char) -> size_t; + pub fn lua_stringtonumber(L: *mut lua_State, s: *const c_char) -> usize; pub fn lua_getallocf(L: *mut lua_State, ud: *mut *mut c_void) -> lua_Alloc; pub fn lua_setallocf(L: *mut lua_State, f: lua_Alloc, ud: *mut c_void); } @@ -392,7 +392,7 @@ pub unsafe fn lua_isnoneornil(L: *mut lua_State, n: c_int) -> c_int { pub unsafe fn lua_pushliteral(L: *mut lua_State, s: &'static str) -> *const c_char { use std::ffi::CString; let c_str = CString::new(s).unwrap(); - lua_pushlstring(L, c_str.as_ptr(), c_str.as_bytes().len() as size_t) + lua_pushlstring(L, c_str.as_ptr(), c_str.as_bytes().len()) } #[inline(always)] diff --git a/src/ffi/luaconf.rs b/src/ffi/luaconf.rs index 7adf54d..ad33352 100644 --- a/src/ffi/luaconf.rs +++ b/src/ffi/luaconf.rs @@ -33,9 +33,9 @@ pub use super::glue::{LUA_MAXINTEGER, LUA_MININTEGER}; pub use super::glue::LUAI_MAXSTACK; pub use super::glue::LUAL_NUMSIZES; -pub use super::glue::LUA_KCONTEXT; +pub type LUA_KCONTEXT = isize; // intptr_t -use libc::c_int; +use std::os::raw::c_int; #[inline(always)] pub unsafe fn lua_numtointeger(n: LUA_NUMBER, p: *mut LUA_INTEGER) -> c_int { diff --git a/src/ffi/lualib.rs b/src/ffi/lualib.rs index c25609d..520e499 100644 --- a/src/ffi/lualib.rs +++ b/src/ffi/lualib.rs @@ -22,7 +22,7 @@ //! Contains definitions from `lualib.h`. -use libc::c_int; +use std::os::raw::c_int; use super::lua::lua_State; diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index f45c227..8e41355 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -159,7 +159,7 @@ pub use self::lua::{ }; // auxiliary library types -pub use self::lauxlib::{luaL_Buffer, luaL_Reg, luaL_Stream}; +pub use self::lauxlib::{luaL_Buffer, luaL_Reg}; // auxiliary library functions pub use self::lauxlib::{ diff --git a/tests/_lua.rs b/tests/_lua.rs index 405e5b2..4d49a76 100644 --- a/tests/_lua.rs +++ b/tests/_lua.rs @@ -1,29 +1,29 @@ #[allow(non_camel_case_types)] -type lua_State = libc::c_void; +type lua_State = std::os::raw::c_void; #[allow(non_camel_case_types)] -type lua_CFunction = unsafe extern "C" fn(L: *mut lua_State) -> libc::c_int; +type lua_CFunction = unsafe extern "C" fn(L: *mut lua_State) -> std::os::raw::c_int; extern "C" { fn luaL_newstate() -> *mut lua_State; fn luaL_requiref( L: *mut lua_State, - modname: *const libc::c_char, + modname: *const std::os::raw::c_char, openf: lua_CFunction, - glb: libc::c_int, + glb: std::os::raw::c_int, ); - fn lua_settop(L: *mut lua_State, idx: libc::c_int); + fn lua_settop(L: *mut lua_State, idx: std::os::raw::c_int); - fn luaopen_base(L: *mut lua_State) -> libc::c_int; - fn luaopen_coroutine(L: *mut lua_State) -> libc::c_int; - fn luaopen_table(L: *mut lua_State) -> libc::c_int; - fn luaopen_io(L: *mut lua_State) -> libc::c_int; - fn luaopen_os(L: *mut lua_State) -> libc::c_int; - fn luaopen_string(L: *mut lua_State) -> libc::c_int; - fn luaopen_math(L: *mut lua_State) -> libc::c_int; - fn luaopen_package(L: *mut lua_State) -> libc::c_int; + fn luaopen_base(L: *mut lua_State) -> std::os::raw::c_int; + fn luaopen_coroutine(L: *mut lua_State) -> std::os::raw::c_int; + fn luaopen_table(L: *mut lua_State) -> std::os::raw::c_int; + fn luaopen_io(L: *mut lua_State) -> std::os::raw::c_int; + fn luaopen_os(L: *mut lua_State) -> std::os::raw::c_int; + fn luaopen_string(L: *mut lua_State) -> std::os::raw::c_int; + fn luaopen_math(L: *mut lua_State) -> std::os::raw::c_int; + fn luaopen_package(L: *mut lua_State) -> std::os::raw::c_int; } #[allow(unused)]