Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
ldump.c File Reference
#include "lprefix.h"
#include <stddef.h>
#include "lua.h"
#include "lobject.h"
#include "lstate.h"
#include "lundump.h"

Go to the source code of this file.

Data Structures

struct  DumpState
 

Macros

#define ldump_c
 
#define LUA_CORE
 
#define dumpVector(D, v, n)   dumpBlock(D,v,(n)*sizeof((v)[0]))
 
#define dumpLiteral(D, s)   dumpBlock(D,s,sizeof(s) - sizeof(char))
 
#define dumpVar(D, x)   dumpVector(D,&x,1)
 
#define DIBS   ((sizeof(size_t) * 8 / 7) + 1)
 

Functions

static void dumpBlock (DumpState *D, const void *b, size_t size)
 
static void dumpByte (DumpState *D, int y)
 
static void dumpSize (DumpState *D, size_t x)
 
static void dumpInt (DumpState *D, int x)
 
static void dumpNumber (DumpState *D, lua_Number x)
 
static void dumpInteger (DumpState *D, lua_Integer x)
 
static void dumpString (DumpState *D, const TString *s)
 
static void dumpCode (DumpState *D, const Proto *f)
 
static void dumpFunction (DumpState *D, const Proto *f, TString *psource)
 
static void dumpConstants (DumpState *D, const Proto *f)
 
static void dumpProtos (DumpState *D, const Proto *f)
 
static void dumpUpvalues (DumpState *D, const Proto *f)
 
static void dumpDebug (DumpState *D, const Proto *f)
 
static void dumpHeader (DumpState *D)
 
int luaU_dump (lua_State *L, const Proto *f, lua_Writer w, void *data, int strip)
 

Macro Definition Documentation

◆ DIBS

#define DIBS   ((sizeof(size_t) * 8 / 7) + 1)

Definition at line 59 of file lua-5.4.3/src/ldump.c.

Referenced by dumpSize().

◆ dumpLiteral

#define dumpLiteral ( D,
s )   dumpBlock(D,s,sizeof(s) - sizeof(char))

Definition at line 37 of file lua-5.4.3/src/ldump.c.

Referenced by dumpHeader().

◆ dumpVar

#define dumpVar ( D,
x )   dumpVector(D,&x,1)

Definition at line 49 of file lua-5.4.3/src/ldump.c.

Referenced by dumpByte(), dumpInteger(), and dumpNumber().

◆ dumpVector

#define dumpVector ( D,
v,
n )   dumpBlock(D,v,(n)*sizeof((v)[0]))

Definition at line 35 of file lua-5.4.3/src/ldump.c.

Referenced by dumpCode(), dumpDebug(), dumpSize(), and dumpString().

◆ ldump_c

#define ldump_c

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

◆ LUA_CORE

#define LUA_CORE

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

Function Documentation

◆ dumpBlock()

static void dumpBlock ( DumpState * D,
const void * b,
size_t size )
static

Definition at line 40 of file lua-5.4.3/src/ldump.c.

40 {
41 if (D->status == 0 && size > 0) {
42 lua_unlock(D->L);
43 D->status = (*D->writer)(D->L, b, size, D->data);
44 lua_lock(D->L);
45 }
46}
#define lua_unlock(L)
#define lua_lock(L)
lua_State * L
lua_Writer writer

References DumpState::data, DumpState::L, lua_lock, lua_unlock, DumpState::status, and DumpState::writer.

◆ dumpByte()

static void dumpByte ( DumpState * D,
int y )
static

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

52 {
53 lu_byte x = (lu_byte)y;
54 dumpVar(D, x);
55}
unsigned char lu_byte
#define dumpVar(D, x)

References dumpVar.

Referenced by dumpConstants(), dumpFunction(), dumpHeader(), dumpUpvalues(), and luaU_dump().

◆ dumpCode()

static void dumpCode ( DumpState * D,
const Proto * f )
static

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

100 {
101 dumpInt(D, f->sizecode);
102 dumpVector(D, f->code, f->sizecode);
103}
#define dumpVector(D, v, n)
static void dumpInt(DumpState *D, int x)
Instruction * code

References Proto::code, dumpInt(), dumpVector, and Proto::sizecode.

Referenced by dumpFunction().

◆ dumpConstants()

static void dumpConstants ( DumpState * D,
const Proto * f )
static

Definition at line 108 of file lua-5.4.3/src/ldump.c.

