lua-users home
lua-l archive

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


Justin Cormack wrote:
> On Tue, 2011-04-26 at 00:13 +0200, Mike Pall wrote:
> > I have a couple of ideas on how to provide a portable ffi.C.errno
> > abstraction which doesn't lose its state. But no convincing
> > solution. And then there's GetLastError() on Windows, too ...

I've fixed this in git HEAD. LuaJIT now preserves errno across
hooks, memory allocations, invocations of the JIT compiler and
other internal VM activity. Ditto for GetLastError() on Windows.

And I've added ffi.errno() which provides an OS-independent and
portable way to get errno. See:
  http://luajit.org/ext_ffi_api.html#ffi_errno

On Windows you need to declare and call GetLastError() yourself
(note: this does _not_ hold the same value as errno).

> Thinking about this some more, I wonder if you might be persuaded to add
> an ffi.syscall() function; obviously it would be architecture dependent,
> and there might have to be a few OS variations if people dont use the
> standard ABI. This could know how registers are clobbered and so on.
> Then it would be easy to wrap the standard system call functions, with
> no errno issues in pure Lua for each OS with just a small amount of
> code. I dont think the errno issue is so important for the non syscall C
> functions, as most of these have Lua equivalents anyway...

I think that would go a bit too far. However, I'm planning to add
user-definable inline machine code (*). This would allow you to
directly invoke system calls.

(*) Maybe like this:

ffi.cdef[[
void __prefetchnta(void *p) __mcode("0F180m");
float __rsqrtss(float x) __mcode("F30F52rM");
]]

I'll probably need this e.g. for SIMD ops on native vector types.
But it's only an idea right now. No ETA for this feature, yet.

--Mike