lua-users home
lua-l archive

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


It was thus said that the Great Sean Bolton once stated:
> Hi Sean,
> 
> On Fri May 10 2013, Sean Conner wrote:
> > I wrote a function that calls pipe() [1].  Once that succeeds, I call
> > fdopen() [2] on each file descriptor, and then I create
> > LUA_FILEHANDLES from these and return both of them (in a table).  The
> > create portion is fine, but when I try to close one of the pipes:
> > 
> > [spc]lucy:/tmp>lua luafilehandle.lua 
> > 2011
> > about to create
> > 
> > file (0x96647e8)        file (0x967b148)
> > about to close read
> > 
> > Segmentation fault (core dumped)
> 
> [snip]
> 
> > Is there something I should be doing?  Code below.
> 
> Yes, you're not setting the environment of the file handle userdata, or
> better yet, of my_pipe() (so that all userdata created by it inherit
> the correct environment). It's from the file handle object's environment
> that Lua 5.1.x gets the function to use to close the handle. Since your
> userdata don't have that set, the close crashes.  Grep for 'fenv' in
> liolib.c for more information.  (Note that 5.2 uses a different
> scheme.) HTH,

  Yup.  That was it.  I was able to grab the environment from io.open() and
use that, and the problem was fixed.

  -spc