aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-03 13:02:41 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-07-03 13:02:41 -0300
commit0280407fc54f9b6225139c5ac27326f98f0cf043 (patch)
tree74a7c1f7cde9120d67e17ce40602b4cfd7498d80
parentae809e9fd132ab867741a6a777450f9bc0d49be4 (diff)
downloadlua-0280407fc54f9b6225139c5ac27326f98f0cf043.tar.gz
lua-0280407fc54f9b6225139c5ac27326f98f0cf043.tar.bz2
lua-0280407fc54f9b6225139c5ac27326f98f0cf043.zip
Details
Comments in makefile and function 'l_str2d'.
-rw-r--r--lobject.c21
-rw-r--r--makefile19
2 files changed, 23 insertions, 17 deletions
diff --git a/lobject.c b/lobject.c
index 223bbd0c..f8ea917a 100644
--- a/lobject.c
+++ b/lobject.c
@@ -220,32 +220,37 @@ static lua_Number lua_strx2number (const char *s, char **endptr) {
220#define L_MAXLENNUM 200 220#define L_MAXLENNUM 200
221#endif 221#endif
222 222
223/*
224** Convert string 's' to a Lua number (put in 'result'). Return NULL on
225** fail or the address of the ending '\0' on success. ('mode' == 'x')
226** means a hexadecimal numeral.
227*/
223static const char *l_str2dloc (const char *s, lua_Number *result, int mode) { 228static const char *l_str2dloc (const char *s, lua_Number *result, int mode) {
224 char *endptr; 229 char *endptr;
225 *result = (mode == 'x') ? lua_strx2number(s, &endptr) /* try to convert */ 230 *result = (mode == 'x') ? lua_strx2number(s, &endptr) /* try to convert */
226 : lua_str2number(s, &endptr); 231 : lua_str2number(s, &endptr);
227 if (endptr == s) return NULL; /* nothing recognized? */ 232 if (endptr == s) return NULL; /* nothing recognized? */
228 while (lisspace(cast_uchar(*endptr))) endptr++; /* skip trailing spaces */ 233 while (lisspace(cast_uchar(*endptr))) endptr++; /* skip trailing spaces */
229 return (*endptr == '\0') ? endptr : NULL; /* OK if no trailing characters */ 234 return (*endptr == '\0') ? endptr : NULL; /* OK iff no trailing chars */
230} 235}
231 236
232 237
233/* 238/*
234** Convert string 's' to a Lua number (put in 'result'). Return NULL 239** Convert string 's' to a Lua number (put in 'result') handling the
235** on fail or the address of the ending '\0' on success. 240** current locale.
236** 'pmode' points to (and 'mode' contains) special things in the string:
237** - 'x'/'X' means a hexadecimal numeral
238** - 'n'/'N' means 'inf' or 'nan' (which should be rejected)
239** - '.' just optimizes the search for the common case (nothing special)
240** This function accepts both the current locale or a dot as the radix 241** This function accepts both the current locale or a dot as the radix
241** mark. If the conversion fails, it may mean number has a dot but 242** mark. If the conversion fails, it may mean number has a dot but
242** locale accepts something else. In that case, the code copies 's' 243** locale accepts something else. In that case, the code copies 's'
243** to a buffer (because 's' is read-only), changes the dot to the 244** to a buffer (because 's' is read-only), changes the dot to the
244** current locale radix mark, and tries to convert again. 245** current locale radix mark, and tries to convert again.
246** The variable 'mode' checks for special characters in the string:
247** - 'n' means 'inf' or 'nan' (which should be rejected)
248** - 'x' means a hexadecimal numeral
249** - '.' just optimizes the search for the common case (no special chars)
245*/ 250*/
246static const char *l_str2d (const char *s, lua_Number *result) { 251static const char *l_str2d (const char *s, lua_Number *result) {
247 const char *endptr; 252 const char *endptr;
248 const char *pmode = strpbrk(s, ".xXnN"); 253 const char *pmode = strpbrk(s, ".xXnN"); /* look for special chars */
249 int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0; 254 int mode = pmode ? ltolower(cast_uchar(*pmode)) : 0;
250 if (mode == 'n') /* reject 'inf' and 'nan' */ 255 if (mode == 'n') /* reject 'inf' and 'nan' */
251 return NULL; 256 return NULL;
diff --git a/makefile b/makefile
index 9be23925..baa6e673 100644
--- a/makefile
+++ b/makefile
@@ -37,10 +37,15 @@ CWARNSC= -Wdeclaration-after-statement \
37 37
38CWARNS= $(CWARNSCPP) $(CWARNSC) 38CWARNS= $(CWARNSCPP) $(CWARNSC)
39 39
40# Some useful compiler options for internal tests:
41# -DHARDSTACKTESTS forces a reallocation of the stack at every point where
42# the stack can be reallocated.
43# -DHARDMEMTESTS forces an emergency collection at every single allocation.
44# -DEXTERNMEMCHECK removes internal consistency checking of blocks being
45# deallocated (useful when an external tool like valgrind does the check).
46# -DMAXINDEXRK=k limits range of constants in RK instruction operands.
47# -DLUA_COMPAT_5_3
40 48
41# -DEXTERNMEMCHECK -DHARDSTACKTESTS -DHARDMEMTESTS -DTRACEMEM='"tempmem"'
42# -DMAXINDEXRK=1 -DLUA_COMPAT_5_3
43# -g -DLUA_USER_H='"ltests.h"'
44# -pg -malign-double 49# -pg -malign-double
45# -DLUA_USE_CTYPE -DLUA_USE_APICHECK 50# -DLUA_USE_CTYPE -DLUA_USE_APICHECK
46# ('-ftrapv' for runtime checks of integer overflows) 51# ('-ftrapv' for runtime checks of integer overflows)
@@ -81,11 +86,9 @@ LIB_O= lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o lstrlib.o \
81LUA_T= lua 86LUA_T= lua
82LUA_O= lua.o 87LUA_O= lua.o
83 88
84# LUAC_T= luac
85# LUAC_O= luac.o print.o
86 89
87ALL_T= $(CORE_T) $(LUA_T) $(LUAC_T) 90ALL_T= $(CORE_T) $(LUA_T)
88ALL_O= $(CORE_O) $(LUA_O) $(LUAC_O) $(AUX_O) $(LIB_O) 91ALL_O= $(CORE_O) $(LUA_O) $(AUX_O) $(LIB_O)
89ALL_A= $(CORE_T) 92ALL_A= $(CORE_T)
90 93
91all: $(ALL_T) 94all: $(ALL_T)
@@ -102,8 +105,6 @@ $(CORE_T): $(CORE_O) $(AUX_O) $(LIB_O)
102$(LUA_T): $(LUA_O) $(CORE_T) 105$(LUA_T): $(LUA_O) $(CORE_T)
103 $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(CORE_T) $(LIBS) $(MYLIBS) $(DL) 106 $(CC) -o $@ $(MYLDFLAGS) $(LUA_O) $(CORE_T) $(LIBS) $(MYLIBS) $(DL)
104 107
105$(LUAC_T): $(LUAC_O) $(CORE_T)
106 $(CC) -o $@ $(MYLDFLAGS) $(LUAC_O) $(CORE_T) $(LIBS) $(MYLIBS)
107 108
108llex.o: 109llex.o:
109 $(CC) $(CFLAGS) -Os -c llex.c 110 $(CC) $(CFLAGS) -Os -c llex.c