[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua error handling and C++
- From: Glenn Maynard <glenn@...>
- Date: Mon, 16 Oct 2006 15:27:30 -0400
On Mon, Oct 16, 2006 at 12:14:53PM -0700, Sam Roberts wrote:
> On Mon, Oct 16, 2006 at 02:49:25PM -0400, Glenn Maynard wrote:
> > On Mon, Oct 16, 2006 at 11:31:28AM -0700, Sam Roberts wrote:
> > > Can't the C++ code catch all exceptions, and re-raise with lua_error()?
> >
> > The problem is that C++ exceptions bloat executables too much to be
> > practical to leave enabled in many cases. The use of a 150k library
> > requiring enabling an option that would bloat my binary by over 1MB
> > means it's effectively a 1.15MB library.
>
> Then I lost the thread. If you aren't using exceptions, what is the
> C++-specific problem you have encountered?
Lua error handling, currently, depends on either using longjmp or C++
exceptions.
longjmp is incompatible with C++ destructors, and will result in leaks.
That's why Lua allows C++ exceptions to be used instead.
But I find C++ exceptions are rarely an option: on large code, they
bloat the code massively, and if you're writing small code for a small
arch, then you can't afford the smaller bloat, either. (I ported to
a 32MB arch, and disabling exceptions won me that 1MB, which was
enormous.)
int mybinding(lua_State *L)
{
std::string s1 = luaL_checkstring(L, 1);
std::string s2 = luaL_checkstring(L, 2);
...
}
works fine, unless the second arg throws an error, in which case you'll
probably leak s1. (This one's easy to sidestep; as binding become
less trivial, it becomes harder.)
So, I'm asking for other options. (Not with a great deal of hope, but
maybe someone's thought of something I havn't ...)
--
Glenn Maynard