From c1c6dbe7c23e294270bb7a484fc0415275062122 Mon Sep 17 00:00:00 2001 From: Polite Kiwi Date: Thu, 24 Jan 2019 05:50:25 -0500 Subject: [PATCH] Fixed a few problems - JIT modules now copy over when building with luajit as driver or package - jitargs now handles the args properly - jit regression fixed for -O -b -j - windows now delete bin correctly when cleaning - uses less mallocs due to removal of a couple arrays - fully fixed regression where D command didn't work properly --- build.bat | 7 ++++++- build.msvs.bat | 7 ++++++- build.sh | 11 +++++++++++ src/jitsupport.c | 36 +++++++++++++++++++++--------------- src/jitsupport.h | 4 ++-- src/lang.h | 3 +++ src/ldata.c | 7 ++----- src/luadriver.c | 33 +++++++-------------------------- src/luadriver.h | 9 ++++++--- 9 files changed, 64 insertions(+), 53 deletions(-) diff --git a/build.bat b/build.bat index 9976dec..4d2f7e0 100644 --- a/build.bat +++ b/build.bat @@ -60,7 +60,8 @@ setlocal del include\*.h del dll\*.dll del obj\*.o - rmdir /S /Q bin\* + rmdir /S /Q bin\Release + rmdir /S /Q bin\Debug echo Done. exit /b 0 @@ -146,6 +147,8 @@ setlocal REM Build dependencies IF [%2] == [luajit] ( call :build_luajit + mkdir %root%\jit + xcopy /E /Y luajit-2.0\src\jit\* %root%\jit ) ELSE ( IF NOT EXIST "lua-all\%2" ( echo Not a valid lua version! @@ -185,6 +188,8 @@ setlocal IF [%2] == [luajit] ( call :build_luajit + mkdir %root%\jit + xcopy /E /Y luajit-2.0\src\jit\* %root%\jit ) ELSE ( IF NOT EXIST "lua-all\%2" ( echo Not a valid lua version! diff --git a/build.msvs.bat b/build.msvs.bat index c704c06..4c7226d 100644 --- a/build.msvs.bat +++ b/build.msvs.bat @@ -57,7 +57,8 @@ setlocal del dll\*.lib del dll\*.exp del obj\*.obj - rmdir /S /Q bin\* + rmdir /S /Q bin\Release + rmdir /S /Q bin\Debug echo Done. exit /b 0 @@ -143,6 +144,8 @@ setlocal REM Build dependencies IF [%2] == [luajit] ( call :build_luajit + mkdir %root%\jit + xcopy /E /Y luajit-2.0\src\jit\* %root%\jit ) ELSE ( IF NOT EXIST "lua-all\%2" ( echo Not a valid lua version! @@ -184,6 +187,8 @@ setlocal IF [%2] == [luajit] ( call :build_luajit + mkdir %root%\jit + xcopy /E /Y luajit-2.0\src\jit\* %root%\jit ) ELSE ( IF NOT EXIST "lua-all\%2" ( echo Not a valid lua version! diff --git a/build.sh b/build.sh index bc85290..f6c2c08 100755 --- a/build.sh +++ b/build.sh @@ -237,6 +237,7 @@ build_install () { mv *.o $objdir if [ "$1" = "luajit" ]; then cp -r $dlldir/* $root + mkdir $root/jit else cp $dlldir/$1.so $root/dll fi @@ -302,6 +303,11 @@ if [ "$1" = "driver" ]; then # Build dependencies if [ "$2" = "luajit" ]; then build_luajit + if [ ! -d "$root/jit" ]; then + mkdir -p $root/jit + cp -r luajit-2.0/src/jit/* $root/jit + ls $root/jit + fi else if [ ! -d "lua-all/$2" ]; then echo Not a valid lua version! @@ -342,6 +348,11 @@ if [ "$1" = "package" ]; then if [ "$2" = "luajit" ]; then build_luajit + if [ ! -d "$root/jit" ]; then + mkdir -p $root/jit + cp -r luajit-2.0/src/jit/* $root/jit + ls $root/jit + fi else if [ ! -d "lua-all/$2" ]; then echo Not a valid lua version! diff --git a/src/jitsupport.c b/src/jitsupport.c index 129de04..a4d57ce 100644 --- a/src/jitsupport.c +++ b/src/jitsupport.c @@ -22,6 +22,7 @@ */ #if defined(LUA_JIT_51) +# include "luadriver.h" # include "jitsupport.h" # include "lang.h" @@ -169,26 +170,31 @@ } - int jitargs(lua_State* L, Array* luajit_jcmds, Array* luajit_opts, - char** luajit_bc, int squelch, int post_exist) - { - if(luajit_jcmds != NULL) { - for(size_t i=0; isize; i++) - if(dojitcmd(L, (const char*) array_get(luajit_jcmds, i)) != 0) - fputs(_("JS_FAILED_CONTROL_CMD"), stderr); + int jitargs(lua_State* L, LC_ARGS ARGS) { + + if(ARGS.jitjcmd != NULL) { + const char* cmd = (*(ARGS.jitjcmd[ARGS.jitjcmd_argc] + 2) == '\0') + ? ARGS.jitjcmd[ARGS.jitjcmd_argc + 1] + : ARGS.jitjcmd[ARGS.jitjcmd_argc] + 2; + + if(cmd == 0) + fputs(_("MALFORMED_J_NO_PARAM"), stderr); + + if(dojitcmd(L, cmd) == 1) + fputs(_("JS_FAILED_CONTROL_CMD"), stderr); } - - if(luajit_opts != NULL) { - for(size_t i=0; isize; i++) - if(dojitopt(L, (const char*) array_get(luajit_opts, i)) != 0) - fputs(_("JS_FAILED_SET_O"), stderr); + + if(ARGS.jitocmd != NULL) { + if(dojitopt(L, ARGS.jitocmd[ARGS.jitocmd_argc] + 2) == 1) + fputs(_("JS_FAILED_SET_O"), stderr); } - if(squelch == 0 && post_exist == 1) + if(ARGS.copyright_squelch == 0 && ARGS.post_exist == 1) print_jit_status(L); - if(luajit_bc != NULL) - return dobytecode(L, luajit_bc); + if(ARGS.jitbcmd != NULL) + return dobytecode(L, ARGS.jitbcmd + ARGS.jitjcmd_argc + 1); + return 0; // success } diff --git a/src/jitsupport.h b/src/jitsupport.h index 7d17e7c..f0afef8 100644 --- a/src/jitsupport.h +++ b/src/jitsupport.h @@ -28,6 +28,7 @@ # include "lualib.h" # include "lauxlib.h" # include "luajit.h" +# include "luadriver.h" # include "darr.h" @@ -38,8 +39,7 @@ int dobytecode(lua_State* L, char** argv); void print_jit_status(lua_State* L); - int jitargs(lua_State* L, Array* luajit_jcmds, Array* luajit_opts, - char** luajit_bc, int squelch, int post_exist); + int jitargs(lua_State* L, LC_ARGS ARGS); #endif // EOF if defined(LUA_JIT_51) diff --git a/src/lang.h b/src/lang.h index 5158ef5..529b34e 100644 --- a/src/lang.h +++ b/src/lang.h @@ -1,6 +1,9 @@ #pragma once +#include +#include + #include "darr.h" typedef struct LangCache { diff --git a/src/ldata.c b/src/ldata.c index 1083b55..697d7ee 100644 --- a/src/ldata.c +++ b/src/ldata.c @@ -202,11 +202,8 @@ LC_LD_API int luacon_loaddll(LC_ARGS _ARGS, LangCache* _lang) #if defined(LUA_JIT_51) if(ARGS.no_libraries == 0) { - int status = jitargs(L, - ARGS.luajit_jcmds, ARGS.luajit_opts, ARGS.luajit_bc, - ARGS.copyright_squelch, ARGS.post_exist); - - if(ARGS.luajit_bc != NULL) + int status = jitargs(L, ARGS); + if(status != 0) return status; } #endif diff --git a/src/luadriver.c b/src/luadriver.c index 867dc07..68eb01a 100644 --- a/src/luadriver.c +++ b/src/luadriver.c @@ -239,34 +239,17 @@ int main(int argc, char** argv) { i = argc; break; case 'j': - if(ARGS.luajit_jcmds == NULL) - ARGS.luajit_jcmds = array_new(DEFINES_INIT, DEFINES_EXPANSION); - check_error_OOM(ARGS.luajit_jcmds == NULL, __LINE__); - - char* jcmd = argv[i] + 2; - if(*jcmd == ' ' || *jcmd == '\0') { - if(i + 1 >= argc) { - fprintf(stderr, _("MALFORMED_J_NO_PARAM")); - break; - } else - jcmd = argv[i+1]; - } - array_push(ARGS.luajit_jcmds, jcmd); + ARGS.jitjcmd = argv; + ARGS.jitjcmd_argc = i; break; case 'O': - if(ARGS.luajit_opts == NULL) - ARGS.luajit_opts = array_new(DEFINES_INIT, DEFINES_EXPANSION); - check_error_OOM(ARGS.luajit_opts == NULL, __LINE__); - if(strlen(argv[i]) > 2) - array_push(ARGS.luajit_opts, argv[i] + 2); - else - fprintf(stderr, _("MALFORMED_O_NO_PARAM")); + ARGS.jitocmd = argv; + ARGS.jitocmd_argc = i; break; case 'b': - if(i + 1 < argc) - ARGS.luajit_bc = argv + i; - else - fprintf(stderr, _("MALFORMED_B_NO_PARAM")); + ARGS.post_exist = 0; + ARGS.jitbcmd = argv; + ARGS.jitbcmd_argc = i; break; case '?': ARGS.do_help = 1; @@ -319,8 +302,6 @@ int main(int argc, char** argv) { langfile_free(lang); array_free(ARGS.globals); array_free(ARGS.libraries); - array_free(ARGS.luajit_jcmds); - array_free(ARGS.luajit_opts); #if defined(_WIN32) || defined(_WIN64) FreeLibrary(luacxt); diff --git a/src/luadriver.h b/src/luadriver.h index e825015..1d9fbfe 100644 --- a/src/luadriver.h +++ b/src/luadriver.h @@ -35,12 +35,15 @@ typedef struct tag_LC_ARGS { char* run_str; Array* globals; Array* libraries; - Array* luajit_jcmds; - Array* luajit_opts; char** parameters_argv; - char** luajit_bc; char** files_index; char** luac_argv; + char** jitjcmd; + char** jitocmd; + char** jitbcmd; + int jitjcmd_argc; + int jitocmd_argc; + int jitbcmd_argc; int luac_argc; int do_luac; int do_help;