Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lundump.c File Reference
#include "lprefix.h"
#include <string.h>
#include "lua.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lmem.h"
#include "lobject.h"
#include "lstring.h"
#include "lundump.h"
#include "lzio.h"

Go to the source code of this file.

Data Structures

struct  LoadState
 

Macros

#define lundump_c
 
#define LUA_CORE
 
#define luai_verifycode(L, b, f)   /* empty */
 
#define LoadVector(S, b, n)   LoadBlock(S,b,(n)*sizeof((b)[0]))
 
#define LoadVar(S, x)   LoadVector(S,&x,1)
 
#define checksize(S, t)   fchecksize(S,sizeof(t),#t)
 

Functions

static l_noret error (LoadState *S, const char *why)
 
static void LoadBlock (LoadState *S, void *b, size_t size)
 
static lu_byte LoadByte (LoadState *S)
 
static int LoadInt (LoadState *S)
 
static lua_Number LoadNumber (LoadState *S)
 
static lua_Integer LoadInteger (LoadState *S)
 
static TStringLoadString (LoadState *S, Proto *p)
 
static void LoadCode (LoadState *S, Proto *f)
 
static void LoadFunction (LoadState *S, Proto *f, TString *psource)
 
static void LoadConstants (LoadState *S, Proto *f)
 
static void LoadProtos (LoadState *S, Proto *f)
 
static void LoadUpvalues (LoadState *S, Proto *f)
 
static void LoadDebug (LoadState *S, Proto *f)
 
static void checkliteral (LoadState *S, const char *s, const char *msg)
 
static void fchecksize (LoadState *S, size_t size, const char *tname)
 
static void checkHeader (LoadState *S)
 
LClosureluaU_undump (lua_State *L, ZIO *Z, const char *name)
 

Macro Definition Documentation

◆ checksize

#define checksize ( S,
t )   fchecksize(S,sizeof(t),#t)

Definition at line 241 of file lua-5.3.6/src/lundump.c.

Referenced by checkHeader().

◆ LoadVar

#define LoadVar ( S,
x )   LoadVector(S,&x,1)

Definition at line 57 of file lua-5.3.6/src/lundump.c.

Referenced by LoadByte(), LoadInt(), LoadInteger(), LoadNumber(), and LoadString().

◆ LoadVector

#define LoadVector ( S,
b,
n )   LoadBlock(S,b,(n)*sizeof((b)[0]))

Definition at line 49 of file lua-5.3.6/src/lundump.c.

Referenced by checkliteral(), LoadCode(), LoadDebug(), and LoadString().

◆ LUA_CORE

#define LUA_CORE

Definition at line 8 of file lua-5.3.6/src/lundump.c.

◆ luai_verifycode

#define luai_verifycode ( L,
b,
f )   /* empty */

Definition at line 28 of file lua-5.3.6/src/lundump.c.

Referenced by luaU_undump().

◆ lundump_c

#define lundump_c

Definition at line 7 of file lua-5.3.6/src/lundump.c.

Function Documentation

◆ checkHeader()

static void checkHeader ( LoadState * S)
static

Definition at line 243 of file lua-5.3.6/src/lundump.c.

243 {
244 checkliteral(S, LUA_SIGNATURE + 1, "not a"); /* 1st char already checked */
245 if (LoadByte(S) != LUAC_VERSION)
246 error(S, "version mismatch in");
247 if (LoadByte(S) != LUAC_FORMAT)
248 error(S, "format mismatch in");
249 checkliteral(S, LUAC_DATA, "corrupted");
250 checksize(S, int);
251 checksize(S, size_t);
255 if (LoadInteger(S) != LUAC_INT)
256 error(S, "endianness mismatch in");
257 if (LoadNumber(S) != LUAC_NUM)
258 error(S, "float format mismatch in");
259}
lu_int32 Instruction
LUA_INTEGER lua_Integer
LUA_NUMBER lua_Number
#define LUA_SIGNATURE
#define LoadByte(S)
#define LUAC_FORMAT
#define LUAC_VERSION
static void checkliteral(LoadState *S, const char *s, const char *msg)
#define checksize(S, t)
static lua_Integer LoadInteger(LoadState *S)
static lua_Number LoadNumber(LoadState *S)
static l_noret error(LoadState *S, const char *why)
#define LUAC_NUM
#define LUAC_DATA
#define LUAC_INT
#define S(x)
Definition print.c:159

References checkliteral(), checksize, error(), LoadByte, LoadInteger(), LoadNumber(), LUA_SIGNATURE, LUAC_DATA, LUAC_FORMAT, LUAC_INT, LUAC_NUM, LUAC_VERSION, and S.

