Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: builds

on:
push:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: read-all

jobs:

linux:
name: Linux
runs-on: ubuntu-latest
container: almalinux:9
steps:
- run: |
dnf -y install \
cargo \
rustc
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- run: cargo build

cross-compile:
name: Cross Compile
runs-on: ubuntu-latest
container: almalinux:9
steps:
- run: |
dnf -y install dnf-plugins-core
dnf config-manager --set-enable crb
dnf -y install \
gcc \
make \
mingw64-gcc
- run: curl https://sh.rustup.rs -sSf | sh -s -- -y
- run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- run: rustup target add x86_64-pc-windows-gnu
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- run: |
RANLIB=x86_64-w64-mingw32-ranlib \
AR=x86_64-w64-mingw32-ar \
CC=x86_64-w64-mingw32-gcc \
cargo build --target x86_64-pc-windows-gnu

windows-msys2-mingw64:
name: Windows MSYS2 MINGW64
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: git mingw-w64-x86_64-toolchain make mingw-w64-x86_64-rust
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- run: cargo build
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "suricata-lua-sys"
description = "Vendored Lua for Suricata"
version = "0.1.0-alpha.5"
version = "0.1.0-alpha.6"
edition = "2021"
rust-version = "1.56.0"
license = "MIT"
Expand Down
5 changes: 4 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ fn main() {
let host = env::var_os("HOST")
.map(|host| host.into_string().unwrap())
.unwrap();
let target = env::var_os("TARGET")
.map(|host| host.into_string().unwrap())
.unwrap();

let out_dir = env::var_os("OUT_DIR").map(PathBuf::from).unwrap();
let build_dir = out_dir.join("lua");
Expand All @@ -25,7 +28,7 @@ fn main() {
fs_extra::dir::copy(&src_dir, &build_dir, &opts).unwrap();

let mut command = Command::new("make");
if host.contains("windows") {
if host.contains("windows") || target.contains("windows") {
command.arg("mingw");
}

Expand Down
30 changes: 16 additions & 14 deletions lua/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
# Your platform. See PLATS for possible values.
PLAT= guess

CC= gcc -std=gnu99
CC?= gcc
CC_CMD= $(CC) -std=gnu99
CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS)
LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
LIBS= -lm $(SYSLIBS) $(MYLIBS)

AR= ar rcu
RANLIB= ranlib
AR?= ar rcu
AR_CMD = $(AR) rcu
RANLIB?= ranlib
RM= rm -f
UNAME= uname

Expand Down Expand Up @@ -57,14 +59,14 @@ o: $(ALL_O)
a: $(ALL_A)

$(LUA_A): $(BASE_O)
$(AR) $@ $(BASE_O)
$(AR_CMD) $@ $(BASE_O)
$(RANLIB) $@

$(LUA_T): $(LUA_O) $(LUA_A)
$(CC) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)
$(CC_CMD) -o $@ $(LDFLAGS) $(LUA_O) $(LUA_A) $(LIBS)

$(LUAC_T): $(LUAC_O) $(LUA_A)
$(CC) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)
$(CC_CMD) -o $@ $(LDFLAGS) $(LUAC_O) $(LUA_A) $(LIBS)

test:
./$(LUA_T) -v
Expand All @@ -73,7 +75,7 @@ clean:
$(RM) $(ALL_T) $(ALL_O)

depend:
@$(CC) $(CFLAGS) -MM l*.c
@$(CC_CMD) $(CFLAGS) -MM l*.c

echo:
@echo "PLAT= $(PLAT)"
Expand All @@ -99,21 +101,21 @@ guess:
@$(MAKE) `$(UNAME)`

AIX aix:
$(MAKE) $(ALL) CC="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall"
$(MAKE) $(ALL) CC_CMD="xlc" CFLAGS="-O2 -DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-ldl" SYSLDFLAGS="-brtl -bexpall"

bsd:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX -DLUA_USE_DLOPEN" SYSLIBS="-Wl,-E"

c89:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_C89" CC="gcc -std=c89"
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_C89" CC_CMD="gcc -std=c89"
@echo ''
@echo '*** C89 does not guarantee 64-bit integers for Lua.'
@echo '*** Make sure to compile all external Lua libraries'
@echo '*** with LUA_USE_C89 to ensure consistency'
@echo ''

FreeBSD NetBSD OpenBSD freebsd:
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc"
$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC_CMD="cc"

generic: $(ALL)

Expand All @@ -133,7 +135,7 @@ Darwin macos macosx:

mingw:
$(MAKE) "LUA_A=lua54.dll" "LUA_T=lua.exe" \
"AR=$(CC) -shared -o" "RANLIB=strip --strip-unneeded" \
"AR_CMD=$(CC_CMD) -shared -o" "RANLIB=strip --strip-unneeded" \
"SYSCFLAGS=-DLUA_BUILD_AS_DLL" "SYSLIBS=" "SYSLDFLAGS=-s" lua.exe
$(MAKE) "LUAC_T=luac.exe" luac.exe

