From c62dcccd4122b47aef47062cc4956e6cb5f427d1 Mon Sep 17 00:00:00 2001 From: Thanatos Date: Sun, 31 Dec 2023 08:19:53 +0100 Subject: [PATCH] remove duplicate declarations change memory managemnet --- lupa/_lupa.pyx | 8 +++----- lupa/luaapi.pxd | 4 ---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/lupa/_lupa.pyx b/lupa/_lupa.pyx index ad539e68..25e5b30f 100644 --- a/lupa/_lupa.pyx +++ b/lupa/_lupa.pyx @@ -629,6 +629,8 @@ cdef class LuaRuntime: cdef size_t size cdef const char *err cdef ByteDescriptor bd + bd.length = 0 + bd.data = NULL cdef void* ptr cdef TValue* o try: @@ -636,8 +638,6 @@ cdef class LuaRuntime: status = lua.luaL_loadbuffer(L, lua_code_bytes, len(lua_code_bytes), NULL) if status == 0: ptr = &bd - bd.length = 0 - bd.data = NULL o = L.top - 1 lua.luaU_dump(L, clvalue(o).l.p, byte_writer, ptr, 1) return PyBytes_FromStringAndSize(bd.data, bd.length) @@ -653,8 +653,7 @@ cdef class LuaRuntime: raise LuaMemoryError(error) raise LuaSyntaxError(error) finally: - if bd.length != 0: - free(bd.data) + free(bd.data) lua.lua_settop(L, old_top) unlock_runtime(self) @@ -2544,6 +2543,5 @@ cdef int byte_writer(lua_State* L, void* new_data, size_t new_size, void* desc) bd.data = data bd.length = bd.length + new_size else: - free(data) return 1 return 0 \ No newline at end of file diff --git a/lupa/luaapi.pxd b/lupa/luaapi.pxd index 9fd70792..58f956f7 100644 --- a/lupa/luaapi.pxd +++ b/lupa/luaapi.pxd @@ -273,22 +273,18 @@ cdef extern from "lua.h" nogil: cdef extern from "lstate.h" nogil: cppclass Proto: pass - ctypedef Proto Proto ctypedef struct LClosure: Proto* p union Closure: LClosure l - ctypedef Closure Closure union GCObject: Closure cl - ctypedef GCObject GCObject union Value: GCObject* gc - ctypedef Value Value ctypedef struct lua_TValue: Value value