Skip to content

Commit ef5d171

Browse files
committed
New macro 'l_numbits'
1 parent b0f3df1 commit ef5d171

6 files changed

Lines changed: 9 additions & 15 deletions

File tree

ldump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static void dumpByte (DumpState *D, int y) {
8787
** size for 'dumpVarint' buffer: each byte can store up to 7 bits.
8888
** (The "+6" rounds up the division.)
8989
*/
90-
#define DIBS ((sizeof(size_t) * CHAR_BIT + 6) / 7)
90+
#define DIBS ((l_numbits(size_t) + 6) / 7)
9191

9292
/*
9393
** Dumps an unsigned integer using the MSB Varint encoding

lfunc.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,8 @@ static void prepcallclosemth (lua_State *L, StkId level, TStatus status,
162162
}
163163

164164

165-
/*
166-
** Maximum value for deltas in 'tbclist', dependent on the type
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)
165+
/* Maximum value for deltas in 'tbclist' */
166+
#define MAXDELTA USHRT_MAX
172167

173168

174169
/*

llimits.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include "lua.h"
1616

1717

18+
#define l_numbits(t) cast_int(sizeof(t) * CHAR_BIT)
19+
1820
/*
1921
** 'l_mem' is a signed integer big enough to count the total memory
2022
** used by Lua. (It is signed due to the use of debt in several
@@ -33,7 +35,7 @@ typedef unsigned long lu_mem;
3335
#endif /* } */
3436

3537
#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)
3739

3840

3941
/* chars used as small naturals (so that 'char' is reserved for characters) */
@@ -61,7 +63,7 @@ typedef lu_byte TStatus;
6163
** floor of the log2 of the maximum signed value for integral type 't'.
6264
** (That is, maximum 'n' such that '2^n' fits in the given signed type.)
6365
*/
64-
#define log2maxs(t) cast_int(sizeof(t) * 8 - 2)
66+
#define log2maxs(t) (l_numbits(t) - 2)
6567

6668

6769
/*

ltable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ typedef union {
6767
** MAXABITS is the largest integer such that 2^MAXABITS fits in an
6868
** unsigned int.
6969
*/
70-
#define MAXABITS cast_int(sizeof(int) * CHAR_BIT - 1)
70+
#define MAXABITS (l_numbits(int) - 1)
7171

7272

7373
/*

ltests.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ LUA_API void *debug_realloc (void *ud, void *block,
142142
#define STRCACHE_N 23
143143
#define STRCACHE_M 5
144144

145-
#undef LUAI_USER_ALIGNMENT_T
146-
#define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; }
147-
148145

149146
/*
150147
** This one is not compatible with tests for opcode optimizations,

lvm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ lua_Number luaV_modf (lua_State *L, lua_Number m, lua_Number n) {
774774

775775

776776
/* number of bits in an integer */
777-
#define NBITS cast_int(sizeof(lua_Integer) * CHAR_BIT)
777+
#define NBITS l_numbits(lua_Integer)
778778

779779

780780
/*

0 commit comments

Comments
 (0)