Luabind, objects, and exceptions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Luabind, objects, and exceptions

Jason McKesson
I've discovered something that may constitute a bug. Or, at least, a
design flaw.

Pure Lua prefers to communicate useful error messages via the Lua stack.
Luabind prefers to communicate with exceptions. Both of these are
servicable methods of doing so, but the current implementation clashes.

It clashes because the Luabind exception doesn't actually communicate
anything. Any actually useful error messages are still supposed to be
passed through the Lua stack. The problem is that exceptions cause the
stack to be unwound up until the appropriate catch clause.

This is a problem because, unless you catch every exception at the
moment you make Luabind calls (which makes exceptions just a verbose
return flag), there's a good chance that the C++ stack unwinding is
going to start poking at the Lua stack. Like if you have a
luabind::object on the stack. Possibly as a temporary that you used to
make the actual call. Something as simple as this:

luabind::call_function<void>(someObject[anIndex], ...);

can fail. The [] operator creates a luabind::object temporary, and stack
unwinding, no matter where you put the try/catch block, is going to
collect this. That action is going to do highly unpleasant things to the
Lua stack.

This wouldn't be a problem if luabind::error worked like most exceptions
and actually carried error data. I generally do this by having the
exception object store a large char[] array. It's not heap-allocated, so
copying into/out of this buffer is perfectly fine. Sure, the exception
object is huge, but that's better than having information destroyed.

------------------------------------------------------------------------------

_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user
Reply | Threaded
Open this post in threaded view
|

Re: Luabind, objects, and exceptions

Daniel Wallin
On Fri, May 28, 2010 at 11:56:37PM -0700, Jason McKesson wrote:
> I've discovered something that may constitute a bug. Or, at least, a
> design flaw.
[...]
> This wouldn't be a problem if luabind::error worked like most exceptions
> and actually carried error data. I generally do this by having the
> exception object store a large char[] array. It's not heap-allocated, so
> copying into/out of this buffer is perfectly fine. Sure, the exception
> object is huge, but that's better than having information destroyed.

Good point.

Do you want to produce a patch for this? I'd consider both embedding a
fixed size char array and allocating memory and managing it with
reference counting workable solutions.

--
Daniel Wallin
BoostPro Computing
http://www.boostpro.com

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
luabind-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/luabind-user