Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lundump.c File Reference
#include "lprefix.h"
#include <limits.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, 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 size_t loadUnsigned (LoadState *S, size_t limit)
 
static size_t loadSize (LoadState *S)
 
static int loadInt (LoadState *S)
 
static lua_Number loadNumber (LoadState *S)
 
static lua_Integer loadInteger (LoadState *S)
 
static TStringloadStringN (LoadState *S, Proto *p)
 
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 288 of file lua-5.4.3/src/lundump.c.

Referenced by checkHeader().

◆ loadVar

#define loadVar ( S,
x )   loadVector(S,&x,1)

Definition at line 58 of file lua-5.4.3/src/lundump.c.

Referenced by loadInteger(), and loadNumber().

◆ loadVector

#define loadVector ( S,
b,
n )   loadBlock(S,b,(n)*sizeof((b)[0]))

Definition at line 50 of file lua-5.4.3/src/lundump.c.

Referenced by checkliteral(), loadCode(), loadDebug(), and loadStringN().

◆ LUA_CORE

#define LUA_CORE

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

◆ luai_verifycode

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

Definition at line 29 of file lua-5.4.3/src/lundump.c.

Referenced by luaU_undump().

◆ lundump_c

#define lundump_c

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

Function Documentation

◆ checkHeader()

static void checkHeader ( LoadState * S)
static

Definition at line 290 of file lua-5.4.3/src/lundump.c.

290 {
291 /* skip 1st char (already read and checked) */
292 checkliteral(S, &LUA_SIGNATURE[1], "not a binary chunk");
293 if (loadByte(S) != LUAC_VERSION)
294 error(S, "version mismatch");
295 if (loadByte(S) != LUAC_FORMAT)
296 error(S, "format mismatch");
297 checkliteral(S, LUAC_DATA, "corrupted chunk");
301 if (loadInteger(S) != LUAC_INT)
302 error(S, "integer format mismatch");
303 if (loadNumber(S) != LUAC_NUM)
304 error(S, "float format mismatch");
305}
lu_int32 Instruction
LUA_INTEGER lua_Integer
LUA_NUMBER lua_Number
#define LUA_SIGNATURE
#define LUAC_FORMAT
#define LUAC_VERSION
#define LUAC_NUM
#define LUAC_DATA
#define LUAC_INT
static void checkliteral(LoadState *S, const char *s, const char *msg)
#define checksize(S, t)
static lu_byte loadByte(LoadState *S)
static l_noret error(LoadState *S, const char *why)
static lua_Integer loadInteger(LoadState *S)
static lua_Number loadNumber(LoadState *S)
#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 273 of file lua-5.4.3/src/lundump.c.

273 {
274 char buff[sizeof(LUA_SIGNATURE) + sizeof(LUAC_DATA)]; /* larger than both */
275 size_t len = strlen(s);
276 loadVector(S, buff, len);
277 if (memcmp(s, buff, len) != 0)
278 error(S, msg);
279}
#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 40 of file lua-5.4.3/src/lundump.c.

40 {
41 luaO_pushfstring(S->L, "%s: bad binary format (%s)", S->name, why);
43}
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(), loadBlock(), loadByte(), loadString(), and loadUnsigned().

◆ fchecksize()

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

Definition at line 282 of file lua-5.4.3/src/lundump.c.

282 {
283 if (loadByte(S) != size)
284 error(S, luaO_pushfstring(S->L, "%s size mismatch", tname));
285}

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

◆ loadBlock()

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

Definition at line 52 of file lua-5.4.3/src/lundump.c.

52 {
53 if (luaZ_read(S->Z, b, size) != 0)
54 error(S, "truncated chunk");
55}
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 61 of file lua-5.4.3/src/lundump.c.

61 {
62 int b = zgetc(S->Z);
63 if (b == EOZ)
64 error(S, "truncated chunk");
65 return cast_byte(b);
66}
#define cast_byte(i)
#define EOZ
#define zgetc(z)

References cast_byte, EOZ, error(), S, and zgetc.

Referenced by checkHeader(), fchecksize(), loadConstants(), loadFunction(), loadUnsigned(), loadUpvalues(), and luaU_undump().

◆ loadCode()

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

Definition at line 144 of file lua-5.4.3/src/lundump.c.

144 {
145 int n = loadInt(S);
147 f->sizecode = n;
148 loadVector(S, f->code, n);
149}
#define luaM_newvectorchecked(L, n, t)
static int loadInt(LoadState *S)
Instruction * code

References Proto::code, loadInt(), loadVector, luaM_newvectorchecked, S, and Proto::sizecode.

Referenced by loadFunction().

◆ loadConstants()

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

Definition at line 155 of file lua-5.4.3/src/lundump.c.