Referenced by luaU_undump().

◆ checkliteral()

static void checkliteral ( LoadState * S,
const char * s,
const char * msg )
static

Definition at line 226 of file lua-5.3.6/src/lundump.c.

226 {
227 char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */
228 size_t len = strlen(s);
229 LoadVector(S, buff, len);
230 if (memcmp(s, buff, len) != 0)
231 error(S, msg);
232}
#define LoadVector(S, b, n)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References error(), LoadVector, LUA_SIGNATURE, LUAC_DATA, S, and s.

Referenced by checkHeader().

◆ error()

static l_noret error ( LoadState * S,
const char * why )
static

Definition at line 39 of file lua-5.3.6/src/lundump.c.

39 {
40 luaO_pushfstring(S->L, "%s: %s precompiled chunk", S->name, why);
42}
void luaD_throw(lua_State *L, int errcode)
const char * luaO_pushfstring(lua_State *L, const char *fmt,...)
#define LUA_ERRSYNTAX

References LUA_ERRSYNTAX, luaD_throw(), luaO_pushfstring(), and S.

Referenced by checkHeader(), checkliteral(), fchecksize(), and LoadBlock().

◆ fchecksize()

static void fchecksize ( LoadState * S,
size_t size,
const char * tname )
static

Definition at line 235 of file lua-5.3.6/src/lundump.c.

235 {
236 if (LoadByte(S) != size)
237 error(S, luaO_pushfstring(S->L, "%s size mismatch in", tname));
238}

References error(), LoadByte, luaO_pushfstring(), and S.

◆ LoadBlock()

static void LoadBlock ( LoadState * S,
void * b,
size_t size )
static

Definition at line 51 of file lua-5.3.6/src/lundump.c.

51 {
52 if (luaZ_read(S->Z, b, size) != 0)
53 error(S, "truncated");
54}
size_t luaZ_read(ZIO *z, void *b, size_t n)

References error(), luaZ_read(), and S.

◆ LoadByte()

static lu_byte LoadByte ( LoadState * S)
static

Definition at line 60 of file lua-5.3.6/src/lundump.c.

60 {
61 lu_byte x;
62 LoadVar(S, x);
63 return x;
64}
unsigned char lu_byte
#define LoadVar(S, x)

References LoadVar, and S.

◆ LoadCode()

static void LoadCode ( LoadState * S,
Proto * f )
static

Definition at line 113 of file lua-5.3.6/src/lundump.c.

113 {
114 int n = LoadInt(S);
115 f->code = luaM_newvector(S->L, n, Instruction);
116 f->sizecode = n;
117 LoadVector(S, f->code, n);
118}
#define luaM_newvector(L, n, t)
static int LoadInt(LoadState *S)
Instruction * code

References Proto::code, LoadInt(), LoadVector, luaM_newvector, S, and Proto::sizecode.

Referenced by LoadFunction().

◆ LoadConstants()

static void LoadConstants ( LoadState * S,
Proto * f )
static

Definition at line 124 of file lua-5.3.6/src/lundump.c.

124 {
125 int i;
126 int n = LoadInt(S);
127 f->k = luaM_newvector(S->L, n, TValue);
128 f->sizek = n;
129 for (i = 0; i < n; i++)
130 setnilvalue(&f->k[i]);
131 for (i = 0; i < n; i++) {
132 TValue *o = &f->k[i];
133 int t = LoadByte(S);
134 switch (t) {
135 case LUA_TNIL:
136 setnilvalue(o);
137 break;
138 case LUA_TBOOLEAN:
139 setbvalue(o, LoadByte(S));
140 break;
141 case LUA_TNUMFLT:
143 break;
144 case LUA_TNUMINT:
146 break;
147 case LUA_TSHRSTR:
148 case LUA_TLNGSTR:
149 setsvalue2n(S->L, o, LoadString(S, f));
150 break;
151 default:
152 lua_assert(0);
153 }
154 }
155}
#define lua_assert(c)
#define setbvalue(obj, x)
#define setsvalue2n
#define setnilvalue(obj)
#define LUA_TBOOLEAN
#define LUA_TNIL
#define LUA_TSHRSTR
#define LUA_TLNGSTR
#define LUA_TNUMINT
#define setfltvalue(obj, x)
#define LUA_TNUMFLT
#define setivalue(obj, x)
static TString * LoadString(LoadState *S, Proto *p)

