Skip to content

Commit

Permalink
Fixed a few problems
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
tilkinsc committed Jan 24, 2019
1 parent 2a4e4a0 commit c1c6dbe
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 53 deletions.
7 changes: 6 additions & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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!
Expand Down
7 changes: 6 additions & 1 deletion build.msvs.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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!
Expand Down
11 changes: 11 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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!
Expand Down
36 changes: 21 additions & 15 deletions src/jitsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

#if defined(LUA_JIT_51)
# include "luadriver.h"
# include "jitsupport.h"

# include "lang.h"
Expand Down Expand Up @@ -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; i<luajit_jcmds->size; 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; i<luajit_opts->size; 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
}
Expand Down
4 changes: 2 additions & 2 deletions src/jitsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# include "lualib.h"
# include "lauxlib.h"
# include "luajit.h"
# include "luadriver.h"

# include "darr.h"

Expand All @@ -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)

3 changes: 3 additions & 0 deletions src/lang.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

#pragma once

#include <stdlib.h>
#include <stdio.h>

#include "darr.h"

typedef struct LangCache {
Expand Down
7 changes: 2 additions & 5 deletions src/ldata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 7 additions & 26 deletions src/luadriver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/luadriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c1c6dbe

Please sign in to comment.