diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-07-27 13:32:59 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-07-27 13:32:59 -0300 |
| commit | 0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b (patch) | |
| tree | 0ac634fed90877130b1f102bf4075af999de2158 /lundump.c | |
| parent | 15231d4fb2f6984b25e0353ff46eda1a180b686d (diff) | |
| download | lua-0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b.tar.gz lua-0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b.tar.bz2 lua-0acd55898d0aaae8dbc14c8a1bc1e3bdffc8701b.zip | |
Added gcc option '-Wconversion'
No warnings for standard numerical types. Still pending alternative
numerical types.
Diffstat (limited to 'lundump.c')
| -rw-r--r-- | lundump.c | 62 |
1 files changed, 35 insertions, 27 deletions
| @@ -36,7 +36,7 @@ typedef struct { | |||
| 36 | ZIO *Z; | 36 | ZIO *Z; |
| 37 | const char *name; | 37 | const char *name; |
| 38 | Table *h; /* list for string reuse */ | 38 | Table *h; /* list for string reuse */ |
| 39 | lu_mem offset; /* current position relative to beginning of dump */ | 39 | size_t offset; /* current position relative to beginning of dump */ |
| 40 | lua_Integer nstr; /* number of strings in the list */ | 40 | lua_Integer nstr; /* number of strings in the list */ |
| 41 | lu_byte fixed; /* dump is fixed in memory */ | 41 | lu_byte fixed; /* dump is fixed in memory */ |
| 42 | } LoadState; | 42 | } LoadState; |
| @@ -61,8 +61,8 @@ static void loadBlock (LoadState *S, void *b, size_t size) { | |||
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | 63 | ||
| 64 | static void loadAlign (LoadState *S, int align) { | 64 | static void loadAlign (LoadState *S, unsigned align) { |
| 65 | int padding = align - (S->offset % align); | 65 | unsigned padding = align - cast_uint(S->offset % align); |
| 66 | if (padding < align) { /* apd == align means no padding */ | 66 | if (padding < align) { /* apd == align means no padding */ |
| 67 | lua_Integer paddingContent; | 67 | lua_Integer paddingContent; |
| 68 | loadBlock(S, &paddingContent, padding); | 68 | loadBlock(S, &paddingContent, padding); |
| @@ -113,11 +113,19 @@ static size_t loadSize (LoadState *S) { | |||
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | 115 | ||
| 116 | /* | ||
| 117 | ** Read an non-negative int */ | ||
| 118 | static unsigned loadUint (LoadState *S) { | ||
| 119 | return cast_uint(loadVarint(S, cast_sizet(INT_MAX))); | ||
| 120 | } | ||
| 121 | |||
| 122 | |||
| 116 | static int loadInt (LoadState *S) { | 123 | static int loadInt (LoadState *S) { |
| 117 | return cast_int(loadVarint(S, cast_sizet(INT_MAX))); | 124 | return cast_int(loadVarint(S, cast_sizet(INT_MAX))); |
| 118 | } | 125 | } |
| 119 | 126 | ||
| 120 | 127 | ||
| 128 | |||
| 121 | static lua_Number loadNumber (LoadState *S) { | 129 | static lua_Number loadNumber (LoadState *S) { |
| 122 | lua_Number x; | 130 | lua_Number x; |
| 123 | loadVar(S, x); | 131 | loadVar(S, x); |
| @@ -180,15 +188,15 @@ static void loadString (LoadState *S, Proto *p, TString **sl) { | |||
| 180 | 188 | ||
| 181 | 189 | ||
| 182 | static void loadCode (LoadState *S, Proto *f) { | 190 | static void loadCode (LoadState *S, Proto *f) { |
| 183 | int n = loadInt(S); | 191 | unsigned n = loadUint(S); |
| 184 | loadAlign(S, sizeof(f->code[0])); | 192 | loadAlign(S, sizeof(f->code[0])); |
| 185 | if (S->fixed) { | 193 | if (S->fixed) { |
| 186 | f->code = getaddr(S, n, Instruction); | 194 | f->code = getaddr(S, n, Instruction); |
| 187 | f->sizecode = n; | 195 | f->sizecode = cast_int(n); |
| 188 | } | 196 | } |
| 189 | else { | 197 | else { |
| 190 | f->code = luaM_newvectorchecked(S->L, n, Instruction); | 198 | f->code = luaM_newvectorchecked(S->L, n, Instruction); |
| 191 | f->sizecode = n; | 199 | f->sizecode = cast_int(n); |
| 192 | loadVector(S, f->code, n); | 200 | loadVector(S, f->code, n); |
| 193 | } | 201 | } |
| 194 | } | 202 | } |
| @@ -198,10 +206,10 @@ static void loadFunction(LoadState *S, Proto *f); | |||
| 198 | 206 | ||
| 199 | 207 | ||
| 200 | static void loadConstants (LoadState *S, Proto *f) { | 208 | static void loadConstants (LoadState *S, Proto *f) { |
| 201 | int i; | 209 | unsigned i; |
| 202 | int n = loadInt(S); | 210 | unsigned n = loadUint(S); |
| 203 | f->k = luaM_newvectorchecked(S->L, n, TValue); | 211 | f->k = luaM_newvectorchecked(S->L, n, TValue); |
| 204 | f->sizek = n; | 212 | f->sizek = cast_int(n); |
| 205 | for (i = 0; i < n; i++) | 213 | for (i = 0; i < n; i++) |
| 206 | setnilvalue(&f->k[i]); | 214 | setnilvalue(&f->k[i]); |
| 207 | for (i = 0; i < n; i++) { | 215 | for (i = 0; i < n; i++) { |
| @@ -240,10 +248,10 @@ static void loadConstants (LoadState *S, Proto *f) { | |||
| 240 | 248 | ||
| 241 | 249 | ||
| 242 | static void loadProtos (LoadState *S, Proto *f) { | 250 | static void loadProtos (LoadState *S, Proto *f) { |
| 243 | int i; | 251 | unsigned i; |
| 244 | int n = loadInt(S); | 252 | unsigned n = loadUint(S); |
| 245 | f->p = luaM_newvectorchecked(S->L, n, Proto *); | 253 | f->p = luaM_newvectorchecked(S->L, n, Proto *); |
| 246 | f->sizep = n; | 254 | f->sizep = cast_int(n); |
| 247 | for (i = 0; i < n; i++) | 255 | for (i = 0; i < n; i++) |
| 248 | f->p[i] = NULL; | 256 | f->p[i] = NULL; |
| 249 | for (i = 0; i < n; i++) { | 257 | for (i = 0; i < n; i++) { |
| @@ -261,10 +269,10 @@ static void loadProtos (LoadState *S, Proto *f) { | |||
| 261 | ** in that case all prototypes must be consistent for the GC. | 269 | ** in that case all prototypes must be consistent for the GC. |
| 262 | */ | 270 | */ |
| 263 | static void loadUpvalues (LoadState *S, Proto *f) { | 271 | static void loadUpvalues (LoadState *S, Proto *f) { |
| 264 | int i, n; | 272 | unsigned i; |
| 265 | n = loadInt(S); | 273 | unsigned n = loadUint(S); |
| 266 | f->upvalues = luaM_newvectorchecked(S->L, n, Upvaldesc); | 274 | f->upvalues = luaM_newvectorchecked(S->L, n, Upvaldesc); |
| 267 | f->sizeupvalues = n; | 275 | f->sizeupvalues = cast_int(n); |
| 268 | for (i = 0; i < n; i++) /* make array valid for GC */ | 276 | for (i = 0; i < n; i++) /* make array valid for GC */ |
| 269 | f->upvalues[i].name = NULL; | 277 | f->upvalues[i].name = NULL; |
| 270 | for (i = 0; i < n; i++) { /* following calls can raise errors */ | 278 | for (i = 0; i < n; i++) { /* following calls can raise errors */ |
| @@ -276,33 +284,33 @@ static void loadUpvalues (LoadState *S, Proto *f) { | |||
| 276 | 284 | ||
| 277 | 285 | ||
| 278 | static void loadDebug (LoadState *S, Proto *f) { | 286 | static void loadDebug (LoadState *S, Proto *f) { |
| 279 | int i, n; | 287 | unsigned i; |
| 280 | n = loadInt(S); | 288 | unsigned n = loadUint(S); |
| 281 | if (S->fixed) { | 289 | if (S->fixed) { |
| 282 | f->lineinfo = getaddr(S, n, ls_byte); | 290 | f->lineinfo = getaddr(S, n, ls_byte); |
| 283 | f->sizelineinfo = n; | 291 | f->sizelineinfo = cast_int(n); |
| 284 | } | 292 | } |
| 285 | else { | 293 | else { |
| 286 | f->lineinfo = luaM_newvectorchecked(S->L, n, ls_byte); | 294 | f->lineinfo = luaM_newvectorchecked(S->L, n, ls_byte); |
| 287 | f->sizelineinfo = n; | 295 | f->sizelineinfo = cast_int(n); |
| 288 | loadVector(S, f->lineinfo, n); | 296 | loadVector(S, f->lineinfo, n); |
| 289 | } | 297 | } |
| 290 | n = loadInt(S); | 298 | n = loadUint(S); |
| 291 | if (n > 0) { | 299 | if (n > 0) { |
| 292 | loadAlign(S, sizeof(int)); | 300 | loadAlign(S, sizeof(int)); |
| 293 | if (S->fixed) { | 301 | if (S->fixed) { |
| 294 | f->abslineinfo = getaddr(S, n, AbsLineInfo); | 302 | f->abslineinfo = getaddr(S, n, AbsLineInfo); |
| 295 | f->sizeabslineinfo = n; | 303 | f->sizeabslineinfo = cast_int(n); |
| 296 | } | 304 | } |
| 297 | else { | 305 | else { |
| 298 | f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo); | 306 | f->abslineinfo = luaM_newvectorchecked(S->L, n, AbsLineInfo); |
| 299 | f->sizeabslineinfo = n; | 307 | f->sizeabslineinfo = cast_int(n); |
| 300 | loadVector(S, f->abslineinfo, n); | 308 | loadVector(S, f->abslineinfo, n); |
| 301 | } | 309 | } |
| 302 | } | 310 | } |
| 303 | n = loadInt(S); | 311 | n = loadUint(S); |
| 304 | f->locvars = luaM_newvectorchecked(S->L, n, LocVar); | 312 | f->locvars = luaM_newvectorchecked(S->L, n, LocVar); |
| 305 | f->sizelocvars = n; | 313 | f->sizelocvars = cast_int(n); |
| 306 | for (i = 0; i < n; i++) | 314 | for (i = 0; i < n; i++) |
| 307 | f->locvars[i].varname = NULL; | 315 | f->locvars[i].varname = NULL; |
| 308 | for (i = 0; i < n; i++) { | 316 | for (i = 0; i < n; i++) { |
| @@ -310,9 +318,9 @@ static void loadDebug (LoadState *S, Proto *f) { | |||
| 310 | f->locvars[i].startpc = loadInt(S); | 318 | f->locvars[i].startpc = loadInt(S); |
| 311 | f->locvars[i].endpc = loadInt(S); | 319 | f->locvars[i].endpc = loadInt(S); |
| 312 | } | 320 | } |
| 313 | n = loadInt(S); | 321 | n = loadUint(S); |
| 314 | if (n != 0) /* does it have debug information? */ | 322 | if (n != 0) /* does it have debug information? */ |
| 315 | n = f->sizeupvalues; /* must be this many */ | 323 | n = cast_uint(f->sizeupvalues); /* must be this many */ |
| 316 | for (i = 0; i < n; i++) | 324 | for (i = 0; i < n; i++) |
| 317 | loadString(S, f, &f->upvalues[i].name); | 325 | loadString(S, f, &f->upvalues[i].name); |
| 318 | } | 326 | } |
| @@ -384,7 +392,7 @@ LClosure *luaU_undump (lua_State *L, ZIO *Z, const char *name, int fixed) { | |||
| 384 | S.name = name; | 392 | S.name = name; |
| 385 | S.L = L; | 393 | S.L = L; |
| 386 | S.Z = Z; | 394 | S.Z = Z; |
| 387 | S.fixed = fixed; | 395 | S.fixed = cast_byte(fixed); |
| 388 | S.offset = 1; /* fist byte was already read */ | 396 | S.offset = 1; /* fist byte was already read */ |
| 389 | checkHeader(&S); | 397 | checkHeader(&S); |
| 390 | cl = luaF_newLclosure(L, loadByte(&S)); | 398 | cl = luaF_newLclosure(L, loadByte(&S)); |