155 {
156 int i;
157 int n = loadInt(S);
158 f->k = luaM_newvectorchecked(S->L, n, TValue);
159 f->sizek = n;
160 for (i = 0; i < n; i++)
161 setnilvalue(&f->k[i]);
162 for (i = 0; i < n; i++) {
163 TValue *o = &f->k[i];
164 int t = loadByte(S);
165 switch (t) {
166 case LUA_VNIL:
167 setnilvalue(o);
168 break;
169 case LUA_VFALSE:
170 setbfvalue(o);
171 break;
172 case LUA_VTRUE:
173 setbtvalue(o);
174 break;
175 case LUA_VNUMFLT:
177 break;
178 case LUA_VNUMINT:
180 break;
181 case LUA_VSHRSTR:
182 case LUA_VLNGSTR:
183 setsvalue2n(S->L, o, loadString(S, f));
184 break;
185 default: lua_assert(0);
186 }
187 }
188}
#define lua_assert(c)
#define setsvalue2n
#define setnilvalue(obj)
#define setfltvalue(obj, x)
#define setivalue(obj, x)
#define LUA_VNUMFLT
#define setbtvalue(obj)
#define LUA_VLNGSTR
#define LUA_VNUMINT
#define LUA_VSHRSTR
#define LUA_VFALSE
#define LUA_VNIL
#define setbfvalue(obj)
#define LUA_VTRUE
static TString * loadString(LoadState *S, Proto *p)

References Proto::k, loadByte(), loadInt(), loadInteger(), loadNumber(), loadString(), lua_assert, LUA_VFALSE, LUA_VLNGSTR, LUA_VNIL, LUA_VNUMFLT, LUA_VNUMINT, LUA_VSHRSTR, LUA_VTRUE, luaM_newvectorchecked, S, setbfvalue, setbtvalue, setfltvalue, setivalue, setnilvalue, setsvalue2n, and Proto::sizek.

Referenced by loadFunction().

◆ loadDebug()

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

Definition at line 227 of file lua-5.4.3/src/lundump.c.

227 {
228 int i, n;
229 n = loadInt(S);
231 f->sizelineinfo = n;
232 loadVector(S, f->lineinfo, n);
233 n = loadInt(S);
235 f->sizeabslineinfo = n;
236 for (i = 0; i < n; i++) {
237 f->abslineinfo[i].pc = loadInt(S);
238 f->abslineinfo[i].line = loadInt(S);
239 }
240 n = loadInt(S);
242 f->sizelocvars = n;
243 for (i = 0; i < n; i++)
244 f->locvars[i].varname = NULL;
245 for (i = 0; i < n; i++) {
246 f->locvars[i].varname = loadStringN(S, f);
247 f->locvars[i].startpc = loadInt(S);
248 f->locvars[i].endpc = loadInt(S);
249 }
250 n = loadInt(S);
251 for (i = 0; i < n; i++)
252 f->upvalues[i].name = loadStringN(S, f);
253}
#define NULL
Definition gmacros.h:924
signed char ls_byte
static TString * loadStringN(LoadState *S, Proto *p)
TString * varname
AbsLineInfo * abslineinfo
struct LocVar * locvars
TString ** upvalues

References Proto::abslineinfo, LocVar::endpc, AbsLineInfo::line, Proto::lineinfo, loadInt(), loadStringN(), loadVector, Proto::locvars, luaM_newvectorchecked, NULL, AbsLineInfo::pc, S, Proto::sizeabslineinfo, 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 256 of file lua-5.4.3/src/lundump.c.