Expand All @@ -148,13 +150,13 @@ SunOS solaris:

# Compiler modules may use special flags.
llex.o:
$(CC) $(CFLAGS) $(CMCFLAGS) -c llex.c
$(CC_CMD) $(CFLAGS) $(CMCFLAGS) -c llex.c

lparser.o:
$(CC) $(CFLAGS) $(CMCFLAGS) -c lparser.c
$(CC_CMD) $(CFLAGS) $(CMCFLAGS) -c lparser.c

lcode.o:
$(CC) $(CFLAGS) $(CMCFLAGS) -c lcode.c
$(CC_CMD) $(CFLAGS) $(CMCFLAGS) -c lcode.c

# DO NOT DELETE

Expand Down
4 changes: 2 additions & 2 deletions lua/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,9 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) {
o = index2value(L, idx); /* previous call may reallocate the stack */
}
if (len != NULL)
*len = vslen(o);
*len = tsslen(tsvalue(o));
lua_unlock(L);
return svalue(o);
return getstr(tsvalue(o));
}


Expand Down
28 changes: 21 additions & 7 deletions lua/lauxlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ static int pushglobalfuncname (lua_State *L, lua_Debug *ar) {
int top = lua_gettop(L);
lua_getinfo(L, "f", ar); /* push function */
lua_getfield(L, LUA_REGISTRYINDEX, LUA_LOADED_TABLE);
luaL_checkstack(L, 6, "not enough stack"); /* slots for 'findfield' */
if (findfield(L, top + 1, 2)) {
const char *name = lua_tostring(L, -1);
if (strncmp(name, LUA_GNAME ".", 3) == 0) { /* name start with '_G.'? */
Expand Down Expand Up @@ -249,11 +250,13 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
return 1;
}
else {
const char *msg;
luaL_pushfail(L);
msg = (en != 0) ? strerror(en) : "(no extra info)";
if (fname)
lua_pushfstring(L, "%s: %s", fname, strerror(en));
lua_pushfstring(L, "%s: %s", fname, msg);
else
lua_pushstring(L, strerror(en));
lua_pushstring(L, msg);
lua_pushinteger(L, en);
return 3;
}
Expand Down Expand Up @@ -732,9 +735,12 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {


static int errfile (lua_State *L, const char *what, int fnameindex) {
const char *serr = strerror(errno);
int err = errno;
const char *filename = lua_tostring(L, fnameindex) + 1;
lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr);
if (err != 0)
lua_pushfstring(L, "cannot %s %s: %s", what, filename, strerror(err));
else
lua_pushfstring(L, "cannot %s %s", what, filename);
lua_remove(L, fnameindex);
return LUA_ERRFILE;
}
Expand Down Expand Up @@ -787,6 +793,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
}
else {
lua_pushfstring(L, "@%s", filename);
errno = 0;
lf.f = fopen(filename, "r");
if (lf.f == NULL) return errfile(L, "open", fnameindex);
}
Expand All @@ -796,13 +803,15 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
if (c == LUA_SIGNATURE[0]) { /* binary file? */
lf.n = 0; /* remove possible newline */
if (filename) { /* "real" file? */
errno = 0;
lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
skipcomment(lf.f, &c); /* re-read initial portion */
}
}
if (c != EOF)
lf.buff[lf.n++] = c; /* 'c' is the first character of the stream */
errno = 0;
status = lua_load(L, getF, &lf, lua_tostring(L, -1), mode);
readstatus = ferror(lf.f);
if (filename) fclose(lf.f); /* close file (even in case of errors) */
Expand Down Expand Up @@ -933,7 +942,7 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
luaL_checkstack(L, nup, "too many upvalues");
for (; l->name != NULL; l++) { /* fill the table with given functions */
if (l->func == NULL) /* place holder? */
if (l->func == NULL) /* placeholder? */
lua_pushboolean(L, 0);
else {
int i;
Expand Down Expand Up @@ -1025,9 +1034,14 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
}


/*
** Standard panic funcion just prints an error message. The test
** with 'lua_type' avoids possible memory errors in 'lua_tostring'.
*/
static int panic (lua_State *L) {
const char *msg = lua_tostring(L, -1);
if (msg == NULL) msg = "error object is not a string";
const char *msg = (lua_type(L, -1) == LUA_TSTRING)
? lua_tostring(L, -1)
: "error object is not a string";
lua_writestringerror("PANIC: unprotected error in call to Lua API (%s)\n",
msg);
return 0; /* return to Lua to abort */
Expand Down
Loading
Loading