aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-05-24 16:48:09 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-05-24 16:48:09 -0300
commit1e6918d553e0d76148f7de0af63fdce326e049b8 (patch)
tree0f20249f37a4d36b0c4b21e2dc629cb0ab722faa
parent681297187ec45268e872b26753c441586c12bdd8 (diff)
downloadlua-1e6918d553e0d76148f7de0af63fdce326e049b8.tar.gz
lua-1e6918d553e0d76148f7de0af63fdce326e049b8.tar.bz2
lua-1e6918d553e0d76148f7de0af63fdce326e049b8.zip
Details
- Removed unused (and trivial) definition LUA_UNSIGNEDBITS - Alignment structure in pack/unpack moved to a narrower scope
-rw-r--r--lstrlib.c17
-rw-r--r--luaconf.h4
2 files changed, 7 insertions, 14 deletions
diff --git a/lstrlib.c b/lstrlib.c
index 47e5b27a..74501f78 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1352,15 +1352,6 @@ static const union {
1352} nativeendian = {1}; 1352} nativeendian = {1};
1353 1353
1354 1354
1355/* dummy structure to get native alignment requirements */
1356struct cD {
1357 char c;
1358 union { double d; void *p; lua_Integer i; lua_Number n; } u;
1359};
1360
1361#define MAXALIGN (offsetof(struct cD, u))
1362
1363
1364/* 1355/*
1365** information to pack/unpack stuff 1356** information to pack/unpack stuff
1366*/ 1357*/
@@ -1435,6 +1426,8 @@ static void initheader (lua_State *L, Header *h) {
1435** Read and classify next option. 'size' is filled with option's size. 1426** Read and classify next option. 'size' is filled with option's size.
1436*/ 1427*/
1437static KOption getoption (Header *h, const char **fmt, int *size) { 1428static KOption getoption (Header *h, const char **fmt, int *size) {
1429 /* dummy structure to get native alignment requirements */
1430 struct cD { char c; union { LUAI_MAXALIGN; } u; };
1438 int opt = *((*fmt)++); 1431 int opt = *((*fmt)++);
1439 *size = 0; /* default */ 1432 *size = 0; /* default */
1440 switch (opt) { 1433 switch (opt) {
@@ -1465,7 +1458,11 @@ static KOption getoption (Header *h, const char **fmt, int *size) {
1465 case '<': h->islittle = 1; break; 1458 case '<': h->islittle = 1; break;
1466 case '>': h->islittle = 0; break; 1459 case '>': h->islittle = 0; break;
1467 case '=': h->islittle = nativeendian.little; break; 1460 case '=': h->islittle = nativeendian.little; break;
1468 case '!': h->maxalign = getnumlimit(h, fmt, MAXALIGN); break; 1461 case '!': {
1462 const int maxalign = offsetof(struct cD, u);
1463 h->maxalign = getnumlimit(h, fmt, maxalign);
1464 break;
1465 }
1469 default: luaL_error(h->L, "invalid format option '%c'", opt); 1466 default: luaL_error(h->L, "invalid format option '%c'", opt);
1470 } 1467 }
1471 return Knop; 1468 return Knop;
diff --git a/luaconf.h b/luaconf.h
index e64d2ee3..d42d14b7 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -485,7 +485,6 @@
485@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER. 485@@ LUA_MAXINTEGER is the maximum value for a LUA_INTEGER.
486@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER. 486@@ LUA_MININTEGER is the minimum value for a LUA_INTEGER.
487@@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED. 487@@ LUA_MAXUNSIGNED is the maximum value for a LUA_UNSIGNED.
488@@ LUA_UNSIGNEDBITS is the number of bits in a LUA_UNSIGNED.
489@@ lua_integer2str converts an integer to a string. 488@@ lua_integer2str converts an integer to a string.
490*/ 489*/
491 490
@@ -506,9 +505,6 @@
506#define LUA_UNSIGNED unsigned LUAI_UACINT 505#define LUA_UNSIGNED unsigned LUAI_UACINT
507 506
508 507
509#define LUA_UNSIGNEDBITS (sizeof(LUA_UNSIGNED) * CHAR_BIT)
510
511
512/* now the variable definitions */ 508/* now the variable definitions */
513 509
514#if LUA_INT_TYPE == LUA_INT_INT /* { int */ 510#if LUA_INT_TYPE == LUA_INT_INT /* { int */