lua-users home
lua-l archive

warnings in 5.1.3-rc1

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


There are a few places in lua-5.1.3-rc1 (and also lua-5.1.2) that can trigger
compiler warnings and such. These are described in the points below.
(1)
When Lua is compiled with "make posix" (instead of "make ansi"), this defines
LUA_USE_POSIX, which in turn defines LUA_USE_ULONGJMP, which in turn causes
_setjmp/_longjmp (rather than setjmp/longjmp) to be used.
Under Cygwin (gcc version 3.4.4), though both setjmp/longjmp and
_setjmp/_longjmp exist in libc.a (as seen by running "nm /usr/lib/libc.a | grep
jmp"), only setjmp/longjmp are defined in setjmp.h. Though Lua compiles, a
warning is generated, as illustrated below:
 $ gcc -c -Wall -DLUA_USE_ULONGJMP src/ldo.c
 src/ldo.c: In function `luaD_throw':
 src/ldo.c:97: warning: implicit declaration of function `_longjmp'
 src/ldo.c: In function `luaD_rawrunprotected':
 src/ldo.c:116: warning: implicit declaration of function `_setjmp'
Some info:
 http://www.cygwin.com/ml/cygwin-developers/2007-06/msg00001.html
 http://www.opengroup.org/onlinepubs/009695399/functions/_longjmp.html
I'm not sure the best resolution for this, except maybe for luaconf.h to have
 #ifndef __CYGWIN__
 LUA_USE_ULONGJMP
 #endif
(2)
The following code in loslib.c causes warnings under MSVC2005 -W4:
 static int os_exit (lua_State *L) {
 exit(luaL_optint(L, 1, EXIT_SUCCESS));
 return 0; /* to avoid warnings */
 }
$ cl -nologo -D_CRT_SECURE_NO_WARNINGS -c -W4 src/loslib.c loslib.c
u:\tmp\lua-5.1.3\src\loslib.c(218) : warning C4702: unreachable code
Some prior info:
 http://lua-users.org/lists/lua-l/2002-06/msg00063.html
 http://lua-users.org/lists/lua-l/2006-09/msg00872.html
 http://lua-users.org/lists/lua-l/2001-11/msg00412.html
Simply removing the "return 0" causes no warnings under MSVC2005 -W4 and GCC
-Wall. I wonder what compiler "return 0;" is added for. "return 0;" is a hack,
MSVC is an important compiler, and less is better.
Another approach, which I compare to a band-aid on top of a band-aid, is
 static void os_exit2 (lua_State *L) {
 exit(luaL_optint(L, 1, EXIT_SUCCESS));
 }
 static int os_exit (lua_State *L) {
 os_exit2(L);
 return 0; /* to avoid warnings */
 }
MSVC-specific workarounds to disable this specific warning include adding
"#pragma warning(disable:4702)" to the source or setting the "-wd4702" compiler
flag.
(3)
The following code in lundump.c triggers a warning in MSVC2005 -W4:
 IF (1, "bad constant");
 $ cl -nologo -D_CRT_SECURE_NO_WARNINGS -W4 -c src/lundump.c lundump.c
 src/lundump.c(125) : warning C4127: conditional expression is constant
That's easy enough to resolve:
~~~~~
$ diff -u lundump.c~ lundump.c
--- lundump.c~ 2007年12月27日 08:02:25.000000000 -0500
+++ lundump.c 2008年01月17日 22:38:56.125000000 -0500
@@ -28,9 +28,11 @@
 } LoadState;
 #ifdef LUAC_TRUST_BINARIES
+#define DO(s)
 #define IF(c,s)
 #else
-#define IF(c,s) if (c) error(S,s)
+#define DO(s) error(S,s)
+#define IF(c,s) if (c) DO(s)
 static void error(LoadState* S, const char* why)
 {
@@ -122,7 +124,7 @@
 setsvalue2n(S->L,o,LoadString(S));
 break;
 default:
- IF (1, "bad constant");
+ DO ("bad constant");
 break;
 }
 }