References Proto::k, LoadByte, LoadInt(), LoadInteger(), LoadNumber(), LoadString(), lua_assert, LUA_TBOOLEAN, LUA_TLNGSTR, LUA_TNIL, LUA_TNUMFLT, LUA_TNUMINT, LUA_TSHRSTR, luaM_newvector, S, setbvalue, setfltvalue, setivalue, setnilvalue, setsvalue2n, and Proto::sizek.

Referenced by LoadFunction().

◆ LoadDebug()

static void LoadDebug ( LoadState * S,
Proto * f )
static

Definition at line 187 of file lua-5.3.6/src/lundump.c.

187 {
188 int i, n;
189 n = LoadInt(S);
190 f->lineinfo = luaM_newvector(S->L, n, int);
191 f->sizelineinfo = n;
192 LoadVector(S, f->lineinfo, n);
193 n = LoadInt(S);
194 f->locvars = luaM_newvector(S->L, n, LocVar);
195 f->sizelocvars = n;
196 for (i = 0; i < n; i++)
197 f->locvars[i].varname = NULL;
198 for (i = 0; i < n; i++) {
199 f->locvars[i].varname = LoadString(S, f);
200 f->locvars[i].startpc = LoadInt(S);
201 f->locvars[i].endpc = LoadInt(S);
202 }
203 n = LoadInt(S);
204 for (i = 0; i < n; i++)
205 f->upvalues[i].name = LoadString(S, f);
206}
#define NULL
Definition gmacros.h:924
TString * varname
struct LocVar * locvars
TString ** upvalues

References LocVar::endpc, Proto::lineinfo, LoadInt(), LoadString(), LoadVector, Proto::locvars, luaM_newvector, NULL, S, Proto::sizelineinfo, Proto::sizelocvars, LocVar::startpc, Proto::upvalues, and LocVar::varname.

Referenced by LoadFunction().

◆ LoadFunction()

static void LoadFunction ( LoadState * S,
Proto * f,
TString * psource )
static

Definition at line 209 of file lua-5.3.6/src/lundump.c.

209 {
210 f->source = LoadString(S, f);
211 if (f->source == NULL) /* no source in dump? */
212 f->source = psource; /* reuse parent's source */
213 f->linedefined = LoadInt(S);
215 f->numparams = LoadByte(S);
216 f->is_vararg = LoadByte(S);
217 f->maxstacksize = LoadByte(S);
218 LoadCode(S, f);
219 LoadConstants(S, f);
220 LoadUpvalues(S, f);
221 LoadProtos(S, f);
222 LoadDebug(S, f);
223}
static void LoadProtos(LoadState *S, Proto *f)
static void LoadConstants(LoadState *S, Proto *f)
static void LoadUpvalues(LoadState *S, Proto *f)
static void LoadDebug(LoadState *S, Proto *f)
static void LoadCode(LoadState *S, Proto *f)
lu_byte maxstacksize
TString * source

References Proto::is_vararg, Proto::lastlinedefined, Proto::linedefined, LoadByte, LoadCode(), LoadConstants(), LoadDebug(), LoadInt(), LoadProtos(), LoadString(), LoadUpvalues(), Proto::maxstacksize, NULL, Proto::numparams, S, and Proto::source.

Referenced by LoadProtos(), and luaU_undump().

◆ LoadInt()

static int LoadInt ( LoadState * S)
static

Definition at line 67 of file lua-5.3.6/src/lundump.c.

67 {
68 int x;
69 LoadVar(S, x);
70 return x;
71}

References LoadVar, and S.

Referenced by LoadCode(), LoadConstants(), LoadDebug(), LoadFunction(), LoadProtos(), and LoadUpvalues().

◆ LoadInteger()

static lua_Integer LoadInteger ( LoadState * S)
static

Definition at line 81 of file lua-5.3.6/src/lundump.c.

81 {
83 LoadVar(S, x);
84 return x;
85}

References LoadVar, and S.

Referenced by checkHeader(), and LoadConstants().

◆ LoadNumber()

static lua_Number LoadNumber ( LoadState * S)
static

Definition at line 74 of file lua-5.3.6/src/lundump.c.

74 {
75 lua_Number x;
76 LoadVar(S, x);
77 return x;
78}

References LoadVar, and S.

Referenced by checkHeader(), and LoadConstants().

◆ LoadProtos()

static void LoadProtos ( LoadState * S,
Proto * f )
static

Definition at line 158 of file lua-5.3.6/src/lundump.c.

