lua-users home
lua-l archive

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


Thank you very much for your response. Sorry for inconvenience with the patch.

I was trying to create a cocoa pod, and those warnings, which you deducted perfectly, made lua not usable in such a way. 

LUA_USE_POSIX - that is great, you miss things like that when you are in a hurry :(.

"What is wrong with 'system()'?”

While compiling against iOS8 'system()’ call is marked as deprecated - proposed solution is to use posix API-s. So maybe at least I found one useful thing :)

-  lua_Integer ni;

This one, I’ll see if I can tune the compiler to be smarter then.

Once again thanks for the response, and sorry for the noob-ish questions.

Szymon Kuczur, iOS Developer at whallalabs.com
mobile is eating the world
talk: 509838714

Wiadomość napisana przez Roberto Ierusalimschy <roberto@inf.puc-rio.br> w dniu 23 lip 2015, o godz. 17:47:

I was working recently with lua 5.3.1 and stumbled upon couple of compilation warnings on Xcode 6.4 (LLVM 6.1). I’ve fixed them but I ask you, can somebody look at those changes? Would they brake something or should they be incorporated into new release? I’m mostly talking about loslib.c.

Sorry if this is not the way to ask about this kind of things.

.patch file as an attachment.

We usually do not like patches. They give too much useless details (we
all know how to program) and do not show the important part---Why the
changes. What were the warnings?


/* ISO C definitions */
#define LUA_TMPNAMBUFSIZE L_tmpnam
-#define lua_tmpnam(b,e) { e = (tmpnam(b) == NULL); }
+#define lua_tmpnam(b,e) { e = (mkstemp(b) == -1); }

As the comment says, these are ISO C definitions. mkstemp is not ISO C,
so it should not appear here. Isn't your system Posix? (It seems to
be, by your next correction.) If so, you should compile Lua with
the option LUA_USE_POSIX, which will use mkstemp.

Otherwise, if you cannot use LUA_USE_POSIX but wants to use mkstemp,
you can define that in your configuration file (see macro lua_tmpnam
in file loslib.c).


+#include <spawn.h>
+extern char **environ;

static int os_execute (lua_State *L) {
  const char *cmd = luaL_optstring(L, 1, NULL);
-  int stat = system(cmd);
+    
+  pid_t pid;
+  char *argv[] = {
+    (char *)cmd,
+    NULL
+  };
+    
+  int stat = posix_spawn(&pid, argv[0], NULL, NULL, argv, environ);
+  waitpid(pid, NULL, 0);
  if (cmd != NULL)
    return luaL_execresult(L, stat);

What is wrong with 'system'? 'posix_spawn' does not seem to be commonly
available in non-POSIX C compilers...


-  lua_Integer ni;
+  lua_Integer ni = 0;

Any reason for that? A warning that 'ni' can be used without
initialization? (If so, the compiler is broken; there is no path to
the use of 'ni' not passing on its assignment. If we add this "fix",
a smarter compiler could warn with "value not used" or "useless
assignment".)


-        b = luaD_poscall(L, ra, (b != 0 ? b - 1 : L->top - ra));
+        b = luaD_poscall(L, ra, (int)(b != 0 ? b - 1 : L->top - ra));

That one has been fixed for the next release:

       b = luaD_poscall(L, ra, (b != 0 ? b - 1 : cast_int(L->top - ra)));


-- Roberto