~~~~~
(4)
If both #2 and #3 are resolved, then the warning level in luavs.bat can be
increased from /W3 to /W4 without causing warnings.
(5)
The output of etc/luavs.bat can be made more terse as follows:
~~~~~
$ diff -u luavs.bat~ luavs.bat
--- luavs.bat~	2008年01月17日 22:53:39.625000000 -0500
+++ luavs.bat	2008年01月17日 22:54:34.453125000 -0500
@@ -1,15 +1,15 @@
-rem script to build Lua under "Visual Studio .NET Command Prompt".
-rem do not run it from this directory, run it from the toplevel: etc\luavs.bat
-rem it creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src.
+@rem script to build Lua under "Visual Studio .NET Command Prompt".
+@rem do not run it from this directory, run it from the toplevel: etc\luavs.bat
+@rem it creates lua51.dll, lua51.lib, lua.exe, and luac.exe in src.
 
 cd src
-cl /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE
/DLUA_BUILD_AS_DLL l*.c
+cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
/D_CRT_NONSTDC_NO_DEPRECATE /DLUA_BUILD_AS_DLL l*.c
 del lua.obj luac.obj
-link /DLL /out:lua51.dll l*.obj
-cl /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE
/DLUA_BUILD_AS_DLL lua.c
-link /out:lua.exe lua.obj lua51.lib
-cl /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE /D_CRT_NONSTDC_NO_DEPRECATE l*.c
print.c
+link /nologo /DLL /out:lua51.dll l*.obj
+cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
/D_CRT_NONSTDC_NO_DEPRECATE /DLUA_BUILD_AS_DLL lua.c
+link /nologo /out:lua.exe lua.obj lua51.lib
+cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
/D_CRT_NONSTDC_NO_DEPRECATE l*.c print.c
 del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lmathlib.obj
loslib.obj ltablib.obj lstrlib.obj loadlib.obj
-link /out:luac.exe *.obj
+link /nologo /out:luac.exe *.obj
 del *.obj
 cd ..
~~~~~
Example output after making this change:
~~~~~
U:\temp\lua-5.1.3>etc\luavs.bat
U:\temp\lua-5.1.3>cd src
U:\temp\lua-5.1.3\src>cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
/D_CRT_NONSTDC_NO_DEPRECATE /DLUA_BUILD_AS_DLL l*.c
lapi.c
lauxlib.c
lbaselib.c
lcode.c
ldblib.c
ldebug.c
ldo.c
ldump.c
lfunc.c
lgc.c
linit.c
liolib.c
llex.c
lmathlib.c
lmem.c
loadlib.c
lobject.c
lopcodes.c
loslib.c
lparser.c
Generating Code...
Compiling...
lstate.c
lstring.c
lstrlib.c
ltable.c
ltablib.c
ltm.c
lua.c
luac.c
lundump.c
lvm.c
lzio.c
Generating Code...
C:\temp\lua-5.1.3\src>del lua.obj luac.obj
C:\temp\lua-5.1.3\src>link /nologo /DLL /out:lua51.dll l*.obj
 Creating library lua51.lib and object lua51.exp
C:\temp\lua-5.1.3\src>cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
/D_CRT_NONSTDC_NO_DEPRECATE /DLUA_BUILD_AS_DLL lua.c
lua.c
C:\temp\lua-5.1.3\src>link /nologo /out:lua.exe lua.obj lua51.lib
C:\temp\lua-5.1.3\src>cl /nologo /MD /O2 /W3 /c /D_CRT_SECURE_NO_DEPRECATE
/D_CRT_NONSTDC_NO_DEPRECATE l*.c print.c
lapi.c
lauxlib.c
lbaselib.c
lcode.c
ldblib.c
ldebug.c
ldo.c
ldump.c
lfunc.c
lgc.c
linit.c
liolib.c
llex.c
lmathlib.c
lmem.c
loadlib.c
lobject.c
lopcodes.c
loslib.c
lparser.c
Generating Code...
Compiling...
lstate.c
lstring.c
lstrlib.c
ltable.c
ltablib.c
ltm.c
lua.c
luac.c
lundump.c
lvm.c
lzio.c
print.c
Generating Code...
C:\temp\lua-5.1.3\src>del lua.obj linit.obj lbaselib.obj ldblib.obj liolib.obj lm
athlib.obj loslib.obj ltablib.obj lstrlib.obj loadlib.obj
C:\temp\lua-5.1.3\src>link /nologo /out:luac.exe *.obj
C:\temp\lua-5.1.3\src>del *.obj
C:\temp\lua-5.1.3\src>cd ..
~~~~~
(6)
There's some inconsistencies in the Lua HTML docs. For example, some have a
DOCTYPE, while others don't. Both XHTML-style lower-case and old-style ALL CAPS
tags are used. See http://validator.w3.org/ . I did run it through a link
checker and found no errors.

AltStyle によって変換されたページ (->オリジナル) /