Skip to content

Commit

Permalink
remove duplicate declarations
Browse files Browse the repository at this point in the history
change memory managemnet
  • Loading branch information
ThanatosGit committed Dec 31, 2023
1 parent 0a4fa77 commit c62dccc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
8 changes: 3 additions & 5 deletions lupa/_lupa.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -629,15 +629,15 @@ 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:
check_lua_stack(L, 1)
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 = <TValue*> L.top - 1
lua.luaU_dump(L, clvalue(o).l.p, byte_writer, ptr, 1)
return PyBytes_FromStringAndSize(bd.data, bd.length)
Expand All @@ -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)

Expand Down Expand Up @@ -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
4 changes: 0 additions & 4 deletions lupa/luaapi.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c62dccc

Please sign in to comment.