4

I see in the documentation ffi.C.free is something I can use to free up malloc. I am attempting to do so here:

callbacks.free_buffer = function(buffer) 
  print("free_buffer_callback") 
  ffi.C.free(buffer)
end

I get this error:

missing declaration for symbol 'free'

does this mean I have to malloc the memory myself with the FFI first? I cannot do that in this particular function (because it is a parameter in a callback). What can I do to free this buffer?

EDIT: Looks like all ffi.C functions don't work, even outside the callback function. My ffi seems to be working fine otherwise?

theman
  • 345
  • 1
  • 14
  • The error message you're posting ("missing deceleration…") doesn't look right. Please copy and paste the *exact* message you're receiving, rather than trying to paraphrase it. –  Sep 14 '14 at 01:37
  • 2
    Are other `ffi.C` functions working correctly? In callbacks? Because that message sounds like it means that luajit cannot find a C library function by that name... which strikes me as very odd. – Etan Reisner Sep 14 '14 at 01:41
  • @EtanReisner it looks like no C function are working... `ffi.C.printf("Hello %s!", "world")` gives me a missing declaration on printf. the ffi seems to be working elsewhere though? (ffi.C doesn't work properly anywhere though, even outside the callback). – theman Sep 14 '14 at 01:50

1 Answers1

6

Oops, didn't put free into my cdef! Fixed.

ffi.cdef[[
  void free(void *ptr);
]]
Farzher
  • 13,934
  • 21
  • 69
  • 100
theman
  • 345
  • 1
  • 14
  • 2
    Please accept you own answer (and consider adding some essential details -- as it is I cannot upvote) – Oliver Sep 14 '14 at 02:06