Shane Liesegang | 8 Jul 2012 15:12
Gravatar

Reading from io.popen handle crashes in release build Lua

I have this bit of (what I think is) innocuous Lua code:

  local f = assert(io.popen(path .. " -version", 'r'))
  local s = assert(f:read('*a'))
  f:close()

Where "path" is a string pointing to a configuration program, and I do some processing on "s" afterwards to make sure it's at the correct version before proceeding.

This worked fine in Lua 5.1.5, and it works fine when I build Lua 5.2.1 in debug mode, but when I have a release version of the lua executable, it crashes on the second line with "Interrupted system call."

I'm not sure which optimization in my particular Release configuration is causing the issue, but I figured it worth asking if anyone had an idea of what might cause a problem like this, what might have changed in io between 5.1 and 5.2, etc.

Is there a new, better way to get the output from an external program?

steve donovan | 8 Jul 2012 15:31
Picon

Re: Reading from io.popen handle crashes in release build Lua

On Sun, Jul 8, 2012 at 3:12 PM, Shane Liesegang <shane <at> techie.net> wrote:
> This worked fine in Lua 5.1.5, and it works fine when I build Lua 5.2.1 in
> debug mode, but when I have a release version of the lua executable, it
> crashes on the second line with "Interrupted system call."

It would be useful to know what platform and what compiler version.

These things matter; for instance, with the clang that comes with the
new Ubuntu LTS a simple f:close() will cause a segfault on release
builds.  I haven't found any issues with gcc, however, except the new
default of 4.6 is to leave out stack frames, which caused trouble on
Windows executable builds.

steve d.

Shmuel Zeigerman | 8 Jul 2012 15:44

Re: Reading from io.popen handle crashes in release build Lua

On 08/07/2012 16:31, steve donovan wrote:
> I haven't found any issues with gcc, however, except the new
> default of 4.6 is to leave out stack frames, which caused trouble on
> Windows executable builds.

I experienced troubles with gcc 4.6.1 but 4.6.2 works fine for me on 
Windows.

--

-- 
Shmuel

Shane Liesegang | 8 Jul 2012 15:57
Gravatar

Re: Reading from io.popen handle crashes in release build Lua

On Sun, Jul 8, 2012 at 9:31 AM, steve donovan <steve.j.donovan <at> gmail.com> wrote:

It would be useful to know what platform and what compiler version.

These things matter; for instance, with the clang that comes with the
new Ubuntu LTS a simple f:close() will cause a segfault on release
builds.  I haven't found any issues with gcc, however, except the new
default of 4.6 is to leave out stack frames, which caused trouble on
Windows executable builds.

Oh, sure! My mistake; obviously that's a handy bit of background for this kind of problem.

I'm also using clang, but on OS X. So I'm guessing it could be the same issue as on Ubuntu?
 
Shane Liesegang | 8 Jul 2012 15:59
Gravatar

Re: Reading from io.popen handle crashes in release build Lua

On Sun, Jul 8, 2012 at 9:57 AM, Shane Liesegang <shane <at> techie.net> wrote:

I'm also using clang, but on OS X. So I'm guessing it could be the same issue as on Ubuntu?

Complete version information, if it makes a difference:

Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
 
steve donovan | 8 Jul 2012 16:15
Picon

Re: Reading from io.popen handle crashes in release build Lua

On Sun, Jul 8, 2012 at 3:57 PM, Shane Liesegang <shane <at> techie.net> wrote:
> I'm also using clang, but on OS X. So I'm guessing it could be the same
> issue as on Ubuntu?

Could well be - if it's the same problem, then _simply closing a file_
will cause the crash!

Sounds like a compiler bug - it's related to the new representation of
file objects in Lua 5.2.

steve d.


Gmane