Commit 41b2544a authored by Vladimír Čunát's avatar Vladimír Čunát

lua nitpicks: memory management

parent 3be76db7
......@@ -135,6 +135,8 @@ local rrset_buflen = (64 + 1) * 1024
local rrset_buf = ffi.new('char[?]', rrset_buflen)
local knot_rrset_t = ffi.typeof('knot_rrset_t')
ffi.metatype( knot_rrset_t, {
-- beware: `owner` and `rdata` are typed as a plain lua strings
-- and not the real types they represent.
__index = {
owner = function(rr) return ffi.string(rr._owner, knot.knot_dname_size(rr._owner)) end,
ttl = function(rr) return tonumber(knot.knot_rrset_ttl(rr)) end,
......@@ -317,7 +319,7 @@ local function rr2str(rr, style)
-- Construct a single-RR temporary set while minimizing copying.
local rrs = knot_rrset_t()
knot.knot_rrset_init_empty(rrs)
rrs._owner = ffi.cast('char *', rr.owner) -- explicit cast needed here
rrs._owner = ffi.cast('knot_dname_t *', rr.owner) -- explicit cast needed here
rrs.type = rr.type
rrs.rclass = kres.class.IN
knot.knot_rrset_add_rdata(rrs, rr.rdata, #rr.rdata, rr.ttl, nil)
......
......@@ -30,7 +30,7 @@ mod.layer = {
if orig.type == kres.type.A then
local rrs = ffi.typeof('knot_rrset_t')()
ffi.C.knot_rrset_init_empty(rrs)
rrs._owner = ffi.cast('char *', orig:owner()) -- explicit cast needed here
rrs._owner = ffi.cast('knot_dname_t *', orig:owner()) -- explicit cast needed here
rrs.type = kres.type.AAAA
rrs.rclass = orig.rclass
for k = 1, orig.rrs.rr_count do
......@@ -39,6 +39,8 @@ mod.layer = {
ffi.copy(addr_buf + 12, rdata, 4)
ffi.C.knot_rrset_add_rdata(rrs, ffi.string(addr_buf, 16), 16, orig:ttl(), req.pool)
end
-- All referred memory is copied within the function,
-- so it doesn't matter that lua GCs our variables.
ffi.C.kr_ranked_rrarray_add(
req.answ_selected,
rrs,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment