Skip to content

Commit

Permalink
Remove unused code.
Browse files Browse the repository at this point in the history
This is a completely automatic change made by the 'unifdef' program. It
rewrites all the source files to resolve #if/#ifdef statements based on
chosen values.

Touches a lot of code...
  • Loading branch information
lukego committed Mar 12, 2017
1 parent 827e3d6 commit 40381fa
Show file tree
Hide file tree
Showing 94 changed files with 3 additions and 7,809 deletions.
25 changes: 0 additions & 25 deletions src/lib_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
#include "lj_trace.h"
#include "lj_lib.h"

#if LJ_TARGET_POSIX
#include <sys/wait.h>
#endif

/* -- I/O error handling -------------------------------------------------- */

Expand All @@ -49,7 +47,6 @@ LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)
LUALIB_API int luaL_execresult(lua_State *L, int stat)
{
if (stat != -1) {
#if LJ_TARGET_POSIX
if (WIFSIGNALED(stat)) {
stat = WTERMSIG(stat);
setnilV(L->top++);
Expand All @@ -63,13 +60,6 @@ LUALIB_API int luaL_execresult(lua_State *L, int stat)
setnilV(L->top++);
lua_pushliteral(L, "exit");
}
#else
if (stat == 0)
setboolV(L->top++, 1);
else
setnilV(L->top++);
lua_pushliteral(L, "exit");
#endif
setintV(L->top++, stat);
return 3;
}
Expand Down Expand Up @@ -302,9 +292,6 @@ static int panic(lua_State *L)

#ifdef LUAJIT_USE_SYSMALLOC

#if LJ_64 && !LJ_GC64 && !defined(LUAJIT_USE_VALGRIND)
#error "Must use builtin allocator for 64 bit target"
#endif

static void *mem_alloc(void *ud, void *ptr, size_t osize, size_t nsize)
{
Expand Down Expand Up @@ -334,23 +321,11 @@ LUALIB_API lua_State *luaL_newstate(void)
lua_State *L;
void *ud = lj_alloc_create();
if (ud == NULL) return NULL;
#if LJ_64 && !LJ_GC64
L = lj_state_newstate(lj_alloc_f, ud);
#else
L = lua_newstate(lj_alloc_f, ud);
#endif
if (L) G(L)->panic = panic;
return L;
}

#if LJ_64 && !LJ_GC64
LUA_API lua_State *lua_newstate(lua_Alloc f, void *ud)
{
UNUSED(f); UNUSED(ud);
fputs("Must use luaL_newstate() for 64 bit target\n", stderr);
return NULL;
}
#endif

#endif

10 changes: 0 additions & 10 deletions src/lib_base.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
#include "lj_meta.h"
#include "lj_state.h"
#include "lj_frame.h"
#if LJ_HASFFI
#include "lj_ctype.h"
#include "lj_cconv.h"
#endif
#include "lj_bc.h"
#include "lj_ff.h"
#include "lj_dispatch.h"
Expand Down Expand Up @@ -81,7 +79,6 @@ LJLIB_ASM(next)
return FFH_UNREACHABLE;
}

#if LJ_52 || LJ_HASFFI
static int ffh_pairs(lua_State *L, MMS mm)
{
TValue *o = lj_lib_checkany(L, 1);
Expand All @@ -98,9 +95,6 @@ static int ffh_pairs(lua_State *L, MMS mm)
return FFH_RES(3);
}
}
#else
#define ffh_pairs(L, mm) (lj_lib_checktab(L, 1), FFH_UNREACHABLE)
#endif

LJLIB_PUSH(lastcl)
LJLIB_ASM(pairs) LJLIB_REC(xpairs 0)
Expand Down Expand Up @@ -265,7 +259,6 @@ LJLIB_ASM(tonumber) LJLIB_REC(.)
copyTV(L, L->base-1-LJ_FR2, o);
return FFH_RES(1);
}
#if LJ_HASFFI
if (tviscdata(o)) {
CTState *cts = ctype_cts(L);
CType *ct = lj_ctype_rawref(cts, cdataV(o)->ctypeid);
Expand All @@ -283,7 +276,6 @@ LJLIB_ASM(tonumber) LJLIB_REC(.)
return FFH_RES(1);
}
}
#endif
} else {
const char *p = strdata(lj_lib_checkstr(L, 1));
char *ep;
Expand Down Expand Up @@ -608,10 +600,8 @@ LJLIB_NOREG LJLIB_ASM(coroutine_wrap_aux)

/* Inline declarations. */
LJ_ASMF void lj_ff_coroutine_wrap_aux(void);
#if !(LJ_TARGET_MIPS && defined(ljamalg_c))
LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,
lua_State *co);
#endif

/* Error handler, called from assembler VM. */
void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L, lua_State *co)
Expand Down
54 changes: 0 additions & 54 deletions src/lib_bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,48 @@
#include "lj_buf.h"
#include "lj_strscan.h"
#include "lj_strfmt.h"
#if LJ_HASFFI
#include "lj_ctype.h"
#include "lj_cdata.h"
#include "lj_cconv.h"
#include "lj_carith.h"
#endif
#include "lj_ff.h"
#include "lj_lib.h"

