Re: cdata finalizer called twice

  • From: Peter Colberg <peter@xxxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 13 Nov 2014 10:14:17 -0500

On Thu, Nov 13, 2014 at 11:47:43AM +0100, Mike Pall wrote:
> This looks suspicious: 'event' is not anchored and you create a
> new cdata pointer object from it with 'event[0]', which has the
> finalizer attached.

event[0] is of type pointer, so LuaJIT implicitly makes a copy.

To be sure I replaced that code with

  local cl_event = ffi.typeof("cl_event")
  local cl_event_1 = ffi.typeof("cl_event[1]")

  function queue.enqueue_marker(queue)
    local event = cl_event_1()
    local status = C.clEnqueueMarker(queue, event)
    if status ~= C.CL_SUCCESS then return error(errors[status]) end
    return ffi.gc(cl_event(event[0]), release_event)
  end

and LuaJIT still finalizes some objects twice as described.

Thanks,
Peter

Other related posts: