aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-03-27 12:38:29 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-03-27 12:38:29 -0300
commitef5d171cc89b19ac1fea905b99d819b5f97cba00 (patch)
treebdc900455d00c0e8cfdcbb64993842a502fc9e21
parentb0f3df16a495745cf16657a48dde6845ec85c732 (diff)
downloadlua-ef5d171cc89b19ac1fea905b99d819b5f97cba00.tar.gz
lua-ef5d171cc89b19ac1fea905b99d819b5f97cba00.tar.bz2
lua-ef5d171cc89b19ac1fea905b99d819b5f97cba00.zip
New macro 'l_numbits'
Diffstat (limited to '')
-rw-r--r--ldump.c2
-rw-r--r--lfunc.c9
-rw-r--r--llimits.h6
-rw-r--r--ltable.c2
-rw-r--r--ltests.h3
-rw-r--r--lvm.c2
6 files changed, 9 insertions, 15 deletions
diff --git a/ldump.c b/ldump.c
index 54f96674..d8fca317 100644
--- a/ldump.c
+++ b/ldump.c
@@ -87,7 +87,7 @@ static void dumpByte (DumpState *D, int y) {
87** size for 'dumpVarint' buffer: each byte can store up to 7 bits. 87** size for 'dumpVarint' buffer: each byte can store up to 7 bits.
88** (The "+6" rounds up the division.) 88** (The "+6" rounds up the division.)
89*/ 89*/
90#define DIBS ((sizeof(size_t) * CHAR_BIT + 6) / 7) 90#define DIBS ((l_numbits(size_t) + 6) / 7)
91 91
92/* 92/*
93** Dumps an unsigned integer using the MSB Varint encoding 93** Dumps an unsigned integer using the MSB Varint encoding
diff --git a/lfunc.c b/lfunc.c
index c62a5d23..da7c6239 100644
--- a/lfunc.c
+++ b/lfunc.c
@@ -162,13 +162,8 @@ static void prepcallclosemth (lua_State *L, StkId level, TStatus status,
162} 162}
163 163
164 164
165/* 165/* Maximum value for deltas in 'tbclist' */
166** Maximum value for deltas in 'tbclist', dependent on the type 166#define MAXDELTA USHRT_MAX
167** of delta. (This macro assumes that an 'L' is in scope where it
168** is used.)
169*/
170#define MAXDELTA \
171 ((256ul << ((sizeof(L->stack.p->tbclist.delta) - 1) * 8)) - 1)
172 167
173 168
174/* 169/*
diff --git a/llimits.h b/llimits.h
index d206e9e1..710dc1b4 100644
--- a/llimits.h
+++ b/llimits.h
@@ -15,6 +15,8 @@
15#include "lua.h" 15#include "lua.h"
16 16
17 17
18#define l_numbits(t) cast_int(sizeof(t) * CHAR_BIT)
19
18/* 20/*
19** 'l_mem' is a signed integer big enough to count the total memory 21** 'l_mem' is a signed integer big enough to count the total memory
20** used by Lua. (It is signed due to the use of debt in several 22** used by Lua. (It is signed due to the use of debt in several
@@ -33,7 +35,7 @@ typedef unsigned long lu_mem;
33#endif /* } */ 35#endif /* } */
34 36
35#define MAX_LMEM \ 37#define MAX_LMEM \
36 cast(l_mem, (cast(lu_mem, 1) << (sizeof(l_mem) * 8 - 1)) - 1) 38 cast(l_mem, (cast(lu_mem, 1) << (l_numbits(l_mem) - 1)) - 1)
37 39
38 40
39/* chars used as small naturals (so that 'char' is reserved for characters) */ 41/* chars used as small naturals (so that 'char' is reserved for characters) */
@@ -61,7 +63,7 @@ typedef lu_byte TStatus;
61** floor of the log2 of the maximum signed value for integral type 't'. 63** floor of the log2 of the maximum signed value for integral type 't'.
62** (That is, maximum 'n' such that '2^n' fits in the given signed type.) 64** (That is, maximum 'n' such that '2^n' fits in the given signed type.)
63*/ 65*/
64#define log2maxs(t) cast_int(sizeof(t) * 8 - 2) 66#define log2maxs(t) (l_numbits(t) - 2)
65 67
66 68
67/* 69/*
diff --git a/ltable.c b/ltable.c
index 8df9a4fb..0b3ec176 100644
--- a/ltable.c
+++ b/ltable.c
@@ -67,7 +67,7 @@ typedef union {
67** MAXABITS is the largest integer such that 2^MAXABITS fits in an 67** MAXABITS is the largest integer such that 2^MAXABITS fits in an
68** unsigned int. 68** unsigned int.
69*/ 69*/
70#define MAXABITS cast_int(sizeof(int) * CHAR_BIT - 1) 70#define MAXABITS (l_numbits(int) - 1)
71 71
72 72
73/* 73/*
diff --git a/ltests.h b/ltests.h
index af5641ba..34205167 100644
--- a/ltests.h
+++ b/ltests.h
@@ -142,9 +142,6 @@ LUA_API void *debug_realloc (void *ud, void *block,
142#define STRCACHE_N 23 142#define STRCACHE_N 23
143#define STRCACHE_M 5 143#define STRCACHE_M 5
144 144
145#undef LUAI_USER_ALIGNMENT_T
146#define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; }
147
148 145
149/* 146/*
150** This one is not compatible with tests for opcode optimizations, 147** This one is not compatible with tests for opcode optimizations,
diff --git a/lvm.c b/lvm.c
index f14397d4..e2c36ef5 100644
--- a/lvm.c
+++ b/lvm.c
@@ -774,7 +774,7 @@ lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
774 774
775 775
776/* number of bits in an integer */ 776/* number of bits in an integer */
777#define NBITS cast_int(sizeof(lua_Integer) * CHAR_BIT) 777#define NBITS l_numbits(lua_Integer)
778 778
779 779
780/* 780/*