256 {
257 f->source = loadStringN(S, f);
258 if (f->source == NULL) /* no source in dump? */
259 f->source = psource; /* reuse parent's source */
260 f->linedefined = loadInt(S);
262 f->numparams = loadByte(S);
263 f->is_vararg = loadByte(S);
264 f->maxstacksize = loadByte(S);
265 loadCode(S, f);
266 loadConstants(S, f);
267 loadUpvalues(S, f);
268 loadProtos(S, f);
269 loadDebug(S, f);
270}
static void loadUpvalues(LoadState *S, Proto *f)
static void loadDebug(LoadState *S, Proto *f)
static void loadConstants(LoadState *S, Proto *f)
static void loadProtos(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(), loadStringN(), 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 88 of file lua-5.4.3/src/lundump.c.

88 {
89 return cast_int(loadUnsigned(S, INT_MAX));
90}
#define cast_int(i)
static size_t loadUnsigned(LoadState *S, size_t limit)

References cast_int, loadUnsigned(), and S.

Referenced by loadCode(), loadConstants(), loadDebug(), loadFunction(), loadProtos(), and loadUpvalues().

◆ loadInteger()

static lua_Integer loadInteger ( LoadState * S)
static

Definition at line 100 of file lua-5.4.3/src/lundump.c.

100 {
101 lua_Integer x;
102 loadVar(S, x);
103 return x;
104}
#define loadVar(S, x)

References loadVar, and S.

Referenced by checkHeader(), and loadConstants().

◆ loadNumber()

static lua_Number loadNumber ( LoadState * S)
static

Definition at line 93 of file lua-5.4.3/src/lundump.c.

93 {
94 lua_Number x;
95 loadVar(S, x);
96 return x;
97}

References loadVar, and S.

Referenced by checkHeader(), and loadConstants().

◆ loadProtos()

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

Definition at line 191 of file lua-5.4.3/src/lundump.c.

191 {
192 int i;
193 int n = loadInt(S);
194 f->p = luaM_newvectorchecked(S->L, n, Proto *);
195 f->sizep = n;
196 for (i = 0; i < n; i++)
197 f->p[i] = NULL;
198 for (i = 0; i < n; i++) {
199 f->p[i] = luaF_newproto(S->L);
200 luaC_objbarrier(S->L, f, f->p[i]);
201 loadFunction(S, f->p[i], f->source);
202 }
203}
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_newvectorchecked, NULL, Proto::p, S, Proto::sizep, and Proto::source.

Referenced by loadFunction().

◆ loadSize()

static size_t loadSize ( LoadState * S)
static

Definition at line 83 of file lua-5.4.3/src/lundump.c.

83 {
84 return loadUnsigned(S, ~(size_t)0);
85}

References loadUnsigned(), and S.

Referenced by loadStringN().

◆ loadString()

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

Definition at line 136 of file lua-5.4.3/src/lundump.c.

136 {
137 TString *st = loadStringN(S, p);
138 if (st == NULL)
139 error(S, "bad format for constant string");
140 return st;
141}

References error(), loadStringN(), NULL, and S.

Referenced by loadConstants().

◆ loadStringN()

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

Definition at line 110 of file lua-5.4.3/src/lundump.c.

110 {
111 lua_State *L = S->L;
112 TString *ts;
113 size_t size = loadSize(S);
114 if (size == 0) /* no string? */
115 return NULL;
116 else if (--size <= LUAI_MAXSHORTLEN) { /* short string? */
117 char buff[LUAI_MAXSHORTLEN];
118 loadVector(S, buff, size); /* load string into buffer */
119 ts = luaS_newlstr(L, buff, size); /* create string */
120 }
121 else { /* long string */
122 ts = luaS_createlngstrobj(L, size); /* create string */
123 setsvalue2s(L, L->top, ts); /* anchor it ('loadVector' can GC) */
124 luaD_inctop(L);
125 loadVector(S, getstr(ts), size); /* load directly in final place */
126 L->top--; /* pop string */
127 }
128 luaC_objbarrier(L, p, ts);
129 return ts;
130}
#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)
static size_t loadSize(LoadState *S)

References getstr, loadSize(), loadVector, luaC_objbarrier, luaD_inctop(), LUAI_MAXSHORTLEN, luaS_createlngstrobj(), luaS_newlstr(), NULL, S, setsvalue2s, and lua_State::top.

Referenced by loadDebug(), loadFunction(), and loadString().

◆ loadUnsigned()

static size_t loadUnsigned ( LoadState * S,
size_t limit )
static

Definition at line 69 of file lua-5.4.3/src/lundump.c.

69 {
70 size_t x = 0;
71 int b;
72 limit >>= 7;
73 do {
74 b = loadByte(S);
75 if (x >= limit)
76 error(S, "integer overflow");
77 x = (x << 7) | (b & 0x7f);
78 } while ((b & 0x80) == 0);
79 return x;
80}

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

Referenced by loadInt(), and loadSize().

◆ loadUpvalues()

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

Definition at line 212 of file lua-5.4.3/src/lundump.c.

212 {
213 int i, n;
214 n = loadInt(S);
216 f->sizeupvalues = n;
217 for (i = 0; i < n; i++) /* make array valid for GC */
218 f->upvalues[i].name = NULL;
219 for (i = 0; i < n; i++) { /* following calls can raise errors */
220 f->upvalues[i].instack = loadByte(S);
221 f->upvalues[i].idx = loadByte(S);
222 f->upvalues[i].kind = loadByte(S);
223 }
224}

References loadByte(), loadInt(), luaM_newvectorchecked, 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 311 of file lua-5.4.3/src/lundump.c.

311 {
312 LoadState S;
313 LClosure *cl;
314 if (*name == '@' || *name == '=')
315 S.name = name + 1;
316 else if (*name == LUA_SIGNATURE[0])
317 S.name = "binary string";
318 else
319 S.name = name;
320 S.L = L;
321 S.Z = Z;
322 checkHeader(&S);
323 cl = luaF_newLclosure(L, loadByte(&S));
324 setclLvalue2s(L, L->top, cl);
325 luaD_inctop(L);
326 cl->p = luaF_newproto(L);
327 luaC_objbarrier(L, cl, cl->p);
328 loadFunction(&S, cl->p, NULL);
329 lua_assert(cl->nupvalues == cl->p->sizeupvalues);
330 luai_verifycode(L, cl->p);
331 return cl;
332}
const char * name
Definition lsqlite3.c:2154
Closure * luaF_newLclosure(lua_State *L, int nelems, Table *e)
#define setclLvalue2s(L, o, cl)
#define luai_verifycode(L, 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, setclLvalue2s, Proto::sizeupvalues, and lua_State::top.