diff --git a/lupa/_lupa.pyx b/lupa/_lupa.pyx index 9af27175..4a4841f7 100644 --- a/lupa/_lupa.pyx +++ b/lupa/_lupa.pyx @@ -721,7 +721,7 @@ cdef class _LuaObject: def __dealloc__(self): if self._runtime is None: return - cdef lua_State* L = self._state + cdef lua_State* L = self._runtime._state if L is not NULL and self._ref != lua.LUA_NOREF: locked = lock_runtime(self._runtime) lua.luaL_unref(L, lua.LUA_REGISTRYINDEX, self._ref) diff --git a/lupa/tests/test.py b/lupa/tests/test.py index d8706919..bace4091 100644 --- a/lupa/tests/test.py +++ b/lupa/tests/test.py @@ -2972,6 +2972,49 @@ def test_bad_tostring(self): def test_tostring_err(self): self.assertRaises(lupa.LuaError, str, self.lua.eval('setmetatable({}, {__tostring = function() error() end})')) +class TestSigSegScenarios(SetupLuaRuntimeMixin, unittest.TestCase): + class PendingRequest(object): + + def __init__(self, callback): + self.__callback = callback + + def make_request(self, callback): + return TestSigSegScenarios.PendingRequest(callback) + + def test_callback_passing(self): + self.lua.globals().make_request = self.make_request + run = self.lua.eval(""" + function() + make_request(function() end) + end + """) + + for i in range(10000): + thread = run.coroutine() + try: + thread.send(None) + except StopIteration: + pass + + # assert no segmentation fault + + def test_callback_passing_with_exception(self): + self.lua.globals().make_request = self.make_request + run = self.lua.eval(""" + function() + make_request(function() end) + error('test error') + end + """) + + for i in range(10000): + thread = run.coroutine() + try: + thread.send(None) + except Exception: + pass + + # assert no segmentation fault if __name__ == '__main__': def print_version():