lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>> No, LUA_MAXUNSIGNED is (-0x8000000000000000)

> Where did this definition come from?

Um, looking at that now it's probably wrong.  I typed that into the
email; it probably is the min signed, not the max unsigned.

I clearly should stop trying answer email when I'm rushed.

Here's the diff, copied into the email mechanically rather than
manually.  In particular, I find

#define LUA_MAXINTEGER		0x7fffffffffffffff
#define LUA_MININTEGER		(-0x8000000000000000)
#define LUA_MAXUNSIGNED		0xffffffffffffffff

which make a lot more sense.  (One Makefile change perhaps needs
remark: the change of CC.  wgcc is a local script that runs gcc with a
bunch of warning options.  As used here, the list is -Werror -W -Wall
-Wpointer-arith -Wcast-qual -Wwrite-strings -Wstrict-prototypes
-Wmissing-prototypes -Wno-uninitialized -Wno-sign-compare
-Wno-missing-init, which (as you can see below) I then append
-Wno-cast-qual to because there's way too much code in Lua that casts
away qualifiers for leaving that to be sane.

commit 910d3add3aa499b27594369a48f6476f83909c7e
Author: Mouse <mouse@Rodents-Montreal.ORG>
Date:   Thu Nov 24 16:23:38 2022 -0500

    Make it build on 1.4T/sparc.

diff --git a/lua-5.4.4/src/Makefile b/lua-5.4.4/src/Makefile
index 1907381..dec5cd8 100644
--- a/lua-5.4.4/src/Makefile
+++ b/lua-5.4.4/src/Makefile
@@ -4,10 +4,10 @@
 # == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
 
 # Your platform. See PLATS for possible values.
-PLAT= guess
+PLAT=NetBSD
 
-CC= gcc -std=gnu99
-CFLAGS= -O2 -Wall -Wextra -DLUA_COMPAT_5_3 $(SYSCFLAGS) $(MYCFLAGS)
+CC=wgcc -Wno-cast-qual
+CFLAGS= -O2 -DLUA_COMPAT_5_3 $(SYSCFLAGS) -DLUA_NOBUILTIN
 LDFLAGS= $(SYSLDFLAGS) $(MYLDFLAGS)
 LIBS= -lm $(SYSLIBS) $(MYLIBS)
 
@@ -26,7 +26,7 @@ MYLIBS=
 MYOBJS=
 
 # Special flags for compiler modules; -Os reduces code size.
-CMCFLAGS= 
+CMCFLAGS=
 
 # == END OF USER SETTINGS -- NO NEED TO CHANGE ANYTHING BELOW THIS LINE =======
 
@@ -112,9 +112,12 @@ c89:
 	@echo '*** with LUA_USE_C89 to ensure consistency'
 	@echo ''
 
-FreeBSD NetBSD OpenBSD freebsd:
+FreeBSD OpenBSD freebsd:
 	$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX -DLUA_USE_READLINE -I/usr/include/edit" SYSLIBS="-Wl,-E -ledit" CC="cc"
 
+NetBSD:
+	$(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_POSIX"
+
 generic: $(ALL)
 
 Linux linux:	linux-noreadline
diff --git a/lua-5.4.4/src/liolib.c b/lua-5.4.4/src/liolib.c
index b08397d..de88400 100644
--- a/lua-5.4.4/src/liolib.c
+++ b/lua-5.4.4/src/liolib.c
@@ -94,7 +94,7 @@ static int l_checkmode (const char *mode) {
 
 #if !defined(l_getc)		/* { */
 
-#if defined(LUA_USE_POSIX)
+#if defined(LUA_USE_POSIX) && !defined(NO_UNLOCKED_STDIO)
 #define l_getc(f)		getc_unlocked(f)
 #define l_lockfile(f)		flockfile(f)
 #define l_unlockfile(f)		funlockfile(f)
@@ -115,7 +115,7 @@ static int l_checkmode (const char *mode) {
 
 #if !defined(l_fseek)		/* { */
 
-#if defined(LUA_USE_POSIX)	/* { */
+#if defined(LUA_USE_POSIX) && !defined(NO_FSEEKO) /* { */
 
 #include <sys/types.h>
 
@@ -825,4 +825,3 @@ LUAMOD_API int luaopen_io (lua_State *L) {
   createstdfile(L, stderr, NULL, "stderr");
   return 1;
 }
-
diff --git a/lua-5.4.4/src/lmathlib.c b/lua-5.4.4/src/lmathlib.c
index e0c61a1..51d24f3 100644
--- a/lua-5.4.4/src/lmathlib.c
+++ b/lua-5.4.4/src/lmathlib.c
@@ -173,7 +173,7 @@ static int math_log (lua_State *L) {
     res = l_mathop(log)(x);
   else {
     lua_Number base = luaL_checknumber(L, 2);
-#if !defined(LUA_USE_C89)
+#if !defined(LUA_USE_C89) && !defined(NO_LOG_2)
     if (base == l_mathop(2.0))
       res = l_mathop(log2)(x);
     else
@@ -277,7 +277,15 @@ static int math_type (lua_State *L) {
 /* there is a 'long long' type (which must have at least 64 bits) */
 #define Rand64		unsigned long long
 
-#elif (LUA_MAXUNSIGNED >> 31 >> 31) >= 3
+/*
+ * I've been unable to figure out how to avoid getting
+ *	"lmathlib.c", line 280: warning: integer constant out of range
+ *  for this on 1.4T.  So, ugly as it is, we hardwire the knowledge
+ *  that all systems this patch tree will be used on have 64-bit
+ *  integers.
+ */
+/* #elif (LUA_MAXUNSIGNED >> 31 >> 31) >= 3 */
+#elif 1
 
 /* 'lua_Integer' has at least 64 bits */
 #define Rand64		lua_Unsigned
@@ -541,7 +549,15 @@ static lua_Unsigned project (lua_Unsigned ran, lua_Unsigned n,
     lim |= (lim >> 4);
     lim |= (lim >> 8);
     lim |= (lim >> 16);
-#if (LUA_MAXUNSIGNED >> 31) >= 3
+/*
+ * I've been unable to figure out how to avoid getting
+ *	"lmathlib.c", line 552: warning: integer constant out of range
+ *  for this on 1.4T.  So, ugly as it is, we hardwire the knowledge
+ *  that all systems this patch tree will be used on have 64-bit
+ *  integers.
+ */
+/* #if (LUA_MAXUNSIGNED >> 31) >= 3 */
+#if 1
     lim |= (lim >> 32);  /* integer type has more than 32 bits */
 #endif
     lua_assert((lim & (lim + 1)) == 0  /* 'lim + 1' is a power of 2, */
@@ -761,4 +777,3 @@ LUAMOD_API int luaopen_math (lua_State *L) {
   setrandfunc(L);
   return 1;
 }
-
diff --git a/lua-5.4.4/src/loslib.c b/lua-5.4.4/src/loslib.c
index 3e20d62..356fe71 100644
--- a/lua-5.4.4/src/loslib.c
+++ b/lua-5.4.4/src/loslib.c
@@ -207,10 +207,20 @@ static int os_clock (lua_State *L) {
 ** to compute the year.
 */
 static void setfield (lua_State *L, const char *key, int value, int delta) {
-  #if (defined(LUA_NUMTIME) && LUA_MAXINTEGER <= INT_MAX)
+/*
+ * I've been unable to figure out how to avoid getting
+ *	"loslib.c", line 210: warning: integer constant out of range
+ *  for this on 1.4T.  So, ugly as it is, we hardwire the knowledge
+ *  that all systems this patch tree will be used on have 64-bit
+ *  integers.  I'm not sure the claim in the comment above about time
+ *  being unable to overflow 64 bits is correct (though any _likely_
+ *  time is fine), but we certainly have LUA_MAXINTEGER > INT_MAX, so
+ *  removing this block is no worse than having it compile as designed.
+ */
+/*  #if (defined(LUA_NUMTIME) && LUA_MAXINTEGER <= INT_MAX)
     if (l_unlikely(value > LUA_MAXINTEGER - delta))
       luaL_error(L, "field '%s' is out-of-bound", key);
-  #endif
+  #endif */
   lua_pushinteger(L, (lua_Integer)value + delta);
   lua_setfield(L, -2, key);
 }
@@ -427,4 +437,3 @@ LUAMOD_API int luaopen_os (lua_State *L) {
   luaL_newlib(L, syslib);
   return 1;
 }
-
diff --git a/lua-5.4.4/src/lstrlib.c b/lua-5.4.4/src/lstrlib.c
index 0b4fdbb..fafbddc 100644
--- a/lua-5.4.4/src/lstrlib.c
+++ b/lua-5.4.4/src/lstrlib.c
@@ -1871,4 +1871,3 @@ LUAMOD_API int luaopen_string (lua_State *L) {
   createmetatable(L);
   return 1;
 }
-
diff --git a/lua-5.4.4/src/luaconf.h b/lua-5.4.4/src/luaconf.h
index d42d14b..89ffb2d 100644
--- a/lua-5.4.4/src/luaconf.h
+++ b/lua-5.4.4/src/luaconf.h
@@ -58,6 +58,17 @@
 #endif
 
 
+/* #include this for __NetBSD_Version__ */
+#include <sys/param.h>
+#if __NetBSD_Version__ == 104200000
+#define NO_UNLOCKED_STDIO
+#define NO_FSEEKO
+#define INTEGER_IS_64
+#define NO_PERCENT_A
+#define NO_LOG_2
+#endif
+
+
 #if defined(LUA_USE_LINUX)
 #define LUA_USE_POSIX
 #define LUA_USE_DLOPEN		/* needs an extra library: -ldl */
@@ -73,7 +84,7 @@
 /*
 @@ LUAI_IS32INT is true iff 'int' has (at least) 32 bits.
 */
-#define LUAI_IS32INT	((UINT_MAX >> 30) >= 3)
+#define LUAI_IS32INT	1
 
 /* }================================================================== */
 
@@ -217,9 +228,8 @@
 
 #else			/* }{ */
 
-#define LUA_ROOT	"/usr/local/"
-#define LUA_LDIR	LUA_ROOT "share/lua/" LUA_VDIR "/"
-#define LUA_CDIR	LUA_ROOT "lib/lua/" LUA_VDIR "/"
+#define LUA_LDIR "/local/lib/lua/lua/" LUA_VDIR "/"
+#define LUA_CDIR "/local/lib/lua/C/" LUA_VDIR "/"
 
 #if !defined(LUA_PATH_DEFAULT)
 #define LUA_PATH_DEFAULT  \
@@ -230,7 +240,7 @@
 
 #if !defined(LUA_CPATH_DEFAULT)
 #define LUA_CPATH_DEFAULT \
-		LUA_CDIR"?.so;" LUA_CDIR"loadall.so;" "./?.so"
+		""
 #endif
 
 #endif			/* } */
@@ -529,17 +539,16 @@
 
 #elif LUA_INT_TYPE == LUA_INT_LONGLONG	/* }{ long long */
 
-/* use presence of macro LLONG_MAX as proxy for C99 compliance */
-#if defined(LLONG_MAX)		/* { */
+#if 1
 /* use ISO C99 stuff */
 
 #define LUA_INTEGER		long long
 #define LUA_INTEGER_FRMLEN	"ll"
 
-#define LUA_MAXINTEGER		LLONG_MAX
-#define LUA_MININTEGER		LLONG_MIN
+#define LUA_MAXINTEGER		0x7fffffffffffffff
+#define LUA_MININTEGER		(-0x8000000000000000)
 
-#define LUA_MAXUNSIGNED		ULLONG_MAX
+#define LUA_MAXUNSIGNED		0xffffffffffffffff
 
 #elif defined(LUA_USE_WINDOWS) /* }{ */
 /* in Windows, can use specific Windows types */
@@ -609,7 +618,7 @@
 ** Otherwise, you can leave 'lua_number2strx' undefined and Lua will
 ** provide its own implementation.
 */
-#if !defined(LUA_USE_C89)
+#if !defined(LUA_USE_C89) && !defined(NO_PERCENT_A)
 #define lua_number2strx(L,b,sz,f,n)  \
 	((void)L, l_sprintf(b,sz,f,(LUAI_UACNUMBER)(n)))
 #endif
@@ -783,4 +792,3 @@
 
 
 #endif
-
diff --git a/lua-5.4.4/src/lvm.c b/lua-5.4.4/src/lvm.c
index 2ec3440..139eabd 100644
--- a/lua-5.4.4/src/lvm.c
+++ b/lua-5.4.4/src/lvm.c
@@ -64,8 +64,16 @@
 ** of an integer. In a worst case, NBM == 113 for long double and
 ** sizeof(long) == 32.)
 */
-#if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \
-	>> (NBM - (3 * (NBM / 4))))  >  0
+/*
+ * I've been unable to figure out how to avoid getting
+ *	"lvm.c", line 70: warning: integer constant out of range
+ *  for this on 1.4T.  So, ugly as it is, we hardwire the knowledge
+ *  that all systems this patch tree will be used on have 64-bit
+ *  integers and doubles with <64 mantissa bits.
+ */
+/* #if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \
+	>> (NBM - (3 * (NBM / 4))))  >  0 */
+#if 1
 
 /* limit for integers that fit in a float */
 #define MAXINTFITSF	((lua_Unsigned)1 << NBM)

/~\ The ASCII				  Mouse
\ / Ribbon Campaign
 X  Against HTML		mouse@rodents-montreal.org
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B