/* ------------------------------------------------------------------------ */

#define LJLIB_MODULE_bit

#if LJ_HASFFI
static int bit_result64(lua_State *L, CTypeID id, uint64_t x)
{
GCcdata *cd = lj_cdata_new_(L, id, 8);
*(uint64_t *)cdataptr(cd) = x;
setcdataV(L, L->base-1-LJ_FR2, cd);
return FFH_RES(1);
}
#else
static int32_t bit_checkbit(lua_State *L, int narg)
{
TValue *o = L->base + narg-1;
if (!(o < L->top && lj_strscan_numberobj(o)))
lj_err_argt(L, narg, LUA_TNUMBER);
if (LJ_LIKELY(tvisint(o))) {
return intV(o);
} else {
int32_t i = lj_num2bit(numV(o));
if (LJ_DUALNUM) setintV(o, i);
return i;
}
}
#endif

LJLIB_ASM(bit_tobit) LJLIB_REC(bit_tobit)
{
#if LJ_HASFFI
CTypeID id = 0;
setintV(L->base-1-LJ_FR2, (int32_t)lj_carith_check64(L, 1, &id));
return FFH_RES(1);
#else
lj_lib_checknumber(L, 1);
return FFH_RETRY;
#endif
}

LJLIB_ASM(bit_bnot) LJLIB_REC(bit_unary IR_BNOT)
{
#if LJ_HASFFI
CTypeID id = 0;
uint64_t x = lj_carith_check64(L, 1, &id);
return id ? bit_result64(L, id, ~x) : FFH_RETRY;
#else
lj_lib_checknumber(L, 1);
return FFH_RETRY;
#endif
}

LJLIB_ASM(bit_bswap) LJLIB_REC(bit_unary IR_BSWAP)
{
#if LJ_HASFFI
CTypeID id = 0;
uint64_t x = lj_carith_check64(L, 1, &id);
return id ? bit_result64(L, id, lj_bswap64(x)) : FFH_RETRY;
#else
lj_lib_checknumber(L, 1);
return FFH_RETRY;
#endif
}

LJLIB_ASM(bit_lshift) LJLIB_REC(bit_shift IR_BSHL)
{
#if LJ_HASFFI
CTypeID id = 0, id2 = 0;
uint64_t x = lj_carith_check64(L, 1, &id);
int32_t sh = (int32_t)lj_carith_check64(L, 2, &id2);
Expand All @@ -100,11 +66,6 @@ LJLIB_ASM(bit_lshift) LJLIB_REC(bit_shift IR_BSHL)
}
if (id2) setintV(L->base+1, sh);
return FFH_RETRY;
#else
lj_lib_checknumber(L, 1);
bit_checkbit(L, 2);
return FFH_RETRY;
#endif
}
LJLIB_ASM_(bit_rshift) LJLIB_REC(bit_shift IR_BSHR)
LJLIB_ASM_(bit_arshift) LJLIB_REC(bit_shift IR_BSAR)
Expand All @@ -113,7 +74,6 @@ LJLIB_ASM_(bit_ror) LJLIB_REC(bit_shift IR_BROR)

LJLIB_ASM(bit_band) LJLIB_REC(bit_nary IR_BAND)
{
#if LJ_HASFFI
CTypeID id = 0;
TValue *o = L->base, *top = L->top;
int i = 0;
Expand All @@ -131,11 +91,6 @@ LJLIB_ASM(bit_band) LJLIB_REC(bit_nary IR_BAND)
return bit_result64(L, id, y);
}
return FFH_RETRY;
#else
int i = 0;
do { lj_lib_checknumber(L, ++i); } while (L->base+i < L->top);
return FFH_RETRY;
#endif
}
LJLIB_ASM_(bit_bor) LJLIB_REC(bit_nary IR_BOR)
LJLIB_ASM_(bit_bxor) LJLIB_REC(bit_nary IR_BXOR)
Expand All @@ -144,24 +99,15 @@ LJLIB_ASM_(bit_bxor) LJLIB_REC(bit_nary IR_BXOR)

LJLIB_CF(bit_tohex) LJLIB_REC(.)
{
#if LJ_HASFFI
CTypeID id = 0, id2 = 0;
uint64_t b = lj_carith_check64(L, 1, &id);
int32_t n = L->base+1>=L->top ? (id ? 16 : 8) :
(int32_t)lj_carith_check64(L, 2, &id2);
#else
uint32_t b = (uint32_t)bit_checkbit(L, 1);
int32_t n = L->base+1>=L->top ? 8 : bit_checkbit(L, 2);
#endif
SBuf *sb = lj_buf_tmp_(L);
SFormat sf = (STRFMT_UINT|STRFMT_T_HEX);
if (n < 0) { n = -n; sf |= STRFMT_F_UPPER; }
sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC);
#if LJ_HASFFI
if (n < 16) b &= ((uint64_t)1 << 4*n)-1;
#else
if (n < 8) b &= (1u << 4*n)-1;
#endif
sb = lj_strfmt_putfxint(sb, sf, b);
setstrV(L, L->top-1, lj_buf_str(L, sb));
lj_gc_check(L);
Expand Down
18 changes: 0 additions & 18 deletions src/lib_ffi.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "lj_obj.h"

