Skip to content

Commit dee6433

Browse files
committed
Forbid changing numerical types through compiler options
'luaconf.h' always defines options LUA_32BITS, LUA_C89_NUMBERS, LUA_INT_TYPE, and LUA_FLOAT_TYPE (using 0/1 for the first two), to avoid they being set through compiler options. (It is too easy to forget these options when compiling other software that interoperates with Lua.)
1 parent 2bfa13e commit dee6433

File tree

1 file changed

+42
-41
lines changed

1 file changed

+42
-41
lines changed

luaconf.h

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
** ===================================================================
1717
** General Configuration File for Lua
1818
**
19-
** Some definitions here can be changed externally, through the
20-
** compiler (e.g., with '-D' options). Those are protected by
21-
** '#if !defined' guards. However, several other definitions should
22-
** be changed directly here, either because they affect the Lua
23-
** ABI (by making the changes here, you ensure that all software
24-
** connected to Lua, such as C libraries, will be compiled with the
25-
** same configuration); or because they are seldom changed.
19+
** Some definitions here can be changed externally, through the compiler
20+
** (e.g., with '-D' options): They are commented out or protected
21+
** by '#if !defined' guards. However, several other definitions
22+
** should be changed directly here, either because they affect the
23+
** Lua ABI (by making the changes here, you ensure that all software
24+
** connected to Lua, such as C libraries, will be compiled with the same
25+
** configuration); or because they are seldom changed.
2626
**
2727
** Search for "@@" to find all configurable definitions.
2828
** ===================================================================
@@ -81,26 +81,12 @@
8181

8282
/*
8383
** {==================================================================
84-
** Configuration for Number types.
84+
** Configuration for Number types. These options should not be
85+
** set externally, because any other code connected to Lua must
86+
** use the same configuration.
8587
** ===================================================================
8688
*/
8789

88-
/*
89-
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.
90-
*/
91-
/* #define LUA_32BITS */
92-
93-
94-
/*
95-
@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
96-
** C89 ('long' and 'double'); Windows always has '__int64', so it does
97-
** not need to use this case.
98-
*/
99-
#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
100-
#define LUA_C89_NUMBERS
101-
#endif
102-
103-
10490
/*
10591
@@ LUA_INT_TYPE defines the type for Lua integers.
10692
@@ LUA_FLOAT_TYPE defines the type for Lua floats.
@@ -121,7 +107,31 @@
121107
#define LUA_FLOAT_DOUBLE 2
122108
#define LUA_FLOAT_LONGDOUBLE 3
123109

124-
#if defined(LUA_32BITS) /* { */
110+
111+
/* Default configuration ('long long' and 'double', for 64-bit Lua) */
112+
#define LUA_INT_DEFAULT LUA_INT_LONGLONG
113+
#define LUA_FLOAT_DEFAULT LUA_FLOAT_DOUBLE
114+
115+
116+
/*
117+
@@ LUA_32BITS enables Lua with 32-bit integers and 32-bit floats.
118+
*/
119+
#define LUA_32BITS 0
120+
121+
122+
/*
123+
@@ LUA_C89_NUMBERS ensures that Lua uses the largest types available for
124+
** C89 ('long' and 'double'); Windows always has '__int64', so it does
125+
** not need to use this case.
126+
*/
127+
#if defined(LUA_USE_C89) && !defined(LUA_USE_WINDOWS)
128+
#define LUA_C89_NUMBERS 1
129+
#else
130+
#define LUA_C89_NUMBERS 0
131+
#endif
132+
133+
134+
#if LUA_32BITS /* { */
125135
/*
126136
** 32-bit integers and 'float'
127137
*/
@@ -132,26 +142,21 @@
132142
#endif
133143
#define LUA_FLOAT_TYPE LUA_FLOAT_FLOAT
134144

135-
#elif defined(LUA_C89_NUMBERS) /* }{ */
145+
#elif LUA_C89_NUMBERS /* }{ */
136146
/*
137147
** largest types available for C89 ('long' and 'double')
138148
*/
139149
#define LUA_INT_TYPE LUA_INT_LONG
140150
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
141151

142-
#endif /* } */
152+
#else /* }{ */
153+
/* use defaults */
143154

155+
#define LUA_INT_TYPE LUA_INT_DEFAULT
156+
#define LUA_FLOAT_TYPE LUA_FLOAT_DEFAULT
144157

145-
/*
146-
** default configuration for 64-bit Lua ('long long' and 'double')
147-
*/
148-
#if !defined(LUA_INT_TYPE)
149-
#define LUA_INT_TYPE LUA_INT_LONGLONG
150-
#endif
158+
#endif /* } */
151159

152-
#if !defined(LUA_FLOAT_TYPE)
153-
#define LUA_FLOAT_TYPE LUA_FLOAT_DOUBLE
154-
#endif
155160

156161
/* }================================================================== */
157162

@@ -373,14 +378,13 @@
373378

374379
/*
375380
** {==================================================================
376-
** Configuration for Numbers.
381+
** Configuration for Numbers (low-level part).
377382
** Change these definitions if no predefined LUA_FLOAT_* / LUA_INT_*
378383
** satisfy your needs.
379384
** ===================================================================
380385
*/
381386

382387
/*
383-
@@ LUA_NUMBER is the floating-point type used by Lua.
384388
@@ LUAI_UACNUMBER is the result of a 'default argument promotion'
385389
@@ over a floating number.
386390
@@ l_floatatt(x) corrects float attribute 'x' to the proper float type
@@ -473,10 +477,7 @@
473477

474478

475479
/*
476-
@@ LUA_INTEGER is the integer type used by Lua.
477-
**
478480
@@ LUA_UNSIGNED is the unsigned version of LUA_INTEGER.
479-
**
480481
@@ LUAI_UACINT is the result of a 'default argument promotion'
481482
@@ over a LUA_INTEGER.
482483
@@ LUA_INTEGER_FRMLEN is the length modifier for reading/writing integers.

0 commit comments

Comments
 (0)