aboutsummaryrefslogtreecommitdiff
path: root/ldump.c
diff options
context:
space:
mode:
Diffstat (limited to 'ldump.c')
-rw-r--r--ldump.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/ldump.c b/ldump.c
index 3e91190c..50d09f9a 100644
--- a/ldump.c
+++ b/ldump.c
@@ -26,6 +26,7 @@ typedef struct {
26 lua_State *L; 26 lua_State *L;
27 lua_Writer writer; 27 lua_Writer writer;
28 void *data; 28 void *data;
29 lu_mem offset; /* current position relative to beginning of dump */
29 int strip; 30 int strip;
30 int status; 31 int status;
31 Table *h; /* table to track saved strings */ 32 Table *h; /* table to track saved strings */
@@ -47,6 +48,17 @@ static void dumpBlock (DumpState *D, const void *b, size_t size) {
47 lua_unlock(D->L); 48 lua_unlock(D->L);
48 D->status = (*D->writer)(D->L, b, size, D->data); 49 D->status = (*D->writer)(D->L, b, size, D->data);
49 lua_lock(D->L); 50 lua_lock(D->L);
51 D->offset += size;
52 }
53}
54
55
56static void dumpAlign (DumpState *D, int align) {
57 int padding = align - (D->offset % align);
58 if (padding < align) { /* apd == align means no padding */
59 static lua_Integer paddingContent = 0;
60 dumpBlock(D, &paddingContent, padding);
61 lua_assert(D->offset % align == 0);
50 } 62 }
51} 63}
52 64
@@ -126,6 +138,7 @@ static void dumpString (DumpState *D, TString *s) {
126 138
127static void dumpCode (DumpState *D, const Proto *f) { 139static void dumpCode (DumpState *D, const Proto *f) {
128 dumpInt(D, f->sizecode); 140 dumpInt(D, f->sizecode);
141 dumpAlign(D, sizeof(f->code[0]));
129 dumpVector(D, f->code, f->sizecode); 142 dumpVector(D, f->code, f->sizecode);
130} 143}
131 144
@@ -242,6 +255,7 @@ int luaU_dump(lua_State *L, const Proto *f, lua_Writer w, void *data,
242 DumpState D; 255 DumpState D;
243 D.L = L; 256 D.L = L;
244 D.writer = w; 257 D.writer = w;
258 D.offset = 0;
245 D.data = data; 259 D.data = data;
246 D.strip = strip; 260 D.strip = strip;
247 D.status = 0; 261 D.status = 0;