forked from enlightenment/efl
elua: free format buffers immediately
This commit is contained in:
parent
e8b356858b
commit
ab05d47d7c
|
@ -204,6 +204,8 @@ local Str_Buf = ffi.metatype("Str_Buf", {
|
||||||
free = function(self)
|
free = function(self)
|
||||||
C.free(self.buf)
|
C.free(self.buf)
|
||||||
self.buf = nil
|
self.buf = nil
|
||||||
|
self.len = 0
|
||||||
|
self.cap = 0
|
||||||
end,
|
end,
|
||||||
clear = function(self)
|
clear = function(self)
|
||||||
self.len = 0
|
self.len = 0
|
||||||
|
@ -212,8 +214,8 @@ local Str_Buf = ffi.metatype("Str_Buf", {
|
||||||
local oldcap = self.cap
|
local oldcap = self.cap
|
||||||
if oldcap >= newcap then return end
|
if oldcap >= newcap then return end
|
||||||
local buf = C.malloc(newcap)
|
local buf = C.malloc(newcap)
|
||||||
copy(buf, self.buf, self.len)
|
if self.len ~= 0 then copy(buf, self.buf, self.len) end
|
||||||
C.free(self.buf)
|
if self.buf ~= nil then C.free(self.buf) end
|
||||||
self.buf = buf
|
self.buf = buf
|
||||||
self.cap = newcap
|
self.cap = newcap
|
||||||
end,
|
end,
|
||||||
|
@ -340,7 +342,10 @@ getmetatable("").__mod = function(fmts, params)
|
||||||
end
|
end
|
||||||
c, s = s[0], s + 1
|
c, s = s[0], s + 1
|
||||||
end
|
end
|
||||||
return tostr(buf)
|
nbuf:free()
|
||||||
|
local ret = tostr(buf)
|
||||||
|
buf:free()
|
||||||
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
Loading…
Reference in New Issue