mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-04-20 22:13:25 +00:00
Add an option to disable loadfile APIs
This commit is contained in:
parent
d0e88930dd
commit
df1336f86c
@ -387,6 +387,8 @@ void emit_lib(BuildCtx *ctx)
|
|||||||
ok = LJ_HASFFI;
|
ok = LJ_HASFFI;
|
||||||
else if (!strcmp(buf, "#if LJ_HASBUFFER\n"))
|
else if (!strcmp(buf, "#if LJ_HASBUFFER\n"))
|
||||||
ok = LJ_HASBUFFER;
|
ok = LJ_HASBUFFER;
|
||||||
|
else if (!strcmp(buf, "#if LJ_HASLOADFILE\n"))
|
||||||
|
ok = LJ_HASLOADFILE;
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
int lvl = 1;
|
int lvl = 1;
|
||||||
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
while (fgets(buf, sizeof(buf), fp) != NULL) {
|
||||||
|
@ -62,7 +62,9 @@ LUALIB_API int (luaL_checkoption) (lua_State *L, int narg, const char *def,
|
|||||||
LUALIB_API int (luaL_ref) (lua_State *L, int t);
|
LUALIB_API int (luaL_ref) (lua_State *L, int t);
|
||||||
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
|
LUALIB_API void (luaL_unref) (lua_State *L, int t, int ref);
|
||||||
|
|
||||||
|
#ifndef LUAJIT_DISABLE_LOADFILE
|
||||||
LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
|
LUALIB_API int (luaL_loadfile) (lua_State *L, const char *filename);
|
||||||
|
#endif
|
||||||
LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
|
LUALIB_API int (luaL_loadbuffer) (lua_State *L, const char *buff, size_t sz,
|
||||||
const char *name);
|
const char *name);
|
||||||
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
|
LUALIB_API int (luaL_loadstring) (lua_State *L, const char *s);
|
||||||
@ -79,8 +81,10 @@ LUALIB_API const char *(luaL_findtable) (lua_State *L, int idx,
|
|||||||
/* From Lua 5.2. */
|
/* From Lua 5.2. */
|
||||||
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname);
|
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname);
|
||||||
LUALIB_API int luaL_execresult(lua_State *L, int stat);
|
LUALIB_API int luaL_execresult(lua_State *L, int stat);
|
||||||
|
#ifndef LUAJIT_DISABLE_LOADFILE
|
||||||
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
|
LUALIB_API int (luaL_loadfilex) (lua_State *L, const char *filename,
|
||||||
const char *mode);
|
const char *mode);
|
||||||
|
#endif
|
||||||
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
|
LUALIB_API int (luaL_loadbufferx) (lua_State *L, const char *buff, size_t sz,
|
||||||
const char *name, const char *mode);
|
const char *name, const char *mode);
|
||||||
LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
|
LUALIB_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg,
|
||||||
|
@ -373,6 +373,8 @@ static int load_aux(lua_State *L, int status, int envarg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LJ_HASLOADFILE
|
||||||
|
|
||||||
LJLIB_CF(loadfile)
|
LJLIB_CF(loadfile)
|
||||||
{
|
{
|
||||||
GCstr *fname = lj_lib_optstr(L, 1);
|
GCstr *fname = lj_lib_optstr(L, 1);
|
||||||
@ -384,6 +386,8 @@ LJLIB_CF(loadfile)
|
|||||||
return load_aux(L, status, 3);
|
return load_aux(L, status, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
static const char *reader_func(lua_State *L, void *ud, size_t *size)
|
static const char *reader_func(lua_State *L, void *ud, size_t *size)
|
||||||
{
|
{
|
||||||
UNUSED(ud);
|
UNUSED(ud);
|
||||||
@ -439,6 +443,8 @@ LJLIB_CF(loadstring)
|
|||||||
return lj_cf_load(L);
|
return lj_cf_load(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LJ_HASLOADFILE
|
||||||
|
|
||||||
LJLIB_CF(dofile)
|
LJLIB_CF(dofile)
|
||||||
{
|
{
|
||||||
GCstr *fname = lj_lib_optstr(L, 1);
|
GCstr *fname = lj_lib_optstr(L, 1);
|
||||||
@ -450,6 +456,8 @@ LJLIB_CF(dofile)
|
|||||||
return (int)(L->top - L->base) - 1;
|
return (int)(L->top - L->base) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/* -- Base library: GC control -------------------------------------------- */
|
/* -- Base library: GC control -------------------------------------------- */
|
||||||
|
|
||||||
LJLIB_CF(gcinfo)
|
LJLIB_CF(gcinfo)
|
||||||
|
@ -594,6 +594,12 @@
|
|||||||
#define LJ_HASPROFILE 0
|
#define LJ_HASPROFILE 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(LUAJIT_DISABLE_LOADFILE)
|
||||||
|
#define LJ_HASLOADFILE 0
|
||||||
|
#else
|
||||||
|
#define LJ_HASLOADFILE 1
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef LJ_ARCH_HASFPU
|
#ifndef LJ_ARCH_HASFPU
|
||||||
#define LJ_ARCH_HASFPU 1
|
#define LJ_ARCH_HASFPU 1
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,6 +67,8 @@ LUA_API int lua_load(lua_State *L, lua_Reader reader, void *data,
|
|||||||
return lua_loadx(L, reader, data, chunkname, NULL);
|
return lua_loadx(L, reader, data, chunkname, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LJ_HASLOADFILE
|
||||||
|
|
||||||
typedef struct FileReaderCtx {
|
typedef struct FileReaderCtx {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
char buf[LUAL_BUFFERSIZE];
|
char buf[LUAL_BUFFERSIZE];
|
||||||
@ -119,6 +121,8 @@ LUALIB_API int luaL_loadfile(lua_State *L, const char *filename)
|
|||||||
return luaL_loadfilex(L, filename, NULL);
|
return luaL_loadfilex(L, filename, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct StringReaderCtx {
|
typedef struct StringReaderCtx {
|
||||||
const char *str;
|
const char *str;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
Loading…
Reference in New Issue
Block a user