108 {
109 int i;
110 int n = f->sizek;
111 dumpInt(D, n);
112 for (i = 0; i < n; i++) {
113 const TValue *o = &f->k[i];
114 int tt = ttypetag(o);
115 dumpByte(D, tt);
116 switch (tt) {
117 case LUA_VNUMFLT:
118 dumpNumber(D, fltvalue(o));
119 break;
120 case LUA_VNUMINT:
121 dumpInteger(D, ivalue(o));
122 break;
123 case LUA_VSHRSTR:
124 case LUA_VLNGSTR:
125 dumpString(D, tsvalue(o));
126 break;
127 default:
128 lua_assert(tt == LUA_VNIL || tt == LUA_VFALSE || tt == LUA_VTRUE);
129 }
130 }
131}
#define lua_assert(c)
#define tsvalue(o)
#define fltvalue(o)
#define ivalue(o)
static void dumpByte(DumpState *D, int y)
static void dumpInteger(DumpState *D, lua_Integer x)
static void dumpString(DumpState *D, const TString *s)
static void dumpNumber(DumpState *D, lua_Number x)
#define ttypetag(o)
#define LUA_VNUMFLT
#define LUA_VLNGSTR
#define LUA_VNUMINT
#define LUA_VSHRSTR
#define LUA_VFALSE
#define LUA_VNIL
#define LUA_VTRUE

References dumpByte(), dumpInt(), dumpInteger(), dumpNumber(), dumpString(), fltvalue, ivalue, Proto::k, lua_assert, LUA_VFALSE, LUA_VLNGSTR, LUA_VNIL, LUA_VNUMFLT, LUA_VNUMINT, LUA_VSHRSTR, LUA_VTRUE, Proto::sizek, tsvalue, and ttypetag.

Referenced by dumpFunction().

◆ dumpDebug()

static void dumpDebug ( DumpState * D,
const Proto * f )
static

Definition at line 154 of file lua-5.4.3/src/ldump.c.

154 {
155 int i, n;
156 n = (D->strip) ? 0 : f->sizelineinfo;
157 dumpInt(D, n);
158 dumpVector(D, f->lineinfo, n);
159 n = (D->strip) ? 0 : f->sizeabslineinfo;
160 dumpInt(D, n);
161 for (i = 0; i < n; i++) {
162 dumpInt(D, f->abslineinfo[i].pc);
163 dumpInt(D, f->abslineinfo[i].line);
164 }
165 n = (D->strip) ? 0 : f->sizelocvars;
166 dumpInt(D, n);
167 for (i = 0; i < n; i++) {
168 dumpString(D, f->locvars[i].varname);
169 dumpInt(D, f->locvars[i].startpc);
170 dumpInt(D, f->locvars[i].endpc);
171 }
172 n = (D->strip) ? 0 : f->sizeupvalues;
173 dumpInt(D, n);
174 for (i = 0; i < n; i++)
175 dumpString(D, f->upvalues[i].name);
176}
TString * varname
AbsLineInfo * abslineinfo
struct LocVar * locvars
TString ** upvalues

References Proto::abslineinfo, dumpInt(), dumpString(), dumpVector, LocVar::endpc, AbsLineInfo::line, Proto::lineinfo, Proto::locvars, AbsLineInfo::pc, Proto::sizeabslineinfo, Proto::sizelineinfo, Proto::sizelocvars, Proto::sizeupvalues, LocVar::startpc, DumpState::strip, Proto::upvalues, and LocVar::varname.

Referenced by dumpFunction().

◆ dumpFunction()

static void dumpFunction ( DumpState * D,
const Proto * f,
TString * psource )
static

Definition at line 179 of file lua-5.4.3/src/ldump.c.

179 {
180 if (D->strip || f->source == psource)
181 dumpString(D, NULL); /* no debug info or same source as its parent */
182 else
183 dumpString(D, f->source);
184 dumpInt(D, f->linedefined);
186 dumpByte(D, f->numparams);
187 dumpByte(D, f->is_vararg);
188 dumpByte(D, f->maxstacksize);
189 dumpCode(D, f);
190 dumpConstants(D, f);
191 dumpUpvalues(D, f);
192 dumpProtos(D, f);
193 dumpDebug(D, f);
194}
#define NULL
Definition gmacros.h:924
static void dumpConstants(DumpState *D, const Proto *f)
static void dumpProtos(DumpState *D, const Proto *f)
static void dumpDebug(DumpState *D, const Proto *f)
static void dumpUpvalues(DumpState *D, const Proto *f)
static void dumpCode(DumpState *D, const Proto *f)
lu_byte maxstacksize
TString * source

References dumpByte(), dumpCode(), dumpConstants(), dumpDebug(), dumpInt(), dumpProtos(), dumpString(), dumpUpvalues(), Proto::is_vararg, Proto::lastlinedefined, Proto::linedefined, Proto::maxstacksize, NULL, Proto::numparams, Proto::source, and DumpState::strip.

Referenced by dumpProtos(), and luaU_dump().

◆ dumpHeader()

static void dumpHeader ( DumpState * D)
static

Definition at line 197 of file lua-5.4.3/src/ldump.c.

