Enrico Tassi <gareuselesi...@debian.org> writes:

> I've prepared that patch a while ago (so it may not apply 100% clean).
> I'm attaching it, it is for the lua5.1 package of course. 
> Could you please test it?

Thank you.  The patch conflicted in debian/changelog only.
I had some difficulty getting the Makefile changes applied, due
to unfamiliarity with quilt.  After that, the package compiled
OK, and the resulting shared object does call destructors when
unwinding from an error.  I am attaching my test program.
Compile with:
g++ lua_error.cc $(pkg-config --cflags --libs lua5.1-c++) -o lua_error

Because you made the C++ variant a separate library with mangled
names, it is not compatible with previously compiled modules.
For example, liblua5.1-curl.so.0.0.0 in liblua5.1-curl0 0.3.0-5
wants to call lua_type rather than _Z8lua_typeP9lua_Statei.
This will not be a problem for Bos Wars, which does not use such
modules anyway; but perhaps you should change LUA_CPATH_DEFAULT
in liblua5.1-c++, to support installing C++ variants of modules
as well.

(I wonder why liblua5.1-curl.so.0.0.0 does not declare a
dependency on liblua5.1.so.0 even though it uses functions from
that.)

#include <setjmp.h>
#include <stdlib.h>
#include <stdio.h>
#include <lua.h>

struct Test
{
	static int refs;
	Test()
	{
		puts("Test::Test()");
		++refs;
	}

	Test(const Test &)
	{
		puts("Test::Test(const Test &)");
		++refs;
	}

	~Test()
	{
		puts("Test::~Test()");
		--refs;
	}
};

int Test::refs = 0;

void *
alloc(void *ud, void *ptr, size_t osize, size_t nsize)
{
	if (nsize == 0)
	{
		free(ptr);
		return NULL;
	}
	else
	{
		return realloc(ptr, nsize);
	}
}

int
inner(lua_State *lua)
{
	puts("entered inner");
	Test test;
	puts("before lua_pushstring");
	lua_pushstring(lua, "just testing");
	puts("before lua_error");
	lua_error(lua);
	puts("lua_error returned; impossible");
	return 1;
}

int
main()
{
	puts("before lua_newstate");
	lua_State *lua = lua_newstate(alloc, NULL);
	int error = lua_cpcall(lua, inner, NULL);
	switch (error)
	{
	case 0:
		puts("success");
		break;
	case LUA_ERRRUN:
		puts("LUA_ERRRUN");
		break;
	case LUA_ERRMEM:
		puts("LUA_ERRMEM");
		break;
	case LUA_ERRERR:
		puts("LUA_ERRERR");
		break;
	default:
		printf("error %d\n", error);
		break;
	}
	lua_close(lua);

	if (Test::refs == 0)
	{
		printf("Test::refs == %d (OK)\n", Test::refs);
		return EXIT_SUCCESS;
	}
	else
	{
		printf("Test::refs == %d (error)\n", Test::refs);
		return EXIT_SUCCESS;
	}
}

Attachment: pgpGwj4OZkwQr.pgp
Description: PGP signature

Reply via email to