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,
-- 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)
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
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,