197 {
202 dumpByte(D, sizeof(Instruction));
203 dumpByte(D, sizeof(lua_Integer));
204 dumpByte(D, sizeof(lua_Number));
207}
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
#define dumpLiteral(D, s)

References dumpByte(), dumpInteger(), dumpLiteral, dumpNumber(), LUA_SIGNATURE, LUAC_DATA, LUAC_FORMAT, LUAC_INT, LUAC_NUM, and LUAC_VERSION.

Referenced by luaU_dump().

◆ dumpInt()

static void dumpInt ( DumpState * D,
int x )
static

Definition at line 73 of file lua-5.4.3/src/ldump.c.

73 {
74 dumpSize(D, x);
75}
static void dumpSize(DumpState *D, size_t x)

References dumpSize().

Referenced by dumpCode(), dumpConstants(), dumpDebug(), dumpFunction(), dumpProtos(), and dumpUpvalues().

◆ dumpInteger()

static void dumpInteger ( DumpState * D,
lua_Integer x )
static

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

83 {
84 dumpVar(D, x);
85}

References dumpVar.

Referenced by dumpConstants(), and dumpHeader().

◆ dumpNumber()

static void dumpNumber ( DumpState * D,
lua_Number x )
static

Definition at line 78 of file lua-5.4.3/src/ldump.c.

78 {
79 dumpVar(D, x);
80}

References dumpVar.

Referenced by dumpConstants(), and dumpHeader().

◆ dumpProtos()

static void dumpProtos ( DumpState * D,
const Proto * f )
static

Definition at line 134 of file lua-5.4.3/src/ldump.c.

134 {
135 int i;
136 int n = f->sizep;
137 dumpInt(D, n);
138 for (i = 0; i < n; i++)
139 dumpFunction(D, f->p[i], f->source);
140}
static void dumpFunction(DumpState *D, const Proto *f, TString *psource)
struct Proto ** p

References dumpFunction(), dumpInt(), Proto::p, Proto::sizep, and Proto::source.

Referenced by dumpFunction().

◆ dumpSize()

static void dumpSize ( DumpState * D,
size_t x )
static

Definition at line 61 of file lua-5.4.3/src/ldump.c.

61 {
62 lu_byte buff[DIBS];
63 int n = 0;
64 do {
65 buff[DIBS - (++n)] = x & 0x7f; /* fill buffer in reverse order */
66 x >>= 7;
67 } while (x != 0);
68 buff[DIBS - 1] |= 0x80; /* mark last byte */
69 dumpVector(D, buff + DIBS - n, n);
70}
#define DIBS

References DIBS, and dumpVector.

Referenced by dumpInt(), and dumpString().

◆ dumpString()

static void dumpString ( DumpState * D,
const TString * s )
static

Definition at line 88 of file lua-5.4.3/src/ldump.c.

88 {
89 if (s == NULL)
90 dumpSize(D, 0);
91 else {
92 size_t size = tsslen(s);
93 const char *str = getstr(s);
94 dumpSize(D, size + 1);
95 dumpVector(D, str, size);
96 }
97}
#define getstr(ts)
#define tsslen(s)
CURL_EXTERN CURLMcode curl_socket_t s
Definition multi.h:318

References dumpSize(), dumpVector, getstr, NULL, s, and tsslen.

Referenced by dumpConstants(), dumpDebug(), and dumpFunction().

◆ dumpUpvalues()

static void dumpUpvalues ( DumpState * D,
const Proto * f )
static

Definition at line 143 of file lua-5.4.3/src/ldump.c.

143 {
144 int i, n = f->sizeupvalues;
145 dumpInt(D, n);
146 for (i = 0; i < n; i++) {
147 dumpByte(D, f->upvalues[i].instack);
148 dumpByte(D, f->upvalues[i].idx);
149 dumpByte(D, f->upvalues[i].kind);
150 }
151}

References dumpByte(), dumpInt(), Proto::sizeupvalues, and Proto::upvalues.

Referenced by dumpFunction().

◆ luaU_dump()

int luaU_dump ( lua_State * L,
const Proto * f,
lua_Writer w,
void * data,
int strip )

Definition at line 213 of file lua-5.4.3/src/ldump.c.

214 {
215 DumpState D;
216 D.L = L;
217 D.writer = w;
218 D.data = data;
219 D.strip = strip;
220 D.status = 0;
221 dumpHeader(&D);
222 dumpByte(&D, f->sizeupvalues);
223 dumpFunction(&D, f, NULL);
224 return D.status;
225}
static void dumpHeader(DumpState *D)

References DumpState::data, dumpByte(), dumpFunction(), dumpHeader(), DumpState::L, NULL, Proto::sizeupvalues, DumpState::status, DumpState::strip, and DumpState::writer.