From 99a1c06ea34c823e7692deac3a23fec4831d8f79 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 28 Feb 2014 13:13:01 -0300 Subject: more regularity with vectors + sizeof computed by the macros themselves --- ldump.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'ldump.c') diff --git a/ldump.c b/ldump.c index fcdd0acc..1078910f 100644 --- a/ldump.c +++ b/ldump.c @@ -1,5 +1,5 @@ /* -** $Id: ldump.c,v 2.21 2014/02/27 18:56:15 roberto Exp roberto $ +** $Id: ldump.c,v 2.22 2014/02/28 12:25:12 roberto Exp roberto $ ** save precompiled Lua chunks ** See Copyright Notice in lua.h */ @@ -23,8 +23,9 @@ typedef struct { int status; } DumpState; -#define DumpMem(b,n,size,D) DumpBlock(b,(n)*(size),D) -#define DumpVar(x,D) DumpMem(&x,1,sizeof(x),D) + +#define DumpVar(x,D) DumpBlock(&x,sizeof(x),D) +#define DumpVector(v,n,D) DumpBlock(v,(n)*sizeof((v)[0]),D) static void DumpBlock(const void* b, size_t size, DumpState* D) { @@ -57,12 +58,6 @@ static void DumpInteger(lua_Integer x, DumpState* D) DumpVar(x,D); } -static void DumpVector(const void* b, int n, size_t size, DumpState* D) -{ - DumpInt(n,D); - DumpMem(b,n,size,D); -} - static void DumpString(const TString* s, DumpState* D) { if (s==NULL) @@ -78,7 +73,11 @@ static void DumpString(const TString* s, DumpState* D) } } -#define DumpCode(f,D) DumpVector(f->code,f->sizecode,sizeof(Instruction),D) +static void DumpCode(const Proto* f, DumpState* D) +{ + DumpInt(f->sizecode,D); + DumpVector(f->code,f->sizecode,D); +} static void DumpFunction(const Proto* f, DumpState* D); @@ -130,7 +129,8 @@ static void DumpDebug(const Proto* f, DumpState* D) int i,n; DumpString((D->strip) ? NULL : f->source,D); n= (D->strip) ? 0 : f->sizelineinfo; - DumpVector(f->lineinfo,n,sizeof(int),D); + DumpInt(n,D); + DumpVector(f->lineinfo,n,D); n= (D->strip) ? 0 : f->sizelocvars; DumpInt(n,D); for (i=0; i