#if LJ_HASFFI

#include "lj_gc.h"
#include "lj_err.h"
Expand Down Expand Up @@ -728,29 +727,13 @@ LJLIB_CF(ffi_abi) LJLIB_REC(.)
GCstr *s = lj_lib_checkstr(L, 1);
int b = 0;
switch (s->hash) {
#if LJ_64
case H_(849858eb,ad35fd06): b = 1; break; /* 64bit */
#else
case H_(662d3c79,d0e22477): b = 1; break; /* 32bit */
#endif
#if LJ_ARCH_HASFPU
case H_(e33ee463,e33ee463): b = 1; break; /* fpu */
#endif
#if LJ_ABI_SOFTFP
case H_(61211a23,c2e8c81c): b = 1; break; /* softfp */
#else
case H_(539417a8,8ce0812f): b = 1; break; /* hardfp */
#endif
#if LJ_ABI_EABI
case H_(2182df8f,f2ed1152): b = 1; break; /* eabi */
#endif
#if LJ_ABI_WIN
case H_(4ab624a8,4ab624a8): b = 1; break; /* win */
#endif
case H_(3af93066,1f001464): b = 1; break; /* le/be */
#if LJ_GC64
case H_(9e89d2c9,13c83c92): b = 1; break; /* gc64 */
#endif
default:
break;
}
Expand Down Expand Up @@ -866,4 +849,3 @@ LUALIB_API int luaopen_ffi(lua_State *L)
return 1;
}

#endif
2 changes: 0 additions & 2 deletions src/lib_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ static const luaL_Reg lj_lib_load[] = {
};

static const luaL_Reg lj_lib_preload[] = {
#if LJ_HASFFI
{ LUA_FFILIBNAME, luaopen_ffi },
#endif
{ NULL, NULL }
};

Expand Down
35 changes: 0 additions & 35 deletions src/lib_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,7 @@ static int io_file_close(lua_State *L, IOFileUD *iof)
ok = (fclose(iof->fp) == 0);
} else if ((iof->type & IOFILE_TYPE_MASK) == IOFILE_TYPE_PIPE) {
int stat = -1;
#if LJ_TARGET_POSIX
stat = pclose(iof->fp);
#elif LJ_TARGET_WINDOWS && !LJ_TARGET_XBOXONE
stat = _pclose(iof->fp);
#else
lua_assert(0);
return 0;
#endif
#if LJ_52
iof->fp = NULL;
return luaL_execresult(L, stat);
Expand Down Expand Up @@ -325,26 +318,10 @@ LJLIB_CF(io_method_seek)
else if (!tvisnil(o))
lj_err_argt(L, 3, LUA_TNUMBER);
}
#if LJ_TARGET_POSIX
res = fseeko(fp, ofs, opt);
#elif _MSC_VER >= 1400
res = _fseeki64(fp, ofs, opt);
#elif defined(__MINGW32__)
res = fseeko64(fp, ofs, opt);
#else
res = fseek(fp, (long)ofs, opt);
#endif
if (res)
return luaL_fileresult(L, 0, NULL);
#if LJ_TARGET_POSIX
ofs = ftello(fp);
#elif _MSC_VER >= 1400
ofs = _ftelli64(fp);
#elif defined(__MINGW32__)
ofs = ftello64(fp);
#else
ofs = (int64_t)ftell(fp);
#endif
setint64V(L->top-1, ofs);
return 1;
}
Expand Down Expand Up @@ -406,32 +383,20 @@ LJLIB_CF(io_open)

LJLIB_CF(io_popen)
{
#if LJ_TARGET_POSIX || (LJ_TARGET_WINDOWS && !LJ_TARGET_XBOXONE)
const char *fname = strdata(lj_lib_checkstr(L, 1));
GCstr *s = lj_lib_optstr(L, 2);
const char *mode = s ? strdata(s) : "r";
IOFileUD *iof = io_file_new(L);
iof->type = IOFILE_TYPE_PIPE;
#if LJ_TARGET_POSIX
fflush(NULL);
iof->fp = popen(fname, mode);
#else
iof->fp = _popen(fname, mode);
#endif
return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, fname);
#else
return luaL_error(L, LUA_QL("popen") " not supported");
#endif
}

LJLIB_CF(io_tmpfile)
{
IOFileUD *iof = io_file_new(L);
#if LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PSVITA
iof->fp = NULL; errno = ENOSYS;
#else
iof->fp = tmpfile();
#endif
return iof->fp != NULL ? 1 : luaL_fileresult(L, 0, NULL);
}

Expand Down
Loading

0 comments on commit 40381fa

Please sign in to comment.