158 {
159 int i;
160 int n = LoadInt(S);
161 f->p = luaM_newvector(S->L, n, Proto *);
162 f->sizep = n;
163 for (i = 0; i < n; i++)
164 f->p[i] = NULL;
165 for (i = 0; i < n; i++) {
166 f->p[i] = luaF_newproto(S->L);
167 luaC_objbarrier(S->L, f, f->p[i]);
168 LoadFunction(S, f->p[i], f->source);
169 }
170}
Proto * luaF_newproto(lua_State *L)
#define luaC_objbarrier(L, p, o)
static void LoadFunction(LoadState *S, Proto *f, TString *psource)
struct Proto ** p

References LoadFunction(), LoadInt(), luaC_objbarrier, luaF_newproto(), luaM_newvector, NULL, Proto::p, S, Proto::sizep, and Proto::source.

Referenced by LoadFunction().

◆ LoadString()

static TString * LoadString ( LoadState * S,
Proto * p )
static

Definition at line 88 of file lua-5.3.6/src/lundump.c.

88 {
89 lua_State *L = S->L;
90 size_t size = LoadByte(S);
91 TString *ts;
92 if (size == 0xFF)
93 LoadVar(S, size);
94 if (size == 0)
95 return NULL;
96 else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */
97 char buff[LUAI_MAXSHORTLEN];
98 LoadVector(S, buff, size);
99 ts = luaS_newlstr(L, buff, size);
100 }
101 else { /* long string */
102 ts = luaS_createlngstrobj(L, size);
103 setsvalue2s(L, L->top, ts); /* anchor it ('loadVector' can GC) */
104 luaD_inctop(L);
105 LoadVector(S, getstr(ts), size); /* load directly in final place */
106 L->top--; /* pop string */
107 }
108 luaC_objbarrier(L, p, ts);
109 return ts;
110}
#define setsvalue2s
#define getstr(ts)
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
#define LUAI_MAXSHORTLEN
void luaD_inctop(lua_State *L)
TString * luaS_createlngstrobj(lua_State *L, size_t l)

References getstr, LoadByte, LoadVar, LoadVector, luaC_objbarrier, luaD_inctop(), LUAI_MAXSHORTLEN, luaS_createlngstrobj(), luaS_newlstr(), NULL, S, setsvalue2s, and lua_State::top.

Referenced by LoadConstants(), LoadDebug(), and LoadFunction().

◆ LoadUpvalues()

static void LoadUpvalues ( LoadState * S,
Proto * f )
static

Definition at line 173 of file lua-5.3.6/src/lundump.c.

173 {
174 int i, n;
175 n = LoadInt(S);
176 f->upvalues = luaM_newvector(S->L, n, Upvaldesc);
177 f->sizeupvalues = n;
178 for (i = 0; i < n; i++)
179 f->upvalues[i].name = NULL;
180 for (i = 0; i < n; i++) {
181 f->upvalues[i].instack = LoadByte(S);
182 f->upvalues[i].idx = LoadByte(S);
183 }
184}

References LoadByte, LoadInt(), luaM_newvector, NULL, S, Proto::sizeupvalues, and Proto::upvalues.

Referenced by LoadFunction().

◆ luaU_undump()

LClosure * luaU_undump ( lua_State * L,
ZIO * Z,
const char * name )

Definition at line 265 of file lua-5.3.6/src/lundump.c.

265 {
266 LoadState S;
267 LClosure *cl;
268 if (*name == '@' || *name == '=')
269 S.name = name + 1;
270 else if (*name == LUA_SIGNATURE[0])
271 S.name = "binary string";
272 else
273 S.name = name;
274 S.L = L;
275 S.Z = Z;
276 checkHeader(&S);
277 cl = luaF_newLclosure(L, LoadByte(&S));
278 setclLvalue(L, L->top, cl);
279 luaD_inctop(L);
280 cl->p = luaF_newproto(L);
281 luaC_objbarrier(L, cl, cl->p);
282 LoadFunction(&S, cl->p, NULL);
283 lua_assert(cl->nupvalues == cl->p->sizeupvalues);
284 luai_verifycode(L, buff, cl->p);
285 return cl;
286}
const char * name
Definition lsqlite3.c:2154
Closure * luaF_newLclosure(lua_State *L, int nelems, Table *e)
#define setclLvalue(L, obj, x)
#define luai_verifycode(L, b, f)
static void checkHeader(LoadState *S)
struct Proto * p

References checkHeader(), LoadByte, LoadFunction(), lua_assert, LUA_SIGNATURE, luaC_objbarrier, luaD_inctop(), luaF_newLclosure(), luaF_newproto(), luai_verifycode, name, NULL, LClosure::p, S, setclLvalue, Proto::sizeupvalues, and lua_State::top.